Skip to content

Commit 9e2d826

Browse files
authored
Add Modify Project Metadata... command (#1326)
1 parent 954f3f1 commit 9e2d826

File tree

3 files changed

+111
-44
lines changed

3 files changed

+111
-44
lines changed

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@
458458
"when": "view == ObjectScriptProjectsExplorer && viewItem == dataNode:projectNode",
459459
"group": "5_objectscript_prj@7"
460460
},
461+
{
462+
"command": "vscode-objectscript.modifyProjectMetadata",
463+
"when": "view == ObjectScriptProjectsExplorer && viewItem == dataNode:projectNode",
464+
"group": "5_objectscript_prj@8"
465+
},
461466
{
462467
"command": "vscode-objectscript.explorer.project.closeOtherServerNs",
463468
"when": "view == ObjectScriptProjectsExplorer && viewItem == projectsServerNsNode:extra",
@@ -598,6 +603,11 @@
598603
"when": "vscode-objectscript.connectActive && resourceScheme =~ /^isfs(-readonly)?$/ && resource =~ /project%3D/ && explorerResourceIsRoot",
599604
"group": "objectscript_prj@2"
600605
},
606+
{
607+
"command": "vscode-objectscript.modifyProjectMetadata",
608+
"when": "vscode-objectscript.connectActive && resourceScheme =~ /^isfs(-readonly)?$/ && resource =~ /project%3D/ && explorerResourceIsRoot",
609+
"group": "objectscript_prj@3"
610+
},
601611
{
602612
"command": "vscode-objectscript.importLocalFilesServerSide",
603613
"when": "vscode-objectscript.connectActive && resourceScheme == isfs && explorerResourceIsRoot",
@@ -1033,6 +1043,11 @@
10331043
"title": "Remove Items from Project...",
10341044
"category": "ObjectScript"
10351045
},
1046+
{
1047+
"command": "vscode-objectscript.modifyProjectMetadata",
1048+
"title": "Modify Project Metadata...",
1049+
"category": "ObjectScript"
1050+
},
10361051
{
10371052
"command": "vscode-objectscript.removeFromProject",
10381053
"title": "Remove from Project",

src/commands/project.ts

Lines changed: 89 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -706,35 +706,9 @@ export async function modifyProject(
706706
nodeOrUri: NodeBase | vscode.Uri | undefined,
707707
type: "add" | "remove"
708708
): Promise<any> {
709-
let node: NodeBase;
710-
let api: AtelierAPI;
711-
let project: string;
712-
if (nodeOrUri instanceof NodeBase) {
713-
// Called from Projects Explorer
714-
node = nodeOrUri;
715-
api = new AtelierAPI(node.workspaceFolderUri);
716-
api.setNamespace(node.namespace);
717-
project = node.options.project;
718-
} else if (nodeOrUri instanceof vscode.Uri) {
719-
// Called from files explorer
720-
api = new AtelierAPI(nodeOrUri);
721-
project = new URLSearchParams(nodeOrUri.query).get("project");
722-
} else {
723-
// Function was called from the command palette so there's no first argument
724-
// Have the user pick a server and namespace
725-
const picks = await pickServerAndNamespace();
726-
if (picks == undefined) {
727-
return;
728-
}
729-
const { serverName, namespace } = picks;
730-
api = new AtelierAPI(vscode.Uri.parse(`isfs://${serverName}:${namespace}/`));
731-
}
732-
if (project === undefined) {
733-
project = await pickProject(api);
734-
if (project === undefined) {
735-
return;
736-
}
737-
}
709+
const args = await handleCommandArg(nodeOrUri);
710+
if (!args) return;
711+
const { node, api, project } = args;
738712

739713
// Technically a project is a "document", so tell the server that we're opening it
740714
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument).catch(() => {
@@ -1177,3 +1151,89 @@ export function addWorkspaceFolderForProject(node: ProjectNode): void {
11771151
// Switch to Explorer view so user sees the outcome
11781152
vscode.commands.executeCommand("workbench.view.explorer");
11791153
}
1154+
1155+
async function handleCommandArg(
1156+
nodeOrUri: NodeBase | vscode.Uri | undefined
1157+
): Promise<{ node: NodeBase; api: AtelierAPI; project: string } | undefined> {
1158+
let node: NodeBase;
1159+
let api: AtelierAPI;
1160+
let project: string;
1161+
if (nodeOrUri instanceof NodeBase) {
1162+
// Called from Projects Explorer
1163+
node = nodeOrUri;
1164+
api = new AtelierAPI(node.workspaceFolderUri);
1165+
api.setNamespace(node.namespace);
1166+
project = node.options.project;
1167+
} else if (nodeOrUri instanceof vscode.Uri) {
1168+
// Called from files explorer
1169+
api = new AtelierAPI(nodeOrUri);
1170+
project = new URLSearchParams(nodeOrUri.query).get("project");
1171+
} else {
1172+
// Function was called from the command palette so there's no first argument
1173+
// Have the user pick a server and namespace
1174+
const picks = await pickServerAndNamespace();
1175+
if (picks == undefined) {
1176+
return;
1177+
}
1178+
const { serverName, namespace } = picks;
1179+
api = new AtelierAPI(vscode.Uri.parse(`isfs://${serverName}:${namespace}/`));
1180+
}
1181+
if (project === undefined) {
1182+
project = await pickProject(api);
1183+
if (project === undefined) {
1184+
return;
1185+
}
1186+
}
1187+
return { node, api, project };
1188+
}
1189+
1190+
export async function modifyProjectMetadata(nodeOrUri: NodeBase | vscode.Uri | undefined): Promise<void> {
1191+
const args = await handleCommandArg(nodeOrUri);
1192+
if (!args) return;
1193+
const { api, project } = args;
1194+
1195+
// Technically a project is a "document", so tell the server that we're opening it
1196+
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument).catch(() => {
1197+
// Swallow error because showing it is more disruptive than using a potentially outdated project definition
1198+
});
1199+
1200+
try {
1201+
const oldDesc: string = await api
1202+
.actionQuery("SELECT Description FROM %Studio.Project WHERE Name = ?", [project])
1203+
.then((data) => data.result.content[0]?.Description);
1204+
const newDesc = await vscode.window.showInputBox({
1205+
prompt: `Enter a description for project '${project}'`,
1206+
value: oldDesc,
1207+
});
1208+
if (!newDesc || newDesc == oldDesc) return;
1209+
1210+
// Technically a project is a "document", so tell the server that we're editing it
1211+
const studioActions = new StudioActions();
1212+
await studioActions.fireProjectUserAction(api, project, OtherStudioAction.AttemptedEdit);
1213+
if (studioActions.projectEditAnswer != "1") {
1214+
// Don't perform the edit
1215+
if (studioActions.projectEditAnswer == "-1") {
1216+
// Source control action failed
1217+
vscode.window.showErrorMessage(
1218+
`'AttemptedEdit' source control action failed for project '${project}'. Check the 'ObjectScript' Output channel for details.`,
1219+
"Dismiss"
1220+
);
1221+
}
1222+
return;
1223+
}
1224+
1225+
// Modify the project
1226+
await api.actionQuery("UPDATE %Studio.Project SET Description = ? WHERE Name = ?", [newDesc, project]);
1227+
1228+
// Refesh the explorer
1229+
projectsExplorerProvider.refresh();
1230+
} catch (error) {
1231+
let message = `Failed to modify metadata of project '${project}'.`;
1232+
if (error && error.errorText && error.errorText !== "") {
1233+
outputChannel.appendLine("\n" + error.errorText);
1234+
outputChannel.show(true);
1235+
message += " Check 'ObjectScript' output channel for details.";
1236+
}
1237+
vscode.window.showErrorMessage(message, "Dismiss");
1238+
}
1239+
}

src/extension.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ import {
126126
deleteProject,
127127
exportProjectContents,
128128
modifyProject,
129+
modifyProjectMetadata,
129130
} from "./commands/project";
130131
import { NodeBase } from "./explorer/models/nodeBase";
131132
import { loadStudioColors, loadStudioSnippets } from "./commands/studioMigration";
@@ -1094,25 +1095,16 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
10941095
}
10951096
}),
10961097
vscode.commands.registerCommand("vscode-objectscript.addItemsToProject", (item) => {
1097-
if (item instanceof NodeBase || item instanceof vscode.Uri) {
1098-
return modifyProject(item, "add");
1099-
} else {
1100-
return modifyProject(undefined, "add");
1101-
}
1098+
return modifyProject(item instanceof NodeBase || item instanceof vscode.Uri ? item : undefined, "add");
11021099
}),
11031100
vscode.commands.registerCommand("vscode-objectscript.removeFromProject", (item) => {
1104-
if (item instanceof NodeBase || item instanceof vscode.Uri) {
1105-
return modifyProject(item, "remove");
1106-
} else {
1107-
return modifyProject(undefined, "remove");
1108-
}
1101+
return modifyProject(item instanceof NodeBase || item instanceof vscode.Uri ? item : undefined, "remove");
11091102
}),
11101103
vscode.commands.registerCommand("vscode-objectscript.removeItemsFromProject", (item) => {
1111-
if (item instanceof NodeBase || item instanceof vscode.Uri) {
1112-
return modifyProject(item, "remove");
1113-
} else {
1114-
return modifyProject(undefined, "remove");
1115-
}
1104+
return modifyProject(item instanceof NodeBase || item instanceof vscode.Uri ? item : undefined, "remove");
1105+
}),
1106+
vscode.commands.registerCommand("vscode-objectscript.modifyProjectMetadata", (item) => {
1107+
return modifyProjectMetadata(item instanceof NodeBase || item instanceof vscode.Uri ? item : undefined);
11161108
}),
11171109
vscode.commands.registerCommand("vscode-objectscript.createProject", (node) => createProject(node)),
11181110
vscode.commands.registerCommand("vscode-objectscript.deleteProject", (node) => deleteProject(node)),

0 commit comments

Comments
 (0)