summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCinghio Pinghio <cinghio@linuxmail.org>2014-01-28 15:18:46 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2014-08-02 17:35:32 +0200
commitbf8e01d4132a073c3ef2059b2d0f0e55e2fe2562 (patch)
tree09116c93734d0e75d5e1cb6aa124bd83c41d34f3
parent880cd37cf5104d386d82bc86b5279ba4e753baa7 (diff)
added check to bindings commands; added settings.get_keybindings(self,mode)
-rw-r--r--alot/commands/globals.py7
-rw-r--r--alot/settings/manager.py42
2 files changed, 40 insertions, 9 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index 7073d524..3820cca0 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -577,12 +577,7 @@ class HelpCommand(Command):
title_att = settings.get_theming_attribute('help', 'title')
section_att = settings.get_theming_attribute('help', 'section')
# get mappings
- if ui.mode in settings._bindings:
- modemaps = dict(settings._bindings[ui.mode].items())
- else:
- modemaps = {}
- is_scalar = lambda k_v: k_v[0] in settings._bindings.scalars
- globalmaps = dict(filter(is_scalar, settings._bindings.items()))
+ globalmaps, modemaps = settings.get_keybindings(ui.mode)
# build table
maxkeylength = len(max((modemaps).keys() + globalmaps.keys(),
diff --git a/alot/settings/manager.py b/alot/settings/manager.py
index eb95db61..9aa61f87 100644
--- a/alot/settings/manager.py
+++ b/alot/settings/manager.py
@@ -310,9 +310,9 @@ class SettingsManager(object):
return None
def get_mapped_input_keysequences(self, mode='global', prefix=u''):
- candidates = self._bindings.scalars
- if mode != 'global':
- candidates = candidates + self._bindings[mode].scalars
+ # get all bindings in this mode
+ globalmaps, modemaps = self.get_keybindings(mode)
+ candidates = globalmaps.keys() + modemaps.keys()
if prefix is not None:
prefixs = prefix + ' '
cand = filter(lambda x: x.startswith(prefixs), candidates)
@@ -322,6 +322,39 @@ class SettingsManager(object):
candidates = cand
return candidates
+ def get_keybindings(self, mode):
+ """look up keybindings from `MODE-maps` sections
+
+ :param mode: mode identifier
+ :type mode: str
+ :returns: dictionaries of key-cmd for global and specific mode
+ :rtype: 2-tuple of dicts
+ """
+ globalmaps, modemaps = {},{}
+ bindings = self._bindings
+ # get bindings for mode `mode`
+ # retain empty assignations to silence corresponding global mappings
+ if mode in bindings.sections:
+ for key in bindings[mode].scalars:
+ value = bindings[mode][key]
+ if isinstance(value, list):
+ value = ','.join(value)
+ modemaps[key] = value
+ # get global bindings
+ # ignore the ones already mapped in mode bindings
+ for key in bindings.scalars:
+ if key not in modemaps:
+ value = bindings[key]
+ if isinstance(value, list):
+ value = ','.join(value)
+ if value and value != '':
+ globalmaps[key] = value
+ # get rid of empty commands left in mode bindings
+ for key in [k for k,v in modemaps.items() if not v or v=='']:
+ del modemaps[key]
+
+ return globalmaps, modemaps
+
def get_keybinding(self, mode, key):
"""look up keybinding from `MODE-maps` sections
@@ -341,6 +374,9 @@ class SettingsManager(object):
value = bindings[mode][key]
if value:
cmdline = value
+ else:
+ # to be sure it isn't mapped globally
+ cmdline = None
# Workaround for ConfigObj misbehaviour. cf issue #500
# this ensures that we get at least strings only as commandlines
if isinstance(cmdline, list):