From e6145c0ee66698bfffc7fca0f0a456bbe0adafe3 Mon Sep 17 00:00:00 2001 From: Vbialk Date: Tue, 2 May 2023 09:24:14 +0200 Subject: [PATCH 1/2] Add keyboard shortcut MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A keyboard shortcut is added to run the delete-all action using the key combination Ctrl+Alt+D. Ein Tastatur Shortcut wird eingebaut, mit dem die delete-all Aktion über die Tastenkombination Strg+Alt+D ausgeführt werden kann. --- delete_all.py | 5 +++++ i18n/delete_all_de.qm | Bin 608 -> 750 bytes i18n/delete_all_de.ts | 20 +++++++++++++++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/delete_all.py b/delete_all.py index 98d1ad4..a455b4d 100644 --- a/delete_all.py +++ b/delete_all.py @@ -61,6 +61,11 @@ def initGui(self): ) self.action.triggered.connect(self.deleteAll) self.aboutAction.triggered.connect(self.about) + + self.action.setShortcut(self.tr('Ctrl+Alt+D')) + self.action.setToolTip( + '' + self.action.toolTip() + '
' + self.tr('(Ctrl+Alt+D)') + ) self.menu = QMenu(self.tr("&delete-all")) self.menu.setIcon(QIcon(os.path.join(self.plugin_dir, "delete_all.png"))) diff --git a/i18n/delete_all_de.qm b/i18n/delete_all_de.qm index 4020b3ebeafff25474ac817526d2c416680764e9..d4b916c8c57709f36ba7eb8def811163dc0ac387 100644 GIT binary patch delta 152 zcmaFB@{V@db1{@IU@iR^dY7I delta 47 zcmaFI`haDEoS+5+m%$eX28K5b$DZZ@=~)x?#n>57XEHD_@lK4HH`#_UX!9vX6-EG9 C`wja5 diff --git a/i18n/delete_all_de.ts b/i18n/delete_all_de.ts index 4f81150..30e35a8 100644 --- a/i18n/delete_all_de.ts +++ b/i18n/delete_all_de.ts @@ -4,29 +4,39 @@ DeleteAll - + delete-all alles-löschen - + &delete-all &alles-löschen - + QGIS plugin to delete all groups and layers from the layer widget QGIS-Plugin zum Löschen aller Gruppen und Layer im Layer-Fenster - + About delete-all Über alles-löschen - + &About delete-all &Über alles-löschen + + + Ctrl+Alt+D + Strg+Alt+D + + + + (Ctrl+Alt+D) + (Strg+Alt+D) + From ee5b949f227c50bd9993d32b303edeb3832f7d60 Mon Sep 17 00:00:00 2001 From: Vbialk Date: Tue, 16 May 2023 10:11:00 +0200 Subject: [PATCH 2/2] fix shortcut The shortcut is now implemented with a MainWindowAction (default shortcut) and the QgsShortcutsManager. If the shortcut is set and no other shortcut is assigned to the combination "Ctrl+Alt+D", the default shortcut is assigned. @pathmapper this should realize your suggetions, please test it :-) --- delete_all.py | 11 ++++++----- i18n/delete_all_de.qm | Bin 750 -> 676 bytes i18n/delete_all_de.ts | 15 +++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/delete_all.py b/delete_all.py index a455b4d..043c269 100644 --- a/delete_all.py +++ b/delete_all.py @@ -21,6 +21,7 @@ import os from qgis.core import QgsProject +from qgis.gui import QgsGui from qgis.PyQt.QtCore import QCoreApplication, QSettings, QTranslator from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtWidgets import QAction, QMenu, QMessageBox @@ -61,11 +62,10 @@ def initGui(self): ) self.action.triggered.connect(self.deleteAll) self.aboutAction.triggered.connect(self.about) - - self.action.setShortcut(self.tr('Ctrl+Alt+D')) - self.action.setToolTip( - '' + self.action.toolTip() + '
' + self.tr('(Ctrl+Alt+D)') - ) + + self.iface.registerMainWindowAction(self.action, self.tr("Ctrl+Alt+D")) + if self.action.shortcut().isEmpty() and QgsGui.shortcutsManager().actionForSequence(self.tr("Ctrl+Alt+D")) is None: + QgsGui.shortcutsManager().setObjectKeySequence(self.action, self.tr("Ctrl+Alt+D")) self.menu = QMenu(self.tr("&delete-all")) self.menu.setIcon(QIcon(os.path.join(self.plugin_dir, "delete_all.png"))) @@ -77,6 +77,7 @@ def initGui(self): def unload(self): self.iface.removePluginMenu(self.tr("&delete-all"), self.action) self.iface.removePluginMenu(self.tr("&delete-all"), self.aboutAction) + self.iface.unregisterMainWindowAction(self.action) del self.action del self.toolbar diff --git a/i18n/delete_all_de.qm b/i18n/delete_all_de.qm index d4b916c8c57709f36ba7eb8def811163dc0ac387..60423d0962545565c78c2d92cc929c8df8622a74 100644 GIT binary patch delta 50 zcmaFIx`cItoS*>%m%$eX21X5rV^4D!7#LkIwv|ThO8!`%S I{IrP?02Uz{y#N3J diff --git a/i18n/delete_all_de.ts b/i18n/delete_all_de.ts index 30e35a8..eb554d1 100644 --- a/i18n/delete_all_de.ts +++ b/i18n/delete_all_de.ts @@ -4,7 +4,7 @@ DeleteAll - + delete-all alles-löschen @@ -14,29 +14,24 @@ &alles-löschen - + QGIS plugin to delete all groups and layers from the layer widget QGIS-Plugin zum Löschen aller Gruppen und Layer im Layer-Fenster - + About delete-all Über alles-löschen - + &About delete-all &Über alles-löschen - + Ctrl+Alt+D Strg+Alt+D - - - (Ctrl+Alt+D) - (Strg+Alt+D) -