Skip to content

Commit 1d5351e

Browse files
authored
Merge pull request #665 from vssdeo/559-Add-menu-autocomplete
[bug 559] Add menu autocomplete #559
2 parents a6b78bb + d08cee4 commit 1d5351e

3 files changed

Lines changed: 81 additions & 5 deletions

File tree

‎terminatorlib/preferences.glade‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3720,6 +3720,21 @@
37203720
</packing>
37213721
</child>
37223722
<child>
3723+
<object class="GtkVBox" id="vbox124">
3724+
<child>
3725+
<object class="GtkEntry" id="keybindingsearchentry">
3726+
<property name="visible">True</property>
3727+
<property name="can-focus">True</property>
3728+
<property name="has-focus">False</property>
3729+
<property name="placeholder_text">filter keybindings</property>
3730+
</object>
3731+
<packing>
3732+
<property name="expand">False</property>
3733+
<property name="fill">False</property>
3734+
<property name="position">0</property>
3735+
</packing>
3736+
</child>
3737+
<child>
37233738
<object class="GtkScrolledWindow" id="scrolledwindow1">
37243739
<property name="visible">True</property>
37253740
<property name="can-focus">True</property>
@@ -3779,6 +3794,8 @@
37793794
</object>
37803795
</child>
37813796
</object>
3797+
</child>
3798+
</object>
37823799
<packing>
37833800
<property name="position">3</property>
37843801
</packing>

‎terminatorlib/prefseditor.py‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,47 @@ def set_values(self):
416416
selection.connect('changed', self.on_layout_item_selection_changed)
417417

418418
## Keybindings tab
419-
widget = guiget('keybindingtreeview')
419+
widget = guiget('keybindingtreeview')
420+
kbsearch = guiget('keybindingsearchentry')
421+
self.keybind_filter_str = ""
422+
423+
#lets hide whatever we can in nested scope
424+
def filter_visible(model, treeiter, data):
425+
act = model[treeiter][0]
426+
keys = data[act] if act in data else ""
427+
desc = model[treeiter][1]
428+
kval = model[treeiter][2]
429+
mask = model[treeiter][3]
430+
#so user can search for disabled keys also
431+
if not (len(keys) and kval and mask):
432+
act = "Disabled"
433+
434+
self.keybind_filter_str = self.keybind_filter_str.lower()
435+
searchtxt = (act + " " + keys + " " + desc).lower()
436+
pos = searchtxt.find(self.keybind_filter_str)
437+
if (pos >= 0):
438+
dbg("filter find:%s in search text: %s" %
439+
(self.keybind_filter_str, searchtxt))
440+
return True
441+
442+
return False
443+
444+
def on_search(widget, text):
445+
MAX_SEARCH_LEN = 10
446+
self.keybind_filter_str = widget.get_text()
447+
ln = len(self.keybind_filter_str)
448+
#its a small list & we are eager for quick search, but limit
449+
if (ln >=2 and ln < MAX_SEARCH_LEN):
450+
dbg("filter search str: %s" % self.keybind_filter_str)
451+
self.treemodelfilter.refilter()
452+
453+
def on_search_refilter(widget):
454+
dbg("refilter")
455+
self.treemodelfilter.refilter()
456+
457+
kbsearch.connect('key-press-event', on_search)
458+
kbsearch.connect('backspace', on_search_refilter)
459+
420460
liststore = widget.get_model()
421461
liststore.set_sort_column_id(0, Gtk.SortType.ASCENDING)
422462
keybindings = self.config['keybindings']
@@ -432,6 +472,10 @@ def set_values(self):
432472
liststore.append([keybinding, self.keybindingnames[keybinding],
433473
keyval, mask])
434474

475+
self.treemodelfilter = liststore.filter_new()
476+
self.treemodelfilter.set_visible_func(filter_visible, keybindings)
477+
widget.set_model(self.treemodelfilter)
478+
435479
## Plugins tab
436480
# Populate the plugin list
437481
widget = guiget('pluginlist')
@@ -1731,6 +1775,11 @@ def on_bold_text_is_bright_checkbutton_toggled(self, widget):
17311775
self.config.save()
17321776

17331777
def on_cellrenderer_accel_edited(self, liststore, path, key, mods, _code):
1778+
inpath = path #save for debugging
1779+
trpath = Gtk.TreePath.new_from_string(inpath)
1780+
path = str(self.treemodelfilter.convert_path_to_child_path(trpath))
1781+
dbg("convert path with filter from: %s to: %s" %
1782+
(inpath, path))
17341783
"""Handle an edited keybinding"""
17351784
# Ignore `Gdk.KEY_Tab` so that `Shift+Tab` is displayed as `Shift+Tab`
17361785
# in `Preferences>Keybindings` and NOT `Left Tab` (see `Gdk.KEY_ISO_Left_Tab`).
@@ -1801,6 +1850,12 @@ def on_cellrenderer_accel_edited(self, liststore, path, key, mods, _code):
18011850
self.config.save()
18021851

18031852
def on_cellrenderer_accel_cleared(self, liststore, path):
1853+
inpath = path #save for debugging
1854+
trpath = Gtk.TreePath.new_from_string(inpath)
1855+
path = str(self.treemodelfilter.convert_path_to_child_path(trpath))
1856+
dbg("convert path with filter from: %s to: %s" %
1857+
(inpath, path))
1858+
18041859
"""Handle the clearing of a keybinding accelerator"""
18051860
celliter = liststore.get_iter_from_string(path)
18061861
liststore.set(celliter, 2, 0, 3, 0)

‎tests/test_prefseditor_keybindings.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def test_message_dialog_is_shown_on_duplicate_accel_assignment(
103103
)
104104

105105
widget = prefs_editor.builder.get_object("keybindingtreeview")
106-
liststore = widget.get_model()
106+
treemodelfilter = widget.get_model()
107+
liststore = treemodelfilter.get_model()
107108

108109
# Replace default accelerator with a test one
109110
prefs_editor.on_cellrenderer_accel_edited(
@@ -150,7 +151,8 @@ def test_duplicate_accels_not_possible_to_set(accel_params):
150151
)
151152

152153
widget = prefs_editor.builder.get_object("keybindingtreeview")
153-
liststore = widget.get_model()
154+
treemodelfilter = widget.get_model()
155+
liststore = treemodelfilter.get_model()
154156
binding = liststore.get_value(liststore.get_iter(path), 0)
155157

156158
all_default_accelerators = {
@@ -231,7 +233,8 @@ def test_keybinding_edit_produce_expected_accels(
231233
prefs_editor = prefseditor.PrefsEditor(term=term)
232234

233235
widget = prefs_editor.builder.get_object("keybindingtreeview")
234-
liststore = widget.get_model()
236+
treemodelfilter = widget.get_model()
237+
liststore = treemodelfilter.get_model()
235238

236239
path = 0 # Edit the first listed key binding in `Preferences>Keybindings`
237240
key, mods, hardware_keycode = input_key_params
@@ -277,7 +280,8 @@ def test_keybinding_successfully_reassigned_after_clearing(accel_params):
277280
prefs_editor = prefseditor.PrefsEditor(term=term)
278281

279282
widget = prefs_editor.builder.get_object("keybindingtreeview")
280-
liststore = widget.get_model()
283+
treemodelfilter = widget.get_model()
284+
liststore = treemodelfilter.get_model()
281285

282286
path, key, mods, hardware_keycode = accel_params
283287
# Assign a key binding

0 commit comments

Comments
 (0)