Blob Blame History Raw
From eb13e65fbd898fca6c4e8f49c278d014a492bbe5 Mon Sep 17 00:00:00 2001
From: Rui Matos <tiagomatos@gmail.com>
Date: Wed, 8 Apr 2015 11:52:36 +0200
Subject: [PATCH 4/8] shell_extensions: Add a sort func to keep the list
 ordered

---
 gtweak/tweaks/tweak_group_shell_extensions.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gtweak/tweaks/tweak_group_shell_extensions.py b/gtweak/tweaks/tweak_group_shell_extensions.py
index fce8abf..c1f41d9 100644
--- a/gtweak/tweaks/tweak_group_shell_extensions.py
+++ b/gtweak/tweaks/tweak_group_shell_extensions.py
@@ -301,16 +301,17 @@ class ShellExtensionTweakGroup(ListBoxTweakGroup):
                 logging.warning("Error listing extensions", exc_info=True)
         except:
             logging.warning("Error detecting shell", exc_info=True)
-        
+
         #add the extension installer
         extension_tweaks.append(
                 _ShellExtensionInstallerTweak(shell, size_group=sg))
-            
+
         ListBoxTweakGroup.__init__(self,
                                    _("Extensions"),
                                    *extension_tweaks)
-        
+
         self.set_header_func(self._list_header_func, None)
+        self.set_sort_func(self._list_sort_func, None)
 
     def _got_info(self, ego, resp, uuid, extension, widget):
         if uuid == extension["uuid"]:
@@ -332,6 +333,14 @@ class ShellExtensionTweakGroup(ListBoxTweakGroup):
         if before and not row.get_header():
             row.set_header (Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
 
+    def _list_sort_func(self, row1, row2, user_data):
+        if isinstance(row1.get_child(), _ShellExtensionInstallerTweak):
+            return 1
+        if isinstance(row2.get_child(), _ShellExtensionInstallerTweak):
+            return -1
+
+        return cmp(row1.name, row2.name)
+
     def _on_extension_status_changed(self, shell, uuid, state, error):
         if uuid not in self._uuids:
             self._add_extension(uuid)
-- 
2.9.3