[gnome-tweak-tool] Implemented search functionality for startup applications



commit 93a4fa55422908396b7ce67072848dc429d0fb3e
Author: Isaac Lenton <isaac isuniversal com>
Date:   Wed Jan 28 02:51:23 2015 +1000

    Implemented search functionality for startup applications
    
    https://bugzilla.gnome.org/show_bug.cgi?id=743586

 gtweak/tweaks/tweak_group_startup.py |   46 +++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/gtweak/tweaks/tweak_group_startup.py b/gtweak/tweaks/tweak_group_startup.py
index aef9cd0..aeebcf3 100644
--- a/gtweak/tweaks/tweak_group_startup.py
+++ b/gtweak/tweaks/tweak_group_startup.py
@@ -20,7 +20,7 @@ import os.path
 import subprocess
 import logging
 
-from gi.repository import Gtk, GLib, Gio
+from gi.repository import Gtk, Gdk, GLib, Gio
 
 from gtweak.tweakmodel import Tweak
 from gtweak.widgets import ListBoxTweakGroup, UI_BOX_SPACING
@@ -37,10 +37,20 @@ class _AppChooser(Gtk.Dialog):
         self._running = {}
         self._all = {}
 
+        self.entry = Gtk.SearchEntry(
+                placeholder_text=_("Search Applications..."))
+        self.entry.set_width_chars(30)
+
+        self.searchbar = Gtk.SearchBar()
+        self.searchbar.add(self.entry)
+        self.searchbar.props.hexpand = True
+
         lb = Gtk.ListBox()
         lb.props.margin = 5
         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())
 
         apps = Gio.app_info_get_all()
         for a in apps:
@@ -61,6 +71,7 @@ class _AppChooser(Gtk.Dialog):
         self.add_button(_("_Close"), Gtk.ResponseType.CLOSE)
         self.add_button(_("Add Application"), Gtk.ResponseType.OK)
 
+        self.get_content_area().pack_start(self.searchbar, False, False, 0)
         self.get_content_area().pack_start(sw, True, True, 0)
         self.set_modal(True)
         self.set_transient_for(main_window)
@@ -68,6 +79,8 @@ class _AppChooser(Gtk.Dialog):
 
         self.listbox = lb
 
+        self.connect("key-press-event", self._on_key_press)
+
     def _sort_apps(self, a, b, user_data):
         arun = self._running.get(a)
         brun = self._running.get(b)
@@ -113,6 +126,37 @@ class _AppChooser(Gtk.Dialog):
         #row.get_style_context().add_class('tweak-white')
         return row
 
+    def _list_filter_func(self, row, unused):
+      txt = self.entry.get_text().lower()
+      grid = row.get_child()
+      for sib in grid.get_children():
+          if type(sib) == Gtk.Label:
+              if txt in sib.get_text().lower():
+                  return True
+              return False
+      return False
+
+    def _on_key_press(self, widget, event):
+      keyname = Gdk.keyval_name(event.keyval)
+      if keyname == 'Escape':
+          if self.entry.is_focus():
+              self.searchbar.set_search_mode(False)
+              return True
+          elif self.searchbar.get_search_mode():
+              self.entry.grab_focus()
+              return True
+      elif keyname not in ['Escape', 'Up', 'Down']:
+          if not self.entry.is_focus() and self.searchbar.get_search_mode():
+              if self.entry.im_context_filter_keypress(event):
+                  self.entry.grab_focus()
+                  l = self.entry.get_text_length()
+                  self.entry.select_region(l, l)
+                  return True
+
+          return self.searchbar.handle_event(event)
+
+      return False
+
     def get_selected_app(self):
         row = self.listbox.get_selected_row()
         if row:


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