diff --git a/src/nostalgia/studio/CMakeLists.txt b/src/nostalgia/studio/CMakeLists.txt index f3abd3e1..7743b755 100644 --- a/src/nostalgia/studio/CMakeLists.txt +++ b/src/nostalgia/studio/CMakeLists.txt @@ -2,6 +2,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) add_executable( nostalgia-studio MACOSX_BUNDLE + json_read.cpp + json_write.cpp main.cpp mainwindow.cpp oxfstreeview.cpp @@ -32,4 +34,19 @@ install( BUNDLE DESTINATION . ) +add_executable( + NostalgiaStudioJsonTest + json_read.cpp + json_write.cpp + json_test.cpp +) + +target_link_libraries( + NostalgiaStudioJsonTest + OxStd + Qt5::Widgets +) + +add_test("Test\\ NostalgiaStudioJson" NostalgiaStudioJsonTest) + add_subdirectory(lib) diff --git a/src/nostalgia/studio/lib/json.hpp b/src/nostalgia/studio/json.hpp similarity index 100% rename from src/nostalgia/studio/lib/json.hpp rename to src/nostalgia/studio/json.hpp diff --git a/src/nostalgia/studio/lib/json_err.hpp b/src/nostalgia/studio/json_err.hpp similarity index 100% rename from src/nostalgia/studio/lib/json_err.hpp rename to src/nostalgia/studio/json_err.hpp diff --git a/src/nostalgia/studio/lib/json_read.cpp b/src/nostalgia/studio/json_read.cpp similarity index 100% rename from src/nostalgia/studio/lib/json_read.cpp rename to src/nostalgia/studio/json_read.cpp diff --git a/src/nostalgia/studio/lib/json_read.hpp b/src/nostalgia/studio/json_read.hpp similarity index 100% rename from src/nostalgia/studio/lib/json_read.hpp rename to src/nostalgia/studio/json_read.hpp diff --git a/src/nostalgia/studio/lib/json_test.cpp b/src/nostalgia/studio/json_test.cpp similarity index 100% rename from src/nostalgia/studio/lib/json_test.cpp rename to src/nostalgia/studio/json_test.cpp diff --git a/src/nostalgia/studio/lib/json_write.cpp b/src/nostalgia/studio/json_write.cpp similarity index 100% rename from src/nostalgia/studio/lib/json_write.cpp rename to src/nostalgia/studio/json_write.cpp diff --git a/src/nostalgia/studio/lib/json_write.hpp b/src/nostalgia/studio/json_write.hpp similarity index 100% rename from src/nostalgia/studio/lib/json_write.hpp rename to src/nostalgia/studio/json_write.hpp diff --git a/src/nostalgia/studio/lib/CMakeLists.txt b/src/nostalgia/studio/lib/CMakeLists.txt index 20795f82..7114b6a8 100644 --- a/src/nostalgia/studio/lib/CMakeLists.txt +++ b/src/nostalgia/studio/lib/CMakeLists.txt @@ -4,8 +4,6 @@ set(CMAKE_AUTOMOC ON) add_library( NostalgiaStudio SHARED editor.cpp - json_read.cpp - json_write.cpp wizard.cpp plugin.cpp project.cpp @@ -27,10 +25,6 @@ target_link_libraries( install( FILES editor.hpp - json.hpp - json_err.hpp - json_read.hpp - json_write.hpp wizard.hpp plugin.hpp project.hpp @@ -38,15 +32,3 @@ install( DESTINATION include/nostalgia/studio/lib ) - -add_executable( - NostalgiaStudioJsonTest - json_test.cpp -) - -target_link_libraries( - NostalgiaStudioJsonTest - NostalgiaStudio -) - -add_test("Test\\ NostalgiaStudioJson" NostalgiaStudioJsonTest) diff --git a/src/nostalgia/studio/lib/context.hpp b/src/nostalgia/studio/lib/context.hpp new file mode 100644 index 00000000..6420e9a4 --- /dev/null +++ b/src/nostalgia/studio/lib/context.hpp @@ -0,0 +1,23 @@ +/* + * Copyright 2016 - 2019 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include +#include + +namespace nostalgia::studio { + +struct Context { + QString appName; + QString orgName; + QWidget* tabParent = nullptr; + const class Project* project = nullptr; +}; + +} diff --git a/src/nostalgia/studio/lib/editor.cpp b/src/nostalgia/studio/lib/editor.cpp index fd42314b..3f91288c 100644 --- a/src/nostalgia/studio/lib/editor.cpp +++ b/src/nostalgia/studio/lib/editor.cpp @@ -13,11 +13,21 @@ namespace nostalgia::studio { Editor::Editor(QWidget *parent): QWidget(parent) { } -void Editor::save() { +void Editor::saveItem() { } QUndoStack *Editor::undoStack() { return nullptr; } +void Editor::save() { + save(); + setUnsavedChanges(false); +} + +void Editor::setUnsavedChanges(bool uc) { + m_unsavedChanges = uc; + emit unsavedChangesUpdate(uc); +} + } diff --git a/src/nostalgia/studio/lib/editor.hpp b/src/nostalgia/studio/lib/editor.hpp index fbebb81b..959b43cd 100644 --- a/src/nostalgia/studio/lib/editor.hpp +++ b/src/nostalgia/studio/lib/editor.hpp @@ -18,6 +18,9 @@ namespace nostalgia::studio { class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { Q_OBJECT + private: + bool m_unsavedChanges = false; + public: Editor(QWidget *parent); @@ -31,13 +34,27 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { /** * Save changes to item being edited. */ - virtual void save(); + virtual void saveItem(); /** * Returns the undo stack holding changes to the item being edited. */ virtual QUndoStack *undoStack(); + /** + * Save changes to item being edited. + */ + void save(); + + /** + * Sets indication of item being edited has unsaved changes. Also emits + * unsavedChangesUpdate signal. + */ + void setUnsavedChanges(bool); + + signals: + void unsavedChangesUpdate(bool); + }; } diff --git a/src/nostalgia/studio/lib/plugin.cpp b/src/nostalgia/studio/lib/plugin.cpp index d22a056d..9abe71bc 100644 --- a/src/nostalgia/studio/lib/plugin.cpp +++ b/src/nostalgia/studio/lib/plugin.cpp @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "context.hpp" #include "plugin.hpp" namespace nostalgia::studio { diff --git a/src/nostalgia/studio/lib/plugin.hpp b/src/nostalgia/studio/lib/plugin.hpp index e04f9ed0..66c6e055 100644 --- a/src/nostalgia/studio/lib/plugin.hpp +++ b/src/nostalgia/studio/lib/plugin.hpp @@ -13,22 +13,13 @@ #include #include -#include "editor.hpp" -#include "project.hpp" #include "wizard.hpp" namespace nostalgia::studio { -struct Context { - QString appName; - QString orgName; - QWidget *tabParent = nullptr; - const Project *project = nullptr; -}; - struct EditorMaker { QStringList fileTypes; - std::function make; + std::function make; }; class Plugin { @@ -36,13 +27,13 @@ class Plugin { public: virtual ~Plugin() = default; - virtual QVector newWizards(const Context *ctx); + virtual QVector newWizards(const class Context *ctx); virtual QVector importWizards(const Context *ctx); - virtual QWidget *makeEditor(QString path, const Context *ctx); + virtual QWidget *makeEditor(QString path, const class Context *ctx); - virtual QVector editors(const Context *ctx); + virtual QVector editors(const class Context *ctx); }; diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index 6b041f39..c7685c0c 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -23,10 +23,10 @@ #include #include "lib/editor.hpp" -#include "lib/json.hpp" #include "lib/project.hpp" #include "lib/wizard.hpp" +#include "json.hpp" #include "mainwindow.hpp" namespace nostalgia::studio { @@ -151,6 +151,17 @@ void MainWindow::setupMenu() { SLOT(openProject()) ); + // Save Project + m_saveAction = addAction( + fileMenu, + tr("&Save File"), + tr(""), + QKeySequence::Save, + this, + SLOT(saveFile()) + ); + m_saveAction->setEnabled(false); + // Exit addAction( fileMenu, @@ -435,6 +446,10 @@ void MainWindow::showNewWizard() { wizard.exec(); } +void MainWindow::saveFile() { + m_currentEditor->save(); +} + void MainWindow::closeTab(int idx) { auto tab = static_cast(m_tabs->widget(idx)); m_undoGroup.removeStack(tab->undoStack()); @@ -456,7 +471,11 @@ void MainWindow::moveTab(int from, int to) { void MainWindow::changeTab(int idx) { auto tab = dynamic_cast(m_tabs->widget(idx)); + disconnect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled); + m_currentEditor = tab; + connect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled); if (!tab) { + m_undoGroup.setActiveStack(nullptr); return; } m_undoGroup.setActiveStack(tab->undoStack()); diff --git a/src/nostalgia/studio/mainwindow.hpp b/src/nostalgia/studio/mainwindow.hpp index ba13b95f..b8b032e8 100644 --- a/src/nostalgia/studio/mainwindow.hpp +++ b/src/nostalgia/studio/mainwindow.hpp @@ -24,6 +24,7 @@ #include +#include "lib/context.hpp" #include "lib/plugin.hpp" #include "lib/project.hpp" @@ -43,22 +44,6 @@ ox::Error model(T *io, NostalgiaStudioState *obj) { return err; } - -struct NostalgiaStudioPluginDef { - QString dir; - QString libName; -}; - -template -ox::Error model(T *io, NostalgiaStudioPluginDef *obj) { - auto err = OxError(0); - oxReturnError(io->setTypeInfo("NostalgiaStudioPluginDef", 2)); - oxReturnError(io->field("dir", &obj->dir)); - oxReturnError(io->field("lib_name", &obj->libName)); - return err; -} - - struct NostalgiaStudioProfile { QString appName; QString orgName; @@ -88,6 +73,7 @@ class MainWindow: public QMainWindow { NostalgiaStudioProfile m_profile; NostalgiaStudioState m_state; QAction *m_importAction = nullptr; + QAction *m_saveAction = nullptr; Context m_ctx; QPointer m_viewMenu; QVector> m_dockWidgets; @@ -97,6 +83,7 @@ class MainWindow: public QMainWindow { QPointer m_oxfsView = nullptr; QTabWidget *m_tabs = nullptr; QUndoGroup m_undoGroup; + Editor* m_currentEditor = nullptr; public: MainWindow(QString profilePath); @@ -110,8 +97,6 @@ class MainWindow: public QMainWindow { void loadPlugin(QString path); - void setupDockWidgets(); - void setupMenu(); void setupProjectExplorer(); @@ -157,6 +142,8 @@ class MainWindow: public QMainWindow { void openFileSlot(QModelIndex); + void saveFile(); + void closeTab(int idx); void moveTab(int from, int to); diff --git a/src/nostalgia/studio/studio.hpp b/src/nostalgia/studio/studio.hpp index bfca30f8..150d1473 100644 --- a/src/nostalgia/studio/studio.hpp +++ b/src/nostalgia/studio/studio.hpp @@ -8,8 +8,8 @@ #pragma once +#include "lib/context.hpp" #include "lib/editor.hpp" -#include "lib/json.hpp" #include "lib/plugin.hpp" #include "lib/project.hpp" #include "lib/wizard.hpp"