mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-07 15:32:13 +00:00
[Fix] Fixed issue #805 - wrong handling of Close
button in Save Project
dialog which had a Discard
meaning
This commit is contained in:
parent
ac4beedbd7
commit
c8f02fd671
@ -423,9 +423,7 @@ bool MainWindow::saveProject(bool quit)
|
|||||||
bool MainWindow::saveProjectAs(bool quit)
|
bool MainWindow::saveProjectAs(bool quit)
|
||||||
{
|
{
|
||||||
SaveProjectDialog dialog(quit, this);
|
SaveProjectDialog dialog(quit, this);
|
||||||
int result = dialog.exec();
|
return SaveProjectDialog::Rejected == dialog.exec();
|
||||||
|
|
||||||
return !quit || result != SaveProjectDialog::Rejected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::refreshOmniBar(const QStringList &flags)
|
void MainWindow::refreshOmniBar(const QStringList &flags)
|
||||||
@ -445,23 +443,22 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||||||
QMessageBox::StandardButton ret = QMessageBox::question(this, APPNAME,
|
QMessageBox::StandardButton ret = QMessageBox::question(this, APPNAME,
|
||||||
tr("Do you really want to exit?\nSave your project before closing!"),
|
tr("Do you really want to exit?\nSave your project before closing!"),
|
||||||
(QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel));
|
(QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel));
|
||||||
if (ret == QMessageBox::Save) {
|
if (ret == QMessageBox::Cancel) {
|
||||||
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 {
|
|
||||||
event->ignore();
|
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()
|
void MainWindow::readSettings()
|
||||||
|
@ -83,7 +83,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @param quit whether to show destructive button in dialog
|
* @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);
|
bool saveProjectAs(bool quit = false);
|
||||||
|
|
||||||
|
@ -61,22 +61,19 @@ void SaveProjectDialog::on_selectProjectsDirButton_clicked()
|
|||||||
|
|
||||||
void SaveProjectDialog::on_buttonBox_clicked(QAbstractButton *button)
|
void SaveProjectDialog::on_buttonBox_clicked(QAbstractButton *button)
|
||||||
{
|
{
|
||||||
switch (ui->buttonBox->buttonRole(button)) {
|
if (QDialogButtonBox::DestructiveRole == ui->buttonBox->buttonRole(button)) {
|
||||||
case QDialogButtonBox::DestructiveRole:
|
QDialog::done(QDialog::Accepted);
|
||||||
QDialog::done(Destructive);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QDialogButtonBox::RejectRole:
|
|
||||||
QDialog::done(Rejected);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveProjectDialog::accept()
|
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;
|
TempConfig tempConfig;
|
||||||
Config()->setDirProjects(ui->projectsDirEdit->text().toUtf8().constData());
|
Config()->setDirProjects(ui->projectsDirEdit->text().toUtf8().constData());
|
||||||
tempConfig.set("dir.projects", Config()->getDirProjects())
|
tempConfig.set("dir.projects", Config()->getDirProjects())
|
||||||
@ -85,18 +82,7 @@ void SaveProjectDialog::accept()
|
|||||||
.set("prj.git", ui->gitCheckBox->isChecked())
|
.set("prj.git", ui->gitCheckBox->isChecked())
|
||||||
.set("prj.zip", ui->zipCheckBox->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);
|
Core()->saveProject(projectName);
|
||||||
|
|
||||||
QDialog::done(Saved);
|
QDialog::accept();
|
||||||
}
|
|
||||||
|
|
||||||
void SaveProjectDialog::reject()
|
|
||||||
{
|
|
||||||
done(Rejected);
|
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,11 @@ class SaveProjectDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Result { Saved, Rejected, Destructive };
|
|
||||||
|
|
||||||
explicit SaveProjectDialog(bool quit, QWidget *parent = nullptr);
|
explicit SaveProjectDialog(bool quit, QWidget *parent = nullptr);
|
||||||
~SaveProjectDialog();
|
~SaveProjectDialog();
|
||||||
|
|
||||||
virtual void accept() override;
|
virtual void accept() override;
|
||||||
virtual void reject() override;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_buttonBox_clicked(QAbstractButton *button);
|
void on_buttonBox_clicked(QAbstractButton *button);
|
||||||
|
Loading…
Reference in New Issue
Block a user