diff options
-rw-r--r-- | qtmips_gui/mainwindow.cpp | 23 | ||||
-rw-r--r-- | qtmips_gui/mainwindow.h | 2 | ||||
-rw-r--r-- | qtmips_gui/savechangeddialog.h | 2 | ||||
-rw-r--r-- | qtmips_gui/srceditor.cpp | 4 | ||||
-rw-r--r-- | qtmips_gui/srceditor.h | 1 |
5 files changed, 19 insertions, 13 deletions
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index b56fa85..cbee3e5 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -452,15 +452,20 @@ void MainWindow::closeEvent(QCloseEvent *event) { QStringList list; if (modified_file_list(list, true) && !ignore_unsaved) { + event->ignore(); SaveChnagedDialog *dialog = new SaveChnagedDialog(list, this); - connect(dialog, SIGNAL(user_decision(bool,QStringList&)), - this, SLOT(save_exit_or_ignore(bool,QStringList&))); + int id = qMetaTypeId<QStringList>(); + if(!QMetaType::isRegistered(id)) { + qRegisterMetaType<QStringList>(); + } + connect(dialog, SIGNAL(user_decision(bool,QStringList)), + this, SLOT(save_exit_or_ignore(bool,QStringList)), + Qt::QueuedConnection); dialog->open(); - event->ignore(); } } -void MainWindow::save_exit_or_ignore(bool cancel, QStringList &tosavelist) { +void MainWindow::save_exit_or_ignore(bool cancel, QStringList tosavelist) { bool save_unnamed = false; if (cancel) return; @@ -739,7 +744,7 @@ void MainWindow::save_source_as() { dialog->setMinimumSize(QSize(200, 100)); dialog->setAttribute(Qt::WA_DeleteOnClose); connect(dialog, SIGNAL(textValueSelected(QString)), - this, SLOT(src_editor_save_to(QString))); + this, SLOT(src_editor_save_to(QString)), Qt::QueuedConnection); dialog->open(); #endif } @@ -768,6 +773,7 @@ void MainWindow::save_source() { #else QHtml5File::save(current_srceditor->document()->toPlainText().toUtf8(), current_srceditor->filename()); + current_srceditor->setModified(false); #endif } @@ -782,18 +788,13 @@ void MainWindow::close_source_check() { QMessageBox *msgbox = new QMessageBox(this); msgbox->setWindowTitle("Close unsaved source"); msgbox->setText("Close unsaved source."); -#ifndef __EMSCRIPTEN__ msgbox->setInformativeText("Do you want to save your changes?"); msgbox->setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); -#else - msgbox->setInformativeText("Discard your changes or cancel close?"); - msgbox->setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel); -#endif msgbox->setDefaultButton(QMessageBox::Save); msgbox->setMinimumSize(QSize(200, 150)); msgbox->setAttribute(Qt::WA_DeleteOnClose); connect(msgbox, SIGNAL(finished(int)), - this, SLOT(close_source_decided(int))); + this, SLOT(close_source_decided(int)), Qt::QueuedConnection); msgbox->open(); } diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h index 51e154b..13c8295 100644 --- a/qtmips_gui/mainwindow.h +++ b/qtmips_gui/mainwindow.h @@ -119,7 +119,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); + void save_exit_or_ignore(bool cancel, QStringList tosavelist); protected: void closeEvent(QCloseEvent *event); diff --git a/qtmips_gui/savechangeddialog.h b/qtmips_gui/savechangeddialog.h index 34eb5cd..11af95f 100644 --- a/qtmips_gui/savechangeddialog.h +++ b/qtmips_gui/savechangeddialog.h @@ -49,7 +49,7 @@ public: explicit SaveChnagedDialog(QStringList &changedlist, QWidget *parent= nullptr); ~SaveChnagedDialog(); signals: - void user_decision(bool cancel, QStringList &tosavelist); + void user_decision(bool cancel, QStringList tosavelist); private slots: void cancel_clicked(); void ignore_clicked(); diff --git a/qtmips_gui/srceditor.cpp b/qtmips_gui/srceditor.cpp index 298b9f2..2d4a5ec 100644 --- a/qtmips_gui/srceditor.cpp +++ b/qtmips_gui/srceditor.cpp @@ -132,6 +132,10 @@ bool SrcEditor::isModified() const { return document()->isModified(); } +void SrcEditor::setModified(bool val) { + document()->setModified(val); +} + void SrcEditor::setSaveAsRequired(bool val) { saveAsRequiredFl = val; } diff --git a/qtmips_gui/srceditor.h b/qtmips_gui/srceditor.h index 328bfb1..f2426cb 100644 --- a/qtmips_gui/srceditor.h +++ b/qtmips_gui/srceditor.h @@ -56,6 +56,7 @@ public: void setCursorToLine(int ln); void setFileName(QString filename); bool isModified() const; + void setModified(bool val); void setSaveAsRequired(bool val); bool saveAsRequired(); private: |