[gnome-shell-extensions] places: Include DESKTOP when desktop icons are enabled



commit 547163e8952229adcc2e620d685d1df92d0b3919
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Sep 4 14:29:16 2015 +0200

    places: Include DESKTOP when desktop icons are enabled
    
    The user explicitly enabling desktop icons is a pretty good hint
    that she intends to use the Desktop folder, so be consistent with
    GTK+ and nautilus and include it when the corresponding setting
    is true.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754578

 extensions/places-menu/placeDisplay.js |   76 +++++++++++++++++++++-----------
 1 files changed, 50 insertions(+), 26 deletions(-)
---
diff --git a/extensions/places-menu/placeDisplay.js b/extensions/places-menu/placeDisplay.js
index f7a2567..bf220c6 100644
--- a/extensions/places-menu/placeDisplay.js
+++ b/extensions/places-menu/placeDisplay.js
@@ -18,6 +18,8 @@ const Gettext = imports.gettext.domain('gnome-shell-extensions');
 const _ = Gettext.gettext;
 const N_ = function(x) { return x; }
 
+const BACKGROUND_SCHEMA = 'org.gnome.desktop.background';
+
 const Hostname1Iface = '<node> \
 <interface name="org.freedesktop.hostname1"> \
 <property name="PrettyHostname" type="s" access="read" /> \
@@ -193,32 +195,11 @@ const PlacesManager = new Lang.Class({
             network: [],
         };
 
-        let homePath = GLib.get_home_dir();
-
-        this._places.special.push(new PlaceInfo('special',
-                                                Gio.File.new_for_path(homePath),
-                                                _("Home")));
-
-        let specials = [];
-        for (let i = 0; i < DEFAULT_DIRECTORIES.length; i++) {
-            let specialPath = GLib.get_user_special_dir(DEFAULT_DIRECTORIES[i]);
-            if (specialPath == null || specialPath == homePath)
-                continue;
-
-            let file = Gio.File.new_for_path(specialPath), info;
-            try {
-                info = new PlaceInfo('special', file);
-            } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND)) {
-                continue;
-            }
-
-            specials.push(info);
-        }
-
-        specials.sort(function(a, b) {
-            return GLib.utf8_collate(a.name, b.name);
-        });
-        this._places.special = this._places.special.concat(specials);
+        this._settings = new Gio.Settings({ schema_id: BACKGROUND_SCHEMA });
+        this._showDesktopIconsChangedId =
+            this._settings.connect('changed::show-desktop-icons',
+                                   Lang.bind(this, this._updateSpecials));
+        this._updateSpecials();
 
         /*
         * Show devices, code more or less ported from nautilus-places-sidebar.c
@@ -262,6 +243,10 @@ const PlacesManager = new Lang.Class({
     },
 
     destroy: function() {
+        if (this._settings)
+            this._settings.disconnect(this._showDesktopIconsChangedId);
+        this._settings = null;
+
         for (let i = 0; i < this._volumeMonitorSignals.length; i++)
             this._volumeMonitor.disconnect(this._volumeMonitorSignals[i]);
 
@@ -271,6 +256,45 @@ const PlacesManager = new Lang.Class({
             Mainloop.source_remove(this._bookmarkTimeoutId);
     },
 
+    _updateSpecials: function() {
+        this._places.special.forEach(function (p) { p.destroy(); });
+        this._places.special = [];
+
+        let homePath = GLib.get_home_dir();
+
+        this._places.special.push(new PlaceInfo('special',
+                                                Gio.File.new_for_path(homePath),
+                                                _("Home")));
+
+        let specials = [];
+        let dirs = DEFAULT_DIRECTORIES.slice();
+
+        if (this._settings.get_boolean('show-desktop-icons'))
+            dirs.push(GLib.UserDirectory.DIRECTORY_DESKTOP);
+
+        for (let i = 0; i < dirs.length; i++) {
+            let specialPath = GLib.get_user_special_dir(dirs[i]);
+            if (specialPath == null || specialPath == homePath)
+                continue;
+
+            let file = Gio.File.new_for_path(specialPath), info;
+            try {
+                info = new PlaceInfo('special', file);
+            } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND)) {
+                continue;
+            }
+
+            specials.push(info);
+        }
+
+        specials.sort(function(a, b) {
+            return GLib.utf8_collate(a.name, b.name);
+        });
+        this._places.special = this._places.special.concat(specials);
+
+        this.emit('special-updated');
+    },
+
     _updateMounts: function() {
         let networkMounts = [];
         let networkVolumes = [];


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