Refactor completion chosing

This commit is contained in:
Florian Bruhin 2014-03-24 11:37:41 +01:00
parent a5702c781f
commit 678b4d54af

View File

@ -156,23 +156,20 @@ class CompletionView(QTreeView):
parts: The command chunks to get a completion for. parts: The command chunks to get a completion for.
""" """
model = None
if len(parts) == 1: if len(parts) == 1:
model = 'command' return 'command'
else: # try to delegate to the command
# try to delegate to the command try:
try: completions = cmdutils.cmd_dict[parts[0]].completion
completions = cmdutils.cmd_dict[parts[0]].completion except KeyError:
logging.debug('completions: {}'.format(completions)) return None
if completions is None: logging.debug('completions: {}'.format(completions))
model = None if completions is None:
else: return None
model = completions[len(parts) - 2] try:
except KeyError: return completions[len(parts) - 2]
logging.debug("No completions for '{}'".format(parts[0])) except IndexError:
model = None return None
# FIXME: if this fails, what do we do?
return model
def set_model(self, model): def set_model(self, model):
"""Switch completion to a new model. """Switch completion to a new model.