[nostalgia/studio] Add save action and cleanup
This commit is contained in:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								src/nostalgia/studio/lib/context.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/nostalgia/studio/lib/context.hpp
									
									
									
									
									
										Normal 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;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -13,22 +13,13 @@
 | 
			
		||||
#include <QVector>
 | 
			
		||||
#include <QWizardPage>
 | 
			
		||||
 | 
			
		||||
#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<Editor*(QString)> make;
 | 
			
		||||
	std::function<class Editor*(QString)> make;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Plugin {
 | 
			
		||||
@@ -36,13 +27,13 @@ class Plugin {
 | 
			
		||||
	public:
 | 
			
		||||
		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 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);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -23,10 +23,10 @@
 | 
			
		||||
#include <QVector>
 | 
			
		||||
 | 
			
		||||
#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<studio::Editor*>(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<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) {
 | 
			
		||||
		m_undoGroup.setActiveStack(nullptr);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	m_undoGroup.setActiveStack(tab->undoStack());
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,7 @@
 | 
			
		||||
 | 
			
		||||
#include <ox/std/types.hpp>
 | 
			
		||||
 | 
			
		||||
#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<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 {
 | 
			
		||||
	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<QMenu> m_viewMenu;
 | 
			
		||||
		QVector<QPointer<QDockWidget>> m_dockWidgets;
 | 
			
		||||
@@ -97,6 +83,7 @@ class MainWindow: public QMainWindow {
 | 
			
		||||
		QPointer<OxFSModel> 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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user