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"