[graphics/krita/krita/4.3] /: Add OS-specific action property retrieval to KisActionRegistry

L. E. Segovia null at kde.org
Wed Nov 4 20:42:45 GMT 2020


Git commit 3a9828651dd5942885b80aa508b59e4ea3bb3ab5 by L. E. Segovia.
Committed on 04/11/2020 at 20:42.
Pushed by lsegovia into branch 'krita/4.3'.

Add OS-specific action property retrieval to KisActionRegistry

This enables the retrieval of operating system-specific action
properties.

OS-specific action properties are labeled with the attributes
"operatingSystem" (for the selected OS; currently only "macos" is
defined) and "operatingSystemElse" (for the rest).

This commit adds a function, getChildContentForOS, that:
- When finding a matching "operatingSystem", returns the given node's
text
- When finding a node with "operatingSystemElse", stores the last seen
one
- When finding a node without any of these parameters, stores the first
seen one and ignores the rest

This commit implements said change on the Del and Backspace key
shortcuts for macOS. See krita.action.

BUG: 425370
CCMAIL: kimageshop at kde.org
(cherry picked from commit 99f7f30391c23f20c2d531619971049756416ef4)

M  +4    -2    krita/kritamenu.action
M  +33   -1    libs/widgetutils/kis_action_registry.cpp

https://invent.kde.org/graphics/krita/commit/3a9828651dd5942885b80aa508b59e4ea3bb3ab5

diff --git a/krita/kritamenu.action b/krita/kritamenu.action
index 9d50fbe159..ff942d1032 100644
--- a/krita/kritamenu.action
+++ b/krita/kritamenu.action
@@ -413,7 +413,8 @@
       <iconText>Clear</iconText>
       <activationFlags>1</activationFlags>
       <activationConditions>0</activationConditions>
-      <shortcut>Del</shortcut>
+      <shortcut operatingSystem="macos">Backspace</shortcut>
+      <shortcut operatingSystemElse="">Del</shortcut>
       <isCheckable>false</isCheckable>
       <statusTip></statusTip>
     </Action>
@@ -437,7 +438,8 @@
       <iconText>Fill with Background Color</iconText>
       <activationFlags>10000</activationFlags>
       <activationConditions>1</activationConditions>
-      <shortcut>Backspace</shortcut>
+      <shortcut operatingSystem="macos">Del</shortcut>
+      <shortcut operatingSystemElse="">Backspace</shortcut>
       <isCheckable>false</isCheckable>
       <statusTip></statusTip>
     </Action>
diff --git a/libs/widgetutils/kis_action_registry.cpp b/libs/widgetutils/kis_action_registry.cpp
index e1b3092a22..88be7a17d1 100644
--- a/libs/widgetutils/kis_action_registry.cpp
+++ b/libs/widgetutils/kis_action_registry.cpp
@@ -26,6 +26,7 @@
 #include <klocalizedstring.h>
 #include <KisShortcutsDialog.h>
 #include <KConfigGroup>
+#include <qdom.h>
 
 #include "kis_debug.h"
 #include "KoResourcePaths.h"
@@ -90,6 +91,33 @@ namespace {
         return xml.firstChildElement(node).text();
     }
 
+    QString getChildContentForOS(QDomElement xml, QString tagName, QString os = QString()) {
+        bool found = false;
+
+        QDomElement node = xml.firstChildElement(tagName);
+        QDomElement nodeElse;
+
+        while(!found && !node.isNull()) {
+            if (node.attribute("operatingSystem") == os) {
+                found = true;
+                break;
+            }
+            else if (node.hasAttribute("operatingSystemElse")) {
+                nodeElse = node;
+            }
+            else if (nodeElse.isNull()) {
+                nodeElse = node;
+            }
+
+            node = node.nextSiblingElement(tagName);
+        }
+
+        if (!found && !nodeElse.isNull()) {
+            return nodeElse.text();
+        }
+        return node.text();
+    }
+
     // Use Krita debug logging categories instead of KDE's default qDebug() for
     // harmless empty strings and translations
     QString quietlyTranslate(const QDomElement &s) {
@@ -390,7 +418,11 @@ void KisActionRegistry::Private::loadActionFiles()
                         info.xmlData         = actionXml;
 
                         // Use empty list to signify no shortcut
-                        QString shortcutText = getChildContent(actionXml, "shortcut");
+#ifdef Q_OS_MACOS
+                        QString shortcutText = getChildContentForOS(actionXml, "shortcut", "macos");
+#else
+                        QString shortcutText = getChildContentForOS(actionXml, "shortcut");
+#endif
                         if (!shortcutText.isEmpty()) {
                             info.setDefaultShortcuts(QKeySequence::listFromString(shortcutText));
                         }


More information about the kimageshop mailing list