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 <QKeyEvent>
#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>
// KDE
@ -63,7 +64,7 @@ KMessageWidget *GenericDialog::initMessageWidget()
return messagewidget;
}
int GenericDialog::saveChangesConfirmation(const QString &text)
int GenericDialog::saveChangesConfirmation(const QString &text, QString applyBtnText)
{
auto msg = new QMessageBox(this);
msg->setIcon(QMessageBox::Warning);
@ -75,8 +76,17 @@ int GenericDialog::saveChangesConfirmation(const QString &text)
msg->setText(text);
}
msg->setStandardButtons(QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel);
msg->setDefaultButton(QMessageBox::Apply);
if (applyBtnText.isEmpty()) {
msg->setStandardButtons(QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel);
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);
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 hideInlineMessage();
int saveChangesConfirmation(const QString &text);
int saveChangesConfirmation(const QString &text, QString applyBtnText = "");
private slots:
KMessageWidget *initMessageWidget();

@ -107,6 +107,7 @@ void ViewsHandler::init()
connect(this, &ViewsHandler::currentLayoutChanged, this, &ViewsHandler::reload);
reload();
m_lastConfirmedLayoutIndex =m_ui->layoutsCmb->currentIndex();
emit currentLayoutChanged();
@ -262,17 +263,25 @@ void ViewsHandler::removeSelectedView()
void ViewsHandler::onCurrentLayoutIndexChanged(int row)
{
bool switchtonewlayout{true};
if (hasChangedData()) {
int result = saveChanges();
if (result == QMessageBox::Apply) {
save();
} else if (result == QMessageBox::Discard) {
//do nothing
} else if (result == QMessageBox::Cancel) {
switchtonewlayout = false;
bool switchtonewlayout{false};
if (m_lastConfirmedLayoutIndex != row) {
if (hasChangedData()) { //new layout was chosen but there are changes
int result = saveChangesConfirmation();
if (result == QMessageBox::Apply) {
switchtonewlayout = true;
m_lastConfirmedLayoutIndex = row;
save();
} else if (result == QMessageBox::Discard) {
switchtonewlayout = true;
m_lastConfirmedLayoutIndex = row;
} else if (result == QMessageBox::Cancel) {
//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()));
}
int ViewsHandler::saveChanges()
int ViewsHandler::saveChangesConfirmation()
{
if (hasChangedData()) {
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;

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

Loading…
Cancel
Save