From e736ff7116fae4de92b3340f10eb9dcf8675817e Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 26 Sep 2017 18:03:58 +0300 Subject: [PATCH] show build operation description in status line - close #284 --- src/dlangide/builders/builder.d | 62 +++++++++++++++++++++++++++++++++ views/res/i18n/en.ini | 6 ++++ views/res/i18n/ru.ini | 6 ++++ 3 files changed, 74 insertions(+) diff --git a/src/dlangide/builders/builder.d b/src/dlangide/builders/builder.d index f13213e..37b17cb 100644 --- a/src/dlangide/builders/builder.d +++ b/src/dlangide/builders/builder.d @@ -14,6 +14,38 @@ import std.conv; alias BuildResultListener = void delegate(int); +dstring replaceVars(dstring source, dstring[dstring] valueMap) { + if (!valueMap.length) + return source; // no var values + if (source.indexOf("{") < 0) + return source; // no vars + dchar[] res; + res.assumeSafeAppend; + res.reserve(source.length + 10); + int varNameStart = -1; + for(int i = 0; i < source.length; i++) { + dchar ch = source[i]; + if (ch == '{') { + varNameStart = i + 1; + } else if (ch == '}') { + if (varNameStart >= 0) { + dstring varName = source[varNameStart .. i]; + if (varName.length) { + if (auto value = varName in valueMap) { + res ~= *value; + } + } + } else { + res ~= ch; + } + varNameStart = -1; + } else if (varNameStart < 0) { + res ~= ch; + } // else it's inside variable name + } + return cast(dstring)res; +} + class Builder : BackgroundOperationWatcher { protected Project _project; protected ExternalProcess _extprocess; @@ -28,6 +60,7 @@ class Builder : BackgroundOperationWatcher { protected int _exitCode = int.min; protected string _toolchain; protected string _arch; + protected dstring _description; @property Project project() { return _project; } @property void project(Project p) { _project = p; } @@ -52,6 +85,33 @@ class Builder : BackgroundOperationWatcher { _arch = arch; _extprocess = new ExternalProcess(); _box = new ProtectedTextStorage(); + string opDescriptionId; + switch(buildOp) with(BuildOperation) { + case Build: + opDescriptionId = "BUILD_OP_DESCRIPTION_BUILD"; + break; + case Clean: + opDescriptionId = "BUILD_OP_DESCRIPTION_CLEAN"; + break; + case Rebuild: + opDescriptionId = "BUILD_OP_DESCRIPTION_REBUILD"; + break; + case Run: + opDescriptionId = "BUILD_OP_DESCRIPTION_RUN"; + break; + case Upgrade: + opDescriptionId = "BUILD_OP_DESCRIPTION_UPGRADE"; + break; + default: + break; + } + if (opDescriptionId) { + import dlangui.core.i18n; + _description = UIString.fromId(opDescriptionId).value; + dstring[dstring] values; + values["projectName"d] = project.name; + _description = replaceVars(_description, values); + } } /// log lines @@ -62,6 +122,8 @@ class Builder : BackgroundOperationWatcher { } } + /// returns description of background operation to show in status line + override @property dstring description() { return _description; } /// returns icon of background operation to show in status line override @property string icon() { return "folder"; } /// update background operation status diff --git a/views/res/i18n/en.ini b/views/res/i18n/en.ini index 3600b0f..5c5db46 100644 --- a/views/res/i18n/en.ini +++ b/views/res/i18n/en.ini @@ -248,3 +248,9 @@ RUNNING=running... QUESTION_CREATE_DIR=The target location does not exist. Do you want to create the target directory? QUESTION_NEW_WORKSPACE=Do you want to create new workspace or use current one? QUESTION_REMOVE_FILE=Do you want to remove file + +BUILD_OP_DESCRIPTION_BUILD=Building project {projectName}... +BUILD_OP_DESCRIPTION_CLEAN=Cleaning up project {projectName}... +BUILD_OP_DESCRIPTION_REBUILD=Rebuilding project {projectName}... +BUILD_OP_DESCRIPTION_RUN=Running project {projectName}... +BUILD_OP_DESCRIPTION_UPGRADE=Upgrading packages for project {projectName}... diff --git a/views/res/i18n/ru.ini b/views/res/i18n/ru.ini index 7c8df4e..d350989 100644 --- a/views/res/i18n/ru.ini +++ b/views/res/i18n/ru.ini @@ -246,3 +246,9 @@ RUNNING=выполнение... QUESTION_CREATE_DIR=Целевой каталог не существует. Желаете создать? QUESTION_NEW_WORKSPACE=Открыть новое рабочее пространство или использовать текущее? QUESTION_REMOVE_FILE=Вы действительно хотите удалить файл + +BUILD_OP_DESCRIPTION_BUILD=Собираем проект {projectName}... +BUILD_OP_DESCRIPTION_CLEAN=Очищаем файлы проекта {projectName}... +BUILD_OP_DESCRIPTION_REBUILD=Перестраиваем проект {projectName}... +BUILD_OP_DESCRIPTION_RUN=Запускаем проект {projectName}... +BUILD_OP_DESCRIPTION_UPGRADE=Обновляем пакеты для проекта {projectName}...