dnd: Centralize drag actor positioning code, use shellWorkspaceLaunch for workspaces
We had multiple copies of the code to position a drag actor given a particular source. Instead, just put it inside dnd.js. Second, rather than test for GenericDisplay/WellDisplayItem etc., in various places, add a new method on each source "shellWorkspaceLaunch" which both marks the item as being droppable on a workspace, and is called by the workspaces code to launch the item.
This commit is contained in:
parent
9563515e97
commit
dd1a309cb6
@ -76,6 +76,10 @@ AppDisplayItem.prototype = {
|
|||||||
// Returns a preview icon for the item.
|
// Returns a preview icon for the item.
|
||||||
_createPreviewIcon : function() {
|
_createPreviewIcon : function() {
|
||||||
return this._appInfo.create_icon_texture(GenericDisplay.PREVIEW_ICON_SIZE);
|
return this._appInfo.create_icon_texture(GenericDisplay.PREVIEW_ICON_SIZE);
|
||||||
|
},
|
||||||
|
|
||||||
|
shellWorkspaceLaunch: function() {
|
||||||
|
this.launch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -540,21 +544,12 @@ WellDisplayItem.prototype = {
|
|||||||
this.appInfo.launch();
|
this.appInfo.launch();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Draggable interface - FIXME deduplicate with GenericDisplay
|
shellWorkspaceLaunch : function() {
|
||||||
getDragActor: function(stageX, stageY) {
|
this.launch();
|
||||||
this.dragActor = this.appInfo.create_icon_texture(APP_ICON_SIZE);
|
},
|
||||||
|
|
||||||
// If the user dragged from the icon itself, then position
|
getDragActor: function(stageX, stageY) {
|
||||||
// the dragActor over the original icon. Otherwise center it
|
return this.appInfo.create_icon_texture(APP_ICON_SIZE);
|
||||||
// around the pointer
|
|
||||||
let [iconX, iconY] = this._icon.get_transformed_position();
|
|
||||||
let [iconWidth, iconHeight] = this._icon.get_transformed_size();
|
|
||||||
if (stageX > iconX && stageX <= iconX + iconWidth &&
|
|
||||||
stageY > iconY && stageY <= iconY + iconHeight)
|
|
||||||
this.dragActor.set_position(iconX, iconY);
|
|
||||||
else
|
|
||||||
this.dragActor.set_position(stageX - this.dragActor.width / 2, stageY - this.dragActor.height / 2);
|
|
||||||
return this.dragActor;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns the original icon that is being used as a source for the cloned texture
|
// Returns the original icon that is being used as a source for the cloned texture
|
||||||
|
13
js/ui/dnd.js
13
js/ui/dnd.js
@ -82,10 +82,21 @@ _Draggable.prototype = {
|
|||||||
// Drag actor does not always have to be the same as actor. For example drag actor
|
// Drag actor does not always have to be the same as actor. For example drag actor
|
||||||
// can be an image that's part of the actor. So to perform "snap back" correctly we need
|
// can be an image that's part of the actor. So to perform "snap back" correctly we need
|
||||||
// to know what was the drag actor source.
|
// to know what was the drag actor source.
|
||||||
if (this.actor._delegate.getDragActorSource)
|
if (this.actor._delegate.getDragActorSource) {
|
||||||
this._dragActorSource = this.actor._delegate.getDragActorSource();
|
this._dragActorSource = this.actor._delegate.getDragActorSource();
|
||||||
|
// If the user dragged from the source, then position
|
||||||
|
// the dragActor over it. Otherwise, center it
|
||||||
|
// around the pointer
|
||||||
|
let [sourceX, sourceY] = this._dragActorSource.get_transformed_position();
|
||||||
|
let [sourceWidth, sourceHeight] = this._dragActorSource.get_transformed_size();
|
||||||
|
if (stageX > sourceX && stageX <= sourceX + sourceWidth &&
|
||||||
|
stageY > sourceY && stageY <= sourceY + sourceHeight)
|
||||||
|
this._dragActor.set_position(sourceX, sourceY);
|
||||||
else
|
else
|
||||||
|
this._dragActor.set_position(stageX - this._dragActor.width / 2, stageY - this._dragActor.height / 2);
|
||||||
|
} else {
|
||||||
this._dragActorSource = this.actor;
|
this._dragActorSource = this.actor;
|
||||||
|
}
|
||||||
this._dragOrigParent = undefined;
|
this._dragOrigParent = undefined;
|
||||||
this._ungrabActor(actor);
|
this._ungrabActor(actor);
|
||||||
this._grabActor(this._dragActor);
|
this._grabActor(this._dragActor);
|
||||||
|
@ -83,6 +83,12 @@ DocDisplayItem.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//// Drag and Drop ////
|
||||||
|
|
||||||
|
shellWorkspaceLaunch: function() {
|
||||||
|
this.launch();
|
||||||
|
},
|
||||||
|
|
||||||
//// Private Methods ////
|
//// Private Methods ////
|
||||||
|
|
||||||
// Updates the last visited time displayed in the description text for the item.
|
// Updates the last visited time displayed in the description text for the item.
|
||||||
|
@ -126,8 +126,6 @@ GenericDisplayItem.prototype = {
|
|||||||
// It is used for updating the description text inside the details actor when
|
// It is used for updating the description text inside the details actor when
|
||||||
// the description text for the item is updated.
|
// the description text for the item is updated.
|
||||||
this._detailsDescriptions = [];
|
this._detailsDescriptions = [];
|
||||||
|
|
||||||
this.dragActor = null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//// Draggable object interface ////
|
//// Draggable object interface ////
|
||||||
@ -135,19 +133,7 @@ GenericDisplayItem.prototype = {
|
|||||||
// Returns a cloned texture of the item's icon to represent the item as it
|
// Returns a cloned texture of the item's icon to represent the item as it
|
||||||
// is being dragged.
|
// is being dragged.
|
||||||
getDragActor: function(stageX, stageY) {
|
getDragActor: function(stageX, stageY) {
|
||||||
this.dragActor = this._createIcon();
|
return this._createIcon();
|
||||||
|
|
||||||
// If the user dragged from the icon itself, then position
|
|
||||||
// the dragActor over the original icon. Otherwise center it
|
|
||||||
// around the pointer
|
|
||||||
let [iconX, iconY] = this._icon.get_transformed_position();
|
|
||||||
let [iconWidth, iconHeight] = this._icon.get_transformed_size();
|
|
||||||
if (stageX > iconX && stageX <= iconX + iconWidth &&
|
|
||||||
stageY > iconY && stageY <= iconY + iconHeight)
|
|
||||||
this.dragActor.set_position(iconX, iconY);
|
|
||||||
else
|
|
||||||
this.dragActor.set_position(stageX - this.dragActor.width / 2, stageY - this.dragActor.height / 2);
|
|
||||||
return this.dragActor;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns the item icon, a separate copy of which is used to
|
// Returns the item icon, a separate copy of which is used to
|
||||||
|
@ -11,9 +11,7 @@ const Pango = imports.gi.Pango;
|
|||||||
const Shell = imports.gi.Shell;
|
const Shell = imports.gi.Shell;
|
||||||
const Signals = imports.signals;
|
const Signals = imports.signals;
|
||||||
|
|
||||||
const AppDisplay = imports.ui.appDisplay;
|
|
||||||
const DND = imports.ui.dnd;
|
const DND = imports.ui.dnd;
|
||||||
const GenericDisplay = imports.ui.genericDisplay;
|
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
const Overview = imports.ui.overview;
|
const Overview = imports.ui.overview;
|
||||||
const Panel = imports.ui.panel;
|
const Panel = imports.ui.panel;
|
||||||
@ -855,9 +853,9 @@ Workspace.prototype = {
|
|||||||
false, // don't create workspace
|
false, // don't create workspace
|
||||||
time);
|
time);
|
||||||
return true;
|
return true;
|
||||||
} else if (source instanceof GenericDisplay.GenericDisplayItem || source instanceof AppDisplay.WellDisplayItem) {
|
} else if (source.shellWorkspaceLaunch) {
|
||||||
this._metaWorkspace.activate(time);
|
this._metaWorkspace.activate(time);
|
||||||
source.launch();
|
source.shellWorkspaceLaunch();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user