Make New Project create new projects

This commit is contained in:
Gary Talent 2017-04-20 23:15:25 -05:00
parent 9730ef773e
commit 51124966c3
5 changed files with 40 additions and 7 deletions

View File

@ -220,5 +220,14 @@ Wizard::Wizard(QWidget *parent): QWizard(parent) {
setModal(true);
}
void Wizard::setAccept(std::function<void()> acceptFunc) {
m_acceptFunc = acceptFunc;
}
void Wizard::accept() {
m_acceptFunc();
QDialog::accept();
}
}
}

View File

@ -80,8 +80,15 @@ class WizardFormPage: public QWizardPage {
class Wizard: public QWizard {
Q_OBJECT
private:
std::function<void()> m_acceptFunc;
public:
Wizard(QWidget *parent = 0);
void setAccept(std::function<void()> acceptFunc);
void accept();
};
}

View File

@ -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();

View File

@ -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();
};
}

View File

@ -14,6 +14,7 @@
#include <QLineEdit>
#include <QMenuBar>
#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();
}