Commit 99f7f303 authored by Amy spark's avatar Amy spark 👉
Browse files

Add OS-specific action property retrieval to KisActionRegistry

This enables the retrieval of operating system-specific action

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
- When finding a node with "operatingSystemElse", stores the last seen
- 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
parent 06b297ae
......@@ -375,7 +375,8 @@
<shortcut operatingSystem="macos">Backspace</shortcut>
<shortcut operatingSystemElse="">Del</shortcut>
......@@ -399,7 +400,8 @@
<iconText>Fill with Background Color</iconText>
<shortcut operatingSystem="macos">Del</shortcut>
<shortcut operatingSystemElse="">Backspace</shortcut>
......@@ -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;
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");
QString shortcutText = getChildContentForOS(actionXml, "shortcut");
if (!shortcutText.isEmpty()) {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment