diff --git a/.gitignore b/.gitignore index 54eb9296..82f95e27 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ nostalgia.gba nostalgia.sav nostalgia_media.oxfs media_header.txt +studio_state.json diff --git a/src/nostalgia/studio/lib/json_write.hpp b/src/nostalgia/studio/lib/json_write.hpp index 6588e2e0..6f405c8b 100644 --- a/src/nostalgia/studio/lib/json_write.hpp +++ b/src/nostalgia/studio/lib/json_write.hpp @@ -55,10 +55,11 @@ ox::Error JsonWriter::op(QString fieldName, T *src) { template ox::Error JsonWriter::op(QString fieldName, QVector *src) { ox::Error err = 0; - auto &a = m_dest[fieldName] = QJsonArray(); + QJsonArray a; for (int i = 0; i < src->size(); i++) { err |= op(a[i], &src->at(i)); } + m_dest[fieldName] = a; return err; }; diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index e59d6cb1..8685cfbd 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -16,8 +16,10 @@ #include #include #include +#include #include +#include "lib/json.hpp" #include "lib/wizard.hpp" #include "lib/oxfstreeview.hpp" #include "lib/project.hpp" @@ -26,6 +28,8 @@ namespace nostalgia { namespace studio { +const QString MainWindow::StateFilePath = "studio_state.json"; + MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) { auto screenSize = QApplication::desktop()->screenGeometry(); @@ -42,6 +46,8 @@ MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) { setupMenu(); setupProjectExplorer(); + + readState(); } MainWindow::~MainWindow() { @@ -151,15 +157,48 @@ QAction *MainWindow::addAction(QMenu *menu, QString text, QString toolTip, return action; } -void MainWindow::openProject() { - auto p = QFileDialog::getExistingDirectory(this, tr("Select Project Directory..."), QDir::homePath()); - auto project = QSharedPointer(new Project(p)); +int MainWindow::readState(QString path) { + int err = 0; + QString json; + QFile file(path); + err |= file.open(QIODevice::ReadOnly); + json = QTextStream(&file).readAll(); + file.close(); + err |= readJson(json, &m_state); + err |= openProject(m_state.projectPath); + return err; +} + +int MainWindow::writeState(QString path) { + int err = 0; + QString json; + err |= writeJson(&json, &m_state); + QFile file(path); + err |= file.open(QIODevice::WriteOnly); + QTextStream(&file) << json; + file.close(); + return err; +} + +int MainWindow::openProject(QString projectPath) { + auto project = QSharedPointer(new Project(projectPath)); auto err = project->open(); if (err == 0) { m_project = project; m_projectExplorer->setModel(new OxFSModel(m_project->romFS())); m_importAction->setEnabled(true); + m_state.projectPath = projectPath; } + return err; +} + +int MainWindow::openProject() { + auto projectPath = QFileDialog::getExistingDirectory(this, tr("Select Project Directory..."), QDir::homePath()); + auto err = openProject(projectPath); + if (err == 0) { + writeState(); + } + return err; } void MainWindow::showNewWizard() { diff --git a/src/nostalgia/studio/mainwindow.hpp b/src/nostalgia/studio/mainwindow.hpp index 1374fe03..15023e4b 100644 --- a/src/nostalgia/studio/mainwindow.hpp +++ b/src/nostalgia/studio/mainwindow.hpp @@ -57,8 +57,10 @@ class MainWindow: public QMainWindow { public: static const QString EditorSettings; static const QString AppTitle; + static const QString StateFilePath; private: + NostalgiaStudioState m_state; QAction *m_importAction = nullptr; QSharedPointer m_project; QPointer m_viewMenu; @@ -71,8 +73,6 @@ class MainWindow: public QMainWindow { virtual ~MainWindow(); - void openProject(QString); - private: void setupDockWidgets(); @@ -85,17 +85,19 @@ class MainWindow: public QMainWindow { QAction *addAction(QMenu *menu, QString text, QString toolTip, const QObject *tgt, const char *cb); QAction *addAction(QMenu *menu, QString text, QString toolTip, - QKeySequence::StandardKey key, const QObject *tgt, const char *cb); + QKeySequence::StandardKey key, const QObject *tgt, const char *cb); QAction *addAction(QMenu *menu, QString text, QString toolTip, - QKeySequence::StandardKey key, void (*cb)()); + QKeySequence::StandardKey key, void (*cb)()); - int readSettings(QString path); + int readState(QString path = StateFilePath); - int writeSettings(QString path); + int writeState(QString path = StateFilePath); + + int openProject(QString); private slots: - void openProject(); + int openProject(); void showNewWizard();