diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index b6f44285..57dc3620 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -3720,6 +3720,21 @@ + + + + True + True + False + filter keybindings + + + False + False + 0 + + + True True @@ -3779,6 +3794,8 @@ + + 3 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index e86766bb..671f2839 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -416,7 +416,47 @@ class PrefsEditor: selection.connect('changed', self.on_layout_item_selection_changed) ## Keybindings tab - widget = guiget('keybindingtreeview') + widget = guiget('keybindingtreeview') + kbsearch = guiget('keybindingsearchentry') + self.keybind_filter_str = "" + + #lets hide whatever we can in nested scope + def filter_visible(model, treeiter, data): + act = model[treeiter][0] + keys = data[act] if act in data else "" + desc = model[treeiter][1] + kval = model[treeiter][2] + mask = model[treeiter][3] + #so user can search for disabled keys also + if not (len(keys) and kval and mask): + act = "Disabled" + + self.keybind_filter_str = self.keybind_filter_str.lower() + searchtxt = (act + " " + keys + " " + desc).lower() + pos = searchtxt.find(self.keybind_filter_str) + if (pos >= 0): + dbg("filter find:%s in search text: %s" % + (self.keybind_filter_str, searchtxt)) + return True + + return False + + def on_search(widget, text): + MAX_SEARCH_LEN = 10 + self.keybind_filter_str = widget.get_text() + ln = len(self.keybind_filter_str) + #its a small list & we are eager for quick search, but limit + if (ln >=2 and ln < MAX_SEARCH_LEN): + dbg("filter search str: %s" % self.keybind_filter_str) + self.treemodelfilter.refilter() + + def on_search_refilter(widget): + dbg("refilter") + self.treemodelfilter.refilter() + + kbsearch.connect('key-press-event', on_search) + kbsearch.connect('backspace', on_search_refilter) + liststore = widget.get_model() liststore.set_sort_column_id(0, Gtk.SortType.ASCENDING) keybindings = self.config['keybindings'] @@ -432,6 +472,10 @@ class PrefsEditor: liststore.append([keybinding, self.keybindingnames[keybinding], keyval, mask]) + self.treemodelfilter = liststore.filter_new() + self.treemodelfilter.set_visible_func(filter_visible, keybindings) + widget.set_model(self.treemodelfilter) + ## Plugins tab # Populate the plugin list widget = guiget('pluginlist') @@ -1731,6 +1775,11 @@ class PrefsEditor: self.config.save() def on_cellrenderer_accel_edited(self, liststore, path, key, mods, _code): + inpath = path #save for debugging + trpath = Gtk.TreePath.new_from_string(inpath) + path = str(self.treemodelfilter.convert_path_to_child_path(trpath)) + dbg("convert path with filter from: %s to: %s" % + (inpath, path)) """Handle an edited keybinding""" # Ignore `Gdk.KEY_Tab` so that `Shift+Tab` is displayed as `Shift+Tab` # in `Preferences>Keybindings` and NOT `Left Tab` (see `Gdk.KEY_ISO_Left_Tab`). @@ -1801,6 +1850,12 @@ class PrefsEditor: self.config.save() def on_cellrenderer_accel_cleared(self, liststore, path): + inpath = path #save for debugging + trpath = Gtk.TreePath.new_from_string(inpath) + path = str(self.treemodelfilter.convert_path_to_child_path(trpath)) + dbg("convert path with filter from: %s to: %s" % + (inpath, path)) + """Handle the clearing of a keybinding accelerator""" celliter = liststore.get_iter_from_string(path) liststore.set(celliter, 2, 0, 3, 0) diff --git a/tests/test_prefseditor_keybindings.py b/tests/test_prefseditor_keybindings.py index 379aa372..56ee3b74 100644 --- a/tests/test_prefseditor_keybindings.py +++ b/tests/test_prefseditor_keybindings.py @@ -103,7 +103,8 @@ def test_message_dialog_is_shown_on_duplicate_accel_assignment( ) widget = prefs_editor.builder.get_object("keybindingtreeview") - liststore = widget.get_model() + treemodelfilter = widget.get_model() + liststore = treemodelfilter.get_model() # Replace default accelerator with a test one prefs_editor.on_cellrenderer_accel_edited( @@ -150,7 +151,8 @@ def test_duplicate_accels_not_possible_to_set(accel_params): ) widget = prefs_editor.builder.get_object("keybindingtreeview") - liststore = widget.get_model() + treemodelfilter = widget.get_model() + liststore = treemodelfilter.get_model() binding = liststore.get_value(liststore.get_iter(path), 0) all_default_accelerators = { @@ -231,7 +233,8 @@ def test_keybinding_edit_produce_expected_accels( prefs_editor = prefseditor.PrefsEditor(term=term) widget = prefs_editor.builder.get_object("keybindingtreeview") - liststore = widget.get_model() + treemodelfilter = widget.get_model() + liststore = treemodelfilter.get_model() path = 0 # Edit the first listed key binding in `Preferences>Keybindings` key, mods, hardware_keycode = input_key_params @@ -277,7 +280,8 @@ def test_keybinding_successfully_reassigned_after_clearing(accel_params): prefs_editor = prefseditor.PrefsEditor(term=term) widget = prefs_editor.builder.get_object("keybindingtreeview") - liststore = widget.get_model() + treemodelfilter = widget.get_model() + liststore = treemodelfilter.get_model() path, key, mods, hardware_keycode = accel_params # Assign a key binding