From fdcf8facf4abcd02dddf86cc20c4309ff4267103 Mon Sep 17 00:00:00 2001 From: Vishweshwar Saran Singh Deo Date: Tue, 1 Nov 2022 15:29:07 +0530 Subject: [PATCH 1/2] [bug 559] Add menu autocomplete #559 - added a filter to the preferences menu for easy access to shortcuts - may require some tweak, on search term size and update Note: when edited in prefs it seems the Short Cut Labes in (right click) Context Menu are not updated will fix that in that bug Issue #662 --- terminatorlib/preferences.glade | 17 ++++++++++ terminatorlib/prefseditor.py | 57 ++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) 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 10339c30..602b5103 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -415,7 +415,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'] @@ -431,6 +471,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') @@ -1730,6 +1774,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`). @@ -1800,6 +1849,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) From d08cee42ee539cc3fc0bacaa1d40534588c5ca8a Mon Sep 17 00:00:00 2001 From: Vishweshwar Saran Singh Deo Date: Tue, 1 Nov 2022 18:24:15 +0530 Subject: [PATCH 2/2] [bug 559] Add menu autocomplete Follwing errors were being thrown: FAILED tests/test_prefseditor_keybindings.py::test_keybinding_successfully_reassigned_after_clearing[accel_params0] - AttributeError: 'TreeModelFilter' object has no attribute 'set' It seems earlier the Gtk.ListStore() was directly being passed in the test cases. After the changes to the Preferences to add a search filter bar we had added a filter Gtk.TreeModelFilter and for the widget we were setting it: widget.set_model(self.treemodelfilter) Now it seemed that instead of Gtk.ListStore() the object Gtk.TreeModelFilter was being received and since it did not have a "set" function the above error was thrown. I have made changes so that the Gtk.ListStore() is taken from Gtk.TreeModelFilter via get_model function and this indirection is removed. --- tests/test_prefseditor_keybindings.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_prefseditor_keybindings.py b/tests/test_prefseditor_keybindings.py index 661d8f3e..9f0586fd 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