[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
This commit is contained in:
Vishweshwar Saran Singh Deo 2022-11-01 15:29:07 +05:30
parent 1aa437d6e3
commit fdcf8facf4
2 changed files with 73 additions and 1 deletions

View File

@ -3719,6 +3719,21 @@
<property name="tab-fill">False</property> <property name="tab-fill">False</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkVBox" id="vbox124">
<child>
<object class="GtkEntry" id="keybindingsearchentry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="has-focus">False</property>
<property name="placeholder_text">filter keybindings</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child> <child>
<object class="GtkScrolledWindow" id="scrolledwindow1"> <object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property> <property name="visible">True</property>
@ -3779,6 +3794,8 @@
</object> </object>
</child> </child>
</object> </object>
</child>
</object>
<packing> <packing>
<property name="position">3</property> <property name="position">3</property>
</packing> </packing>

View File

@ -416,6 +416,46 @@ class PrefsEditor:
## Keybindings tab ## 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 = widget.get_model()
liststore.set_sort_column_id(0, Gtk.SortType.ASCENDING) liststore.set_sort_column_id(0, Gtk.SortType.ASCENDING)
keybindings = self.config['keybindings'] keybindings = self.config['keybindings']
@ -431,6 +471,10 @@ class PrefsEditor:
liststore.append([keybinding, self.keybindingnames[keybinding], liststore.append([keybinding, self.keybindingnames[keybinding],
keyval, mask]) keyval, mask])
self.treemodelfilter = liststore.filter_new()
self.treemodelfilter.set_visible_func(filter_visible, keybindings)
widget.set_model(self.treemodelfilter)
## Plugins tab ## Plugins tab
# Populate the plugin list # Populate the plugin list
widget = guiget('pluginlist') widget = guiget('pluginlist')
@ -1730,6 +1774,11 @@ class PrefsEditor:
self.config.save() self.config.save()
def on_cellrenderer_accel_edited(self, liststore, path, key, mods, _code): 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""" """Handle an edited keybinding"""
# Ignore `Gdk.KEY_Tab` so that `Shift+Tab` is displayed as `Shift+Tab` # 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`). # in `Preferences>Keybindings` and NOT `Left Tab` (see `Gdk.KEY_ISO_Left_Tab`).
@ -1800,6 +1849,12 @@ class PrefsEditor:
self.config.save() self.config.save()
def on_cellrenderer_accel_cleared(self, liststore, path): 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""" """Handle the clearing of a keybinding accelerator"""
celliter = liststore.get_iter_from_string(path) celliter = liststore.get_iter_from_string(path)
liststore.set(celliter, 2, 0, 3, 0) liststore.set(celliter, 2, 0, 3, 0)