mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Prevent misbehaving plugins that delete shortcut actions without unregistering them from causing crashes
This commit is contained in:
parent
95d9151a5c
commit
cc4452f072
@ -10,6 +10,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
import sip
|
||||||
from PyQt5.Qt import (QObject, QKeySequence, QAbstractItemModel, QModelIndex,
|
from PyQt5.Qt import (QObject, QKeySequence, QAbstractItemModel, QModelIndex,
|
||||||
Qt, QStyledItemDelegate, QTextDocument, QStyle, pyqtSignal, QFrame,
|
Qt, QStyledItemDelegate, QTextDocument, QStyle, pyqtSignal, QFrame,
|
||||||
QApplication, QSize, QRectF, QWidget, QTreeView,
|
QApplication, QSize, QRectF, QWidget, QTreeView,
|
||||||
@ -45,7 +46,7 @@ def keysequence_from_event(ev): # {{{
|
|||||||
|
|
||||||
def finalize(shortcuts, custom_keys_map={}): # {{{
|
def finalize(shortcuts, custom_keys_map={}): # {{{
|
||||||
'''
|
'''
|
||||||
Resolve conflicts and assign keys to every action in shorcuts, which must
|
Resolve conflicts and assign keys to every action in shortcuts, which must
|
||||||
be a OrderedDict. User specified mappings of unique names to keys (as a
|
be a OrderedDict. User specified mappings of unique names to keys (as a
|
||||||
list of strings) should be passed in in custom_keys_map. Return a mapping
|
list of strings) should be passed in in custom_keys_map. Return a mapping
|
||||||
of unique names to resolved keys. Also sets the set_to_default member
|
of unique names to resolved keys. Also sets the set_to_default member
|
||||||
@ -53,6 +54,11 @@ def finalize(shortcuts, custom_keys_map={}): # {{{
|
|||||||
'''
|
'''
|
||||||
seen, keys_map = {}, {}
|
seen, keys_map = {}, {}
|
||||||
for unique_name, shortcut in shortcuts.iteritems():
|
for unique_name, shortcut in shortcuts.iteritems():
|
||||||
|
ac = shortcut['action']
|
||||||
|
if ac is None or sip.isdeleted(ac):
|
||||||
|
if ac is not None and DEBUG:
|
||||||
|
prints('Shortcut %r has a deleted action' % unique_name)
|
||||||
|
continue
|
||||||
custom_keys = custom_keys_map.get(unique_name, None)
|
custom_keys = custom_keys_map.get(unique_name, None)
|
||||||
if custom_keys is None:
|
if custom_keys is None:
|
||||||
candidates = shortcut['default_keys']
|
candidates = shortcut['default_keys']
|
||||||
@ -75,8 +81,6 @@ def finalize(shortcuts, custom_keys_map={}): # {{{
|
|||||||
keys = tuple(keys)
|
keys = tuple(keys)
|
||||||
|
|
||||||
keys_map[unique_name] = keys
|
keys_map[unique_name] = keys
|
||||||
ac = shortcut['action']
|
|
||||||
if ac is not None:
|
|
||||||
ac.setShortcuts(list(keys))
|
ac.setShortcuts(list(keys))
|
||||||
|
|
||||||
return keys_map
|
return keys_map
|
||||||
|
Loading…
x
Reference in New Issue
Block a user