Commit cc63a8af authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[KColorSchemeEditor] Turn Save button into Save As

The button effectively saves the theme to be edited as a new file, so turn it into a "Save As" button that is always shown.

Differential Revision: https://phabricator.kde.org/D18519
parent 44aca277
......@@ -49,7 +49,7 @@ int main(int argc, char* argv[])
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 @@ int main(int argc, char* argv[])
}
SchemeEditorDialog dialog(path);
dialog.setOverwriteOnSave(parser.isSet(overwriteOption));
dialog.setShowApplyOverwriteButton(parser.isSet(overwriteOption));
// FIXME doesn't work :(
const QString attachHandle = parser.value(attachOption);
......
......@@ -31,6 +31,7 @@
#include <KConfigGroup>
#include <KColorScheme>
#include <KMessageBox>
#include <KStandardGuiItem>
#include <KWindowSystem>
#include <KNS3/UploadDialog>
......@@ -53,17 +54,16 @@ SchemeEditorDialog::SchemeEditorDialog(const QString &path, QWidget *parent)
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 @@ void SchemeEditorDialog::init()
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 @@ void SchemeEditorDialog::on_buttonBox_clicked(QAbstractButton *button)
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::on_buttonBox_clicked(QAbstractButton *button)
}
}
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,7 +179,7 @@ void SchemeEditorDialog::saveScheme()
// 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"),
......@@ -185,7 +188,7 @@ void SchemeEditorDialog::saveScheme()
//on don't overwrite, call again the function
if(ret == KMessageBox::No){
this->saveScheme();
this->saveScheme(overwrite);
return;
}
}
......@@ -250,13 +253,11 @@ void SchemeEditorDialog::setUnsavedChanges(bool changes)
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);
}
......
......@@ -41,8 +41,8 @@ public:
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 Q_SLOTS:
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 @@ private:
SchemeEditorEffects *m_disabledTab;
SchemeEditorEffects *m_inactiveTab;
bool m_overwriteOnSave = false;
bool m_showApplyOverwriteButton = false;
};
#endif
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