diff --git a/src/studio/lib/newwizard.cpp b/src/studio/lib/newwizard.cpp index afd2ff73..85a6a763 100644 --- a/src/studio/lib/newwizard.cpp +++ b/src/studio/lib/newwizard.cpp @@ -220,5 +220,14 @@ Wizard::Wizard(QWidget *parent): QWizard(parent) { setModal(true); } +void Wizard::setAccept(std::function acceptFunc) { + m_acceptFunc = acceptFunc; +} + +void Wizard::accept() { + m_acceptFunc(); + QDialog::accept(); +} + } } diff --git a/src/studio/lib/newwizard.hpp b/src/studio/lib/newwizard.hpp index bb12542e..60c9cbbc 100644 --- a/src/studio/lib/newwizard.hpp +++ b/src/studio/lib/newwizard.hpp @@ -80,8 +80,15 @@ class WizardFormPage: public QWizardPage { class Wizard: public QWizard { Q_OBJECT + private: + std::function m_acceptFunc; + public: Wizard(QWidget *parent = 0); + + void setAccept(std::function acceptFunc); + + void accept(); }; } diff --git a/src/studio/lib/project.cpp b/src/studio/lib/project.cpp index 2bb756bd..01c2250a 100644 --- a/src/studio/lib/project.cpp +++ b/src/studio/lib/project.cpp @@ -16,14 +16,18 @@ namespace studio { using namespace ox::fs; -void Project::create(QString path) { - QDir().mkpath(path); +Project::Project(QString path) { + m_path = path; +} + +void Project::create() { + QDir().mkpath(m_path); size_t buffLen = 1024; m_romBuff = new QByteArray(buffLen, 0); FileSystem32::format(m_romBuff->data(), buffLen, true); - QFile file(path + "/ROM.oxfs"); + QFile file(m_path + "/ROM.oxfs"); file.open(QIODevice::WriteOnly); file.write(*m_romBuff); file.close(); diff --git a/src/studio/lib/project.hpp b/src/studio/lib/project.hpp index 61bcf3fc..a5b8c949 100644 --- a/src/studio/lib/project.hpp +++ b/src/studio/lib/project.hpp @@ -15,10 +15,13 @@ class Project: public QObject { Q_OBJECT private: + QString m_path = ""; QByteArray *m_romBuff = nullptr; public: - void create(QString path); + Project(QString path); + + void create(); }; } diff --git a/src/studio/mainwindow.cpp b/src/studio/mainwindow.cpp index aca63aa2..cfe3e837 100644 --- a/src/studio/mainwindow.cpp +++ b/src/studio/mainwindow.cpp @@ -14,6 +14,7 @@ #include #include #include "lib/newwizard.hpp" +#include "lib/project.hpp" #include "mainwindow.hpp" namespace nostalgia { @@ -86,16 +87,25 @@ void MainWindow::addAction(QMenu *menu, QString text, QString toolTip, } void MainWindow::showNewWizard() { + const QString PROJECT_NAME = "projectName"; + const QString PROJECT_PATH = "projectPath"; Wizard wizard; auto ws = new WizardSelect(); wizard.addPage(ws); - ws->addOption(tr("Project"), []() { + ws->addOption(tr("Project"), [PROJECT_NAME, PROJECT_PATH]() { auto pg = new WizardFormPage(); - pg->addLineEdit(tr("Project &Name:"), "projectName*"); - pg->addDirBrowse(tr("Project &Path:"), "projectPath*"); + pg->addLineEdit(tr("Project &Name:"), PROJECT_NAME + "*"); + pg->addDirBrowse(tr("Project &Path:"), PROJECT_PATH + "*"); return pg; } ); + wizard.setAccept([&wizard, PROJECT_NAME, PROJECT_PATH]() { + auto projectName = wizard.field(PROJECT_NAME).toString(); + auto projectPath = wizard.field(PROJECT_PATH).toString(); + auto path = projectPath + "/" + projectName; + Project(path).create(); + } + ); wizard.show(); wizard.exec(); }