allView, folderView: Implement moving icons
This makes use of the new BaseAppIcon.moveItem() API. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603
This commit is contained in:
parent
4056c56800
commit
6e3696baad
@ -515,6 +515,37 @@ var AllView = class AllView extends BaseAppView {
|
|||||||
return newApps;
|
return newApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moveItem(item, position) {
|
||||||
|
let visibleApps = this._allItems.filter(icon => icon.actor.visible);
|
||||||
|
let oldPosition = visibleApps.indexOf(item);
|
||||||
|
|
||||||
|
if (oldPosition == position)
|
||||||
|
return;
|
||||||
|
|
||||||
|
super.moveItem(item, position);
|
||||||
|
|
||||||
|
if (position > oldPosition)
|
||||||
|
position -= 1;
|
||||||
|
|
||||||
|
// Update all custom icon positions to match what's visible
|
||||||
|
visibleApps = this._allItems.filter(icon => icon.actor.visible);
|
||||||
|
let iconsData = this._gridSettings.get_value('icons-data').deep_unpack();
|
||||||
|
visibleApps.forEach((icon, index) => {
|
||||||
|
if (!iconsData[icon.id] || icon.id == item.id)
|
||||||
|
return;
|
||||||
|
|
||||||
|
iconsData[icon.id] = new GLib.Variant('a{sv}', {
|
||||||
|
'position': GLib.Variant.new_uint32(index),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
iconsData[item.id] = new GLib.Variant('a{sv}', {
|
||||||
|
'position': GLib.Variant.new_uint32(position),
|
||||||
|
});
|
||||||
|
this._gridSettings.set_value('icons-data',
|
||||||
|
new GLib.Variant('a{sv}', iconsData));
|
||||||
|
}
|
||||||
|
|
||||||
_loadGrid() {
|
_loadGrid() {
|
||||||
super._loadGrid();
|
super._loadGrid();
|
||||||
this._refilterApps();
|
this._refilterApps();
|
||||||
@ -811,45 +842,60 @@ var AllView = class AllView extends BaseAppView {
|
|||||||
if (appIcon.view == this)
|
if (appIcon.view == this)
|
||||||
this._handleDragOvershoot(dragEvent);
|
this._handleDragOvershoot(dragEvent);
|
||||||
|
|
||||||
|
if (dragEvent.targetActor != this._grid)
|
||||||
|
this.removeNudges();
|
||||||
|
|
||||||
return DND.DragMotionResult.CONTINUE;
|
return DND.DragMotionResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDragEnd() {
|
_onDragEnd() {
|
||||||
|
this.removeNudges();
|
||||||
|
|
||||||
if (this._dragMonitor) {
|
if (this._dragMonitor) {
|
||||||
DND.removeDragMonitor(this._dragMonitor);
|
DND.removeDragMonitor(this._dragMonitor);
|
||||||
this._dragMonitor = null;
|
this._dragMonitor = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_canDropAt(source) {
|
|
||||||
if (!(source instanceof AppIcon))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!global.settings.is_writable('favorite-apps'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!(source.view instanceof FolderView))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleDragOver(source, actor, x, y, time) {
|
handleDragOver(source, actor, x, y, time) {
|
||||||
if (!this._canDropAt(source))
|
let sourceIndex = -1;
|
||||||
return DND.DragMotionResult.NO_DROP;
|
if (source.view == this) {
|
||||||
|
let visibleItems = this._allItems.filter(item => item.actor.visible);
|
||||||
|
sourceIndex = visibleItems.indexOf(source);
|
||||||
|
}
|
||||||
|
|
||||||
return DND.DragMotionResult.MOVE_DROP;
|
let [index, dragLocation] = this.canDropAt(x, y);
|
||||||
|
|
||||||
|
this.removeNudges();
|
||||||
|
if (source.view && source.view != this)
|
||||||
|
source.view.removeNudges();
|
||||||
|
|
||||||
|
if (index != -1) {
|
||||||
|
if (sourceIndex == -1 || (index != sourceIndex && index != sourceIndex + 1))
|
||||||
|
this.nudgeItemsAtIndex(index, dragLocation);
|
||||||
|
|
||||||
|
return DND.DragMotionResult.MOVE_DROP;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DND.DragMotionResult.NO_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
acceptDrop(source, actor, x, y, time) {
|
acceptDrop(source, actor, x, y, time) {
|
||||||
if (!this._canDropAt(source))
|
let [index, dragLocation] = this.canDropAt(x, y);
|
||||||
|
|
||||||
|
if (index == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
source.view.removeApp(source.app);
|
if (source.view instanceof FolderView) {
|
||||||
|
source.view.removeApp(source.app);
|
||||||
|
source = this._items[source.id];
|
||||||
|
|
||||||
if (this._currentPopup)
|
if (this._currentPopup)
|
||||||
this._currentPopup.popdown();
|
this._currentPopup.popdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.moveItem(source, index);
|
||||||
|
this.removeNudges();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1228,6 +1274,7 @@ var FolderView = class FolderView extends BaseAppView {
|
|||||||
let scrollableContainer = new St.BoxLayout({ vertical: true, reactive: true });
|
let scrollableContainer = new St.BoxLayout({ vertical: true, reactive: true });
|
||||||
scrollableContainer.add_actor(this._grid);
|
scrollableContainer.add_actor(this._grid);
|
||||||
this.actor.add_actor(scrollableContainer);
|
this.actor.add_actor(scrollableContainer);
|
||||||
|
this._grid._delegate = this;
|
||||||
|
|
||||||
let action = new Clutter.PanAction({ interpolate: true });
|
let action = new Clutter.PanAction({ interpolate: true });
|
||||||
action.connect('pan', this._onPan.bind(this));
|
action.connect('pan', this._onPan.bind(this));
|
||||||
@ -1297,6 +1344,29 @@ var FolderView = class FolderView extends BaseAppView {
|
|||||||
this.actor.set_height(this.usedHeight());
|
this.actor.set_height(this.usedHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleDragOver(source, actor, x, y, time) {
|
||||||
|
let [index, dragLocation] = this.canDropAt(x, y);
|
||||||
|
let sourceIndex = this._allItems.indexOf(source);
|
||||||
|
|
||||||
|
this._parentView.removeNudges();
|
||||||
|
this.removeNudges();
|
||||||
|
if (index != -1 && index != sourceIndex && index != sourceIndex + 1)
|
||||||
|
this.nudgeItemsAtIndex(index, dragLocation);
|
||||||
|
|
||||||
|
return DND.DragMotionResult.MOVE_DROP;
|
||||||
|
}
|
||||||
|
|
||||||
|
acceptDrop(source, actor, x, y, time) {
|
||||||
|
let [index, dragLocation] = this.canDropAt(x, y);
|
||||||
|
let success = index != -1;
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
this.moveItem(source, index);
|
||||||
|
|
||||||
|
this.removeNudges();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
_getPageAvailableSize() {
|
_getPageAvailableSize() {
|
||||||
let pageBox = new Clutter.ActorBox();
|
let pageBox = new Clutter.ActorBox();
|
||||||
pageBox.x1 = pageBox.y1 = 0;
|
pageBox.x1 = pageBox.y1 = 0;
|
||||||
@ -1378,6 +1448,13 @@ var FolderView = class FolderView extends BaseAppView {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moveItem(item, newPosition) {
|
||||||
|
super.moveItem(item, newPosition);
|
||||||
|
|
||||||
|
let appIds = this._allItems.map(icon => icon.id);
|
||||||
|
this._folder.set_strv('apps', appIds);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var FolderIcon = class FolderIcon {
|
var FolderIcon = class FolderIcon {
|
||||||
|
Loading…
Reference in New Issue
Block a user