From 6699865b74b579f632762f2afd26a089aff37ac8 Mon Sep 17 00:00:00 2001 From: Brett Weir Date: Tue, 26 Jul 2016 15:18:15 -0700 Subject: [PATCH] Add support for multiple builders per language definition --- src/propelleride/language.cpp | 55 ++++++++++++++++++++--- src/propelleride/language.h | 10 ++++- src/propelleride/languages/c.json | 4 +- src/propelleride/languages/propbasic.json | 4 +- src/propelleride/languages/spin.json | 5 ++- src/propelleride/pathselector.cpp | 19 +++++++- src/propelleride/pathselector.h | 2 +- 7 files changed, 87 insertions(+), 12 deletions(-) diff --git a/src/propelleride/language.cpp b/src/propelleride/language.cpp index 9ef7a90..2d58164 100644 --- a/src/propelleride/language.cpp +++ b/src/propelleride/language.cpp @@ -183,15 +183,26 @@ void Language::load(QString name, QString filename) _lookup[ext] = name; } - foreach (QVariant stepvar, lang["buildsteps"].toArray().toVariantList()) + data.builder = 0; + + foreach (QVariant steplistvar, lang["buildsteps"].toArray().toVariantList()) { - data.buildsteps << stepvar.toString(); + QStringList steplist = steplistvar.toStringList(); + QStringList buildsteps; + + foreach (QString s, steplist) + { + buildsteps << s; + } + + data.buildsteps << buildsteps; } - qDebug() << "Loading language definition:" - << qPrintable(data.name) - << data.extensions; -// << data.buildsteps; + qDebug() << "Loading language definition:" << qPrintable(data.name); + qDebug() << " Extensions: " << data.extensions; + qDebug() << " Build steps:"; + foreach (QStringList sl, data.buildsteps) + qDebug() << " " << sl; data.includes = lang["includes"].toBool(); @@ -273,7 +284,39 @@ ProjectParser * Language::parser() return language().parser; } + +int Language::builder() +{ + return language().builder; +} + +void Language::setBuilder(int index) +{ + if (!_data.contains(_language)) + return; + + if (!builders()) + _data[_language].builder = -1; + + if (index < 0) + _data[_language].builder = 0; + else if (index > builders()-1) + _data[_language].builder = builders()-1; + else + _data[_language].builder = index; +} + +int Language::builders() +{ + return language().buildsteps.size(); +} + QStringList Language::listBuildSteps() +{ + return language().buildsteps[language().builder]; +} + +QList Language::listAllBuildSteps() { return language().buildsteps; } diff --git a/src/propelleride/language.h b/src/propelleride/language.h index 327e340..189bf5e 100644 --- a/src/propelleride/language.h +++ b/src/propelleride/language.h @@ -18,11 +18,14 @@ class LanguageData case_sensitive = false; enable_blocks = false; includes = false; + builder = -1; } QString name; QStringList extensions; - QStringList buildsteps; + + int builder; + QList buildsteps; ProjectParser * parser; @@ -67,7 +70,12 @@ class Language QStringList extensions(); ProjectParser * parser(); + int builder(); + void setBuilder(int index); + int builders(); QStringList listBuildSteps(); + QList listAllBuildSteps(); + QStringList listKeywords(); QStringList listOperators(); QStringList listNumbers(); diff --git a/src/propelleride/languages/c.json b/src/propelleride/languages/c.json index 83ab5eb..fbf8159 100644 --- a/src/propelleride/languages/c.json +++ b/src/propelleride/languages/c.json @@ -1,7 +1,9 @@ { "name": "C", "extension": [ "c", "h", "cpp", "hpp" ], - "buildsteps": [ ], + "buildsteps": [ + [ ] + ], "includes": true, "syntax": { "case_sensitive": true, diff --git a/src/propelleride/languages/propbasic.json b/src/propelleride/languages/propbasic.json index 22c3ebf..ba34bea 100644 --- a/src/propelleride/languages/propbasic.json +++ b/src/propelleride/languages/propbasic.json @@ -1,7 +1,9 @@ { "name": "PropBASIC", "extension": [ "pbas", "plib" ], - "buildsteps": [ "propbasic", "bstc" ], + "buildsteps": [ + [ "propbasic", "bstc" ] + ], "includes": false, "syntax": { "case_sensitive": false, diff --git a/src/propelleride/languages/spin.json b/src/propelleride/languages/spin.json index 432faf9..ac2ba3d 100644 --- a/src/propelleride/languages/spin.json +++ b/src/propelleride/languages/spin.json @@ -1,7 +1,10 @@ { "name": "Spin", "extension": [ "spin" ], - "buildsteps": [ "bstc" ], + "buildsteps": [ + [ "bstc" ], + [ "openspin" ] + ], "includes": true, "syntax": { "case_sensitive": false, diff --git a/src/propelleride/pathselector.cpp b/src/propelleride/pathselector.cpp index a0d6434..50c956c 100644 --- a/src/propelleride/pathselector.cpp +++ b/src/propelleride/pathselector.cpp @@ -13,13 +13,16 @@ PathSelector::PathSelector(QString languagekey, ui.name->setText(language.name()); ui.compiler->clear(); - ui.compiler->addItem(language.listBuildSteps().join(" > ")); + + foreach (QStringList buildsteps, language.listAllBuildSteps()) + ui.compiler->addItem(buildsteps.join(" > ")); restore(); load(); save(); + connect(ui.compiler, SIGNAL(currentIndexChanged(int)), this, SLOT(setBuildSteps(int))); connect(ui.deletePath, SIGNAL(clicked()), this, SLOT(deletePath())); connect(ui.addPath, SIGNAL(clicked()), this, SLOT(addPath())); } @@ -48,6 +51,12 @@ void PathSelector::setDefaultIncludes(QStringList paths) defaultincludes = paths; } +void PathSelector::setBuildSteps(int index) +{ + language.setBuilder(index); + qDebug() << "COMPILER" << language.listBuildSteps(); +} + void PathSelector::addPath() { int i = ui.includes->currentRow(); @@ -102,6 +111,7 @@ void PathSelector::save() settings.beginGroup("Paths"); settings.beginGroup(language.key()); + settings.setValue("builder",ui.compiler->currentIndex()); settings.setValue("includes",includes); settings.endGroup(); @@ -114,6 +124,13 @@ void PathSelector::load() settings.beginGroup("Paths"); settings.beginGroup(language.key()); + int builder = -1; + if (language.builders()) + builder = settings.value("builder", 0).toInt(); + + ui.compiler->setCurrentIndex(builder); + language.setBuilder(builder); + QStringList inc = settings.value("includes", defaultincludes).toStringList(); setIncludes(inc); diff --git a/src/propelleride/pathselector.h b/src/propelleride/pathselector.h index 4c42765..a63db1a 100644 --- a/src/propelleride/pathselector.h +++ b/src/propelleride/pathselector.h @@ -28,6 +28,7 @@ class PathSelector : public QWidget private slots: void setIncludes(const QStringList & paths); + void setBuildSteps(int index); void addPath(); void deletePath(); @@ -36,7 +37,6 @@ private slots: QWidget * parent = 0); ~PathSelector(); - void setDefaultCompiler(QString path); void setDefaultIncludes(QStringList paths); public slots: