Add PluginArgs for plugin system
This commit is contained in:
@@ -15,16 +15,12 @@ void Plugin::addNewWizard(QString name, std::function<QVector<QWizardPage*>()> m
|
||||
m_newWizards.push_back({name, make});
|
||||
}
|
||||
|
||||
void Plugin::addImportWizard(QString name, std::function<QVector<QWizardPage*>()> make) {
|
||||
m_importWizards.push_back({name, make});
|
||||
QVector<WizardMaker> Plugin::newWizards(PluginArgs) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QVector<WizardMaker> Plugin::newWizards() {
|
||||
return m_newWizards;
|
||||
}
|
||||
|
||||
QVector<WizardMaker> Plugin::importWizards() {
|
||||
return m_importWizards;
|
||||
QVector<WizardMaker> Plugin::importWizards(PluginArgs) {
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,12 +11,20 @@
|
||||
#include <functional>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QPointer>
|
||||
#include <QSharedPointer>
|
||||
#include <QVector>
|
||||
#include <QWizardPage>
|
||||
|
||||
#include "project.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
struct PluginArgs {
|
||||
Project *project = nullptr;
|
||||
};
|
||||
|
||||
struct WizardMaker {
|
||||
QString name;
|
||||
std::function<QVector<QWizardPage*>()> make;
|
||||
@@ -25,16 +33,15 @@ struct WizardMaker {
|
||||
class Plugin {
|
||||
private:
|
||||
QVector<WizardMaker> m_newWizards;
|
||||
QVector<WizardMaker> m_importWizards;
|
||||
|
||||
public:
|
||||
void addNewWizard(QString name, std::function<QVector<QWizardPage*>()> make);
|
||||
|
||||
void addImportWizard(QString name, std::function<QVector<QWizardPage*>()> make);
|
||||
|
||||
QVector<WizardMaker> newWizards();
|
||||
virtual QVector<WizardMaker> newWizards(PluginArgs);
|
||||
|
||||
QVector<WizardMaker> importWizards();
|
||||
virtual QVector<WizardMaker> importWizards(PluginArgs);
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -218,9 +218,13 @@ int MainWindow::writeState(QString path) {
|
||||
|
||||
int MainWindow::openProject(QString projectPath) {
|
||||
auto err = closeProject();
|
||||
auto project = QSharedPointer<Project>(new Project(projectPath));
|
||||
auto project = new Project(projectPath);
|
||||
err |= project->open();
|
||||
if (err == 0) {
|
||||
if (m_project) {
|
||||
delete m_project;
|
||||
m_project = nullptr;
|
||||
}
|
||||
m_project = project;
|
||||
m_projectExplorer->setModel(new OxFSModel(m_project->romFS()));
|
||||
m_importAction->setEnabled(true);
|
||||
@@ -231,7 +235,10 @@ int MainWindow::openProject(QString projectPath) {
|
||||
|
||||
int MainWindow::closeProject() {
|
||||
auto err = 0;
|
||||
m_project = QSharedPointer<Project>(nullptr);
|
||||
if (m_project) {
|
||||
delete m_project;
|
||||
m_project = nullptr;
|
||||
}
|
||||
if (m_projectExplorer->model()) {
|
||||
delete m_projectExplorer->model();
|
||||
}
|
||||
@@ -315,8 +322,10 @@ void MainWindow::showImportWizard() {
|
||||
auto ws = new WizardSelect();
|
||||
wizard.addPage(ws);
|
||||
|
||||
PluginArgs args;
|
||||
args.project = m_project;
|
||||
for (auto p : m_plugins) {
|
||||
for (auto w : p->importWizards()) {
|
||||
for (auto w : p->importWizards(args)) {
|
||||
ws->addOption(w.name, w.make);
|
||||
}
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@ class MainWindow: public QMainWindow {
|
||||
QString m_profilePath;
|
||||
NostalgiaStudioState m_state;
|
||||
QAction *m_importAction = nullptr;
|
||||
QSharedPointer<Project> m_project;
|
||||
Project *m_project = nullptr;
|
||||
QPointer<QMenu> m_viewMenu;
|
||||
QVector<std::function<void()>> m_cleanupTasks;
|
||||
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
||||
|
Reference in New Issue
Block a user