Store save file config state in settings
MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -98,7 +98,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
// setup and connect widgets
connect(editTab, &EditTab::programChanged, ProcessorHandler::get(), &ProcessorHandler::loadProgram);
- connect(editTab, &EditTab::editorStateChanged, [=] { this->m_hasSavedFile = false; });
+ connect(editTab, &EditTab::editorStateChanged, [=] { RipesSettings::setValue(RIPES_SETTING_HAS_SAVEFILE, false); });
connect(ProcessorHandler::get(), &ProcessorHandler::exit, processorTab, &ProcessorTab::processorFinished);
connect(ProcessorHandler::get(), &ProcessorHandler::runFinished, processorTab, &ProcessorTab::runFinished);
@@ -222,7 +222,7 @@ void MainWindow::setupExamplesMenu(QMenu* parent) {
parms.filepath = QString(":/examples/assembly/") + fileName;
parms.type = SourceType::Assembly;
static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->loadExternalFile(parms);
- m_hasSavedFile = false;
+ RipesSettings::setValue(RIPES_SETTING_HAS_SAVEFILE, false);
});
}
}
@@ -236,7 +236,7 @@ void MainWindow::setupExamplesMenu(QMenu* parent) {
parms.filepath = QString(":/examples/C/") + fileName;
parms.type = SourceType::C;
static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->loadExternalFile(parms);
- m_hasSavedFile = false;
+ RipesSettings::setValue(RIPES_SETTING_HAS_SAVEFILE, false);
});
}
}
@@ -258,7 +258,7 @@ void MainWindow::setupExamplesMenu(QMenu* parent) {
parms.filepath = tmpELFFile->fileName();
parms.type = SourceType::ExternalELF;
static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->loadExternalFile(parms);
- m_hasSavedFile = false;
+ RipesSettings::setValue(RIPES_SETTING_HAS_SAVEFILE, false);
tmpELFFile->remove();
});
}
@@ -295,7 +295,7 @@ void MainWindow::loadFileTriggered() {
return;
static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->loadExternalFile(diag.getParams());
- m_hasSavedFile = false;
+ RipesSettings::setValue(RIPES_SETTING_HAS_SAVEFILE, false);
}
void MainWindow::wiki() {
@@ -328,7 +328,7 @@ void writeBinaryFile(QFile& file, const QByteArray& data) {
void MainWindow::saveFilesTriggered() {
SaveDialog diag;
- if (!m_hasSavedFile) {
+ if (!RipesSettings::value(RIPES_SETTING_HAS_SAVEFILE).toBool()) {
saveFilesAsTriggered();
return;
}
@@ -352,7 +352,7 @@ void MainWindow::saveFilesAsTriggered() {
if (ret == QDialog::Rejected) {
return;
}
- m_hasSavedFile = true;
+ RipesSettings::setValue(RIPES_SETTING_HAS_SAVEFILE, true);
saveFilesTriggered();
}
@@ -365,14 +365,15 @@ void MainWindow::newProgramTriggered() {
QMessageBox mbox;
mbox.setWindowTitle("New Program...");
mbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
- if (!static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->getAssemblyText().isEmpty() || m_hasSavedFile) {
+ if (!static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->getAssemblyText().isEmpty() ||
+ RipesSettings::value(RIPES_SETTING_HAS_SAVEFILE).toBool()) {
// User wrote a program but did not save it to a file yet
mbox.setText("Save program before creating new file?");
auto ret = mbox.exec();
switch (ret) {
case QMessageBox::Yes: {
saveFilesTriggered();
- if (!m_hasSavedFile) {
+ if (!RipesSettings::value(RIPES_SETTING_HAS_SAVEFILE).toBool()) {
// User must have rejected the save file dialog
return;
}
@@ -386,7 +387,7 @@ void MainWindow::newProgramTriggered() {
}
}
}
- m_hasSavedFile = false;
+ RipesSettings::setValue(RIPES_SETTING_HAS_SAVEFILE, false);
static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->newProgram();
}

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -63,8 +63,6 @@ private:
QActionGroup* m_binaryStoreAction;
QToolBar* m_toolbar = nullptr;
- bool m_hasSavedFile = false;
-
// Tabs
QStackedWidget* m_stackedTabs = nullptr;
std::map<TabIndex, TabWidgets> m_tabWidgets;

MODIFY
src/ripessettings.cpp
src/ripessettings.cpp
@@ -51,7 +51,12 @@ const std::map<QString, QVariant> s_defaultSettings = {
{RIPES_SETTING_SOURCECODE, ""},
{RIPES_SETTING_DARKMODE, false},
{RIPES_SETTING_INPUT_TYPE, static_cast<unsigned>(SourceType::Assembly)},
- {RIPES_SETTING_AUTOCLOCK_INTERVAL, 100}};
+ {RIPES_SETTING_AUTOCLOCK_INTERVAL, 100},
+
+ {RIPES_SETTING_HAS_SAVEFILE, false},
+ {RIPES_SETTING_SAVEPATH, ""},
+ {RIPES_SETTING_SAVE_ASSEMBLY, true},
+ {RIPES_SETTING_SAVE_BINARY, false}};
void SettingObserver::setValue(const QVariant& v) {
QSettings settings;

MODIFY
src/ripessettings.h
src/ripessettings.h
@@ -45,6 +45,11 @@ namespace Ripes {
#define RIPES_SETTING_DARKMODE ("darkmode")
#define RIPES_SETTING_AUTOCLOCK_INTERVAL ("autoclock_interval")
+#define RIPES_SETTING_HAS_SAVEFILE ("has_savefile")
+#define RIPES_SETTING_SAVEPATH ("savepath")
+#define RIPES_SETTING_SAVE_ASSEMBLY ("save_assembly")
+#define RIPES_SETTING_SAVE_BINARY ("save_binary")
+
// ============= Definitions of all default settings within Ripes ==============
const extern std::map<QString, QVariant> s_defaultSettings;

MODIFY
src/savedialog.cpp
src/savedialog.cpp
namespace Ripes {
-QString SaveDialog::m_path = QString();
-bool SaveDialog::m_saveAssembly = true;
-bool SaveDialog::m_saveBinary = false;
-
SaveDialog::SaveDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::SaveDialog) {
m_ui->setupUi(this);
@@ -20,16 +16,16 @@ SaveDialog::SaveDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::SaveDial
connect(m_ui->saveBinary, &QCheckBox::toggled, this, &SaveDialog::pathChanged);
connect(m_ui->saveAssembly, &QCheckBox::toggled, this, &SaveDialog::pathChanged);
- m_ui->saveAssembly->setChecked(m_saveAssembly);
- m_ui->saveBinary->setChecked(m_saveBinary);
- m_ui->filePath->setText(m_path);
+ m_ui->saveAssembly->setChecked(RipesSettings::value(RIPES_SETTING_SAVE_ASSEMBLY).toBool());
+ m_ui->saveBinary->setChecked(RipesSettings::value(RIPES_SETTING_SAVE_BINARY).toBool());
+ m_ui->filePath->setText(RipesSettings::value(RIPES_SETTING_SAVEPATH).toString());
pathChanged();
}
void SaveDialog::accept() {
- m_saveAssembly = m_ui->saveAssembly->isChecked();
- m_saveBinary = m_ui->saveBinary->isChecked();
- m_path = m_ui->filePath->text();
+ RipesSettings::setValue(RIPES_SETTING_SAVE_ASSEMBLY, m_ui->saveAssembly->isChecked());
+ RipesSettings::setValue(RIPES_SETTING_SAVE_BINARY, m_ui->saveBinary->isChecked());
+ RipesSettings::setValue(RIPES_SETTING_SAVEPATH, m_ui->filePath->text());
QDialog::accept();
}

MODIFY
src/savedialog.h
src/savedialog.h
#pragma once
#include <QDialog>
+#include "ripessettings.h"
namespace Ripes {
@@ -15,9 +16,13 @@ public:
explicit SaveDialog(QWidget* parent = nullptr);
~SaveDialog();
- static const QString& getPath() { return m_path; }
- static QString assemblyPath() { return m_saveAssembly ? m_path + ".s" : QString(); }
- static QString binaryPath() { return m_saveBinary ? m_path + ".bin" : QString(); }
+ static QString getPath() { return RipesSettings::value(RIPES_SETTING_SAVEPATH).toString(); }
+ static QString assemblyPath() {
+ return RipesSettings::value(RIPES_SETTING_SAVE_ASSEMBLY).toBool() ? getPath() + ".s" : QString();
+ }
+ static QString binaryPath() {
+ return RipesSettings::value(RIPES_SETTING_SAVE_BINARY).toBool() ? getPath() + ".bin" : QString();
+ }
void accept() override;
@@ -26,10 +31,6 @@ private:
void pathChanged();
Ui::SaveDialog* m_ui = nullptr;
-
- static QString m_path;
- static bool m_saveAssembly;
- static bool m_saveBinary;
};
} // namespace Ripes

Store save file config state in settings