Commit a6c51c54 authored by Ismael Asensio's avatar Ismael Asensio

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
parent 9ab68806
......@@ -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<int> &indexes)
{
if (indexes.isEmpty()) {
......
......@@ -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<int> &indexes);
Q_INVOKABLE void importFromFile(const QUrl &path);
......
......@@ -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"
......
Markdown is supported
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