aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-08-19 20:01:38 +0200
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-08-19 20:01:38 +0200
commitd8e92264f50553a5cae9ac70150d22584067accf (patch)
treeec5daebd03cfb4adfd173a53922971ab1e09fff8 /qtmips_gui
parentaa8aef6ea9bc2823119ca06936aff9828c75d83e (diff)
downloadqtmips-d8e92264f50553a5cae9ac70150d22584067accf.tar.gz
qtmips-d8e92264f50553a5cae9ac70150d22584067accf.tar.bz2
qtmips-d8e92264f50553a5cae9ac70150d22584067accf.zip
Ask to save modified files on exit.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui')
-rw-r--r--qtmips_gui/mainwindow.cpp23
-rw-r--r--qtmips_gui/mainwindow.h4
2 files changed, 25 insertions, 2 deletions
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp
index db9acce..932a6be 100644
--- a/qtmips_gui/mainwindow.cpp
+++ b/qtmips_gui/mainwindow.cpp
@@ -60,6 +60,7 @@
#endif
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
+ ignore_unsaved = false;
machine = nullptr;
corescene = nullptr;
current_srceditor = nullptr;
@@ -431,10 +432,30 @@ void MainWindow::view_mnemonics_registers(bool enable) {
program->request_update_all();
}
-void MainWindow::closeEvent(QCloseEvent *event __attribute__((unused))) {
+void MainWindow::closeEvent(QCloseEvent *event) {
settings->setValue("windowGeometry", saveGeometry());
settings->setValue("windowState", saveState());
settings->sync();
+
+ QStringList list;
+ if (modified_file_list(list) && !ignore_unsaved) {
+ SaveChnagedDialog *dialog = new SaveChnagedDialog(list, this);
+ connect(dialog, SIGNAL(user_decision(bool,QStringList&)),
+ this, SLOT(save_exit_or_ignore(bool,QStringList&)));
+ dialog->open();
+ event->ignore();
+ }
+}
+
+void MainWindow::save_exit_or_ignore(bool cancel, QStringList &tosavelist) {
+ if (cancel)
+ return;
+ for (const auto &fname : tosavelist) {
+ SrcEditor *editor = source_editor_for_file(fname, false);
+ editor->saveFile();
+ }
+ ignore_unsaved = true;
+ close();
}
void MainWindow::show_dockwidget(QDockWidget *dw, Qt::DockWidgetArea area) {
diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h
index 09c82fd..1a854e6 100644
--- a/qtmips_gui/mainwindow.h
+++ b/qtmips_gui/mainwindow.h
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0+
/*******************************************************************************
* QtMips - MIPS 32-bit Architecture Subset Simulator
*
@@ -116,6 +116,7 @@ public slots:
void tab_widget_destroyed(QObject *obj);
void view_mnemonics_registers(bool enable);
void message_selected(messagetype::Type type, QString file, int line, int column, QString text, QString hint);
+ void save_exit_or_ignore(bool cancel, QStringList &tosavelist);
protected:
void closeEvent(QCloseEvent *event);
@@ -158,6 +159,7 @@ private:
bool modified_file_list(QStringList &list);
SrcEditor *source_editor_for_file(QString filename, bool open);
QPointer<ExtProcess> build_process;
+ bool ignore_unsaved;
};
#endif // MAINWINDOW_H