diff --git a/extensions/places-menu/extension.js b/extensions/places-menu/extension.js index 767fb87802d492306652991fba6643241a2877a7..f7c11c65f4eb272a56d3259d11a367ad10514746 100644 --- a/extensions/places-menu/extension.js +++ b/extensions/places-menu/extension.js @@ -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)); }, diff --git a/extensions/places-menu/placeDisplay.js b/extensions/places-menu/placeDisplay.js index ba316bff8c1c77f750779f3239f54d8d99ffd33f..796619c0ab92363afd056ad47415912495017622 100644 --- a/extensions/places-menu/placeDisplay.js +++ b/extensions/places-menu/placeDisplay.js @@ -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); } });