[kupfer] Read command window keyboard shortcuts from configuration file



commit f3085e23ce1fada3a94de6bd0c992ea591e89828
Author: Karol BÄ?dkowski <karol bedkowski gmail com>
Date:   Thu Apr 7 22:13:13 2005 +0200

    Read command window keyboard shortcuts from configuration file
    
    Allow user to customize the previously hardcoded internal kupfer
    keyboard shortcuts.

 data/defaults.cfg       |   12 ++++++++++++
 kupfer/core/settings.py |   11 +++++++++++
 kupfer/ui/browser.py    |   19 +++++--------------
 3 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/data/defaults.cfg b/data/defaults.cfg
index f3a9d36..ef36c5e 100644
--- a/data/defaults.cfg
+++ b/data/defaults.cfg
@@ -12,6 +12,18 @@ Keybinding = <Ctrl>space
 MagicKeybinding =
 ShowStatusIcon = True
 
+[Keybindings]
+activate = <Alt>a
+compose_action = <Control>Return
+reset_all = <Control>r
+select_quit = <Control>q
+select_selected_file = <Control>g
+select_selected_text = <Control>t
+show_help = F1
+switch_to_source = <Control>s
+toggle_text_mode_quick = <Control>period
+
+
 # Catalog: The sources of the plugin are included
 # as subcatalogs in the main search catalog, and
 # its items are not available in the main catalog
diff --git a/kupfer/core/settings.py b/kupfer/core/settings.py
index 371a93f..9375f89 100644
--- a/kupfer/core/settings.py
+++ b/kupfer/core/settings.py
@@ -37,6 +37,7 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 		},
 		"Directories" : { "direct" : default_directories, "catalog" : (), },
 		"DeepDirectories" : { "direct" : (), "catalog" : (), "depth" : 1, },
+		'Keybindings': {},
 	}
 	def __init__(self):
 		gobject.GObject.__init__(self)
@@ -294,6 +295,16 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 			value_repr = value_type(value)
 		return self._set_raw_config(plug_section, key, value_repr)
 
+	def get_accelerator(self, name):
+		return self.get_config("Keybindings", name)
+
+	def set_accelerator(self, name, key):
+		return self._set_config("Keybindings", name, key)
+
+	def get_accelerators(self):
+		return self._config['Keybindings']
+
+
 # Section, Key, Value
 gobject.signal_new("value-changed", SettingsController, gobject.SIGNAL_RUN_LAST,
 	gobject.TYPE_BOOLEAN, (gobject.TYPE_STRING, gobject.TYPE_STRING,
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index 72ac840..6d3fbe4 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -888,18 +888,10 @@ class Interface (gobject.GObject):
 		keyv = event.keyval
 		key_book = self.key_book
 
-		# FIXME: These should be configurable
-		accels = {
-			"<Control>period" : "toggle_text_mode_quick",
-			"<Control>s" : "switch_to_source",
-			"<Control>r" : "reset_all",
-			"<Control>g" : "select_selected_file",
-			"<Control>t" : "select_selected_text",
-			"<Control>q" : "select_quit",
-			"<Alt>a" : "activate",
-			"<Control>Return": "compose_action",
-			"F1" : "show_help",
-		}
+		from kupfer.core import settings
+		setctl = settings.GetSettingsController()
+		keybindings = setctl.get_accelerators()
+
 		direct_text_key = gtk.gdk.keyval_from_name("period")
 		init_text_keys = map(gtk.gdk.keyval_from_name, ("slash", "equal"))
 		init_text_keys.append(direct_text_key)
@@ -917,12 +909,11 @@ class Interface (gobject.GObject):
 				self._relax_search_terms)
 
 		# process accelerators
-		for accel in accels:
+		for action, accel in keybindings.iteritems():
 			akeyv, amodf = gtk.accelerator_parse(accel)
 			if not akeyv:
 				continue
 			if akeyv == keyv and (amodf == (event.state & modifiers)):
-				action = accels[accel]
 				action_method = getattr(self, action, None)
 				if not action_method:
 					pretty.print_error(__name__, "Action invalid '%s'" % action)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]