Add conclusion page to wizard and prevent recreating already existing
projects
This commit is contained in:
parent
973b7e97b1
commit
258be70528
@ -9,15 +9,17 @@ include(address_sanitizer)
|
|||||||
|
|
||||||
if (WOMBAT_BUILD_TYPE STREQUAL "GBA")
|
if (WOMBAT_BUILD_TYPE STREQUAL "GBA")
|
||||||
include(GBA)
|
include(GBA)
|
||||||
|
add_definitions(
|
||||||
|
-nostdlib
|
||||||
|
-fno-exceptions
|
||||||
|
-fno-rtti
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(
|
add_definitions(
|
||||||
-std=c++11
|
-std=c++11
|
||||||
-Wall
|
-Wall
|
||||||
-Wsign-compare
|
-Wsign-compare
|
||||||
-nostdlib
|
|
||||||
-fno-exceptions
|
|
||||||
-fno-rtti
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
|
@ -39,11 +39,10 @@ WizardSelect::WizardSelect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WizardSelect::initializePage() {
|
void WizardSelect::initializePage() {
|
||||||
m_nextId = -1;
|
|
||||||
emit completeChanged();
|
emit completeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WizardSelect::addOption(QString name, std::function<QWizardPage*()> makePage) {
|
void WizardSelect::addOption(QString name, function<QVector<QWizardPage*>()> makePage) {
|
||||||
m_options[name] = makePage;
|
m_options[name] = makePage;
|
||||||
m_listWidget->addItem(name);
|
m_listWidget->addItem(name);
|
||||||
}
|
}
|
||||||
@ -52,40 +51,45 @@ bool WizardSelect::isComplete() const {
|
|||||||
return m_complete;
|
return m_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WizardSelect::nextId() const {
|
|
||||||
return m_nextId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WizardSelect::itemSelected(int row) {
|
void WizardSelect::itemSelected(int row) {
|
||||||
if (row > -1) {
|
if (row > -1) {
|
||||||
auto w = wizard();
|
auto w = wizard();
|
||||||
|
|
||||||
if (nextId() > -1) {
|
if (nextId() > -1) {
|
||||||
w->removePage(nextId());
|
w->removePage(nextId());
|
||||||
m_nextId = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto selected = m_listWidget->currentItem()->text();
|
auto selected = m_listWidget->currentItem()->text();
|
||||||
if (m_options.contains(selected)) {
|
if (m_options.contains(selected)) {
|
||||||
m_nextId = w->addPage(m_options[selected]());
|
for (auto p : m_options[selected]()) {
|
||||||
|
w->addPage(p);
|
||||||
|
}
|
||||||
// for some reason the continue button only appears correctly after remove runs
|
// for some reason the continue button only appears correctly after remove runs
|
||||||
w->removePage(nextId());
|
w->removePage(w->addPage(new QWizardPage()));
|
||||||
m_nextId = w->addPage(m_options[selected]());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WizardConclusionPage::WizardConclusionPage(QString msg) {
|
WizardConclusionPage::WizardConclusionPage(QString msg, QVector<QString> fields) {
|
||||||
|
m_baseMsg = msg;
|
||||||
|
m_fields = fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
WizardConclusionPage::~WizardConclusionPage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void WizardConclusionPage::initializePage() {
|
||||||
|
QString msg = m_baseMsg;
|
||||||
|
for (auto field : m_fields) {
|
||||||
|
msg = msg.arg(this->field(field).toString());
|
||||||
|
}
|
||||||
auto text = new QLabel(msg, this);
|
auto text = new QLabel(msg, this);
|
||||||
auto layout = new QVBoxLayout(this);
|
auto layout = new QVBoxLayout(this);
|
||||||
layout->addWidget(text);
|
layout->addWidget(text);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
WizardConclusionPage::~WizardConclusionPage() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
WizardFormPage::WizardFormPage() {
|
WizardFormPage::WizardFormPage() {
|
||||||
m_layout = new QGridLayout(this);
|
m_layout = new QGridLayout(this);
|
||||||
|
@ -24,22 +24,19 @@ class WizardSelect: public QWizardPage {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString, std::function<QWizardPage*()>> m_options;
|
QMap<QString, std::function<QVector<QWizardPage*>()>> m_options;
|
||||||
QListWidget *m_listWidget = nullptr;
|
QListWidget *m_listWidget = nullptr;
|
||||||
bool m_complete = false;
|
bool m_complete = false;
|
||||||
int m_nextId = -1;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WizardSelect();
|
WizardSelect();
|
||||||
|
|
||||||
void addOption(QString name, std::function<QWizardPage*()> makePage);
|
void addOption(QString name, std::function<QVector<QWizardPage*>()> makePage);
|
||||||
|
|
||||||
void initializePage() override;
|
void initializePage() override;
|
||||||
|
|
||||||
bool isComplete() const override;
|
bool isComplete() const override;
|
||||||
|
|
||||||
int nextId() const override;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void itemSelected(int row);
|
void itemSelected(int row);
|
||||||
};
|
};
|
||||||
@ -83,11 +80,15 @@ class WizardFormPage: public QWizardPage {
|
|||||||
class WizardConclusionPage: public QWizardPage {
|
class WizardConclusionPage: public QWizardPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
QString m_baseMsg = "";
|
||||||
|
QVector<QString> m_fields;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WizardConclusionPage(QString msg);
|
WizardConclusionPage(QString msg, QVector<QString> field);
|
||||||
|
|
||||||
virtual ~WizardConclusionPage();
|
virtual ~WizardConclusionPage();
|
||||||
|
|
||||||
|
void initializePage() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
#include <QVector>
|
||||||
#include "lib/newwizard.hpp"
|
#include "lib/newwizard.hpp"
|
||||||
#include "lib/project.hpp"
|
#include "lib/project.hpp"
|
||||||
#include "mainwindow.hpp"
|
#include "mainwindow.hpp"
|
||||||
@ -92,14 +93,29 @@ void MainWindow::showNewWizard() {
|
|||||||
Wizard wizard;
|
Wizard wizard;
|
||||||
auto ws = new WizardSelect();
|
auto ws = new WizardSelect();
|
||||||
wizard.addPage(ws);
|
wizard.addPage(ws);
|
||||||
ws->addOption(tr("Project"), [PROJECT_NAME, PROJECT_PATH]() {
|
ws->addOption(tr("Project"),
|
||||||
|
[&wizard, PROJECT_NAME, PROJECT_PATH]() {
|
||||||
|
QVector<QWizardPage*> pgs;
|
||||||
auto pg = new WizardFormPage();
|
auto pg = new WizardFormPage();
|
||||||
pg->addLineEdit(tr("Project &Name:"), PROJECT_NAME + "*");
|
pg->addLineEdit(tr("Project &Name:"), PROJECT_NAME + "*", "", [PROJECT_PATH, pg, &wizard](QString projectName) {
|
||||||
|
auto projectPath = wizard.field(PROJECT_PATH).toString();
|
||||||
|
auto path = projectPath + "/" + projectName;
|
||||||
|
if (!QDir(path).exists()) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
pg->showValidationError(tr("This project directory already exists."));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
pg->addDirBrowse(tr("Project &Path:"), PROJECT_PATH + "*");
|
pg->addDirBrowse(tr("Project &Path:"), PROJECT_PATH + "*");
|
||||||
return pg;
|
pgs.push_back(pg);
|
||||||
|
pgs.push_back(new WizardConclusionPage(tr("Creating project: %1/%2"), {PROJECT_PATH, PROJECT_NAME}));
|
||||||
|
|
||||||
|
return pgs;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
wizard.setAccept([&wizard, PROJECT_NAME, PROJECT_PATH]() {
|
wizard.setAccept([&wizard, ws, PROJECT_NAME, PROJECT_PATH]() {
|
||||||
auto projectName = wizard.field(PROJECT_NAME).toString();
|
auto projectName = wizard.field(PROJECT_NAME).toString();
|
||||||
auto projectPath = wizard.field(PROJECT_PATH).toString();
|
auto projectPath = wizard.field(PROJECT_PATH).toString();
|
||||||
if (QDir(projectPath).exists()) {
|
if (QDir(projectPath).exists()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user