Skip to content

Commit

Permalink
Fix and Add:
Browse files Browse the repository at this point in the history
 - Add jtemblate engine (documentation TODO)
 - New global variable replace engine (WIP)
 - Fix document area buttons position and icon

Signed-off-by: Martin Ribelotta <[email protected]>
  • Loading branch information
martinribelotta committed Jul 29, 2017
1 parent c3d254e commit d6fb2cb
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 193 deletions.
45 changes: 34 additions & 11 deletions appconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ AppConfig& AppConfig::mutableInstance()
return appConfig;
}

const QString AppConfig::filterTextWithVariables(const QString &text) const
{
QString result(text);
for(auto k: filterTextMap.keys())
result.replace(QString("{{%1}}").arg(k), filterTextMap.value(k)());
return result;
}

const QHash<QString, QString> AppConfig::getVariableMap() const
{
QHash<QString, QString> h;
for(auto k: filterTextMap.keys())
h.insert(k, filterTextMap[k]());
return h;
}

const QStringList &AppConfig::buildAdditionalPaths() const
{
return appData()->buildAdditionalPaths;
Expand Down Expand Up @@ -132,17 +148,17 @@ int AppConfig::editorTabWidth() const
return appData()->editorTabWidth;
}

const QString& AppConfig::builDefaultProjectPath() const
const QString& AppConfig::buildDefaultProjectPath() const
{
return appData()->builDefaultProjectPath;
}

const QString &AppConfig::builTemplatePath() const
const QString &AppConfig::buildTemplatePath() const
{
return appData()->builTemplatePath;
}

const QString &AppConfig::builTemplateUrl() const
const QString &AppConfig::buildTemplateUrl() const
{
return appData()->builTemplateUrl;
}
Expand Down Expand Up @@ -226,11 +242,11 @@ void AppConfig::load()
s.value(EDITOR_TABS_TO_SPACES, true).toBool());
this->setEditorTabWidth(
s.value(EDITOR_TAB_WIDTH, 4).toInt());
this->setBuilDefaultProjectPath(
this->setBuildDefaultProjectPath(
s.value(BUILD_DEFAULT_PROJECT_PATH, defaultProjectPath()).toString());
this->setBuilTemplatePath(
this->setBuildTemplatePath(
s.value(BUILD_TEMPLATE_PATH, defaultTemplatePath()).toString());
this->setBuilTemplateUrl(
this->setBuildTemplateUrl(
s.value(BUILD_TEMPLATE_URL, defaultTemplateUrl()).toString());
this->setBuildAdditionalPaths(
s.value(BUILD_ADDITIONAL_PATHS).toStringList());
Expand Down Expand Up @@ -284,6 +300,11 @@ void AppConfig::save()
emit configChanged(this);
}

void AppConfig::addFilterTextVariable(const QString &key, std::function<QString ()> func)
{
filterTextMap[key] = func;
}

void AppConfig::setBuildAdditionalPaths(
const QStringList& buildAdditionalPaths) const
{
Expand Down Expand Up @@ -333,21 +354,23 @@ void AppConfig::setEditorTabWidth(int editorTabWidth)
void AppConfig::setWorkspacePath(const QString &workspacePath)
{
QDir wSpace(workspacePath);
setBuilDefaultProjectPath(wSpace.absoluteFilePath(DEFAULT_PROJECT_PATH_ON_WS));
setBuilTemplatePath(wSpace.absoluteFilePath(DEFAULT_TEMPLATE_PATH_ON_WS));
setBuildDefaultProjectPath(wSpace.absoluteFilePath(DEFAULT_PROJECT_PATH_ON_WS));
setBuildTemplatePath(wSpace.absoluteFilePath(DEFAULT_TEMPLATE_PATH_ON_WS));
}

void AppConfig::setBuilDefaultProjectPath(const QString &builDefaultProjectPath)
void AppConfig::setBuildDefaultProjectPath(const QString &builDefaultProjectPath)
{
appData()->builDefaultProjectPath = builDefaultProjectPath;
addFilterTextVariable("projectPath", [this]{ return buildDefaultProjectPath(); });
}

void AppConfig::setBuilTemplatePath(const QString &builTemplatePath)
void AppConfig::setBuildTemplatePath(const QString &builTemplatePath)
{
appData()->builTemplatePath = builTemplatePath;
addFilterTextVariable("templatePath", [this]{ return buildTemplatePath(); });
}

void AppConfig::setBuilTemplateUrl(const QString &builTemplateUrl)
void AppConfig::setBuildTemplateUrl(const QString &builTemplateUrl)
{
appData()->builTemplateUrl = builTemplateUrl;
}
Expand Down
20 changes: 14 additions & 6 deletions appconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define APPCONFIG_H

#include <QObject>
#include <functional>

#include "configdialog.h"
#include "dialogconfigworkspace.h"
Expand All @@ -22,6 +23,9 @@ class AppConfig : public QObject
None, System, Custom
};

const QString filterTextWithVariables(const QString& text) const;
const QHash<QString, QString> getVariableMap() const;

const QStringList& buildAdditionalPaths() const;
const QString& editorStyle() const;
int editorFontSize() const;
Expand All @@ -37,9 +41,9 @@ class AppConfig : public QObject
bool editorSaveOnAction() const;
bool editorTabsToSpaces() const;
int editorTabWidth() const;
const QString& builDefaultProjectPath() const;
const QString& builTemplatePath() const;
const QString& builTemplateUrl() const;
const QString& buildDefaultProjectPath() const;
const QString& buildTemplatePath() const;
const QString& buildTemplateUrl() const;
QString defaultApplicationResources() const;
QString defaultProjectPath();
QString defaultTemplatePath();
Expand All @@ -59,11 +63,13 @@ class AppConfig : public QObject

signals:
void configChanged(AppConfig*);

private:
AppConfig();
void load();
void save();

void addFilterTextVariable(const QString& key, std::function<QString ()> func);
void setBuildAdditionalPaths(const QStringList& buildAdditionalPaths) const;
void setEditorStyle(const QString& editorStyle);
void setLoggerFontSize(int loggerFontSize);
Expand All @@ -74,16 +80,18 @@ class AppConfig : public QObject
void setEditorTabsToSpaces(bool editorTabsToSpaces);
void setEditorTabWidth(int editorTabWidth);
void setWorkspacePath(const QString& workspacePath);
void setBuilDefaultProjectPath(const QString& builDefaultProjectPath);
void setBuilTemplatePath(const QString& builTemplatePath);
void setBuilTemplateUrl(const QString& builTemplateUrl);
void setBuildDefaultProjectPath(const QString& buildDefaultProjectPath);
void setBuildTemplatePath(const QString& buildTemplatePath);
void setBuildTemplateUrl(const QString& buildTemplateUrl);
void setNetworkProxyHost(const QString& host);
void setNetworkProxyPort(QString host);
void setNetworkProxyUseCredentials(bool useCredentials);
void setNetworkProxyType(NetworkProxyType type);
void setNetworkProxyUsername(const QString& username);
void setNetworkProxyPassword(const QString& password);
void setProjectTmplatesAutoUpdate(bool automatic);

QHash<QString, std::function<QString ()> > filterTextMap;
};

#endif // APPCONFIG_H
18 changes: 9 additions & 9 deletions configdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void ConfigDialog::load()
ui->checkBox_replaceTabsWithSpaces->setChecked(config.editorTabsToSpaces());
ui->spinTabWidth->setValue(config.editorTabWidth());

ui->projectPath->setText(config.builDefaultProjectPath());
ui->projectTemplatesPath->setText(config.builTemplatePath());
ui->templateUrl->setText(config.builTemplateUrl());
ui->projectPath->setText(config.buildDefaultProjectPath());
ui->projectTemplatesPath->setText(config.buildTemplatePath());
ui->templateUrl->setText(config.buildTemplateUrl());

QStringListModel *model =
qobject_cast<QStringListModel*>(ui->additionalPathList->model());
Expand Down Expand Up @@ -133,9 +133,9 @@ void ConfigDialog::save()
config.setEditorSaveOnAction(ui->checkBox_saveOnAction->isChecked());
config.setEditorTabsToSpaces(ui->checkBox_replaceTabsWithSpaces->isChecked());
config.setEditorTabWidth(ui->spinTabWidth->value());
config.setBuilDefaultProjectPath(ui->projectPath->text());
config.setBuilTemplatePath(ui->projectTemplatesPath->text());
config.setBuilTemplateUrl(ui->templateUrl->text());
config.setBuildDefaultProjectPath(ui->projectPath->text());
config.setBuildTemplatePath(ui->projectTemplatesPath->text());
config.setBuildTemplateUrl(ui->templateUrl->text());
QStringListModel *model = qobject_cast<QStringListModel*>(ui->additionalPathList->model());
config.setBuildAdditionalPaths(model->stringList());
auto proxyType = [this](){
Expand Down Expand Up @@ -213,12 +213,12 @@ void ConfigDialog::on_projectTemplatesDownload_clicked()
AppConfig& config = AppConfig::mutableInstance();
QUrl templateUrl(ui->templateUrl->text());
if (!templateUrl.isValid())
templateUrl = QUrl(config.builTemplateUrl());
templateUrl = QUrl(config.buildTemplateUrl());
if (!templateUrl.isValid()) {
QMessageBox::critical(this, tr("Error"), tr("No valid URL: %1").arg(templateUrl.toString()));
return;
}
QDir templatePath(config.builTemplatePath());
QDir templatePath(config.buildTemplatePath());
if (!templatePath.exists()) {
if (!QDir::root().mkpath(templatePath.absolutePath())) {
QMessageBox::critical(this, tr("Error"), tr("Error creating %1")
Expand Down Expand Up @@ -272,7 +272,7 @@ void ConfigDialog::on_projectTemplatesDownload_clicked()
QJsonObject oEntry = entry.toObject();
QString name = oEntry.value("name").toString();
QString download_url = oEntry.value("download_url").toString();
if (QFileInfo(name).suffix() == "template") {
if ((QStringList{"template", "jtemplate"}).contains(QFileInfo(name).suffix())) {
QString localPath = templatePath.absoluteFilePath(name);
downloader->enqueueDownload(QUrl(download_url), localPath);
}
Expand Down
6 changes: 3 additions & 3 deletions documentarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ DocumentArea::DocumentArea(QWidget *parent) :
QStandardItem *item = new QStandardItem(tab->tabText(i));
item->setIcon(QIcon(":/images/document-new.svg"));
item->setData(i);
w->setProperty("comboItem", qVariantFromValue((void*) item));
w->setProperty("comboItem", qVariantFromValue(reinterpret_cast<void*>(item)));
windowListModel->appendRow(item);
}
windowListModel->sort(0);
Expand All @@ -54,13 +54,13 @@ DocumentArea::DocumentArea(QWidget *parent) :
buttonBoxLayout->addWidget(reloadCurrent);
buttonBoxLayout->addWidget(saveCurrent);
buttonBoxLayout->addWidget(saveAll);
buttonBoxLayout->addWidget(closeAll);
buttonBoxLayout->addWidget(closeCurrent);
buttonBoxLayout->addWidget(closeAll);

reloadCurrent->setIcon(QIcon(":/images/actions/view-refresh.svg"));
reloadCurrent->setToolTip(tr("Reload File"));

closeAll->setIcon(QIcon(":/images/actions/window-close.svg"));
closeAll->setIcon(QIcon(":/images/document-close-all.svg"));
closeAll->setToolTip(tr("Close All"));

closeCurrent->setIcon(QIcon(":/images/document-close.svg"));
Expand Down
75 changes: 75 additions & 0 deletions images/document-close-all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ int main(int argc, char *argv[])
QCoreApplication::setApplicationName("embedded IDE");
a.setWindowIcon(QIcon(":/images/embedded-ide.png"));

AppConfig::mutableInstance().addFilterTextVariable(
"appExecPath", QCoreApplication::applicationDirPath);
AppConfig::mutableInstance().addFilterTextVariable(
"appExecName", QCoreApplication::applicationFilePath);

qDebug() << "Support ssl " << QSslSocket::supportsSsl();

QTranslator tr;
Expand All @@ -60,16 +65,16 @@ int main(int argc, char *argv[])
auto hardConf = QJsonDocument::fromJson(hardConfFile.readAll()).object();
QStringList additionalPaths;
for (auto p: hardConf.value("additionalPaths").toArray())
additionalPaths.append(p.toString().replace("{{APP_PATH}}", QCoreApplication::applicationDirPath()));
additionalPaths.append(AppConfig::mutableInstance().filterTextWithVariables(p.toString()));
AppConfig::mutableInstance().setBuildAdditionalPaths(additionalPaths);
AppConfig::mutableInstance().setBuilTemplateUrl(hardConf.value("templateUrl").toString());
AppConfig::mutableInstance().setBuildTemplateUrl(hardConf.value("templateUrl").toString());
AppConfig::mutableInstance().save();
}

AppConfig::mutableInstance().load();
AppConfig::mutableInstance().adjustPath();

QDir projectDir = AppConfig::mutableInstance().builDefaultProjectPath();
QDir projectDir = AppConfig::mutableInstance().buildDefaultProjectPath();
QDir wSpace(QDir::cleanPath(projectDir.absoluteFilePath("..")));
if (!wSpace.exists()) {
DialogConfigWorkspace d;
Expand Down
2 changes: 1 addition & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
static QFileInfoList lastProjectsList(bool includeAllInWorkspace = true) {
QFileInfoList list;
if (includeAllInWorkspace) {
QDir prjDir(AppConfig::mutableInstance().builDefaultProjectPath());
QDir prjDir(AppConfig::mutableInstance().buildDefaultProjectPath());
foreach(QFileInfo dirInfo, prjDir.entryInfoList(QDir::AllDirs|QDir::NoDotAndDotDot)) {
QDir dir(dirInfo.absoluteFilePath());
QFileInfo make(dir.absoluteFilePath("Makefile"));
Expand Down
Loading

0 comments on commit d6fb2cb

Please sign in to comment.