diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-08-22 13:47:41 +0200 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-08-22 13:47:41 +0200 |
commit | 6c09f661b83dd13a8403243c1441efa5c4900538 (patch) | |
tree | fe32eed92f284d08455461c02c158226d760ac4c /qtmips_gui | |
parent | a385be02219abc1fd751908e559286dc1a370e12 (diff) | |
download | qtmips-6c09f661b83dd13a8403243c1441efa5c4900538.tar.gz qtmips-6c09f661b83dd13a8403243c1441efa5c4900538.tar.bz2 qtmips-6c09f661b83dd13a8403243c1441efa5c4900538.zip |
In include, use content from editor if file is already open.
This allows to assemble from modified include files without
need to save their content the first.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui')
-rw-r--r-- | qtmips_gui/mainwindow.cpp | 15 | ||||
-rw-r--r-- | qtmips_gui/mainwindow.h | 14 |
2 files changed, 28 insertions, 1 deletions
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index cbee3e5..09fe660 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -858,6 +858,19 @@ void MainWindow::message_selected(messagetype::Type type, QString file, int line central_window->setCurrentWidget(editor); } +bool SimpleAsmWithEditorCheck::process_file(QString filename, QString *error_ptr) { + SrcEditor *editor = mainwindow->source_editor_for_file(filename, false); + if (editor == nullptr) + return Super::process_file(filename, error_ptr); + QTextDocument *doc = editor->document(); + int ln = 1; + for ( QTextBlock block = doc->begin(); block.isValid(); block = block.next(), ln++) { + QString line = block.text(); + process_line(line, filename, ln); + } + return !error_occured; +} + void MainWindow::compile_source() { bool error_occured = false; if (current_srceditor == nullptr) @@ -883,7 +896,7 @@ void MainWindow::compile_source() { QTextDocument *doc = editor->document(); emit clear_messages(); - SimpleAsm sasm; + SimpleAsmWithEditorCheck sasm(this); connect(&sasm, SIGNAL(report_message(messagetype::Type,QString,int,int,QString,QString)), this, SIGNAL(report_message(messagetype::Type,QString,int,int,QString,QString))); diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h index 13c8295..976c21e 100644 --- a/qtmips_gui/mainwindow.h +++ b/qtmips_gui/mainwindow.h @@ -58,10 +58,12 @@ #include "qtmipsmachine.h" #include "machineconfig.h" #include "srceditor.h" +#include "simpleasm.h" class MainWindow : public QMainWindow { Q_OBJECT + friend class SimpleAsmWithEditorCheck; public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); @@ -165,4 +167,16 @@ private: bool ignore_unsaved; }; +class SimpleAsmWithEditorCheck : public SimpleAsm { + Q_OBJECT + using Super = SimpleAsm; + +public: + SimpleAsmWithEditorCheck(MainWindow *a_mainwindow, QObject *parent = nullptr) : + Super(parent), mainwindow(a_mainwindow) {} + bool process_file(QString filename, QString *error_ptr = nullptr) override; +private: + MainWindow *mainwindow; +}; + #endif // MAINWINDOW_H |