Store input type and source code between program invocations
MODIFY
src/assembler/program.h
src/assembler/program.h
#include <QByteArray>
#include <QMap>
+#include <QMetaType>
#include <QString>
#include <vector>
namespace Ripes {
-enum class SourceType {
+enum SourceType {
/** Assembly text */
Assembly,
/** C text */
@@ -80,3 +81,5 @@ struct Program {
};
} // namespace Ripes
+
+Q_DECLARE_METATYPE(Ripes::SourceType);

MODIFY
src/edittab.cpp
src/edittab.cpp
@@ -75,6 +75,27 @@ EditTab::EditTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent)
onProcessorChanged();
sourceTypeChanged();
enableEditor();
+
+ // State preservation
+ connect(RipesSettings::getObserver(RIPES_GLOBALSIGNAL_QUIT), &SettingObserver::modified, [=] {
+ RipesSettings::setValue(RIPES_SETTING_SOURCECODE, m_ui->codeEditor->document()->toPlainText());
+ RipesSettings::setValue(RIPES_SETTING_INPUT_TYPE, m_currentSourceType);
+ });
+
+ switch (RipesSettings::value(RIPES_SETTING_INPUT_TYPE).toUInt()) {
+ case SourceType::Assembly: {
+ m_ui->setAssemblyInput->toggle();
+ break;
+ }
+ case SourceType::C: {
+ m_ui->setCInput->toggle();
+ break;
+ }
+ default:
+ break;
+ }
+
+ m_ui->codeEditor->document()->setPlainText(RipesSettings::value(RIPES_SETTING_SOURCECODE).toString());
}
void EditTab::showSymbolNavigator() {

MODIFY
src/loaddialog.cpp
src/loaddialog.cpp
#include "elfinfostrings.h"
#include "elfio/elfio.hpp"
-#include "processorhandler.h"
#include "assembler/program.h"
+#include "processorhandler.h"
#include "radix.h"
#include <QButtonGroup>
@@ -27,7 +27,7 @@ LoadDialog::LoadDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::LoadDial
m_fileTypeButtons = new QButtonGroup(this);
m_fileTypeButtons->addButton(m_ui->sourceRadioButton, TypeButtonID::Source);
- m_fileTypeButtons->addButton(m_ui->binaryRadioButton, TypeButtonID::FlatBinary);
+ m_fileTypeButtons->addButton(m_ui->binaryRadioButton, TypeButtonID::Flatbinary);
m_fileTypeButtons->addButton(m_ui->elfRadioButton, TypeButtonID::ELF);
connect(m_fileTypeButtons, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this,
@@ -66,8 +66,8 @@ void LoadDialog::inputTypeChanged() {
updateSourcePageState();
break;
}
- case TypeButtonID::FlatBinary: {
- m_currentType = TypeButtonID::FlatBinary;
+ case TypeButtonID::Flatbinary: {
+ m_currentType = TypeButtonID::Flatbinary;
updateBinaryPageState();
break;
}
@@ -89,7 +89,7 @@ void LoadDialog::openFileButtonTriggered() {
filter = "Source files [*.s, *.as, *.asm, *.c] (*.s *.as *.asm *.c);; All files (*.*)";
break;
}
- case TypeButtonID::FlatBinary: {
+ case TypeButtonID::Flatbinary: {
title = "Open binary file";
filter = "All files (*)";
break;
@@ -201,7 +201,7 @@ bool LoadDialog::fileTypeValidate(const QFile& file) {
switch (m_currentType) {
case TypeButtonID::Source:
return validateSourceFile(file);
- case TypeButtonID::FlatBinary:
+ case TypeButtonID::Flatbinary:
return validateBinaryFile(file);
case TypeButtonID::ELF:
auto info = validateELFFile(file);
@@ -239,7 +239,7 @@ void LoadDialog::accept() {
// Set source type based on file extension
m_params.type = m_params.filepath.endsWith(".c") ? SourceType::C : SourceType::Assembly;
break;
- case TypeButtonID::FlatBinary:
+ case TypeButtonID::Flatbinary:
m_params.type = SourceType::FlatBinary;
break;
case TypeButtonID::ELF:

MODIFY
src/loaddialog.h
src/loaddialog.h
@@ -50,7 +50,7 @@ private slots:
void loadFileError(const QString& filename);
private:
- enum TypeButtonID { Source, FlatBinary, ELF };
+ enum TypeButtonID { Source, Flatbinary, ELF };
static TypeButtonID s_typeIndex;
static QString s_filePath;

MODIFY
src/ripessettings.cpp
src/ripessettings.cpp
#include "ripessettings.h"
+#include "assembler/program.h"
#include <QCoreApplication>
#include <map>
namespace Ripes {
+// ============= Definitions of all default settings within Ripes ==============
+const std::map<QString, QVariant> s_defaultSettings = {
+ // User-modifyable settings
+ {RIPES_SETTING_REWINDSTACKSIZE, 100},
+ {RIPES_SETTING_CCPATH, ""},
+ {RIPES_SETTING_CCARGS, "-O0"},
+ {RIPES_SETTING_LDARGS, "-static-libgcc -lm"}, // Ensure statically linked executable + link with math library
+ {RIPES_SETTING_CONSOLEECHO, "true"},
+ {RIPES_SETTING_CONSOLEBG, QColor(Qt::white)},
+ {RIPES_SETTING_CONSOLEFONTCOLOR, QColor(Qt::black)},
+ {RIPES_SETTING_CONSOLEFONT, QVariant() /* Let Console define its own default font */},
+ {RIPES_SETTING_CONSOLEFONT, QColor(Qt::black)},
+ {RIPES_SETTING_INDENTAMT, 4},
+
+ {RIPES_SETTING_ASSEMBLER_TEXTSTART, 0x0},
+ {RIPES_SETTING_ASSEMBLER_DATASTART, 0x10000000},
+ {RIPES_SETTING_ASSEMBLER_BSSSTART, 0x11000000},
+ {RIPES_SETTING_PERIPHERALS_START, static_cast<unsigned>(0xF0000000)},
+
+ // Program state preserving settings
+ {RIPES_GLOBALSIGNAL_QUIT, 0},
+ {RIPES_SETTING_SETTING_TAB, 0},
+ {RIPES_SETTING_VIEW_ZOOM, 250},
+ {RIPES_SETTING_PERIPHERAL_SETTINGS, ""},
+ {RIPES_SETTING_PROCESSOR_ID, QVariant() /* Let processorhandler define default */},
+ {RIPES_SETTING_PROCESSOR_LAYOUT_ID, 0},
+ {RIPES_SETTING_FOLLOW_EXEC, "true"},
+ {RIPES_SETTING_SOURCECODE, ""},
+ {RIPES_SETTING_DARKMODE, false},
+ {RIPES_SETTING_INPUT_TYPE, static_cast<unsigned>(SourceType::Assembly)}};
+
void SettingObserver::setValue(const QVariant& v) {
QSettings settings;
Q_ASSERT(settings.contains(m_key));

MODIFY
src/ripessettings.h
src/ripessettings.h
@@ -36,36 +36,12 @@ namespace Ripes {
#define RIPES_SETTING_PROCESSOR_ID ("processor_id")
#define RIPES_SETTING_PROCESSOR_LAYOUT_ID ("processor_layout_id")
#define RIPES_SETTING_FOLLOW_EXEC ("follow_execution")
+#define RIPES_SETTING_INPUT_TYPE ("input_type")
+#define RIPES_SETTING_SOURCECODE ("sourcecode")
#define RIPES_SETTING_DARKMODE ("darkmode")
// ============= Definitions of all default settings within Ripes ==============
-const static std::map<QString, QVariant> s_defaultSettings = {
- // User-modifyable settings
- {RIPES_SETTING_REWINDSTACKSIZE, 100},
- {RIPES_SETTING_CCPATH, ""},
- {RIPES_SETTING_CCARGS, "-O0"},
- {RIPES_SETTING_LDARGS, "-static-libgcc -lm"}, // Ensure statically linked executable + link with math library
- {RIPES_SETTING_CONSOLEECHO, "true"},
- {RIPES_SETTING_CONSOLEBG, QColor(Qt::white)},
- {RIPES_SETTING_CONSOLEFONTCOLOR, QColor(Qt::black)},
- {RIPES_SETTING_CONSOLEFONT, QVariant() /* Let Console define its own default font */},
- {RIPES_SETTING_CONSOLEFONT, QColor(Qt::black)},
- {RIPES_SETTING_INDENTAMT, 4},
-
- {RIPES_SETTING_ASSEMBLER_TEXTSTART, 0x0},
- {RIPES_SETTING_ASSEMBLER_DATASTART, 0x10000000},
- {RIPES_SETTING_ASSEMBLER_BSSSTART, 0x11000000},
- {RIPES_SETTING_PERIPHERALS_START, static_cast<unsigned>(0xF0000000)},
-
- // Program state preserving settings
- {RIPES_GLOBALSIGNAL_QUIT, 0},
- {RIPES_SETTING_SETTING_TAB, 0},
- {RIPES_SETTING_VIEW_ZOOM, 250},
- {RIPES_SETTING_PERIPHERAL_SETTINGS, ""},
- {RIPES_SETTING_PROCESSOR_ID, QVariant() /* Let processorhandler define default */},
- {RIPES_SETTING_PROCESSOR_LAYOUT_ID, 0},
- {RIPES_SETTING_FOLLOW_EXEC, "true"},
- {RIPES_SETTING_DARKMODE, false}};
+const extern std::map<QString, QVariant> s_defaultSettings;
/**
* @brief The SettingObserver class

Store input type and source code between program invocations