[gnome-shell-extensions/wip/fmuellner/alacarte-compat: 2/4] apps-menu: Reload on tree changes



commit 59e08dccff664cff1cbf86fc8e002c5e0e533cad
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Oct 13 01:43:20 2017 +0200

    apps-menu: Reload on tree changes
    
    Now that we respect the sort order defined in the .menu file, make
    sure to reload the menu on those changes as well, not just when
    the installed apps themselves change.
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/27

 extensions/apps-menu/extension.js | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js
index dba31e7..600eda3 100644
--- a/extensions/apps-menu/extension.js
+++ b/extensions/apps-menu/extension.js
@@ -466,18 +466,25 @@ const ApplicationsButton = new Lang.Class({
             });
         });
 
+        this._tree = new GMenu.Tree({ menu_basename: 'applications.menu' });
+        this._treeChangedId = this._tree.connect('changed',
+                                                 Lang.bind(this, this._onTreeChanged));
+
         this._applicationsButtons = new Map();
         this.reloadFlag = false;
         this._createLayout();
         this._display();
-        this._installedChangedId = appSys.connect('installed-changed', Lang.bind(this, function() {
-            if (this.menu.isOpen) {
-                this._redisplay();
-                this.mainBox.show();
-            } else {
-                this.reloadFlag = true;
-            }
-        }));
+        this._installedChangedId = appSys.connect('installed-changed',
+                                                  Lang.bind(this, this._onTreeChanged));
+    },
+
+    _onTreeChanged: function() {
+        if (this.menu.isOpen) {
+            this._redisplay();
+            this.mainBox.show();
+        } else {
+            this.reloadFlag = true;
+        }
     },
 
     get hotCorner() {
@@ -495,6 +502,8 @@ const ApplicationsButton = new Lang.Class({
         Main.overview.disconnect(this._showingId);
         Main.overview.disconnect(this._hidingId);
         appSys.disconnect(this._installedChangedId);
+        this._tree.disconnect(this._treeChangedId);
+        this._tree = null;
 
         Main.wm.setCustomKeybindingHandler('panel-main-menu',
                                            Shell.ActionMode.NORMAL |
@@ -675,9 +684,8 @@ const ApplicationsButton = new Lang.Class({
 
         //Load categories
         this.applicationsByCategory = {};
-        let tree = new GMenu.Tree({ menu_basename: 'applications.menu' });
-        tree.load_sync();
-        let root = tree.get_root_directory();
+        this._tree.load_sync();
+        let root = this._tree.get_root_directory();
         let categoryMenuItem = new CategoryMenuItem(this, null);
         this.categoriesBox.add_actor(categoryMenuItem.actor);
         let iter = root.iter();


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