summaryrefslogtreecommitdiff
path: root/kde-frameworks/kxmlgui/files/kxmlgui-5.111.0-fix-xml-merging.patch
blob: 013fbab9d1c7de1a23fb47c758f59c86a22b4348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/190
https://bugs.kde.org/show_bug.cgi?id=475016

From f015fa6006d2e2eea2d2aac11c18219b255722ef Mon Sep 17 00:00:00 2001
From: Mladen Milinkovic <maxrd2@smoothware.net>
Date: Fri, 29 Sep 2023 20:01:49 +0200
Subject: [PATCH] Fix merging of XMLs with multiple ActionProperties tags

BUG: 475016
--- a/autotests/kxmlgui_unittest.cpp
+++ b/autotests/kxmlgui_unittest.cpp
@@ -88,6 +88,26 @@ static void createXmlFile(QFile &file, int version, int flags, const QByteArray
     file.write("</" + toplevelTag + ">\n");
 }
 
+class ShortcutSchemeHandler
+{
+public:
+    ShortcutSchemeHandler(const QString &scheme)
+        : cgScheme(KSharedConfig::openConfig(), "Shortcut Schemes")
+        , prevScheme(cgScheme.readEntry("Current Scheme", QStringLiteral("Default")))
+    {
+        cgScheme.writeEntry("Current Scheme", scheme);
+    }
+
+    ~ShortcutSchemeHandler()
+    {
+        cgScheme.writeEntry("Current Scheme", prevScheme);
+    }
+
+private:
+    KConfigGroup cgScheme;
+    const QString prevScheme;
+};
+
 static void clickApply(KEditToolBar *dialog)
 {
     QDialogButtonBox *box = dialog->findChild<QDialogButtonBox *>();
@@ -106,6 +126,15 @@ void KXmlGui_UnitTest::initTestCase()
         QFile::remove(configFile);
         KSharedConfig::openConfig()->reparseConfiguration();
     }
+
+    // Create "Test" shortcut scheme to eliminate the KF warning
+    QFile testScheme = QFile(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+        + QLatin1String("/%1/shortcuts/%2").arg(QCoreApplication::applicationName(), QStringLiteral("Test")));
+    if (!testScheme.exists()) {
+        QVERIFY(QFileInfo(testScheme).dir().mkpath(QStringLiteral(".")));
+        QVERIFY(testScheme.open(QIODevice::WriteOnly));
+        testScheme.write(QByteArray("<gui><ActionProperties/></gui>"));
+    }
 }
 
 void KXmlGui_UnitTest::testFindVersionNumber_data()
@@ -457,6 +486,56 @@ void KXmlGui_UnitTest::testPartMerging()
     factory.removeClient(&hostClient);
 }
 
+void KXmlGui_UnitTest::testShortcutSchemeMerging()
+{
+    TestGuiClient client;
+
+    ShortcutSchemeHandler sss(QStringLiteral("Test"));
+
+    KActionCollection *ac = client.actionCollection();
+
+    QAction *a = ac->addAction(QStringLiteral("test_action"));
+    ac->setDefaultShortcut(a, QKeySequence(QStringLiteral("Ctrl+A")));
+
+    const QByteArray appXml = R"(<?xml version = "1.0"?>
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui name="foo" version="5">
+<MenuBar>
+  <Menu name="file"><text>&amp;File</text>
+    <Action name="test_action" />
+  </Menu>
+</MenuBar></kpartgui>
+)";
+    client.createGUI(appXml, false);
+
+    const QByteArray settingsXml = R"(<!DOCTYPE kpartgui SYSTEM 'kpartgui.dtd'>
+<kpartgui name="foo" version="1">
+ <MenuBar>
+  <Menu name="file">
+   <text>&amp;File</text>
+   <Action name="test_action" />
+  </Menu>
+ </MenuBar>
+ <ActionProperties scheme="Default">
+  <Action name="test_action" shortcut="Ctrl+B"/>
+ </ActionProperties>
+ <ActionProperties scheme="Test">
+  <Action name="test_action" shortcut="Ctrl+C"/>
+ </ActionProperties>
+</kpartgui>
+)";
+    client.mergeXML(settingsXml);
+
+    KMainWindow mainWindow;
+    KXMLGUIBuilder builder(&mainWindow);
+    KXMLGUIFactory factory(&builder);
+    factory.addClient(&client);
+
+    QCOMPARE(a->shortcut(), QKeySequence(QStringLiteral("Ctrl+C")));
+
+    factory.removeClient(&client);
+}
+
 void KXmlGui_UnitTest::testPartMergingSettings() // #252911
 {
     const QByteArray hostXml =
--- a/autotests/kxmlgui_unittest.h
+++ b/autotests/kxmlgui_unittest.h
@@ -23,6 +23,7 @@ private Q_SLOTS:
     void testVersionHandlerNewVersionUserChanges();
     void testPartMerging();
     void testPartMergingSettings();
+    void testShortcutSchemeMerging();
     void testUiStandardsMerging_data();
     void testUiStandardsMerging();
     void testActionListAndSeparator();
--- a/autotests/testguiclient.h
+++ b/autotests/testguiclient.h
@@ -42,6 +42,10 @@ public:
 
         setXML(QString::fromLatin1(xml), true);
     }
+    void mergeXML(const QByteArray &xml)
+    {
+        setXML(QString::fromLatin1(xml), true);
+    }
     void createActions(const QStringList &actionNames)
     {
         KActionCollection *coll = actionCollection();
--- a/src/kxmlguiclient.cpp
+++ b/src/kxmlguiclient.cpp
@@ -587,6 +587,8 @@ bool KXMLGUIClientPrivate::isEmptyContainer(const QDomElement &base, KActionColl
 
 QDomElement KXMLGUIClientPrivate::findMatchingElement(const QDomElement &base, const QDomElement &additive)
 {
+    const QString idAttribute(base.tagName() == QLatin1String("ActionProperties") ? QStringLiteral("scheme") : QStringLiteral("name"));
+
     QDomNode n = additive.firstChild();
     while (!n.isNull()) {
         QDomElement e = n.toElement();
@@ -604,7 +606,7 @@ QDomElement KXMLGUIClientPrivate::findMatchingElement(const QDomElement &base, c
 
         // now see if our tags are equivalent
         if (equalstr(tag, base.tagName()) //
-            && e.attribute(QStringLiteral("name")) == base.attribute(QStringLiteral("name"))) {
+            && e.attribute(idAttribute) == base.attribute(idAttribute)) {
             return e;
         }
     }
-- 
GitLab