From 258be70528f7e9ac7950d86dab64ca89d1f4207e Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 3 May 2017 23:20:53 -0500 Subject: [PATCH] Add conclusion page to wizard and prevent recreating already existing projects --- CMakeLists.txt | 8 +++++--- src/studio/lib/newwizard.cpp | 32 ++++++++++++++++++-------------- src/studio/lib/newwizard.hpp | 13 +++++++------ src/studio/mainwindow.cpp | 24 ++++++++++++++++++++---- 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44afdc29..3ff96a9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,15 +9,17 @@ include(address_sanitizer) if (WOMBAT_BUILD_TYPE STREQUAL "GBA") include(GBA) + add_definitions( + -nostdlib + -fno-exceptions + -fno-rtti + ) endif() add_definitions( -std=c++11 -Wall -Wsign-compare - -nostdlib - -fno-exceptions - -fno-rtti ) if (CMAKE_BUILD_TYPE STREQUAL "Release") diff --git a/src/studio/lib/newwizard.cpp b/src/studio/lib/newwizard.cpp index 25d40da9..418649d6 100644 --- a/src/studio/lib/newwizard.cpp +++ b/src/studio/lib/newwizard.cpp @@ -39,11 +39,10 @@ WizardSelect::WizardSelect() { } void WizardSelect::initializePage() { - m_nextId = -1; emit completeChanged(); } -void WizardSelect::addOption(QString name, std::function makePage) { +void WizardSelect::addOption(QString name, function()> makePage) { m_options[name] = makePage; m_listWidget->addItem(name); } @@ -52,40 +51,45 @@ bool WizardSelect::isComplete() const { return m_complete; } -int WizardSelect::nextId() const { - return m_nextId; -} - void WizardSelect::itemSelected(int row) { if (row > -1) { auto w = wizard(); if (nextId() > -1) { w->removePage(nextId()); - m_nextId = -1; } auto selected = m_listWidget->currentItem()->text(); 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 - w->removePage(nextId()); - m_nextId = w->addPage(m_options[selected]()); + w->removePage(w->addPage(new QWizardPage())); } } } -WizardConclusionPage::WizardConclusionPage(QString msg) { +WizardConclusionPage::WizardConclusionPage(QString msg, QVector 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 layout = new QVBoxLayout(this); layout->addWidget(text); setLayout(layout); } -WizardConclusionPage::~WizardConclusionPage() { -} - WizardFormPage::WizardFormPage() { m_layout = new QGridLayout(this); diff --git a/src/studio/lib/newwizard.hpp b/src/studio/lib/newwizard.hpp index cd05be8b..86b5a86f 100644 --- a/src/studio/lib/newwizard.hpp +++ b/src/studio/lib/newwizard.hpp @@ -24,22 +24,19 @@ class WizardSelect: public QWizardPage { Q_OBJECT private: - QMap> m_options; + QMap()>> m_options; QListWidget *m_listWidget = nullptr; bool m_complete = false; - int m_nextId = -1; public: WizardSelect(); - void addOption(QString name, std::function makePage); + void addOption(QString name, std::function()> makePage); void initializePage() override; bool isComplete() const override; - int nextId() const override; - private slots: void itemSelected(int row); }; @@ -83,11 +80,15 @@ class WizardFormPage: public QWizardPage { class WizardConclusionPage: public QWizardPage { Q_OBJECT private: + QString m_baseMsg = ""; + QVector m_fields; public: - WizardConclusionPage(QString msg); + WizardConclusionPage(QString msg, QVector field); virtual ~WizardConclusionPage(); + + void initializePage() override; }; diff --git a/src/studio/mainwindow.cpp b/src/studio/mainwindow.cpp index 52acd58a..23c41bc0 100644 --- a/src/studio/mainwindow.cpp +++ b/src/studio/mainwindow.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "lib/newwizard.hpp" #include "lib/project.hpp" #include "mainwindow.hpp" @@ -92,14 +93,29 @@ void MainWindow::showNewWizard() { Wizard wizard; auto ws = new WizardSelect(); wizard.addPage(ws); - ws->addOption(tr("Project"), [PROJECT_NAME, PROJECT_PATH]() { + ws->addOption(tr("Project"), + [&wizard, PROJECT_NAME, PROJECT_PATH]() { + QVector pgs; 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 + "*"); - 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 projectPath = wizard.field(PROJECT_PATH).toString(); if (QDir(projectPath).exists()) {