mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Don't re-register an already registered action in QgsShortcutsManager
Avoids incorrect warnings about duplicate shortcuts on startup. What's happening here is: - on QGIS startup, plugins are loaded, adding their actions to the interface via iface.registerMainWindowAction() - after ALL plugins and qgis native menus and actions are created, the shortcut manager registers ALL children from the main window. This includes the actions and widgets created by plugins, which have already been registered to the manager. - There's no way to avoid this duplicate registration - we could move the child shortcut registration to occur before plugin initialization, but it's actually nice to have this "catch-all" occur after plugins are loaded (so that plugins which don't correctly register actions still have them included in the shortcut manager). Similarly, plugins MUST use the registerMainWindowAction call instead of just relying on the Qt QAction.setShortcut method because otherwise the shortcuts manager is unaware of actions created after QGIS load - e.g. enabling a plugin after startup. So we avoid this by just refusing to re-register a shortcut that the manager is already aware of... no more startup warnings!
This commit is contained in:
parent
63db1be890
commit
c41b2dd11c
@ -77,6 +77,9 @@ void QgsShortcutsManager::registerAllChildShortcuts( QObject *object, bool recur
|
||||
|
||||
bool QgsShortcutsManager::registerAction( QAction *action, const QString &defaultSequence )
|
||||
{
|
||||
if ( mActions.contains( action ) )
|
||||
return false; // already registered
|
||||
|
||||
#ifdef QGISDEBUG
|
||||
// if using a debug build, warn on duplicate actions
|
||||
if ( actionByName( action->text() ) || shortcutByName( action->text() ) )
|
||||
|
@ -90,6 +90,11 @@ class TestQgsShortcutsManager(unittest.TestCase):
|
||||
action2 = QAction('action2', None)
|
||||
action2.setShortcut('y')
|
||||
self.assertTrue(s.registerAction(action2, 'B'))
|
||||
self.assertCountEqual(s.listActions(), [action1, action2])
|
||||
|
||||
# try re-registering an existing action - should fail, but leave action registered
|
||||
self.assertFalse(s.registerAction(action2, 'B'))
|
||||
self.assertCountEqual(s.listActions(), [action1, action2])
|
||||
|
||||
# actions should have been set to default sequences
|
||||
self.assertEqual(action1.shortcut().toString(), 'A')
|
||||
|
Loading…
x
Reference in New Issue
Block a user