Add replace_action() to keyboard manager

This commit is contained in:
Kovid Goyal 2011-08-29 13:02:38 -06:00
parent 604d4ca916
commit b61638fa28
2 changed files with 13 additions and 0 deletions

View File

@ -198,6 +198,10 @@ class InterfaceAction(QObject):
:param shortcut_name: The test displayed to the user when customizing
the keyboard shortcuts for this action. By default it is set to the
value of ``text``.
:return: The created Qation, This action has one extra attribute
calibre_shortcut_unique_name which if not None refers to the unique
name under which this action is registered with the keyboard manager.
'''
if shortcut_name is None:
shortcut_name = unicode(text)
@ -216,10 +220,12 @@ class InterfaceAction(QObject):
ac.setStatusTip(description)
ac.setWhatsThis(description)
ac.calibre_shortcut_unique_name = None
if shortcut is not False:
self.gui.keyboard.register_shortcut(unique_name,
shortcut_name, default_keys=keys,
action=ac, description=description, group=self.action_spec[0])
ac.calibre_shortcut_unique_name = unique_name
if triggered is not None:
ac.triggered.connect(triggered)
return ac

View File

@ -117,6 +117,13 @@ class Manager(QObject): # {{{
#import pprint
#pprint.pprint(self.keys_map)
def replace_action(self, unique_name, new_action):
sc = self.shortcuts[unique_name]
ac = sc['action']
if ac is not None:
new_action.setShortcuts(ac.shortcuts())
ac.setShortcuts([])
# }}}
# Model {{{