Query user to save unsaved files when exiting
MODIFY
external/VSRTL
external/VSRTL
-Subproject commit f24478d8123f65bc90a5b97a14ac81a7e8a722a7
+Subproject commit 91d4203a869a4f8e316e3c925b3ede5052b3ff2e

MODIFY
src/edittab.cpp
src/edittab.cpp
@@ -32,6 +32,8 @@ EditTab::EditTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent)
m_assembler = new Assembler();
connect(m_ui->assemblyedit, &CodeEditor::textChanged, this, &EditTab::assemble);
+
+ enableEditor();
}
void EditTab::loadFile(const LoadFileParams& fileParams) {
@@ -116,7 +118,8 @@ void EditTab::enableAssemblyInput() {
m_activeProgram = Program();
m_ui->binaryedit->clear();
enableEditor();
- emit editorStateChanged(true);
+ m_editorEnabled = true;
+ emit editorStateChanged(m_editorEnabled);
}
void EditTab::setDisassemblerText() {
@@ -139,7 +142,8 @@ void EditTab::disableEditor() {
disconnect(m_ui->assemblyedit, &CodeEditor::textChanged, this, &EditTab::assemble);
m_ui->editorStackedWidget->setCurrentIndex(1);
clearAssemblyEditor();
- emit editorStateChanged(false);
+ m_editorEnabled = false;
+ emit editorStateChanged(m_editorEnabled);
}
void EditTab::on_disassembledViewButton_toggled() {

MODIFY
src/edittab.h
src/edittab.h
@@ -31,6 +31,8 @@ public:
void newProgram();
void clearAssemblyEditor();
+ bool isEditorEnabled() const { return m_editorEnabled; }
+
const QByteArray& getBinaryData();
void loadFile(const LoadFileParams&);
@@ -66,5 +68,7 @@ private:
LoadFileParams m_loadedFile;
Program m_activeProgram;
+
+ bool m_editorEnabled = true;
};
} // namespace Ripes

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -145,8 +145,13 @@ void MainWindow::setupExamplesMenu(QMenu* parent) {
}
}
-void MainWindow::exit() {
- close();
+void MainWindow::closeEvent(QCloseEvent* event) {
+ if (m_editTab->isEditorEnabled() && !m_editTab->getAssemblyText().isEmpty()) {
+ if (QMessageBox::question(this, "Ripes", "Save current program before exiting?") == QMessageBox::Yes) {
+ saveFilesTriggered();
+ }
+ }
+ QMainWindow::closeEvent(event);
}
void MainWindow::loadFileTriggered() {
@@ -193,9 +198,10 @@ void writeBinaryFile(QFile& file, const QByteArray& data) {
void MainWindow::saveFilesTriggered() {
SaveDialog diag;
if (!m_hasSavedFile) {
- diag.exec();
+ if (diag.exec()) {
m_hasSavedFile = true;
}
+ }
if (!diag.assemblyPath().isEmpty()) {
QFile file(diag.assemblyPath());

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -27,8 +27,9 @@ public:
explicit MainWindow(QWidget* parent = nullptr);
~MainWindow() override;
+ void closeEvent(QCloseEvent* event) override;
+
private slots:
- void exit();
void wiki();
void version();

Query user to save unsaved files when exiting