appDisplay: Make FolderIcon draggable

By making it a subclass of AppViewItem, it automagically inherits
the DnD code.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284
This commit is contained in:
Georges Basile Stavracas Neto 2020-05-26 18:26:52 -03:00 committed by Florian Müllner
parent d04d6e069d
commit f4ce1cf462

View File

@ -1067,7 +1067,7 @@ class AppDisplay extends BaseAppView {
} }
_onDragMotion(dragEvent) { _onDragMotion(dragEvent) {
if (!(dragEvent.source instanceof AppIcon)) if (!(dragEvent.source instanceof AppViewItem))
return DND.DragMotionResult.CONTINUE; return DND.DragMotionResult.CONTINUE;
let appIcon = dragEvent.source; let appIcon = dragEvent.source;
@ -1597,21 +1597,20 @@ var FolderIcon = GObject.registerClass({
'apps-changed': {}, 'apps-changed': {},
'name-changed': {}, 'name-changed': {},
}, },
}, class FolderIcon extends St.Button { }, class FolderIcon extends AppViewItem {
_init(id, path, parentView) { _init(id, path, parentView) {
super._init({ super._init({
style_class: 'app-well-app app-folder', style_class: 'app-well-app app-folder',
button_mask: St.ButtonMask.ONE, button_mask: St.ButtonMask.ONE,
toggle_mode: true, toggle_mode: true,
can_focus: true, can_focus: true,
}); }, global.settings.is_writable('app-picker-layout'));
this.id = id; this._id = id;
this.name = ''; this._name = '';
this._parentView = parentView; this._parentView = parentView;
this._folder = new Gio.Settings({ schema_id: 'org.gnome.desktop.app-folders.folder', this._folder = new Gio.Settings({ schema_id: 'org.gnome.desktop.app-folders.folder',
path }); path });
this._delegate = this;
this.icon = new IconGrid.BaseIcon('', { this.icon = new IconGrid.BaseIcon('', {
createIcon: this._createIcon.bind(this), createIcon: this._createIcon.bind(this),
@ -1622,20 +1621,13 @@ var FolderIcon = GObject.registerClass({
this.view = new FolderView(this._folder, id, parentView); this.view = new FolderView(this._folder, id, parentView);
this._iconIsHovering = false;
this.connect('destroy', this._onDestroy.bind(this));
this._folderChangedId = this._folder.connect( this._folderChangedId = this._folder.connect(
'changed', this._sync.bind(this)); 'changed', this._sync.bind(this));
this._sync(); this._sync();
} }
_onDestroy() { _onDestroy() {
if (this._dragMonitor) { super._onDestroy();
DND.removeDragMonitor(this._dragMonitor);
this._dragMonitor = null;
}
if (this._dialog) if (this._dialog)
this._dialog.destroy(); this._dialog.destroy();
@ -1670,29 +1662,39 @@ var FolderIcon = GObject.registerClass({
} }
_setHoveringByDnd(hovering) { _setHoveringByDnd(hovering) {
if (this._iconIsHovering == hovering) if (this._otherIconIsHovering == hovering)
return; return;
this._iconIsHovering = hovering; super._setHoveringByDnd(hovering);
if (hovering) { if (hovering)
this._dragMonitor = {
dragMotion: this._onDragMotion.bind(this),
};
DND.addDragMonitor(this._dragMonitor);
this.add_style_pseudo_class('drop'); this.add_style_pseudo_class('drop');
} else { else
DND.removeDragMonitor(this._dragMonitor);
this.remove_style_pseudo_class('drop'); this.remove_style_pseudo_class('drop');
} }
}
_onDragMotion(dragEvent) { _onDragMotion(dragEvent) {
if (!this.contains(dragEvent.targetActor) || if (!this._canAccept(dragEvent.source))
!this._canAccept(dragEvent.source))
this._setHoveringByDnd(false); this._setHoveringByDnd(false);
return DND.DragMotionResult.CONTINUE; return super._onDragMotion(dragEvent);
}
getDragActor() {
const iconParams = {
createIcon: this._createIcon.bind(this),
showLabel: this.icon.label !== null,
setSizeManually: false,
};
const icon = new IconGrid.BaseIcon(this.name, iconParams);
icon.style_class = this.style_class;
return icon;
}
getDragActorSource() {
return this;
} }
_canAccept(source) { _canAccept(source) {
@ -1709,19 +1711,10 @@ var FolderIcon = GObject.registerClass({
return true; return true;
} }
handleDragOver(source) {
if (!this._canAccept(source))
return DND.DragMotionResult.NO_DROP;
this._setHoveringByDnd(true);
return DND.DragMotionResult.MOVE_DROP;
}
acceptDrop(source) { acceptDrop(source) {
this._setHoveringByDnd(false); const accepted = super.acceptDrop(source);
if (!this._canAccept(source)) if (!accepted)
return false; return false;
this.view.addApp(source.app); this.view.addApp(source.app);
@ -1734,7 +1727,7 @@ var FolderIcon = GObject.registerClass({
if (this.name == name) if (this.name == name)
return; return;
this.name = name; this._name = name;
this.icon.label.text = this.name; this.icon.label.text = this.name;
this.emit('name-changed'); this.emit('name-changed');
} }