diff --git a/kcms/colors/editor/kcolorschemeeditor.cpp b/kcms/colors/editor/kcolorschemeeditor.cpp --- a/kcms/colors/editor/kcolorschemeeditor.cpp +++ b/kcms/colors/editor/kcolorschemeeditor.cpp @@ -49,7 +49,7 @@ parser.addPositionalArgument("theme", i18n("Scheme to edit or to use as a base."), QStringLiteral("kcolorschemeeditor ThemeName")); - QCommandLineOption overwriteOption(QStringLiteral("overwrite"), i18n("Overwrite edited theme when saving")); + QCommandLineOption overwriteOption(QStringLiteral("overwrite"), i18n("Show 'Apply' button that saves changes without asking (unlike 'Save As' button)")); parser.addOption(overwriteOption); QCommandLineOption attachOption(QStringLiteral("attach"), i18n("Makes the dialog transient for another application window specified by handle"), QStringLiteral("handle")); @@ -74,7 +74,7 @@ } SchemeEditorDialog dialog(path); - dialog.setOverwriteOnSave(parser.isSet(overwriteOption)); + dialog.setShowApplyOverwriteButton(parser.isSet(overwriteOption)); // FIXME doesn't work :( const QString attachHandle = parser.value(attachOption); diff --git a/kcms/colors/editor/scmeditordialog.h b/kcms/colors/editor/scmeditordialog.h --- a/kcms/colors/editor/scmeditordialog.h +++ b/kcms/colors/editor/scmeditordialog.h @@ -41,8 +41,8 @@ SchemeEditorDialog(const QString &path, QWidget *parent = nullptr); SchemeEditorDialog(KSharedConfigPtr config, QWidget *parent = nullptr); - bool overwriteOnSave() const; - void setOverwriteOnSave(bool overwrite); + bool showApplyOverwriteButton() const; + void setShowApplyOverwriteButton(bool show); Q_SIGNALS: void changed(bool); @@ -59,7 +59,7 @@ private: void init(); /** save the current scheme */ - void saveScheme(); + void saveScheme(bool overwrite); void setUnsavedChanges(bool changes); const QString m_filePath; @@ -73,7 +73,7 @@ SchemeEditorEffects *m_disabledTab; SchemeEditorEffects *m_inactiveTab; - bool m_overwriteOnSave = false; + bool m_showApplyOverwriteButton = false; }; #endif diff --git a/kcms/colors/editor/scmeditordialog.cpp b/kcms/colors/editor/scmeditordialog.cpp --- a/kcms/colors/editor/scmeditordialog.cpp +++ b/kcms/colors/editor/scmeditordialog.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -53,17 +54,16 @@ init(); } -bool SchemeEditorDialog::overwriteOnSave() const +bool SchemeEditorDialog::showApplyOverwriteButton() const { - return m_overwriteOnSave; + return m_showApplyOverwriteButton; } -void SchemeEditorDialog::setOverwriteOnSave(bool overwrite) +void SchemeEditorDialog::setShowApplyOverwriteButton(bool show) { - m_overwriteOnSave = overwrite; + m_showApplyOverwriteButton = show; - buttonBox->button(QDialogButtonBox::Apply)->setVisible(overwrite); - buttonBox->button(QDialogButtonBox::Save)->setVisible(!overwrite); + buttonBox->button(QDialogButtonBox::Apply)->setVisible(show); } void SchemeEditorDialog::init() @@ -86,11 +86,11 @@ connect(m_disabledTab, &SchemeEditorEffects::changed, this, &SchemeEditorDialog::updateTabs); connect(m_inactiveTab, &SchemeEditorEffects::changed, this, &SchemeEditorDialog::updateTabs); - // In overwrite mode we use "Apply", in regular mode "Save" button + // "Apply" is only shown in overwrite mode buttonBox->button(QDialogButtonBox::Apply)->setVisible(false); buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); - buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); + KGuiItem::assign(buttonBox->button(QDialogButtonBox::Save), KStandardGuiItem::saveAs()); buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false); updateTabs(); } @@ -122,10 +122,13 @@ updateTabs(); setUnsavedChanges(false); } - else if (buttonBox->standardButton(button) == QDialogButtonBox::Save - || buttonBox->standardButton(button) == QDialogButtonBox::Apply) + else if (buttonBox->standardButton(button) == QDialogButtonBox::Save) { - saveScheme(); + saveScheme(false /*overwrite*/); + } + else if (buttonBox->standardButton(button) == QDialogButtonBox::Apply) + { + saveScheme(true /*overwrite*/); } else if (buttonBox->standardButton(button) == QDialogButtonBox::Close) { @@ -144,12 +147,12 @@ } } -void SchemeEditorDialog::saveScheme() +void SchemeEditorDialog::saveScheme(bool overwrite) { QString name = m_schemeName; // prompt for the name to save as - if (!m_overwriteOnSave) { + if (!overwrite) { bool ok; name = QInputDialog::getText(this, i18n("Save Color Scheme"), i18n("&Enter a name for the color scheme:"), QLineEdit::Normal, m_schemeName, &ok); @@ -176,16 +179,16 @@ // or if we can overwrite it if it exists if (path.isEmpty() || !file.exists() || canWrite) { - if(canWrite && !m_overwriteOnSave){ + if(canWrite && !overwrite){ int ret = KMessageBox::questionYesNo(this, i18n("A color scheme with that name already exists.\nDo you want to overwrite it?"), i18n("Save Color Scheme"), KStandardGuiItem::overwrite(), KStandardGuiItem::cancel()); //on don't overwrite, call again the function if(ret == KMessageBox::No){ - this->saveScheme(); + this->saveScheme(overwrite); return; } } @@ -250,13 +253,11 @@ m_unsavedChanges = changes; if (changes) { - buttonBox->button(QDialogButtonBox::Save)->setEnabled(true); buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true); buttonBox->button(QDialogButtonBox::Reset)->setEnabled(true); } else { - buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false); }