Skip to content

Commit ece8dff

Browse files
author
Tim Etchells
committed
Add Enable/Disable Autobuild context items
- These are not available in the command palette, because I don't want to refactor promptForProject to support this (yet) - Toggle AB is still available in the CP - Add Validate context item, when autobuild is off - Refactor the way context IDs are built
1 parent f1fd6e4 commit ece8dff

File tree

8 files changed

+116
-44
lines changed

8 files changed

+116
-44
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ This is the Git repository top-level README.
77
For the README packaged with this extension, see [the extension README](https://github.ibm.com/dev-ex/microclimate-vscode/tree/master/dev/README.md)
88

99
## How to install
10-
1. [Download the newest build from the build branch](https://github.ibm.com/dev-ex/microclimate-vscode/raw/build/vscode-microclimate-tools-0.0.2.vsix)
11-
- The builds are [available on Artifactory too](https://sys-mcs-docker-local.artifactory.swg-devops.com/artifactory/sys-mcs-docker-local/microclimate-vscode/)
10+
1. [Download the newest build from Artifactory](https://sys-mcs-docker-local.artifactory.swg-devops.com/artifactory/sys-mcs-docker-local/microclimate-vscode/)
1211
2. In VSCode, go `View` > `Extensions` > `...` overflow menu > `Install from VSIX...`
1312

1413
## How to use

dev/package.json

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@
152152
"title": "%cmdTitle_toggleAutoBuild%",
153153
"category": "%commandCategory%"
154154
},
155+
{
156+
"command": "%cmdID_enableAutoBuild%",
157+
"title": "%cmdTitle_enableAutoBuild%",
158+
"category": "%commandCategory%"
159+
},
160+
{
161+
"command": "%cmdID_disableAutoBuild%",
162+
"title": "%cmdTitle_disableAutoBuild%",
163+
"category": "%commandCategory%"
164+
},
155165
{
156166
"command": "%cmdID_openAppMonitor%",
157167
"title": "%cmdTitle_openAppMonitor%",
@@ -164,6 +174,16 @@
164174
}
165175
],
166176
"menus": {
177+
"commandPalette": [
178+
{
179+
"command": "%cmdID_enableAutoBuild%",
180+
"when": "never"
181+
},
182+
{
183+
"command": "%cmdID_disableAutoBuild%",
184+
"when": "never"
185+
}
186+
],
167187
"view/title": [
168188
{
169189
"command": "%cmdID_newConnection%",
@@ -213,31 +233,41 @@
213233
{
214234
"command": "%cmdID_projectInfo%",
215235
"when": "%isProject%",
216-
"group": "ext.mc.c"
236+
"group": "ext.mc.c@0"
217237
},
218238
{
219239
"command": "%cmdID_openAppLog%",
220240
"when": "%isEnabledProject%",
221-
"group": "ext.mc.c"
241+
"group": "ext.mc.c@1"
222242
},
223243
{
224244
"command": "%cmdID_openBuildLog%",
225245
"when": "%isEnabledProject%",
226-
"group": "ext.mc.c"
246+
"group": "ext.mc.c@2"
227247
},
228248
{
229249
"command": "%cmdID_requestBuild%",
230250
"when": "%isEnabledProject%",
231251
"group": "ext.mc.d@0"
232252
},
233253
{
234-
"command": "%cmdID_toggleAutoBuild%",
235-
"when": "%isEnabledProject%",
254+
"command": "%cmdID_validate%",
255+
"when": "%isEnabledAutoBuildOff%",
236256
"group": "ext.mc.d@1"
237257
},
238258
{
239-
"command": "ext.mc.attachDebugger",
240-
"when": "%isDebuggingProject%",
259+
"command": "%cmdID_enableAutoBuild%",
260+
"when": "%isEnabledAutoBuildOff%",
261+
"group": "ext.mc.d@2"
262+
},
263+
{
264+
"command": "%cmdID_disableAutoBuild%",
265+
"when": "%isEnabledAutoBuildOn%",
266+
"group": "ext.mc.d@2"
267+
},
268+
{
269+
"command": "%cmdID_attachDebugger%",
270+
"when": "%isDebuggableProject%",
241271
"group": "ext.mc.e"
242272
},
243273
{

dev/package.nls.json

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,37 @@
8080
"cmdID_toggleAutoBuild": "ext.mc.toggleAutoBuild",
8181
"cmdTitle_toggleAutoBuild": "Toggle auto build",
8282

83+
"cmdID_enableAutoBuild": "ext.mc.enableAutoBuild",
84+
"cmdTitle_enableAutoBuild": "Enable auto build",
85+
86+
"cmdID_disableAutoBuild": "ext.mc.disableAutoBuild",
87+
"cmdTitle_disableAutoBuild": "Disable auto build",
88+
8389
"cmdID_openAppMonitor": "ext.mc.openAppMonitor",
8490
"cmdTitle_openAppMonitor": "Open app monitor",
8591
"cmdDescr_openAppMonitor": "Open a project's Application Monitor page in a browser",
8692

8793
"cmdID_validate": "ext.mc.validate",
88-
"cmdTitle_validate": "Validate project",
94+
"cmdTitle_validate": "Validate",
8995

9096
"settingDesc_connections": "URLs of Microclimate instances to connect to. Not intended to be manually edited.",
9197
"settingDesc_showLogOnChange_app": "When a Microclimate project's open application logs change, bring that log to the front",
9298
"settingDesc_showLogOnChange_build": "When a Microclimate project's open build logs change, bring that log to the front",
9399

94100
"// None of items below are exposed to user": [
95-
"Careful! Changing almost any of these will also require",
96-
"a code change in the class that uses the relevant context ID."
101+
"These regexes match Context IDs for Projects and Connections to determine command enablement",
102+
"See ProjectContextID.ts and Connection.ts for how the Context IDs are set"
97103
],
98104

99-
"isInViewWithNothingSelected": "view == ext.mc.mcProjectExplorer && !viewItem",
100-
"isConnectionOrProject": "viewItem =~ /ext.mc.*/",
101-
"isConnection": "viewItem =~ /ext.mc.connectionItem*/",
102-
"isActiveConnection": "viewItem == ext.mc.connectionItem.active",
103-
"isProject": "viewItem =~ /ext.mc.projectItem*/",
104-
"isEnabledProject": "viewItem =~ /ext.mc.projectItem.enabled*/",
105-
"isDisabledProject": "viewItem =~ /ext.mc.projectItem.disabled*/",
106-
"isDebuggingProject": "viewItem =~ /ext.mc.projectItem.enabled.debugging*/"
105+
"isInViewWithNothingSelected": "view == ext\\.mc\\.mcProjectExplorer && !viewItem",
106+
"isConnectionOrProject": "viewItem =~ /ext\\.mc\\.*/",
107+
"isConnection": "viewItem =~ /ext\\.mc\\.connectionItem*/",
108+
"isActiveConnection": "viewItem == ext\\.mc\\.connectionItem\\.active",
109+
110+
"isProject": "viewItem =~ /ext\\.mc\\.projectItem*/",
111+
"isEnabledProject": "viewItem =~ /ext\\.mc\\.projectItem\\.enabled*/",
112+
"isDisabledProject": "viewItem =~ /ext\\.mc\\.projectItem\\.disabled*/",
113+
"isDebuggableProject": "viewItem =~ /ext\\.mc\\.projectItem\\.enabled\\.debuggable*/",
114+
"isEnabledAutoBuildOn": "viewItem =~ /ext\\.mc\\.projectItem\\.enabled.*\\.autoBuildOn/",
115+
"isEnabledAutoBuildOff": "viewItem =~ /ext\\.mc\\.projectItem\\.enabled.*\\.autoBuildOff/"
107116
}

dev/src/command/CommandUtil.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export function createCommands(): vscode.Disposable[] {
5353

5454
vscode.commands.registerCommand(Commands.REQUEST_BUILD, (selection) => requestBuildCmd(selection)),
5555
vscode.commands.registerCommand(Commands.TOGGLE_AUTOBUILD, (selection) => toggleAutoBuildCmd(selection)),
56+
vscode.commands.registerCommand(Commands.ENABLE_AUTOBUILD, (selection) => toggleAutoBuildCmd(selection)),
57+
vscode.commands.registerCommand(Commands.DISABLE_AUTOBUILD, (selection) => toggleAutoBuildCmd(selection)),
5658

5759
vscode.commands.registerCommand(Commands.OPEN_APP_LOG, (selection) => openLogCmd(selection, true)),
5860
vscode.commands.registerCommand(Commands.OPEN_BUILD_LOG, (selection) => openLogCmd(selection, false)),

dev/src/constants/Commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ enum Commands {
1717
OPEN_IN_BROWSER = "ext.mc.openInBrowser",
1818
REQUEST_BUILD = "ext.mc.requestBuild",
1919
TOGGLE_AUTOBUILD = "ext.mc.toggleAutoBuild",
20+
ENABLE_AUTOBUILD = "ext.mc.enableAutoBuild",
21+
DISABLE_AUTOBUILD = "ext.mc.disableAutoBuild",
22+
2023
OPEN_APP_LOG = "ext.mc.openAppLog",
2124
OPEN_BUILD_LOG = "ext.mc.openBuildLog",
2225
DISABLE_PROJECT = "ext.mc.disable",

dev/src/microclimate/project/Project.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@ import Translator from "../../constants/strings/translator";
1313
import StringNamespaces from "../../constants/strings/StringNamespaces";
1414
import ProjectPendingState from "./ProjectPendingState";
1515
import { refreshProjectInfo } from "./ProjectInfo";
16+
import getContextID from "./ProjectContextID";
1617

1718
const STRING_NS = StringNamespaces.PROJECT;
1819

1920
export default class Project implements ITreeItemAdaptable, vscode.QuickPickItem {
2021

21-
// these below must match package.nls.json
22-
private static readonly CONTEXT_ID_BASE: string = "ext.mc.projectItem"; // non-nls
23-
private static readonly CONTEXT_ID_ENABLED: string = Project.CONTEXT_ID_BASE + ".enabled"; // non-nls
24-
private static readonly CONTEXT_ID_DISABLED: string = Project.CONTEXT_ID_BASE + ".disabled"; // non-nls
25-
private static readonly CONTEXT_ID_DEBUGGABLE: string = Project.CONTEXT_ID_ENABLED + ".debugging"; // non-nls
26-
2722
// Immutable project data
2823
public readonly name: string;
2924
public readonly id: string;
@@ -103,33 +98,18 @@ export default class Project implements ITreeItemAdaptable, vscode.QuickPickItem
10398
// ti.resourceUri = this.localPath;
10499
ti.tooltip = this.state.toString();
105100
// There are different context menu actions available to enabled or disabled or debugging projects
106-
ti.contextValue = this.getContextID();
101+
ti.contextValue = getContextID(this);
107102
ti.iconPath = this.type.icon;
108103
// command run on single-click (or double click - depends on a user setting - https://github.com/Microsoft/vscode/issues/39601)
109-
// Focuses on this project in the explorer view. Has no effect if the project is not in the current workspace.
104+
// Focuses on this project in the middle of the explorer view. Has no effect if the project is not in the current workspace.
110105
ti.command = {
111106
command: Commands.VSC_REVEAL_EXPLORER,
112107
title: "", // non-nls
113108
arguments: [this.localPath]
114109
};
115-
// Logger.log(`Created TreeItem`, ti);
116110
return ti;
117111
}
118112

119-
private getContextID(): string {
120-
if (this._state.isEnabled) {
121-
if (ProjectState.getDebuggableStates().includes(this._state.appState)) {
122-
return Project.CONTEXT_ID_DEBUGGABLE;
123-
}
124-
else {
125-
return Project.CONTEXT_ID_ENABLED;
126-
}
127-
}
128-
else {
129-
return Project.CONTEXT_ID_DISABLED;
130-
}
131-
}
132-
133113
// description used by QuickPickItem
134114
public get description(): string {
135115
const appUrl = this.appBaseUrl;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Project from "./Project";
2+
import ProjectState from "./ProjectState";
3+
4+
// All the strings in this file must match the regexes in package.nls.json.
5+
6+
// non-nls-file
7+
8+
const BASE_CONTEXT_ID = "ext.mc.projectItem";
9+
const SEPARATOR = ".";
10+
11+
/**
12+
* A list of states a project can be in that affects its context ID and therefore enabled context menu options.
13+
*/
14+
enum ContextOptions {
15+
// (en|dis)abled are mutex
16+
ENABLED = "enabled",
17+
// debuggable implies (enabled and not disabled)
18+
DISABLED = "disabled",
19+
20+
DEBUGGABLE = "debuggable",
21+
22+
// auto build statuses are mutex
23+
AUTO_BUILD_ON = "autoBuildOn",
24+
AUTO_BUILD_OFF = "autoBuildOff"
25+
}
26+
27+
export default function getContextID(project: Project): string {
28+
const options: ContextOptions[] = [];
29+
30+
if (project.state.isEnabled) {
31+
options.push(ContextOptions.ENABLED);
32+
if (ProjectState.getDebuggableStates().includes(project.state.appState)) {
33+
options.push(ContextOptions.DEBUGGABLE);
34+
}
35+
}
36+
else {
37+
options.push(ContextOptions.DISABLED);
38+
}
39+
40+
if (project.autoBuildEnabled) {
41+
options.push(ContextOptions.AUTO_BUILD_ON);
42+
}
43+
else {
44+
options.push(ContextOptions.AUTO_BUILD_OFF);
45+
}
46+
47+
return BASE_CONTEXT_ID + SEPARATOR + options.join(SEPARATOR);
48+
49+
}

dev/todo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Important:
1212
- Debug mode -> Run mode
1313
- Project will hang in [Starting], even though startMode = run and there is no debug port set (seems Microclimate is doing everything right)
1414
- Restarting again fixes it
15-
- Disable/Enable autobuild instead of toggle, and add Validate when autobuild is disabled
1615
- Should give user a way to remove project logs from output view
16+
- Add a debug init script to generator https://github.com/ibm-developer/generator-ibm-core-node-express/blob/develop/app/templates/package.json
1717

1818
Annoying Release Stuff:
1919
- Icons

0 commit comments

Comments
 (0)