[Fix] Fixed issue #805 - wrong handling of Close button in Save Project dialog which had a Discard meaning

This commit is contained in:
a1ext 2018-10-12 02:24:05 +03:00
parent ac4beedbd7
commit c8f02fd671
No known key found for this signature in database
GPG Key ID: 11A5D9A6B4C28D5B
4 changed files with 25 additions and 44 deletions

View File

@ -423,9 +423,7 @@ bool MainWindow::saveProject(bool quit)
bool MainWindow::saveProjectAs(bool quit)
{
SaveProjectDialog dialog(quit, this);
int result = dialog.exec();
return !quit || result != SaveProjectDialog::Rejected;
return SaveProjectDialog::Rejected == dialog.exec();
}
void MainWindow::refreshOmniBar(const QStringList &flags)
@ -445,23 +443,22 @@ void MainWindow::closeEvent(QCloseEvent *event)
QMessageBox::StandardButton ret = QMessageBox::question(this, APPNAME,
tr("Do you really want to exit?\nSave your project before closing!"),
(QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel));
if (ret == QMessageBox::Save) {
if (saveProject(true) && !core->currentlyDebugging) {
saveSettings();
} else if (core->currentlyDebugging) {
core->stopDebug();
}
QMainWindow::closeEvent(event);
} else if (ret == QMessageBox::Discard) {
if (!core->currentlyDebugging) {
saveSettings();
} else if (core->currentlyDebugging) {
core->stopDebug();
}
QMainWindow::closeEvent(event);
} else {
if (ret == QMessageBox::Cancel) {
event->ignore();
return;
}
if (ret == QMessageBox::Save && !saveProject(true)) {
event->ignore();
return;
}
if (!core->currentlyDebugging) {
saveSettings();
} else {
core->stopDebug();
}
QMainWindow::closeEvent(event);
}
void MainWindow::readSettings()

View File

@ -83,7 +83,7 @@ public:
/*!
* @param quit whether to show destructive button in dialog
* @return if quit is true, false if the application should not close
* @return false if the application should not close
*/
bool saveProjectAs(bool quit = false);

View File

@ -61,22 +61,19 @@ void SaveProjectDialog::on_selectProjectsDirButton_clicked()
void SaveProjectDialog::on_buttonBox_clicked(QAbstractButton *button)
{
switch (ui->buttonBox->buttonRole(button)) {
case QDialogButtonBox::DestructiveRole:
QDialog::done(Destructive);
break;
case QDialogButtonBox::RejectRole:
QDialog::done(Rejected);
break;
default:
break;
if (QDialogButtonBox::DestructiveRole == ui->buttonBox->buttonRole(button)) {
QDialog::done(QDialog::Accepted);
}
}
void SaveProjectDialog::accept()
{
const QString& projectName = ui->nameEdit->text().trimmed();
if (!CutterCore::isProjectNameValid(projectName)) {
QMessageBox::critical(this, tr("Save project"), tr("Invalid project name."));
ui->nameEdit->setFocus();
return;
}
TempConfig tempConfig;
Config()->setDirProjects(ui->projectsDirEdit->text().toUtf8().constData());
tempConfig.set("dir.projects", Config()->getDirProjects())
@ -85,18 +82,7 @@ void SaveProjectDialog::accept()
.set("prj.git", ui->gitCheckBox->isChecked())
.set("prj.zip", ui->zipCheckBox->isChecked());
QString projectName = ui->nameEdit->text().trimmed();
if (!CutterCore::isProjectNameValid(projectName)) {
QMessageBox::critical(this, tr("Save project"), tr("Invalid project name."));
return;
}
Core()->saveProject(projectName);
QDialog::done(Saved);
}
void SaveProjectDialog::reject()
{
done(Rejected);
QDialog::accept();
}

View File

@ -15,13 +15,11 @@ class SaveProjectDialog : public QDialog
Q_OBJECT
public:
enum Result { Saved, Rejected, Destructive };
explicit SaveProjectDialog(bool quit, QWidget *parent = nullptr);
~SaveProjectDialog();
virtual void accept() override;
virtual void reject() override;
private slots:
void on_buttonBox_clicked(QAbstractButton *button);