Refactor configmodel.bind

This commit is contained in:
Florian Bruhin 2018-02-27 16:13:05 +01:00
parent fdc2458657
commit 2ed480b40a

View File

@ -72,24 +72,16 @@ def value(optname, *_values, info):
return model return model
def bind(key, *, info): def _bind_current_default(key, info):
"""A CompletionModel filled with all bindable commands and descriptions. """Get current/default data for the given key."""
Args:
key: the key being bound.
"""
model = completionmodel.CompletionModel(column_widths=(20, 60, 20))
data = [] data = []
try: try:
seq = keyutils.KeySequence.parse(key) seq = keyutils.KeySequence.parse(key)
except keyutils.KeyParseError as e: except keyutils.KeyParseError as e:
seq = None
cmd_text = None
data.append(('', str(e), key)) data.append(('', str(e), key))
return data
if seq: cmd_text = info.keyconf.get_command(seq, 'normal')
cmd_text = info.keyconf.get_command(seq, 'normal')
if cmd_text: if cmd_text:
parser = runners.CommandParser() parser = runners.CommandParser()
try: try:
@ -99,13 +91,24 @@ def bind(key, *, info):
else: else:
data.append((cmd_text, '(Current) {}'.format(cmd.desc), key)) data.append((cmd_text, '(Current) {}'.format(cmd.desc), key))
if seq: cmd_text = info.keyconf.get_command(seq, 'normal')
cmd_text = info.keyconf.get_command(seq, 'normal')
if cmd_text: if cmd_text:
parser = runners.CommandParser() parser = runners.CommandParser()
cmd = parser.parse(cmd_text).cmd cmd = parser.parse(cmd_text).cmd
data.append((cmd_text, '(Default) {}'.format(cmd.desc), key)) data.append((cmd_text, '(Default) {}'.format(cmd.desc), key))
return data
def bind(key, *, info):
"""A CompletionModel filled with all bindable commands and descriptions.
Args:
key: the key being bound.
"""
model = completionmodel.CompletionModel(column_widths=(20, 60, 20))
data = _bind_current_default(key, info)
if data: if data:
model.add_category(listcategory.ListCategory("Current/Default", data)) model.add_category(listcategory.ListCategory("Current/Default", data))