Skip to content

Commit cec9062

Browse files
committed
Replicate Studio's separate menus for Source Control vs other options
1 parent bf89b84 commit cec9062

File tree

4 files changed

+117
-35
lines changed

4 files changed

+117
-35
lines changed

package.json

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,19 @@
128128
"when": "false"
129129
},
130130
{
131-
"command": "vscode-objectscript.studio.actions",
131+
"command": "vscode-objectscript.serverCommands.sourceControl",
132132
"when": "vscode-objectscript.connectActive && resourceScheme == isfs || vscode-objectscript.connectActive && !editorIsOpen"
133133
},
134134
{
135-
"command": "vscode-objectscript.studio.contextActions",
135+
"command": "vscode-objectscript.serverCommands.contextSourceControl",
136+
"when": "false"
137+
},
138+
{
139+
"command": "vscode-objectscript.serverCommands.other",
140+
"when": "vscode-objectscript.connectActive && resourceScheme == isfs || vscode-objectscript.connectActive && !editorIsOpen"
141+
},
142+
{
143+
"command": "vscode-objectscript.serverCommands.contextOther",
136144
"when": "false"
137145
}
138146
],
@@ -161,7 +169,11 @@
161169
"when": "view == ObjectScriptExplorer && viewItem =~ /^dataNode:/"
162170
},
163171
{
164-
"command": "vscode-objectscript.studio.contextActions",
172+
"command": "vscode-objectscript.serverCommands.contextSourceControl",
173+
"when": "view == ObjectScriptExplorer && viewItem =~ /^dataNode:/"
174+
},
175+
{
176+
"command": "vscode-objectscript.serverCommands.contextOther",
165177
"when": "view == ObjectScriptExplorer && viewItem =~ /^dataNode:/"
166178
},
167179
{
@@ -186,27 +198,42 @@
186198
"editor/context": [
187199
{
188200
"command": "vscode-objectscript.viewOthers",
189-
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive"
201+
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive",
202+
"group": "objectscript@1"
190203
},
191204
{
192205
"command": "vscode-objectscript.compile",
193-
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive"
206+
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive",
207+
"group": "objectscript@2"
194208
},
195209
{
196-
"command": "vscode-objectscript.studio.contextActions",
197-
"when": "resourceScheme == isfs && editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive"
210+
"command": "vscode-objectscript.previewXml",
211+
"when": "editorLangId =~ /^xml/",
212+
"group": "objectscript@3"
198213
},
199214
{
200-
"command": "vscode-objectscript.previewXml",
201-
"when": "editorLangId =~ /^xml/"
215+
"command": "vscode-objectscript.serverCommands.contextSourceControl",
216+
"when": "resourceScheme == isfs && editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive",
217+
"group": "objectscript@4"
218+
},
219+
{
220+
"command": "vscode-objectscript.serverCommands.contextOther",
221+
"when": "resourceScheme == isfs && editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive",
222+
"group": "objectscript@5"
202223
}
203224
],
204225
"editor/title": [
205226
{
206-
"command": "vscode-objectscript.studio.actions",
227+
"command": "vscode-objectscript.serverCommands.sourceControl",
207228
"group": "navigation@1",
208229
"when": "vscode-objectscript.connectActive && resourceScheme == isfs"
230+
},
231+
{
232+
"command": "vscode-objectscript.serverCommands.other",
233+
"group": "navigation@2",
234+
"when": "vscode-objectscript.connectActive && resourceScheme == isfs"
209235
}
236+
210237
],
211238
"touchBar": [
212239
{
@@ -223,11 +250,18 @@
223250
"explorer/context": [
224251
{
225252
"command": "vscode-objectscript.compileFolder",
226-
"when": "vscode-objectscript.connectActive"
253+
"when": "vscode-objectscript.connectActive",
254+
"group": "objectscript@1"
255+
},
256+
{
257+
"command": "vscode-objectscript.serverCommands.contextSourceControl",
258+
"when": "resourceScheme == isfs && resourceLangId =~ /^objectscript/ && vscode-objectscript.connectActive",
259+
"group": "objectscript@2"
227260
},
228261
{
229-
"command": "vscode-objectscript.studio.contextActions",
230-
"when": "resourceScheme == isfs && resourceLangId =~ /^objectscript/ && vscode-objectscript.connectActive"
262+
"command": "vscode-objectscript.serverCommands.contextOther",
263+
"when": "resourceScheme == isfs && resourceLangId =~ /^objectscript/ && vscode-objectscript.connectActive",
264+
"group": "objectscript@3"
231265
}
232266
]
233267
},
@@ -420,14 +454,25 @@
420454
},
421455
{
422456
"category": "ObjectScript",
423-
"command": "vscode-objectscript.studio.actions",
457+
"command": "vscode-objectscript.serverCommands.sourceControl",
424458
"title": "Server Source Control...",
425459
"icon": "$(source-control)"
426460
},
427461
{
428462
"category": "ObjectScript",
429-
"command": "vscode-objectscript.studio.contextActions",
463+
"command": "vscode-objectscript.serverCommands.contextSourceControl",
430464
"title": "Server Source Control..."
465+
},
466+
{
467+
"category": "ObjectScript",
468+
"command": "vscode-objectscript.serverCommands.other",
469+
"title": "Server Command Menu...",
470+
"icon": "$(server-environment)"
471+
},
472+
{
473+
"category": "ObjectScript",
474+
"command": "vscode-objectscript.serverCommands.contextOther",
475+
"title": "Server Command Menu..."
431476
}
432477
],
433478
"keybindings": [

src/commands/serverActions.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from "vscode";
22
import { config, workspaceState, checkConnection, FILESYSTEM_SCHEMA } from "../extension";
33
import { currentWorkspaceFolder, terminalWithDocker, currentFile } from "../utils";
4-
import { mainMenu } from "./studio";
4+
import { mainCommandMenu, mainSourceControlMenu } from "./studio";
55

66
export async function serverActions(): Promise<void> {
77
const { active, host, ns, https, port: defaultPort, username, password: defaultPassword, links } = config("conn");
@@ -49,10 +49,15 @@ export async function serverActions(): Promise<void> {
4949
const studio = [];
5050
if (!vscode.window.activeTextEditor || vscode.window.activeTextEditor.document.uri.scheme === FILESYSTEM_SCHEMA) {
5151
studio.push({
52-
id: "studioAction",
52+
id: "serverSourceControlMenu",
5353
label: "Server Source Control...",
5454
detail: "Pick server-side source control action",
5555
});
56+
studio.push({
57+
id: "serverCommandMenu",
58+
label: "Server Command Menu...",
59+
detail: "Pick server-side command",
60+
});
5661
}
5762
return vscode.window
5863
.showQuickPick(
@@ -109,8 +114,12 @@ export async function serverActions(): Promise<void> {
109114
terminalWithDocker();
110115
break;
111116
}
112-
case "studioAction": {
113-
mainMenu();
117+
case "serverSourceControlMenu": {
118+
mainSourceControlMenu();
119+
break;
120+
}
121+
case "serverCommandMenu": {
122+
mainCommandMenu();
114123
break;
115124
}
116125
default: {

src/commands/studio.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export enum OtherStudioAction {
2121
FirstTimeDocumentSave = 7,
2222
}
2323

24+
export enum StudioMenuType {
25+
Main = "main",
26+
Context = "context",
27+
}
28+
2429
interface StudioAction extends vscode.QuickPickItem {
2530
name: string;
2631
id: string;
@@ -156,7 +161,7 @@ class StudioActions {
156161
});
157162
});
158163
case 3: // Run an EXE on the client.
159-
throw new Error("Not suppoorted");
164+
throw new Error("Not supported");
160165
case 4: {
161166
// Insert the text in Target in the current document at the current selection point
162167
const editor = vscode.window.activeTextEditor;
@@ -217,7 +222,7 @@ class StudioActions {
217222
};
218223
});
219224
default:
220-
throw new Error("Not suppoorted");
225+
throw new Error("Not supported");
221226
}
222227
}
223228

@@ -270,9 +275,9 @@ class StudioActions {
270275
);
271276
}
272277

273-
private constructMenu(menu, contextMenu = false): any[] {
274-
return menu
275-
.filter((menuGroup) => !(contextMenu == (menuGroup.type === "main")))
278+
private prepareMenuItems(menus, sourceControl: boolean): any[] {
279+
return menus
280+
.filter((menu) => sourceControl == (menu.id === "%SourceMenu" || menu.id === "%SourceContext"))
276281
.reduce(
277282
(list, sub) =>
278283
list.concat(
@@ -292,7 +297,7 @@ class StudioActions {
292297
);
293298
}
294299

295-
public getMenu(menuType: string, contextOnly = false): Thenable<any> {
300+
public getMenu(menuType: StudioMenuType, sourceControl: boolean): Thenable<any> {
296301
let selectedText = "";
297302
const editor = vscode.window.activeTextEditor;
298303
if (this.uri && editor) {
@@ -306,11 +311,11 @@ class StudioActions {
306311
return this.api
307312
.actionQuery(query, parameters)
308313
.then((data) => data.result.content)
309-
.then((menu) => this.constructMenu(menu, contextOnly))
314+
.then((menus) => this.prepareMenuItems(menus, sourceControl))
310315
.then((menuItems) => {
311316
return vscode.window.showQuickPick<StudioAction>(menuItems, {
312317
canPickMany: false,
313-
placeHolder: `Pick server-side action to perform${this.name ? " on " + this.name : ""}`,
318+
placeHolder: `Pick server-side command to perform${this.name ? " on " + this.name : ""}`,
314319
});
315320
})
316321
.then((action) => this.userAction(action));
@@ -362,22 +367,38 @@ class StudioActions {
362367
}
363368
}
364369

365-
export async function mainMenu(uri?: vscode.Uri): Promise<any> {
370+
export async function mainCommandMenu(uri?: vscode.Uri): Promise<any> {
371+
return _mainMenu(false, uri);
372+
}
373+
374+
export async function mainSourceControlMenu(uri?: vscode.Uri): Promise<any> {
375+
return _mainMenu(true, uri);
376+
}
377+
378+
async function _mainMenu(sourceControl: boolean, uri?: vscode.Uri): Promise<any> {
366379
uri = uri || vscode.window.activeTextEditor?.document.uri;
367380
if (uri && uri.scheme !== FILESYSTEM_SCHEMA) {
368381
return;
369382
}
370383
const studioActions = new StudioActions(uri);
371-
return studioActions && studioActions.getMenu("");
384+
return studioActions && studioActions.getMenu(StudioMenuType.Main, sourceControl);
385+
}
386+
387+
export async function contextCommandMenu(node: PackageNode | ClassNode | RoutineNode): Promise<any> {
388+
return _contextMenu(false, node);
389+
}
390+
391+
export async function contextSourceControlMenu(node: PackageNode | ClassNode | RoutineNode): Promise<any> {
392+
return _contextMenu(true, node);
372393
}
373394

374-
export async function contextMenu(node: PackageNode | ClassNode | RoutineNode): Promise<any> {
395+
export async function _contextMenu(sourceControl: boolean, node: PackageNode | ClassNode | RoutineNode): Promise<any> {
375396
const nodeOrUri = node || vscode.window.activeTextEditor?.document.uri;
376397
if (!nodeOrUri || (nodeOrUri instanceof vscode.Uri && nodeOrUri.scheme !== FILESYSTEM_SCHEMA)) {
377398
return;
378399
}
379400
const studioActions = new StudioActions(nodeOrUri);
380-
return studioActions && studioActions.getMenu("", true);
401+
return studioActions && studioActions.getMenu(StudioMenuType.Context, sourceControl);
381402
}
382403

383404
export async function fireOtherStudioAction(action: OtherStudioAction, uri?: vscode.Uri): Promise<void> {

src/extension.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import { superclass } from "./commands/superclass";
2525
import { viewOthers } from "./commands/viewOthers";
2626
import { xml2doc } from "./commands/xml2doc";
2727
import {
28-
mainMenu,
29-
contextMenu,
28+
mainCommandMenu,
29+
contextCommandMenu,
3030
documentBeingProcessed,
3131
fireOtherStudioAction,
3232
OtherStudioAction,
33+
contextSourceControlMenu,
34+
mainSourceControlMenu,
3335
} from "./commands/studio";
3436

3537
import { getLanguageConfiguration } from "./languageConfiguration";
@@ -395,8 +397,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
395397
});
396398
}),
397399
vscode.commands.registerCommand("vscode-objectscript.viewOthers", viewOthers),
398-
vscode.commands.registerCommand("vscode-objectscript.studio.actions", mainMenu),
399-
vscode.commands.registerCommand("vscode-objectscript.studio.contextActions", contextMenu),
400+
vscode.commands.registerCommand("vscode-objectscript.serverCommands.sourceControl", mainSourceControlMenu),
401+
vscode.commands.registerCommand(
402+
"vscode-objectscript.serverCommands.contextSourceControl",
403+
contextSourceControlMenu
404+
),
405+
vscode.commands.registerCommand("vscode-objectscript.serverCommands.other", mainCommandMenu),
406+
vscode.commands.registerCommand("vscode-objectscript.serverCommands.contextOther", contextCommandMenu),
400407
vscode.commands.registerCommand("vscode-objectscript.subclass", subclass),
401408
vscode.commands.registerCommand("vscode-objectscript.superclass", superclass),
402409
vscode.commands.registerCommand("vscode-objectscript.serverActions", serverActions),

0 commit comments

Comments
 (0)