[gnome-shell-extensions/wip/lefevreremy/places-unmount] places-menu: enable to unmount places



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

    places-menu: enable to unmount places
    
    This patch enable to unmount removable devices and network shares
    from the places menu by checking for each menu entry if the entry
    is removable. If yes, an eject button is placed next to the entry
    label and bind to an eject procedure.
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/17

 extensions/places-menu/extension.js    | 12 ++++++++--
 extensions/places-menu/placeDisplay.js | 40 ++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/extensions/places-menu/extension.js b/extensions/places-menu/extension.js
index 767fb87..28db600 100644
--- a/extensions/places-menu/extension.js
+++ b/extensions/places-menu/extension.js
@@ -33,10 +33,18 @@ const PlaceMenuItem = new Lang.Class({
 
         this._icon = new St.Icon({ gicon: info.icon,
                                    icon_size: PLACE_ICON_SIZE });
-       this.actor.add_child(this._icon);
+        this.actor.add(this._icon);
 
         this._label = new St.Label({ text: info.name });
-        this.actor.add_child(this._label);
+        this.actor.add(this._label, { expand: true });
+
+        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(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..5af6aea 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 true;
+    },
+
+    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]