diff --git a/src/nostalgia/studio/lib/wizard.cpp b/src/nostalgia/studio/lib/wizard.cpp index 4f3a3a67..867948fa 100644 --- a/src/nostalgia/studio/lib/wizard.cpp +++ b/src/nostalgia/studio/lib/wizard.cpp @@ -15,12 +15,26 @@ #include #include +#include "context.hpp" +#include "project.hpp" #include "plugin.hpp" #include "wizard.hpp" namespace nostalgia::studio { -using std::function; +PathExistsValidator::PathExistsValidator(const Context *ctx, QString pathTemplate, bool shouldExist) { + m_ctx = ctx; + m_pathTemplate = pathTemplate; + m_shouldExist = shouldExist; +} + +QValidator::State PathExistsValidator::validate(QString &input, int&) const { + auto path = m_pathTemplate.arg(input); + if (m_ctx->project->exists(path) == m_shouldExist) { + return QValidator::Acceptable; + } + return QValidator::Invalid; +} WizardSelect::WizardSelect() { m_listWidget = new QListWidget(this); @@ -203,7 +217,7 @@ QComboBox *WizardFormPage::addComboBox(QString displayName, QString fieldName, Q return cb; } -QLineEdit *WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal, function validator) { +QLineEdit *WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal, std::function validator) { auto lbl = new QLabel(displayName, this); auto le = new QLineEdit(this); lbl->setBuddy(le); diff --git a/src/nostalgia/studio/lib/wizard.hpp b/src/nostalgia/studio/lib/wizard.hpp index 0f78c860..733c5edb 100644 --- a/src/nostalgia/studio/lib/wizard.hpp +++ b/src/nostalgia/studio/lib/wizard.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,19 @@ namespace nostalgia::studio { +class PathExistsValidator: public QValidator { + private: + const class Context *m_ctx = nullptr; + QString m_pathTemplate; + bool m_shouldExist = true; + + public: + PathExistsValidator(const class Context *ctx, QString pathTemplate, bool shouldExist); + + QValidator::State validate(QString &input, int &pos) const override; + +}; + struct NOSTALGIASTUDIO_EXPORT WizardMaker { QString name; std::function()> make;