[gnome-shell-extensions/wip/lefevreremy/places-unmount] places-menu: Support unmounting ejectable places



commit eb425ac8a2faa56c974c6bae91ad6d67db46d38d
Author: Rémy Lefevre <lefevreremy gmail com>
Date:   Sat Feb 6 15:06:05 2016 +0100

    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

 extensions/places-menu/extension.js    | 10 ++++++++-
 extensions/places-menu/placeDisplay.js | 40 ++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)
---
diff --git a/extensions/places-menu/extension.js b/extensions/places-menu/extension.js
index 767fb87..f7c11c6 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 ba316bf..796619c 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);
     }
 });
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]