places: Implement drag&drop for overview
Add drag and drop. We need to be able to recreate the icon texture, so instead of passing it directly into PlaceDisplay, pass a factory function which knows how to create a new texture.
This commit is contained in:
parent
9f5a5ad635
commit
9dff05a394
@ -10,32 +10,61 @@ const Lang = imports.lang;
|
|||||||
const Mainloop = imports.mainloop;
|
const Mainloop = imports.mainloop;
|
||||||
const Signals = imports.signals;
|
const Signals = imports.signals;
|
||||||
|
|
||||||
|
const DND = imports.ui.dnd;
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
const GenericDisplay = imports.ui.genericDisplay;
|
const GenericDisplay = imports.ui.genericDisplay;
|
||||||
|
|
||||||
const PLACES_VSPACING = 8;
|
const PLACES_VSPACING = 8;
|
||||||
const PLACES_ICON_SIZE = 16;
|
const PLACES_ICON_SIZE = 16;
|
||||||
|
|
||||||
function PlaceDisplay(name, icon, onActivate) {
|
/**
|
||||||
this._init(name, icon, onActivate);
|
* An entry in the places menu.
|
||||||
|
* @name: String title
|
||||||
|
* @iconFactory: A JavaScript callback which will create an icon texture
|
||||||
|
* @onActivate: A JavaScript callback to launch the entry
|
||||||
|
*/
|
||||||
|
function PlaceDisplay(name, iconFactory, onActivate) {
|
||||||
|
this._init(name, iconFactory, onActivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceDisplay.prototype = {
|
PlaceDisplay.prototype = {
|
||||||
_init : function(name, iconTexture, onActivate) {
|
_init : function(name, iconFactory, onActivate) {
|
||||||
this.actor = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
|
this.actor = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
|
||||||
reactive: true,
|
reactive: true,
|
||||||
spacing: 4 });
|
spacing: 4 });
|
||||||
this.actor.connect('button-press-event', Lang.bind(this, function (b, e) {
|
this.actor.connect('button-release-event', Lang.bind(this, function (b, e) {
|
||||||
onActivate(this);
|
onActivate(this);
|
||||||
|
Main.overview.hide();
|
||||||
}));
|
}));
|
||||||
let text = new Clutter.Text({ font_name: "Sans 14px",
|
let text = new Clutter.Text({ font_name: "Sans 14px",
|
||||||
ellipsize: Pango.EllipsizeMode.END,
|
ellipsize: Pango.EllipsizeMode.END,
|
||||||
color: GenericDisplay.ITEM_DISPLAY_NAME_COLOR,
|
color: GenericDisplay.ITEM_DISPLAY_NAME_COLOR,
|
||||||
text: name });
|
text: name });
|
||||||
let iconBox = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
let iconBox = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
||||||
iconBox.append(iconTexture, Big.BoxPackFlags.NONE);
|
this._icon = iconFactory();
|
||||||
|
iconBox.append(this._icon, Big.BoxPackFlags.NONE);
|
||||||
this.actor.append(iconBox, Big.BoxPackFlags.NONE);
|
this.actor.append(iconBox, Big.BoxPackFlags.NONE);
|
||||||
this.actor.append(text, Big.BoxPackFlags.EXPAND);
|
this.actor.append(text, Big.BoxPackFlags.EXPAND);
|
||||||
|
|
||||||
|
this._iconFactory = iconFactory;
|
||||||
|
this._onActivate = onActivate;
|
||||||
|
|
||||||
|
this.actor._delegate = this;
|
||||||
|
let draggable = DND.makeDraggable(this.actor);
|
||||||
|
},
|
||||||
|
|
||||||
|
getDragActorSource: function() {
|
||||||
|
return this._icon;
|
||||||
|
},
|
||||||
|
|
||||||
|
getDragActor: function(stageX, stageY) {
|
||||||
|
return this._iconFactory();
|
||||||
|
},
|
||||||
|
|
||||||
|
//// Drag and drop methods ////
|
||||||
|
|
||||||
|
shellWorkspaceLaunch : function() {
|
||||||
|
this._onActivate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Signals.addSignalMethods(PlaceDisplay.prototype);
|
Signals.addSignalMethods(PlaceDisplay.prototype);
|
||||||
@ -59,11 +88,13 @@ Places.prototype = {
|
|||||||
let homeUri = homeFile.get_uri();
|
let homeUri = homeFile.get_uri();
|
||||||
let homeLabel = Shell.util_get_label_for_uri (homeUri);
|
let homeLabel = Shell.util_get_label_for_uri (homeUri);
|
||||||
let homeIcon = Shell.util_get_icon_for_uri (homeUri);
|
let homeIcon = Shell.util_get_icon_for_uri (homeUri);
|
||||||
let homeTexture = Shell.TextureCache.get_default().load_gicon(homeIcon, PLACES_ICON_SIZE);
|
let home = new PlaceDisplay(homeLabel,
|
||||||
let home = new PlaceDisplay(homeLabel, homeTexture, Lang.bind(this, function() {
|
function() {
|
||||||
Main.overview.hide();
|
return Shell.TextureCache.get_default().load_gicon(homeIcon, PLACES_ICON_SIZE);
|
||||||
Gio.app_info_launch_default_for_uri(homeUri, Main.createAppLaunchContext());
|
},
|
||||||
}));
|
function() {
|
||||||
|
Gio.app_info_launch_default_for_uri(homeUri, Main.createAppLaunchContext());
|
||||||
|
});
|
||||||
|
|
||||||
this._menuBox.append(home.actor, Big.BoxPackFlags.NONE);
|
this._menuBox.append(home.actor, Big.BoxPackFlags.NONE);
|
||||||
|
|
||||||
@ -79,19 +110,23 @@ Places.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (networkApp != null) {
|
if (networkApp != null) {
|
||||||
let networkIcon = networkApp.create_icon_texture(PLACES_ICON_SIZE);
|
let network = new PlaceDisplay(networkApp.get_name(),
|
||||||
let network = new PlaceDisplay(networkApp.get_name(), networkIcon, Lang.bind(this, function () {
|
function() {
|
||||||
Main.overview.hide();
|
return networkApp.create_icon_texture(PLACES_ICON_SIZE);
|
||||||
networkApp.launch();
|
},
|
||||||
}));
|
function () {
|
||||||
|
networkApp.launch();
|
||||||
|
});
|
||||||
this._menuBox.append(network.actor, Big.BoxPackFlags.NONE);
|
this._menuBox.append(network.actor, Big.BoxPackFlags.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
let connectIcon = Shell.TextureCache.get_default().load_icon_name("applications-internet", PLACES_ICON_SIZE);
|
let connect = new PlaceDisplay('Connect to...',
|
||||||
let connect = new PlaceDisplay('Connect to...', connectIcon, Lang.bind(this, function () {
|
function () {
|
||||||
Main.overview.hide();
|
return Shell.TextureCache.get_default().load_icon_name("applications-internet", PLACES_ICON_SIZE);
|
||||||
new Shell.Process({ args: ['nautilus-connect-server'] }).run();
|
},
|
||||||
}));
|
function () {
|
||||||
|
new Shell.Process({ args: ['nautilus-connect-server'] }).run();
|
||||||
|
});
|
||||||
this._menuBox.append(connect.actor, Big.BoxPackFlags.NONE);
|
this._menuBox.append(connect.actor, Big.BoxPackFlags.NONE);
|
||||||
|
|
||||||
this._bookmarksPath = GLib.build_filenamev([GLib.get_home_dir(), ".gtk-bookmarks"]);
|
this._bookmarksPath = GLib.build_filenamev([GLib.get_home_dir(), ".gtk-bookmarks"]);
|
||||||
@ -149,11 +184,14 @@ Places.prototype = {
|
|||||||
if (label == null)
|
if (label == null)
|
||||||
continue;
|
continue;
|
||||||
let icon = Shell.util_get_icon_for_uri(bookmark);
|
let icon = Shell.util_get_icon_for_uri(bookmark);
|
||||||
let iconTexture = Shell.TextureCache.get_default().load_gicon(icon, PLACES_ICON_SIZE);
|
|
||||||
let item = new PlaceDisplay(label, iconTexture, Lang.bind(this, function() {
|
let item = new PlaceDisplay(label,
|
||||||
Main.overview.hide();
|
function() {
|
||||||
Gio.app_info_launch_default_for_uri(bookmark, Main.createAppLaunchContext());
|
return Shell.TextureCache.get_default().load_gicon(icon, PLACES_ICON_SIZE);
|
||||||
}));
|
},
|
||||||
|
function() {
|
||||||
|
Gio.app_info_launch_default_for_uri(bookmark, Main.createAppLaunchContext());
|
||||||
|
});
|
||||||
this._dirsBox.append(item.actor, Big.BoxPackFlags.NONE);
|
this._dirsBox.append(item.actor, Big.BoxPackFlags.NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user