[kupfer: 36/53] Put all accelerators into kupfer/ui/accelerators.py



commit 3b14fabda29796823c3681c2f872907eae3f2cc3
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Mar 24 17:22:39 2011 +0100

    Put all accelerators into kupfer/ui/accelerators.py

 data/defaults.cfg         |    2 ++
 kupfer/ui/accelerators.py |   21 +++++++++++++++++++++
 kupfer/ui/browser.py      |   20 +++++++++++++-------
 kupfer/ui/preferences.py  |   25 ++++---------------------
 4 files changed, 40 insertions(+), 28 deletions(-)
---
diff --git a/data/defaults.cfg b/data/defaults.cfg
index 882a815..015260c 100644
--- a/data/defaults.cfg
+++ b/data/defaults.cfg
@@ -17,6 +17,8 @@ UseCommandKeys = True
 activate = <Alt>a
 comma_trick = <Control>comma
 compose_action = <Control>Return
+erase_affinity_for_first_pane =
+mark_as_default =
 reset_all = <Control>r
 select_quit = <Control>q
 select_selected_file = <Control>g
diff --git a/kupfer/ui/accelerators.py b/kupfer/ui/accelerators.py
new file mode 100644
index 0000000..fbee95d
--- /dev/null
+++ b/kupfer/ui/accelerators.py
@@ -0,0 +1,21 @@
+
+ACCELERATOR_NAMES = {
+	# TRANS: Names of accelerators in the interface
+	'activate': _('Alternate Activate'),
+	# TRANS: The "Comma Trick"/"Put Selection on Stack" allows the
+	# TRANS: user to select many objects to be used for one action
+	'comma_trick': _('Comma Trick'),
+	# TRANS: "Compose Command" makes one object out of the selected
+	# TRANS: object + action (+iobject)
+	'compose_action': _('Compose Command'),
+	'mark_as_default': _('Mark Default Action'),
+	'erase_affinity_for_first_pane': _('Forget Object'),
+	'reset_all': _('Reset All'),
+	'select_quit': _('Select Quit'),
+	'select_selected_file': _('Select Selected File'),
+	'select_selected_text': _('Select Selected Text'),
+	'show_help': _('Show Help'),
+	'show_preferences': _('Show Preferences'),
+	'switch_to_source': _('Switch to First Pane'),
+	"toggle_text_mode_quick": _('Toggle Text Mode'),
+}
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index b04dbf2..fed8f32 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -21,8 +21,9 @@ from kupfer import kupferui
 from kupfer import version
 
 from kupfer import scheduler
-from kupfer.ui import listen
+from kupfer.ui import accelerators
 from kupfer.ui import keybindings
+from kupfer.ui import listen
 from kupfer.ui import uievents
 from kupfer.core import data, relevance, learn
 from kupfer.core import settings
@@ -1353,10 +1354,11 @@ class Interface (gobject.GObject):
 		return True
 
 	def erase_affinity_for_first_pane(self):
+		if self.search.get_match_state() != State.Match:
+			return False
 		self.data_controller.erase_object_affinity(data.SourcePane)
 		return True
 
-
 	def comma_trick(self):
 		if self.current.get_match_state() != State.Match:
 			return False
@@ -1373,13 +1375,17 @@ class Interface (gobject.GObject):
 		Get a list of (name, function) currently
 		active context actions
 		"""
+		def get_accel(key):
+			""" Return name, method pair for @key"""
+			if key not in accelerators.ACCELERATOR_NAMES:
+				raise RuntimeError("Missing accelerator: %s" % key)
+			return (accelerators.ACCELERATOR_NAMES[key], getattr(self, key))
 		has_match = self.current.get_match_state() == State.Match
 		if has_match:
-			yield (_("Compose Command"), self.compose_action)
-			#yield (_("Comma Trick"), self.comma_trick)
-		yield (_("Select Selected Text"), self.select_selected_text)
+			yield get_accel('compose_action')
+		yield get_accel('select_selected_text')
 		if self.get_can_enter_text_mode():
-			yield (_("Toggle Text Mode"), self.toggle_text_mode_quick)
+			yield get_accel('toggle_text_mode_quick')
 		if self.action.get_match_state() == State.Match:
 			smatch = self.search.get_current()
 			amatch = self.action.get_current()
@@ -1394,7 +1400,7 @@ class Interface (gobject.GObject):
 				yield (_('Forget About "%s"') % unicode(match),
 				       self.erase_affinity_for_first_pane)
 		if has_match:
-			yield (_("Reset All"), self.reset_all)
+			yield get_accel('reset_all')
 
 	def _pane_reset(self, controller, pane, item):
 		wid = self._widget_for_pane(pane)
diff --git a/kupfer/ui/preferences.py b/kupfer/ui/preferences.py
index c7682dc..313b5a6 100644
--- a/kupfer/ui/preferences.py
+++ b/kupfer/ui/preferences.py
@@ -17,6 +17,7 @@ from kupfer.ui import keybindings
 from kupfer.ui import uievents
 from kupfer.ui.credentials_dialog import ask_user_credentials
 from kupfer.ui import getkey_dialog
+from kupfer.ui import accelerators
 from kupfer import plugin_support
 from kupfer import terminal
 
@@ -65,24 +66,6 @@ class PreferencesWindowController (pretty.OutputMixin):
 		"magickeybinding": keybindings.KEYBINDING_MAGIC,
 	}
 
-	ACCELERATOR_NAMES = {
-		# TRANS: Names of accelerators in the interface
-		'activate': _('Alternate Activate'),
-		# TRANS: The "Comma Trick"/"Put Selection on Stack" allows the
-		# TRANS: user to select many objects to be used for one action
-		'comma_trick': _('Comma Trick'),
-		# TRANS: "Compose Command" makes one object out of the selected
-		# TRANS: object + action (+iobject)
-		'compose_action': _('Compose Command'),
-		'reset_all': _('Reset All'),
-		'select_quit': _('Select Quit'),
-		'select_selected_file': _('Select Selected File'),
-		'select_selected_text': _('Select Selected Text'),
-		'show_help': _('Show Help'),
-		'show_preferences': _('Show Preferences'),
-		'switch_to_source': _('Switch to First Pane'),
-		"toggle_text_mode_quick": _('Toggle Text Mode'),
-	}
 
 	def __init__(self):
 		"""Load ui from data file"""
@@ -231,15 +214,15 @@ class PreferencesWindowController (pretty.OutputMixin):
 		names = self.KEYBINDING_NAMES
 		self.keybind_store.clear()
 		for binding in sorted(names, key=lambda k: names[k]):
-			accel = setctl.get_global_keybinding(binding)
+			accel = setctl.get_global_keybinding(binding) or ""
 			label = gtk.accelerator_get_label(*gtk.accelerator_parse(accel))
 			self.keybind_store.append((names[binding], label, binding))
 
 	def _show_gkeybindings(self, setctl):
-		names = self.ACCELERATOR_NAMES
+		names = accelerators.ACCELERATOR_NAMES
 		self.gkeybind_store.clear()
 		for binding in sorted(names, key=lambda k: names[k]):
-			accel = setctl.get_accelerator(binding)
+			accel = setctl.get_accelerator(binding) or ""
 			label = gtk.accelerator_get_label(*gtk.accelerator_parse(accel))
 			self.gkeybind_store.append((names[binding], label, binding))
 



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