Skip to content

Commit

Permalink
CoreWM: IconView now supports multiple identical shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Nov 19, 2016
1 parent 4f00b9f commit a89ef7a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 49 deletions.
97 changes: 50 additions & 47 deletions src/packages/default/CoreWM/iconview.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
//this.$element.setAttribute('no-selection', 'true');
this.$element.id = 'CoreWMDesktopIconView';
this.shortcutCache = [];
this.refreshTimeout = null;

GUI.Elements['gui-icon-view'].build(this.$element);

Expand Down Expand Up @@ -165,6 +166,7 @@

DesktopIconView.prototype.destroy = function() {
Utils.$remove(this.$element);
this.refreshTimeout = clearTimeout(this.refreshTimeout);
this.$element = null;
this.$iconview = null;

Expand Down Expand Up @@ -204,38 +206,43 @@
var shortcutPath = Utils.pathJoin(desktopPath, '.shortcuts.json');

this.shortcutCache = [];
VFS.scandir(desktopPath, function(error, result) {
if ( self.$iconview && !error ) {
var entries = result.map(function(iter) {
if ( iter.type === 'application' ) {
self.shortcutCache.push(iter);

this.refreshTimeout = clearTimeout(this.refreshTimeout);
this.refreshTimeout = setTimeout(function() {
VFS.scandir(desktopPath, function(error, result) {
if ( self.$iconview && !error ) {
self.$iconview.clear().add(result.map(function(iter) {
if ( iter.type === 'application' || iter.shortcut === true ) {
var niter = new VFS.File(iter);
niter.shortcut = true;

var idx = self.shortcutCache.push(niter) - 1;

var file = new VFS.File(iter);
file.__index = idx;

return {
_type: iter.type,
icon: API.getFileIcon(iter, '32x32'),
label: iter.filename,
value: file,
args: iter.args || {}
};
}

return {
_type: 'application',
_type: 'vfs',
icon: API.getFileIcon(iter, '32x32'),
label: iter.filename,
value: iter,
args: iter.args || {}
value: iter
};
}

return {
_type: 'vfs',
icon: API.getFileIcon(iter, '32x32'),
label: iter.filename,
value: iter
};

}).filter(function(iter) {
if ( iter.value.path === shortcutPath ) {
return false;
}
return true;
});

self.$iconview.clear().add(entries);
}
});
}).filter(function(iter) {
return iter.value.path !== shortcutPath;
}));
}
});
}, 50);
};

DesktopIconView.prototype._save = function(refresh) {
Expand All @@ -250,9 +257,8 @@
};

DesktopIconView.prototype.updateShortcut = function(data, values) {
var found = this.getShortcutByPath(data.path);
if ( found.item ) {
var o = this.shortcutCache[found.index];
var o = this.shortcutCache[data.__index];
if ( o.path === data.path ) {
Object.keys(values).forEach(function(k) {
o[k] = values[k];
});
Expand All @@ -267,7 +273,7 @@

this.shortcutCache.forEach(function(i, idx) {
if ( !found ) {
if ( i.path === path ) {
if ( i.type !== 'application' && i.path === path ) {
found = i;
index = idx;
}
Expand All @@ -278,28 +284,25 @@
};

DesktopIconView.prototype.addShortcut = function(data, wm, save) {
var found = this.getShortcutByPath(data.path);
if ( !found.item ) {
(['icon']).forEach(function(k) {
if ( data[k] ) {
delete data[k];
}
});

if ( data.type === 'application' ) {
data.args = data.args || {};
(['icon']).forEach(function(k) {
if ( data[k] ) {
delete data[k];
}
});

this.shortcutCache.push(data);
this._save(true);
if ( data.type === 'application' ) {
data.args = data.args || {};
}
};

DesktopIconView.prototype.removeShortcut = function(data, wm) {
var found = this.getShortcutByPath(data.path);
data.shortcut = true;
this.shortcutCache.push(data);
this._save(true);
};

if ( found.item ) {
this.shortcutCache.splice(found.index, 1);
DesktopIconView.prototype.removeShortcut = function(data) {
var o = this.shortcutCache[data.__index];
if ( o && o.path === data.path ) {
this.shortcutCache.splice(data.__index, 1);
this._save(true);
}
};
Expand Down
10 changes: 8 additions & 2 deletions src/packages/default/CoreWM/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,18 +615,24 @@
};

var _openMenu = function(data) {
var pos = {x: ev.clientX, y: ev.clientY};
OSjs.API.createMenu([{
title: OSjs.Applications.CoreWM._('LBL_COPY'),
onClick: function() {
var dst = Utils.pathJoin(OSjs.Core.getWindowManager().getSetting('desktopPath'), data.filename);
VFS.copy(data, dst, function() {});
}
/*}, {
title: OSjs.Applications.CoreWM._('Create shortcut'),
onClick: function() {
_createShortcut.call(self, data);
}
*/
}, {
title: OSjs.Applications.CoreWM._('Set as wallpaper'),
onClick: function() {
_applyWallpaper.call(self, data);
}
}], pos);
}], ev);
};

if ( item ) {
Expand Down

0 comments on commit a89ef7a

Please sign in to comment.