places-menu: Support unmounting ejectable places

Being able to unmount places that can be ejected directly from the
menu is convenient and consistent with Nautilus, so add an eject
button to items that are removable.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/17
This commit is contained in:
Rémy Lefevre
2016-02-06 15:06:05 +01:00
committed by Florian Müllner
parent 724249dd29
commit eb425ac8a2
2 changed files with 49 additions and 1 deletions

View File

@@ -35,9 +35,17 @@ const PlaceMenuItem = new Lang.Class({
icon_size: PLACE_ICON_SIZE });
this.actor.add_child(this._icon);
this._label = new St.Label({ text: info.name });
this._label = new St.Label({ text: info.name, x_expand: true });
this.actor.add_child(this._label);
if (info.isRemovable()) {
this._ejectIcon = new St.Icon({ icon_name: 'media-eject-symbolic',
style_class: 'popup-menu-icon ' });
this._ejectButton = new St.Button({ child: this._ejectIcon });
this._ejectButton.connect('clicked', Lang.bind(info, info.eject));
this.actor.add_child(this._ejectButton);
}
this._changedId = info.connect('changed',
Lang.bind(this, this._propertiesChanged));
},

View File

@@ -180,6 +180,46 @@ const PlaceDeviceInfo = new Lang.Class({
getIcon: function() {
return this._mount.get_symbolic_icon();
},
isRemovable: function() {
return this._mount.can_eject();
},
eject: function() {
let mountOp = new ShellMountOperation.ShellMountOperation(this._mount);
if (this._mount.can_eject())
this._mount.eject_with_operation(Gio.MountUnmountFlags.NONE,
mountOp.mountOp,
null, // Gio.Cancellable
Lang.bind(this, this._ejectFinish));
else
this._mount.unmount_with_operation(Gio.MountUnmountFlags.NONE,
mountOp.mountOp,
null, // Gio.Cancellable
Lang.bind(this, this._unmountFinish));
},
_ejectFinish: function(mount, result) {
try {
mount.eject_with_operation_finish(result);
} catch(e) {
this._reportFailure(e);
}
},
_unmountFinish: function(mount, result) {
try {
mount.unmount_with_operation_finish(result);
} catch(e) {
this._reportFailure(e);
}
},
_reportFailure: function(exception) {
let msg = _("Ejecting drive '%s' failed:").format(this._mount.get_name());
Main.notifyError(msg, exception.message);
}
});