@@ -706,35 +706,9 @@ export async function modifyProject(
706
706
nodeOrUri : NodeBase | vscode . Uri | undefined ,
707
707
type : "add" | "remove"
708
708
) : 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 ;
738
712
739
713
// Technically a project is a "document", so tell the server that we're opening it
740
714
await new StudioActions ( ) . fireProjectUserAction ( api , project , OtherStudioAction . OpenedDocument ) . catch ( ( ) => {
@@ -1177,3 +1151,89 @@ export function addWorkspaceFolderForProject(node: ProjectNode): void {
1177
1151
// Switch to Explorer view so user sees the outcome
1178
1152
vscode . commands . executeCommand ( "workbench.view.explorer" ) ;
1179
1153
}
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
+ }
0 commit comments