Rename FileType to SourceType
MODIFY
src/editor/codeeditor.cpp
src/editor/codeeditor.cpp
@@ -134,6 +134,19 @@ void CodeEditor::resizeEvent(QResizeEvent* e) {
m_lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
}
+void CodeEditor::setSourceType(SourceType type) {
+ m_sourceType = type;
+
+ // Creates AsmHighlighter object and connects it to the current document
+ switch (m_sourceType) {
+ case SourceType::Assembly:
+ m_highlighter = std::make_unique<RVAssemblyHighlighter>(document());
+ break;
+ default:
+ break;
+ }
+}
+
void CodeEditor::highlightCurrentLine() {
QList<QTextEdit::ExtraSelection> extraSelections;
@@ -175,9 +188,4 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event) {
}
}
-void CodeEditor::setupSyntaxHighlighter() {
- // Creates AsmHighlighter object and connects it to the current document
- m_highlighter = std::make_unique<RVAssemblyHighlighter>(document());
-}
-
} // namespace Ripes

MODIFY
src/editor/codeeditor.h
src/editor/codeeditor.h
@@ -22,9 +22,9 @@ class CodeEditor : public QPlainTextEdit {
public:
CodeEditor(QWidget* parent = nullptr);
+ void setSourceType(SourceType type);
void lineNumberAreaPaintEvent(QPaintEvent* event);
int lineNumberAreaWidth();
- void setupSyntaxHighlighter();
void setupChangedTimer();
void reset() {
m_highlighter->reset();
@@ -53,6 +53,8 @@ private:
bool m_syntaxChecking = false;
bool m_breakpointAreaEnabled = false;
+ SourceType m_sourceType = SourceType::Assembly;
+
QFont m_font;
// A timer is needed for only catching one of the multiple wheel events that

MODIFY
src/edittab.cpp
src/edittab.cpp
@@ -22,15 +22,11 @@ EditTab::EditTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent)
connect(m_ui->enableEditor, &QPushButton::clicked, this, &EditTab::enableAssemblyInput);
- // Only add syntax highlighter for code edit view - not for translated code. This is assumed to be correct after a
- // translation is complete
- m_ui->assemblyedit->setupSyntaxHighlighter();
- m_ui->assemblyedit->setupChangedTimer();
m_ui->programViewer->setReadOnly(true);
m_assembler = std::make_unique<Assembler>();
- connect(m_ui->assemblyedit, &CodeEditor::textChanged, this, &EditTab::assemble);
+ connect(m_ui->codeEditor, &CodeEditor::textChanged, this, &EditTab::assemble);
connect(m_ui->setAssemblyInput, &QRadioButton::toggled, this, &EditTab::sourceTypeChanged);
connect(m_ui->setCInput, &QRadioButton::toggled, this, &EditTab::sourceTypeChanged);
@@ -55,13 +51,13 @@ void EditTab::loadFile(const LoadFileParams& fileParams) {
bool success = true;
Program loadedProgram;
switch (fileParams.type) {
- case FileType::Assembly:
+ case SourceType::Assembly:
success &= loadAssemblyFile(loadedProgram, file);
break;
- case FileType::FlatBinary:
+ case SourceType::FlatBinary:
success &= loadFlatBinaryFile(loadedProgram, file, fileParams.binaryEntryPoint, fileParams.binaryLoadAt);
break;
- case FileType::Executable:
+ case SourceType::Executable:
success &= loadElfFile(loadedProgram, file);
break;
}
@@ -76,7 +72,7 @@ void EditTab::loadFile(const LoadFileParams& fileParams) {
}
QString EditTab::getAssemblyText() {
- return m_ui->assemblyedit->toPlainText();
+ return m_ui->codeEditor->toPlainText();
}
const QByteArray& EditTab::getBinaryData() {
@@ -84,7 +80,7 @@ const QByteArray& EditTab::getBinaryData() {
}
void EditTab::clearAssemblyEditor() {
- m_ui->assemblyedit->reset();
+ m_ui->codeEditor->reset();
m_assembler->clear();
}
@@ -95,8 +91,9 @@ void EditTab::updateProgramViewerHighlighting() {
}
void EditTab::sourceTypeChanged() {
+ // Validate source type selection
if (m_ui->setAssemblyInput->isChecked()) {
- m_currentFileType = FileType::Assembly;
+ m_currentFileType = SourceType::Assembly;
} else if (m_ui->setCInput->isChecked()) {
// Ensure that we have a validated C compiler available
if (!CCManager::get().hasValidCC()) {
@@ -105,10 +102,14 @@ void EditTab::sourceTypeChanged() {
"No C compiler set.\n\nProvide a path to a valid C compiler under:\n Edit->Settings->Editor");
// Re-enable assembly input
m_ui->setAssemblyInput->setChecked(true);
+ return;
} else {
- m_currentFileType = FileType::C;
+ m_currentFileType = SourceType::C;
}
}
+
+ // Notify the source type change to the code editor
+ m_ui->codeEditor->setSourceType(m_currentFileType);
}
void EditTab::emitProgramChanged() {
@@ -117,8 +118,8 @@ void EditTab::emitProgramChanged() {
}
void EditTab::assemble() {
- if (m_ui->assemblyedit->syntaxAccepted()) {
- m_assembler->assemble(*m_ui->assemblyedit->document());
+ if (m_ui->codeEditor->syntaxAccepted()) {
+ m_assembler->assemble(*m_ui->codeEditor->document());
if (!m_assembler->hasError()) {
m_activeProgram = m_assembler->getProgram();
emitProgramChanged();
@@ -135,14 +136,14 @@ EditTab::~EditTab() {
}
void EditTab::newProgram() {
- m_ui->assemblyedit->reset();
- m_ui->assemblyedit->clear();
+ m_ui->codeEditor->reset();
+ m_ui->codeEditor->clear();
enableAssemblyInput();
}
void EditTab::setAssemblyText(const QString& text) {
- m_ui->assemblyedit->reset();
- m_ui->assemblyedit->setPlainText(text);
+ m_ui->codeEditor->reset();
+ m_ui->codeEditor->setPlainText(text);
}
void EditTab::enableAssemblyInput() {
@@ -159,12 +160,12 @@ void EditTab::updateProgramViewer() {
}
void EditTab::enableEditor() {
- connect(m_ui->assemblyedit, &CodeEditor::textChanged, this, &EditTab::assemble);
+ connect(m_ui->codeEditor, &CodeEditor::textChanged, this, &EditTab::assemble);
m_ui->editorStackedWidget->setCurrentIndex(0);
}
void EditTab::disableEditor() {
- disconnect(m_ui->assemblyedit, &CodeEditor::textChanged, this, &EditTab::assemble);
+ disconnect(m_ui->codeEditor, &CodeEditor::textChanged, this, &EditTab::assemble);
m_ui->editorStackedWidget->setCurrentIndex(1);
clearAssemblyEditor();
m_editorEnabled = false;

MODIFY
src/edittab.h
src/edittab.h
@@ -77,7 +77,7 @@ private:
Program m_activeProgram;
- FileType m_currentFileType;
+ SourceType m_currentFileType;
bool m_editorEnabled = true;
};

MODIFY
src/edittab.ui
src/edittab.ui
<number>0</number>
</property>
<item row="0" column="0">
- <widget class="CodeEditor" name="assemblyedit"/>
+ <widget class="CodeEditor" name="codeEditor"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
- <widget class="QWidget" name="cSourcePage"/>
</widget>
</item>
</layout>

MODIFY
src/loaddialog.cpp
src/loaddialog.cpp
@@ -61,17 +61,17 @@ void LoadDialog::inputTypeChanged() {
s_typeIndex = static_cast<LoadDialog::TypeButtonID>(m_fileTypeButtons->checkedId());
switch (m_fileTypeButtons->checkedId()) {
case LoadDialog::TypeButtonID::Assembly: {
- m_fileType = FileType::Assembly;
+ m_fileType = SourceType::Assembly;
updateAssemblyPageState();
break;
}
case LoadDialog::TypeButtonID::FlatBinary: {
- m_fileType = FileType::FlatBinary;
+ m_fileType = SourceType::FlatBinary;
updateBinaryPageState();
break;
}
case LoadDialog::TypeButtonID::ELF: {
- m_fileType = FileType::Executable;
+ m_fileType = SourceType::Executable;
updateELFPageState();
break;
}
@@ -83,17 +83,17 @@ void LoadDialog::openFileButtonTriggered() {
QString title;
QString filter;
switch (m_fileType) {
- case FileType::Assembly: {
+ case SourceType::Assembly: {
title = "Open assembly file";
filter = "Assembly files [*.s, *.as, *.asm] (*.s *.as *.asm);; All files (*.*)";
break;
}
- case FileType::FlatBinary: {
+ case SourceType::FlatBinary: {
title = "Open binary file";
filter = "All files (*)";
break;
}
- case FileType::Executable: {
+ case SourceType::Executable: {
title = "Open executable (ELF) file";
filter = "All files (*)";
break;
@@ -198,11 +198,11 @@ finish:
bool LoadDialog::fileTypeValidate(const QFile& file) {
switch (m_fileType) {
- case FileType::Assembly:
+ case SourceType::Assembly:
return validateAssemblyFile(file);
- case FileType::FlatBinary:
+ case SourceType::FlatBinary:
return validateBinaryFile(file);
- case FileType::Executable:
+ case SourceType::Executable:
return validateELFFile(file);
}
Q_UNREACHABLE();

MODIFY
src/loaddialog.h
src/loaddialog.h
@@ -56,7 +56,7 @@ private:
void paletteValidate(QWidget* w, bool valid);
- FileType m_fileType = FileType::Assembly;
+ SourceType m_fileType = SourceType::Assembly;
LoadFileParams m_params;
Ui::LoadDialog* m_ui = nullptr;

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -155,7 +155,7 @@ void MainWindow::setupExamplesMenu(QMenu* parent) {
parent->addAction(fileName, [=] {
LoadFileParams parms;
parms.filepath = QString(":/examples/assembly/") + fileName;
- parms.type = FileType::Assembly;
+ parms.type = SourceType::Assembly;
m_editTab->loadFile(parms);
m_hasSavedFile = false;
});
@@ -176,7 +176,7 @@ void MainWindow::setupExamplesMenu(QMenu* parent) {
LoadFileParams parms;
parms.filepath = tmpELFFile->fileName();
- parms.type = FileType::Executable;
+ parms.type = SourceType::Executable;
m_editTab->loadFile(parms);
m_hasSavedFile = false;
tmpELFFile->remove();

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -48,7 +48,7 @@ signals:
void updateMemoryTab();
private:
- void loadFile(const QString& filename, FileType type);
+ void loadFile(const QString& filename, SourceType type);
void setupMenus();
void setupExamplesMenu(QMenu* parent);

MODIFY
src/program.h
src/program.h
namespace Ripes {
-enum class FileType { Assembly, C, FlatBinary, Executable };
+enum class SourceType { Assembly, C, FlatBinary, Executable };
#define TEXT_SECTION_NAME ".text"
struct LoadFileParams {
QString filepath;
- FileType type;
+ SourceType type;
unsigned long binaryEntryPoint;
unsigned long binaryLoadAt;
};

Rename FileType to SourceType