From a6c51c5445dd89cb09ea110674794a312e33eccc Mon Sep 17 00:00:00 2001 From: Ismael Asensio Date: Fri, 27 Nov 2020 22:06:30 +0100 Subject: [PATCH] kcm/rules: Add a Duplicate action to rules list Useful action, especially for heavy kwin rules users As an example, this can help users to migrate their rules to Wayland (where some matching properties such as window class may be different) while keeping a version of the rule compatible with X11. BUG: 429588 FIXED-IN: 5.21 --- kcmkwin/kwinrules/kcmrules.cpp | 16 ++++++++++++++++ kcmkwin/kwinrules/kcmrules.h | 1 + .../kwinrules/package/contents/ui/RulesList.qml | 9 +++++++++ 3 files changed, 26 insertions(+) diff --git a/kcmkwin/kwinrules/kcmrules.cpp b/kcmkwin/kwinrules/kcmrules.cpp index 9e6cd71482..8eab547d80 100644 --- a/kcmkwin/kwinrules/kcmrules.cpp +++ b/kcmkwin/kwinrules/kcmrules.cpp @@ -161,6 +161,22 @@ void KCMKWinRules::moveRule(int sourceIndex, int destIndex) updateNeedsSave(); } +void KCMKWinRules::duplicateRule(int index) +{ + if (index < 0 || index >= m_ruleBookModel->rowCount()) { + return; + } + + Rules *newRule = new Rules(*(m_ruleBookModel->ruleAt(index))); + const QString newDescription = i18n("Copy of %1", m_ruleBookModel->descriptionAt(index)); + + m_ruleBookModel->insertRow(index + 1); + m_ruleBookModel->setRuleAt(index + 1, newRule); + m_ruleBookModel->setDescriptionAt(index + 1, newDescription); + + updateNeedsSave(); +} + void KCMKWinRules::exportToFile(const QUrl &path, const QList &indexes) { if (indexes.isEmpty()) { diff --git a/kcmkwin/kwinrules/kcmrules.h b/kcmkwin/kwinrules/kcmrules.h index d7a1ae2722..b41c36cede 100644 --- a/kcmkwin/kwinrules/kcmrules.h +++ b/kcmkwin/kwinrules/kcmrules.h @@ -33,6 +33,7 @@ public: Q_INVOKABLE void createRule(); Q_INVOKABLE void removeRule(int index); Q_INVOKABLE void moveRule(int sourceIndex, int destIndex); + Q_INVOKABLE void duplicateRule(int index); Q_INVOKABLE void exportToFile(const QUrl &path, const QList &indexes); Q_INVOKABLE void importFromFile(const QUrl &path); diff --git a/kcmkwin/kwinrules/package/contents/ui/RulesList.qml b/kcmkwin/kwinrules/package/contents/ui/RulesList.qml index c496c11f32..d51ca2e6bb 100644 --- a/kcmkwin/kwinrules/package/contents/ui/RulesList.qml +++ b/kcmkwin/kwinrules/package/contents/ui/RulesList.qml @@ -203,6 +203,15 @@ ScrollViewKCM { } } , + Kirigami.Action { + text: i18n("Duplicate") + iconName: "edit-duplicate" + visible: !exportInfo.visible + onTriggered: { + kcm.duplicateRule(index); + } + } + , Kirigami.Action { text: i18n("Delete") iconName: "entry-delete"