[nostalgia/studio] Add save action and cleanup

This commit is contained in:
Gary Talent 2020-02-29 00:28:32 -06:00
parent eddf89a321
commit 320d8c1143
17 changed files with 100 additions and 53 deletions

View File

@ -2,6 +2,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable( add_executable(
nostalgia-studio MACOSX_BUNDLE nostalgia-studio MACOSX_BUNDLE
json_read.cpp
json_write.cpp
main.cpp main.cpp
mainwindow.cpp mainwindow.cpp
oxfstreeview.cpp oxfstreeview.cpp
@ -32,4 +34,19 @@ install(
BUNDLE DESTINATION . 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) add_subdirectory(lib)

View File

@ -4,8 +4,6 @@ set(CMAKE_AUTOMOC ON)
add_library( add_library(
NostalgiaStudio SHARED NostalgiaStudio SHARED
editor.cpp editor.cpp
json_read.cpp
json_write.cpp
wizard.cpp wizard.cpp
plugin.cpp plugin.cpp
project.cpp project.cpp
@ -27,10 +25,6 @@ target_link_libraries(
install( install(
FILES FILES
editor.hpp editor.hpp
json.hpp
json_err.hpp
json_read.hpp
json_write.hpp
wizard.hpp wizard.hpp
plugin.hpp plugin.hpp
project.hpp project.hpp
@ -38,15 +32,3 @@ install(
DESTINATION DESTINATION
include/nostalgia/studio/lib include/nostalgia/studio/lib
) )
add_executable(
NostalgiaStudioJsonTest
json_test.cpp
)
target_link_libraries(
NostalgiaStudioJsonTest
NostalgiaStudio
)
add_test("Test\\ NostalgiaStudioJson" NostalgiaStudioJsonTest)

View File

@ -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 <QString>
#include <QWidget>
namespace nostalgia::studio {
struct Context {
QString appName;
QString orgName;
QWidget* tabParent = nullptr;
const class Project* project = nullptr;
};
}

View File

@ -13,11 +13,21 @@ namespace nostalgia::studio {
Editor::Editor(QWidget *parent): QWidget(parent) { Editor::Editor(QWidget *parent): QWidget(parent) {
} }
void Editor::save() { void Editor::saveItem() {
} }
QUndoStack *Editor::undoStack() { QUndoStack *Editor::undoStack() {
return nullptr; return nullptr;
} }
void Editor::save() {
save();
setUnsavedChanges(false);
}
void Editor::setUnsavedChanges(bool uc) {
m_unsavedChanges = uc;
emit unsavedChangesUpdate(uc);
}
} }

View File

@ -18,6 +18,9 @@ namespace nostalgia::studio {
class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
Q_OBJECT Q_OBJECT
private:
bool m_unsavedChanges = false;
public: public:
Editor(QWidget *parent); Editor(QWidget *parent);
@ -31,13 +34,27 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
/** /**
* Save changes to item being edited. * Save changes to item being edited.
*/ */
virtual void save(); virtual void saveItem();
/** /**
* Returns the undo stack holding changes to the item being edited. * Returns the undo stack holding changes to the item being edited.
*/ */
virtual QUndoStack *undoStack(); 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);
}; };
} }

View File

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include "context.hpp"
#include "plugin.hpp" #include "plugin.hpp"
namespace nostalgia::studio { namespace nostalgia::studio {

View File

@ -13,22 +13,13 @@
#include <QVector> #include <QVector>
#include <QWizardPage> #include <QWizardPage>
#include "editor.hpp"
#include "project.hpp"
#include "wizard.hpp" #include "wizard.hpp"
namespace nostalgia::studio { namespace nostalgia::studio {
struct Context {
QString appName;
QString orgName;
QWidget *tabParent = nullptr;
const Project *project = nullptr;
};
struct EditorMaker { struct EditorMaker {
QStringList fileTypes; QStringList fileTypes;
std::function<Editor*(QString)> make; std::function<class Editor*(QString)> make;
}; };
class Plugin { class Plugin {
@ -36,13 +27,13 @@ class Plugin {
public: public:
virtual ~Plugin() = default; virtual ~Plugin() = default;
virtual QVector<WizardMaker> newWizards(const Context *ctx); virtual QVector<WizardMaker> newWizards(const class Context *ctx);
virtual QVector<WizardMaker> importWizards(const Context *ctx); virtual QVector<WizardMaker> importWizards(const Context *ctx);
virtual QWidget *makeEditor(QString path, const Context *ctx); virtual QWidget *makeEditor(QString path, const class Context *ctx);
virtual QVector<EditorMaker> editors(const Context *ctx); virtual QVector<EditorMaker> editors(const class Context *ctx);
}; };

View File

@ -23,10 +23,10 @@
#include <QVector> #include <QVector>
#include "lib/editor.hpp" #include "lib/editor.hpp"
#include "lib/json.hpp"
#include "lib/project.hpp" #include "lib/project.hpp"
#include "lib/wizard.hpp" #include "lib/wizard.hpp"
#include "json.hpp"
#include "mainwindow.hpp" #include "mainwindow.hpp"
namespace nostalgia::studio { namespace nostalgia::studio {
@ -151,6 +151,17 @@ void MainWindow::setupMenu() {
SLOT(openProject()) SLOT(openProject())
); );
// Save Project
m_saveAction = addAction(
fileMenu,
tr("&Save File"),
tr(""),
QKeySequence::Save,
this,
SLOT(saveFile())
);
m_saveAction->setEnabled(false);
// Exit // Exit
addAction( addAction(
fileMenu, fileMenu,
@ -435,6 +446,10 @@ void MainWindow::showNewWizard() {
wizard.exec(); wizard.exec();
} }
void MainWindow::saveFile() {
m_currentEditor->save();
}
void MainWindow::closeTab(int idx) { void MainWindow::closeTab(int idx) {
auto tab = static_cast<studio::Editor*>(m_tabs->widget(idx)); auto tab = static_cast<studio::Editor*>(m_tabs->widget(idx));
m_undoGroup.removeStack(tab->undoStack()); m_undoGroup.removeStack(tab->undoStack());
@ -456,7 +471,11 @@ void MainWindow::moveTab(int from, int to) {
void MainWindow::changeTab(int idx) { void MainWindow::changeTab(int idx) {
auto tab = dynamic_cast<studio::Editor*>(m_tabs->widget(idx)); auto tab = dynamic_cast<studio::Editor*>(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) { if (!tab) {
m_undoGroup.setActiveStack(nullptr);
return; return;
} }
m_undoGroup.setActiveStack(tab->undoStack()); m_undoGroup.setActiveStack(tab->undoStack());

View File

@ -24,6 +24,7 @@
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include "lib/context.hpp"
#include "lib/plugin.hpp" #include "lib/plugin.hpp"
#include "lib/project.hpp" #include "lib/project.hpp"
@ -43,22 +44,6 @@ ox::Error model(T *io, NostalgiaStudioState *obj) {
return err; return err;
} }
struct NostalgiaStudioPluginDef {
QString dir;
QString libName;
};
template<typename T>
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 { struct NostalgiaStudioProfile {
QString appName; QString appName;
QString orgName; QString orgName;
@ -88,6 +73,7 @@ class MainWindow: public QMainWindow {
NostalgiaStudioProfile m_profile; NostalgiaStudioProfile m_profile;
NostalgiaStudioState m_state; NostalgiaStudioState m_state;
QAction *m_importAction = nullptr; QAction *m_importAction = nullptr;
QAction *m_saveAction = nullptr;
Context m_ctx; Context m_ctx;
QPointer<QMenu> m_viewMenu; QPointer<QMenu> m_viewMenu;
QVector<QPointer<QDockWidget>> m_dockWidgets; QVector<QPointer<QDockWidget>> m_dockWidgets;
@ -97,6 +83,7 @@ class MainWindow: public QMainWindow {
QPointer<OxFSModel> m_oxfsView = nullptr; QPointer<OxFSModel> m_oxfsView = nullptr;
QTabWidget *m_tabs = nullptr; QTabWidget *m_tabs = nullptr;
QUndoGroup m_undoGroup; QUndoGroup m_undoGroup;
Editor* m_currentEditor = nullptr;
public: public:
MainWindow(QString profilePath); MainWindow(QString profilePath);
@ -110,8 +97,6 @@ class MainWindow: public QMainWindow {
void loadPlugin(QString path); void loadPlugin(QString path);
void setupDockWidgets();
void setupMenu(); void setupMenu();
void setupProjectExplorer(); void setupProjectExplorer();
@ -157,6 +142,8 @@ class MainWindow: public QMainWindow {
void openFileSlot(QModelIndex); void openFileSlot(QModelIndex);
void saveFile();
void closeTab(int idx); void closeTab(int idx);
void moveTab(int from, int to); void moveTab(int from, int to);

View File

@ -8,8 +8,8 @@
#pragma once #pragma once
#include "lib/context.hpp"
#include "lib/editor.hpp" #include "lib/editor.hpp"
#include "lib/json.hpp"
#include "lib/plugin.hpp" #include "lib/plugin.hpp"
#include "lib/project.hpp" #include "lib/project.hpp"
#include "lib/wizard.hpp" #include "lib/wizard.hpp"