viewsdialog:fix save confirmation dialog behavior

--apply also consistent "Apply Now" text for confirmation
dialog
work/spdx
Michail Vourlakos 4 years ago
parent a0bcd9503d
commit 447c08e95e

@ -24,6 +24,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
// KDE // KDE
@ -63,7 +64,7 @@ KMessageWidget *GenericDialog::initMessageWidget()
return messagewidget; return messagewidget;
} }
int GenericDialog::saveChangesConfirmation(const QString &text) int GenericDialog::saveChangesConfirmation(const QString &text, QString applyBtnText)
{ {
auto msg = new QMessageBox(this); auto msg = new QMessageBox(this);
msg->setIcon(QMessageBox::Warning); msg->setIcon(QMessageBox::Warning);
@ -75,8 +76,17 @@ int GenericDialog::saveChangesConfirmation(const QString &text)
msg->setText(text); msg->setText(text);
} }
if (applyBtnText.isEmpty()) {
msg->setStandardButtons(QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel); msg->setStandardButtons(QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel);
msg->setDefaultButton(QMessageBox::Apply); msg->setDefaultButton(QMessageBox::Apply);
} else if (!applyBtnText.isEmpty()) {
msg->setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel);
QPushButton *applyCustomBtn = new QPushButton(msg);
applyCustomBtn->setText(applyBtnText);
applyCustomBtn->setIcon(QIcon::fromTheme("dialog-yes"));
msg->addButton(applyCustomBtn, QMessageBox::AcceptRole);
msg->setDefaultButton(applyCustomBtn);
}
connect(msg, &QFileDialog::finished, msg, &QFileDialog::deleteLater); connect(msg, &QFileDialog::finished, msg, &QFileDialog::deleteLater);
return msg->exec(); return msg->exec();

@ -46,7 +46,7 @@ public:
void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const bool &isPersistent = false, QList<QAction *> actions = QList<QAction *>()); void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const bool &isPersistent = false, QList<QAction *> actions = QList<QAction *>());
void hideInlineMessage(); void hideInlineMessage();
int saveChangesConfirmation(const QString &text); int saveChangesConfirmation(const QString &text, QString applyBtnText = "");
private slots: private slots:
KMessageWidget *initMessageWidget(); KMessageWidget *initMessageWidget();

@ -107,6 +107,7 @@ void ViewsHandler::init()
connect(this, &ViewsHandler::currentLayoutChanged, this, &ViewsHandler::reload); connect(this, &ViewsHandler::currentLayoutChanged, this, &ViewsHandler::reload);
reload(); reload();
m_lastConfirmedLayoutIndex =m_ui->layoutsCmb->currentIndex();
emit currentLayoutChanged(); emit currentLayoutChanged();
@ -262,17 +263,25 @@ void ViewsHandler::removeSelectedView()
void ViewsHandler::onCurrentLayoutIndexChanged(int row) void ViewsHandler::onCurrentLayoutIndexChanged(int row)
{ {
bool switchtonewlayout{true}; bool switchtonewlayout{false};
if (hasChangedData()) { if (m_lastConfirmedLayoutIndex != row) {
int result = saveChanges(); if (hasChangedData()) { //new layout was chosen but there are changes
int result = saveChangesConfirmation();
if (result == QMessageBox::Apply) { if (result == QMessageBox::Apply) {
switchtonewlayout = true;
m_lastConfirmedLayoutIndex = row;
save(); save();
} else if (result == QMessageBox::Discard) { } else if (result == QMessageBox::Discard) {
//do nothing switchtonewlayout = true;
m_lastConfirmedLayoutIndex = row;
} else if (result == QMessageBox::Cancel) { } else if (result == QMessageBox::Cancel) {
switchtonewlayout = false; //do nothing
}
} else { //new layout was chosen and there are no changes
switchtonewlayout = true;
m_lastConfirmedLayoutIndex = row;
} }
} }
@ -292,13 +301,13 @@ void ViewsHandler::updateWindowTitle()
m_dialog->setWindowTitle(i18nc("<layout name> Docks/Panels","%0 Docks/Panels").arg(m_ui->layoutsCmb->currentText())); m_dialog->setWindowTitle(i18nc("<layout name> Docks/Panels","%0 Docks/Panels").arg(m_ui->layoutsCmb->currentText()));
} }
int ViewsHandler::saveChanges() int ViewsHandler::saveChangesConfirmation()
{ {
if (hasChangedData()) { if (hasChangedData()) {
QString layoutName = o_data.name; QString layoutName = o_data.name;
QString saveChangesText = i18n("The settings of <b>%0</b> layout have changed. Do you want to apply the changes or discard them?").arg(layoutName); QString saveChangesText = i18n("The settings of <b>%0</b> layout have changed. Do you want to apply the changes now or discard them?").arg(layoutName);
return m_dialog->saveChangesConfirmation(saveChangesText); return m_dialog->saveChangesConfirmation(saveChangesText, i18n("Apply Now"));
} }
return QMessageBox::Cancel; return QMessageBox::Cancel;

@ -99,7 +99,7 @@ private:
void loadLayout(const Latte::Data::Layout &data); void loadLayout(const Latte::Data::Layout &data);
int saveChanges(); int saveChangesConfirmation();
private: private:
Dialog::ViewsDialog *m_dialog{nullptr}; Dialog::ViewsDialog *m_dialog{nullptr};
@ -110,6 +110,8 @@ private:
Latte::Data::Layout o_data; Latte::Data::Layout o_data;
int m_lastConfirmedLayoutIndex{-1};
//! Actions //! Actions
QAction *m_newViewAction{nullptr}; QAction *m_newViewAction{nullptr};
QAction *m_removeViewAction{nullptr}; QAction *m_removeViewAction{nullptr};

Loading…
Cancel
Save