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
This commit is contained in:
Ismael Asensio 2020-11-27 22:06:30 +01:00
parent 9ab688067a
commit a6c51c5445
3 changed files with 26 additions and 0 deletions

View file

@ -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()) {

View file

@ -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);

View file

@ -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"