[gnome-tweak-tool/gnome-3-16] AppChooser: Desensitize ‘Add’ button when no app is selected



commit 9705f52184db75fb9433cd7695000b4e106fdbd2
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Wed Apr 1 18:37:49 2015 +0100

    AppChooser: Desensitize ‘Add’ button when no app is selected
    
    The ‘Add Application’ button shouldn't be sensitive if there is no
    application currently selected. This is complicated be the fact that
    when Gtk.Listbox filters the list it does not clear the selection so if
    there is a selected row we need to check if it is mapped before changing
    the state of the ‘Add Application’ button.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747983

 gtweak/tweaks/tweak_group_startup.py |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/gtweak/tweaks/tweak_group_startup.py b/gtweak/tweaks/tweak_group_startup.py
index ef74892..e897374 100644
--- a/gtweak/tweaks/tweak_group_startup.py
+++ b/gtweak/tweaks/tweak_group_startup.py
@@ -50,7 +50,8 @@ class _AppChooser(Gtk.Dialog):
         lb.set_sort_func(self._sort_apps, None)
         lb.set_header_func(_list_header_func, None)
         lb.set_filter_func(self._list_filter_func, None)
-        self.entry.connect("search-changed", lambda e: lb.invalidate_filter())
+        self.entry.connect("search-changed", self._on_search_entry_changed)
+        lb.connect("row-selected", self._on_row_selected)
 
         apps = Gio.app_info_get_all()
         for a in apps:
@@ -136,6 +137,20 @@ class _AppChooser(Gtk.Dialog):
                   return True
       return False
 
+    def _on_search_entry_changed(self, editable):
+        self.listbox.invalidate_filter()
+        selected = self.listbox.get_selected_row()
+        if selected and selected.get_mapped():
+            self.set_response_sensitive(Gtk.ResponseType.OK, True)
+        else:
+            self.set_response_sensitive(Gtk.ResponseType.OK, False)
+
+    def _on_row_selected(self, box, row):
+        if row and row.get_mapped():
+            self.set_response_sensitive(Gtk.ResponseType.OK, True)
+        else:
+            self.set_response_sensitive(Gtk.ResponseType.OK, False)
+
     def _on_key_press(self, widget, event):
       keyname = Gdk.keyval_name(event.keyval)
       if keyname == 'Escape':


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