Set saved source file extension based on source type
MODIFY
src/edittab.h
src/edittab.h
@@ -29,7 +29,7 @@ public:
QString getAssemblyText();
void newProgram();
void clearAssemblyEditor();
-
+ SourceType getSourceType() { return m_currentSourceType; }
bool isEditorEnabled() const { return m_editorEnabled; }
const QByteArray* getBinaryData();

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -333,7 +333,7 @@ static void writeBinaryFile(QFile& file, const QByteArray& data) {
}
void MainWindow::saveFilesTriggered() {
- SaveDialog diag;
+ SaveDialog diag(static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->getSourceType());
if (!RipesSettings::value(RIPES_SETTING_HAS_SAVEFILE).toBool()) {
saveFilesAsTriggered();
return;
@@ -342,9 +342,9 @@ void MainWindow::saveFilesTriggered() {
bool didSave = false;
QStringList savedFiles;
- if (!diag.assemblyPath().isEmpty()) {
- QFile file(diag.assemblyPath());
- savedFiles << diag.assemblyPath();
+ if (!diag.sourcePath().isEmpty()) {
+ QFile file(diag.sourcePath());
+ savedFiles << diag.sourcePath();
writeTextFile(file, static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->getAssemblyText());
didSave |= true;
}
@@ -365,7 +365,7 @@ void MainWindow::saveFilesTriggered() {
}
void MainWindow::saveFilesAsTriggered() {
- SaveDialog diag;
+ SaveDialog diag(static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->getSourceType());
auto ret = diag.exec();
if (ret == QDialog::Rejected) {
return;

MODIFY
src/ripessettings.cpp
src/ripessettings.cpp
@@ -59,7 +59,7 @@ const std::map<QString, QVariant> s_defaultSettings = {
{RIPES_SETTING_HAS_SAVEFILE, false},
{RIPES_SETTING_SAVEPATH, ""},
- {RIPES_SETTING_SAVE_ASSEMBLY, true},
+ {RIPES_SETTING_SAVE_SOURCE, true},
{RIPES_SETTING_SAVE_BINARY, false}};
void SettingObserver::setValue(const QVariant& v) {

MODIFY
src/ripessettings.h
src/ripessettings.h
@@ -51,7 +51,7 @@ namespace Ripes {
#define RIPES_SETTING_HAS_SAVEFILE ("has_savefile")
#define RIPES_SETTING_SAVEPATH ("savepath")
-#define RIPES_SETTING_SAVE_ASSEMBLY ("save_assembly")
+#define RIPES_SETTING_SAVE_SOURCE ("save_source")
#define RIPES_SETTING_SAVE_BINARY ("save_binary")
// ============= Definitions of all default settings within Ripes ==============

MODIFY
src/savedialog.cpp
src/savedialog.cpp
namespace Ripes {
-SaveDialog::SaveDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::SaveDialog) {
+SaveDialog::SaveDialog(SourceType sourceType, QWidget* parent)
+ : QDialog(parent), m_ui(new Ui::SaveDialog), sourceType(sourceType) {
m_ui->setupUi(this);
setWindowTitle("Save files...");
@@ -14,16 +15,16 @@ SaveDialog::SaveDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::SaveDial
connect(m_ui->openFile, &QPushButton::clicked, this, &SaveDialog::openFileButtonTriggered);
connect(m_ui->filePath, &QLineEdit::textChanged, this, &SaveDialog::pathChanged);
connect(m_ui->saveBinary, &QCheckBox::toggled, this, &SaveDialog::pathChanged);
- connect(m_ui->saveAssembly, &QCheckBox::toggled, this, &SaveDialog::pathChanged);
+ connect(m_ui->saveSource, &QCheckBox::toggled, this, &SaveDialog::pathChanged);
- m_ui->saveAssembly->setChecked(RipesSettings::value(RIPES_SETTING_SAVE_ASSEMBLY).toBool());
+ m_ui->saveSource->setChecked(RipesSettings::value(RIPES_SETTING_SAVE_SOURCE).toBool());
m_ui->saveBinary->setChecked(RipesSettings::value(RIPES_SETTING_SAVE_BINARY).toBool());
- QString path = QFileInfo(RipesSettings::value(RIPES_SETTING_SAVEPATH).toString()).absolutePath();
- if (path.isEmpty()) {
+ QString path = RipesSettings::value(RIPES_SETTING_SAVEPATH).toString();
+ if (!QFileInfo(path).dir().exists()) {
path = QDir::currentPath();
}
- if (!path.endsWith(QDir::separator())) {
+ if (QFileInfo(path).isDir()) {
path += QDir::separator();
}
m_ui->filePath->setText(path);
@@ -32,7 +33,7 @@ SaveDialog::SaveDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::SaveDial
}
void SaveDialog::accept() {
- RipesSettings::setValue(RIPES_SETTING_SAVE_ASSEMBLY, m_ui->saveAssembly->isChecked());
+ RipesSettings::setValue(RIPES_SETTING_SAVE_SOURCE, m_ui->saveSource->isChecked());
RipesSettings::setValue(RIPES_SETTING_SAVE_BINARY, m_ui->saveBinary->isChecked());
RipesSettings::setValue(RIPES_SETTING_SAVEPATH, m_ui->filePath->text());
@@ -41,14 +42,16 @@ void SaveDialog::accept() {
void SaveDialog::pathChanged() {
bool okEnabled = !QFileInfo(m_ui->filePath->text()).fileName().isEmpty();
- okEnabled &= m_ui->saveAssembly->isChecked() | m_ui->saveBinary->isChecked();
+ okEnabled &= m_ui->saveSource->isChecked() | m_ui->saveBinary->isChecked();
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(okEnabled);
QStringList filesToSave;
const QString& path = m_ui->filePath->text();
- if (m_ui->saveAssembly->isChecked() && !path.isEmpty())
- filesToSave << m_ui->filePath->text() + ".s";
+ if (m_ui->saveSource->isChecked() && !path.isEmpty() &&
+ (sourceType == SourceType::Assembly || sourceType == SourceType::C)) {
+ filesToSave << m_ui->filePath->text() + (sourceType == SourceType::Assembly ? ".s" : ".c");
+ }
if (m_ui->saveBinary->isChecked() && !path.isEmpty())
filesToSave << m_ui->filePath->text() + ".bin";

MODIFY
src/savedialog.h
src/savedialog.h
#pragma once
#include <QDialog>
+#include "program.h"
#include "ripessettings.h"
namespace Ripes {
@@ -13,14 +14,16 @@ class SaveDialog : public QDialog {
Q_OBJECT
public:
- explicit SaveDialog(QWidget* parent = nullptr);
+ explicit SaveDialog(SourceType sourceType, QWidget* parent = nullptr);
~SaveDialog();
- static QString getPath() { return RipesSettings::value(RIPES_SETTING_SAVEPATH).toString(); }
- static QString assemblyPath() {
- return RipesSettings::value(RIPES_SETTING_SAVE_ASSEMBLY).toBool() ? getPath() + ".s" : QString();
+ QString getPath() { return RipesSettings::value(RIPES_SETTING_SAVEPATH).toString(); }
+ QString sourcePath() {
+ return RipesSettings::value(RIPES_SETTING_SAVE_SOURCE).toBool()
+ ? getPath() + (sourceType == SourceType::C ? ".c" : ".s")
+ : QString();
}
- static QString binaryPath() {
+ QString binaryPath() {
return RipesSettings::value(RIPES_SETTING_SAVE_BINARY).toBool() ? getPath() + ".bin" : QString();
}
@@ -31,6 +34,7 @@ private:
void pathChanged();
Ui::SaveDialog* m_ui = nullptr;
+ SourceType sourceType;
};
} // namespace Ripes

MODIFY
src/savedialog.ui
src/savedialog.ui
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QCheckBox" name="saveAssembly">
+ <widget class="QCheckBox" name="saveSource">
<property name="text">
- <string>Assembly source</string>
+ <string>source code</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="saveBinary">
<property name="text">
- <string>Assembled binary</string>
+ <string>assembled/compiled binary</string>
</property>
</widget>
</item>

Set saved source file extension based on source type