aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-07-03 09:56:11 +0200
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-07-03 09:56:11 +0200
commit9f4c221eb9767adec56f57c2479be5fa38049397 (patch)
tree74e4fdd6e395077ae61e7b42ab5e6de75c86753f
parentbfc4ab63d2b3cf32459a11a12489a73d2addca9d (diff)
downloadqtmips-9f4c221eb9767adec56f57c2479be5fa38049397.tar.gz
qtmips-9f4c221eb9767adec56f57c2479be5fa38049397.tar.bz2
qtmips-9f4c221eb9767adec56f57c2479be5fa38049397.zip
Store and restore open source files editors.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
-rw-r--r--qtmips_gui/mainwindow.cpp46
-rw-r--r--qtmips_gui/mainwindow.h2
2 files changed, 40 insertions, 8 deletions
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp
index 685a84a..d0338cc 100644
--- a/qtmips_gui/mainwindow.cpp
+++ b/qtmips_gui/mainwindow.cpp
@@ -142,6 +142,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
// Source editor related actions
connect(central_window, SIGNAL(currentChanged(int)), this, SLOT(central_tab_changed(int)));
+
+ foreach (QString file_name, settings->value("openSrcFiles").toStringList()) {
+ if (file_name.isEmpty())
+ continue;
+ SrcEditor *editor = new SrcEditor();
+ if (editor->loadFile(file_name)) {
+ add_src_editor_to_tabs(editor);
+ } else {
+ delete(editor);
+ }
+ }
}
MainWindow::~MainWindow() {
@@ -488,13 +499,34 @@ void MainWindow::central_tab_changed(int index) {
setCurrentSrcEditor(srceditor);
}
-void MainWindow::new_source() {
- SrcEditor *editor = new SrcEditor();
+void MainWindow::add_src_editor_to_tabs(SrcEditor *editor) {
central_window->addTab(editor, editor->title());
central_window->setCurrentWidget(editor);
connect(editor, SIGNAL(destroyed(QObject*)), this, SLOT(tab_widget_destroyed(QObject*)));
}
+void MainWindow::update_open_file_list() {
+ QStringList open_src_files;
+ if ((central_window == nullptr) || (settings == nullptr))
+ return;
+ for (int i = 0; i < central_window->count(); i++) {
+ QWidget *w = central_window->widget(i);
+ SrcEditor *editor = dynamic_cast<SrcEditor *>(w);
+ if (editor == nullptr)
+ continue;
+ if (editor->filename() == "")
+ continue;
+ open_src_files.append(editor->filename());
+ }
+ settings->setValue("openSrcFiles", open_src_files);
+}
+
+void MainWindow::new_source() {
+ SrcEditor *editor = new SrcEditor();
+ add_src_editor_to_tabs(editor);
+ update_open_file_list();
+}
+
void MainWindow::open_source() {
#ifndef __EMSCRIPTEN__
QString file_name = "";
@@ -504,9 +536,7 @@ void MainWindow::open_source() {
if (!file_name.isEmpty()) {
SrcEditor *editor = new SrcEditor();
if (editor->loadFile(file_name)) {
- central_window->addTab(editor, editor->title());
- central_window->setCurrentWidget(editor);
- connect(editor, SIGNAL(destroyed(QObject*)), this, SLOT(tab_widget_destroyed(QObject*)));
+ add_src_editor_to_tabs(editor);
} else {
QMessageBox::critical(this, "QtMips Error", tr("Cannot open file '%1' for reading.").arg(file_name));
delete(editor);
@@ -516,11 +546,10 @@ void MainWindow::open_source() {
QHtml5File::load("*", [&](const QByteArray &content, const QString &filename) {
SrcEditor *editor = new SrcEditor();
editor->loadByteArray(content, filename);
- central_window->addTab(editor, editor->title());
- central_window->setCurrentWidget(editor);
- connect(editor, SIGNAL(destroyed(QObject*)), this, SLOT(tab_widget_destroyed(QObject*)));
+ add_src_editor_to_tabs(editor);
});
#endif
+ update_open_file_list();
}
void MainWindow::save_source_as() {
@@ -539,6 +568,7 @@ void MainWindow::save_source_as() {
} else {
QMessageBox::critical(this, "QtMips Error", tr("Cannot save file '%1'.").arg(fn));
}
+ update_open_file_list();
}
void MainWindow::save_source() {
diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h
index f75d31e..9c7bb25 100644
--- a/qtmips_gui/mainwindow.h
+++ b/qtmips_gui/mainwindow.h
@@ -132,6 +132,8 @@ private:
machine::QtMipsMachine *machine; // Current simulated machine
void show_dockwidget(QDockWidget *w, Qt::DockWidgetArea area = Qt::RightDockWidgetArea);
+ void add_src_editor_to_tabs(SrcEditor *editor);
+ void update_open_file_list();
};
#endif // MAINWINDOW_H