diff options
-rw-r--r-- | qtmips_gui/mainwindow.cpp | 23 | ||||
-rw-r--r-- | qtmips_gui/mainwindow.h | 4 |
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 |