Merge pull request #665 from vssdeo/559-Add-menu-autocomplete
[bug 559] Add menu autocomplete #559
This commit is contained in:
commit
1d5351ed86
@ -3720,6 +3720,21 @@
|
||||
</packing>
|
||||
</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>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
@ -3779,6 +3794,8 @@
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user