@@ -32,17 +32,15 @@ class StudioActions {
32
32
private name : string ;
33
33
34
34
public constructor ( uriOrNode ?: vscode . Uri | PackageNode | ClassNode | RoutineNode ) {
35
- if ( uriOrNode instanceof vscode . Uri ) {
35
+ if ( uriOrNode instanceof vscode . Uri ) {
36
36
const uri : vscode . Uri = uriOrNode ;
37
37
this . uri = uri ;
38
38
this . name = this . uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
39
39
this . api = new AtelierAPI ( uri . authority ) ;
40
- } else if ( uriOrNode ) {
40
+ } else if ( uriOrNode ) {
41
41
const node : NodeBase = uriOrNode ;
42
42
this . api = new AtelierAPI ( ) ;
43
- this . name = ( node instanceof PackageNode )
44
- ? node . fullName + ".PKG"
45
- : node . fullName ;
43
+ this . name = node instanceof PackageNode ? node . fullName + ".PKG" : node . fullName ;
46
44
} else {
47
45
this . api = new AtelierAPI ( ) ;
48
46
}
@@ -55,11 +53,11 @@ class StudioActions {
55
53
outputChannel . appendLine ( errorText ) ;
56
54
outputChannel . show ( ) ;
57
55
}
58
- if ( userAction . reload ) {
56
+ if ( userAction . reload ) {
59
57
const document = vscode . window . activeTextEditor . document ;
60
58
loadChanges ( [ currentFile ( document ) ] ) ;
61
59
}
62
- if ( config ( ) . studioActionDebugOutput ) {
60
+ if ( config ( ) . studioActionDebugOutput ) {
63
61
outputChannel . appendLine ( JSON . stringify ( userAction ) ) ;
64
62
}
65
63
switch ( serverAction ) {
@@ -71,12 +69,10 @@ class StudioActions {
71
69
. showWarningMessage ( target , { modal : true } , "Yes" , "No" )
72
70
. then ( answer => ( answer === "Yes" ? "1" : answer === "No" ? "0" : "2" ) ) ;
73
71
case 2 : // Run a CSP page/Template. The Target is the full url to the CSP page/Template
74
- return new Promise ( ( resolve ) => {
72
+ return new Promise ( resolve => {
75
73
let answer = "2" ;
76
74
const conn = config ( ) . conn ;
77
- const column = vscode . window . activeTextEditor
78
- ? vscode . window . activeTextEditor . viewColumn
79
- : undefined ;
75
+ const column = vscode . window . activeTextEditor ? vscode . window . activeTextEditor . viewColumn : undefined ;
80
76
const panel = vscode . window . createWebviewPanel (
81
77
"studioactionwebview" ,
82
78
"Studio Extension Page" ,
@@ -86,7 +82,7 @@ class StudioActions {
86
82
}
87
83
) ;
88
84
panel . webview . onDidReceiveMessage ( message => {
89
- if ( message . result && message . result === "done" ) {
85
+ if ( message . result && message . result === "done" ) {
90
86
answer = "1" ;
91
87
panel . dispose ( ) ;
92
88
}
@@ -97,8 +93,8 @@ class StudioActions {
97
93
const api = new AtelierAPI ( ) ;
98
94
api . actionQuery ( "select %Atelier_v1_Utils.General_GetCSPToken(?) token" , [ url . toString ( ) ] ) . then ( tokenObj => {
99
95
const csptoken = tokenObj . result . content [ 0 ] . token ;
100
- url . searchParams . set ( ' CSPCHD' , csptoken ) ;
101
- url . searchParams . set ( ' Namespace' , conn . ns ) ;
96
+ url . searchParams . set ( " CSPCHD" , csptoken ) ;
97
+ url . searchParams . set ( " Namespace" , conn . ns ) ;
102
98
panel . webview . html = `
103
99
<!DOCTYPE html>
104
100
<html lang="en">
@@ -133,7 +129,7 @@ class StudioActions {
133
129
throw new Error ( "Not suppoorted" ) ;
134
130
case 4 : // Insert the text in Target in the current document at the current selection point
135
131
const editor = vscode . window . activeTextEditor ;
136
- if ( editor ) {
132
+ if ( editor ) {
137
133
editor . edit ( editBuilder => {
138
134
editBuilder . replace ( editor . selection , target ) ;
139
135
} ) ;
@@ -144,28 +140,27 @@ class StudioActions {
144
140
let classname = element ;
145
141
let method : string ;
146
142
let offset = 0 ;
147
- if ( element . includes ( ":" ) ) {
143
+ if ( element . includes ( ":" ) ) {
148
144
[ classname , method ] = element . split ( ":" ) ;
149
- if ( method . includes ( "+" ) ) {
145
+ if ( method . includes ( "+" ) ) {
150
146
offset = + method . split ( "+" ) [ 1 ] ;
151
147
method = method . split ( "+" ) [ 0 ] ;
152
148
}
153
149
}
154
150
155
151
const splitClassname = classname . split ( "." ) ;
156
152
const filetype = splitClassname [ splitClassname . length - 1 ] ;
157
- const isCorrectMethod = ( text : string ) => ( filetype === "cls" )
158
- ? text . match ( "Method " + method )
159
- : text . startsWith ( method ) ;
153
+ const isCorrectMethod = ( text : string ) =>
154
+ filetype === "cls" ? text . match ( "Method " + method ) : text . startsWith ( method ) ;
160
155
161
156
const uri = DocumentContentProvider . getUri ( classname ) ;
162
- vscode . window . showTextDocument ( uri , { " preview" : false } ) . then ( newEditor => {
163
- if ( method ) {
157
+ vscode . window . showTextDocument ( uri , { preview : false } ) . then ( newEditor => {
158
+ if ( method ) {
164
159
const document = newEditor . document ;
165
- for ( let i = 0 ; i < document . lineCount ; i ++ ) {
160
+ for ( let i = 0 ; i < document . lineCount ; i ++ ) {
166
161
const line = document . lineAt ( i ) ;
167
- if ( isCorrectMethod ( line . text ) ) {
168
- if ( ! line . text . endsWith ( "{" ) ) offset ++ ;
162
+ if ( isCorrectMethod ( line . text ) ) {
163
+ if ( ! line . text . endsWith ( "{" ) ) offset ++ ;
169
164
const cursor = newEditor . selection . active ;
170
165
const newPosition = cursor . with ( i + offset , 0 ) ;
171
166
newEditor . selection = new vscode . Selection ( newPosition , newPosition ) ;
@@ -179,14 +174,16 @@ class StudioActions {
179
174
case 6 : // Display an alert dialog in Studio with the text from the Target variable.
180
175
return vscode . window . showWarningMessage ( target , { modal : true } ) ;
181
176
case 7 : // Display a dialog with a textbox and Yes/No/Cancel buttons.
182
- return vscode . window . showInputBox ( {
183
- prompt : target ,
184
- } ) . then ( msg => {
185
- return {
186
- "msg" : ( msg ? msg : "" ) ,
187
- "answer" : ( msg ? 1 : 2 )
188
- }
189
- } ) ;
177
+ return vscode . window
178
+ . showInputBox ( {
179
+ prompt : target ,
180
+ } )
181
+ . then ( msg => {
182
+ return {
183
+ msg : msg ? msg : "" ,
184
+ answer : msg ? 1 : 2 ,
185
+ } ;
186
+ } ) ;
190
187
default :
191
188
throw new Error ( "Not suppoorted" ) ;
192
189
}
@@ -219,7 +216,7 @@ class StudioActions {
219
216
this . api
220
217
. actionQuery ( query , parameters )
221
218
. then ( async data => {
222
- if ( action . save ) {
219
+ if ( action . save ) {
223
220
await this . processSaveFlag ( action . save ) ;
224
221
}
225
222
outputConsole ( data . console ) ;
@@ -228,7 +225,7 @@ class StudioActions {
228
225
. then ( this . processUserAction )
229
226
. then ( answer => {
230
227
if ( answer ) {
231
- return ( answer . msg || answer . msg === "" )
228
+ return answer . msg || answer . msg === ""
232
229
? this . userAction ( action , true , answer . answer , answer . msg , type )
233
230
: this . userAction ( action , true , answer , "" , type ) ;
234
231
}
@@ -241,9 +238,9 @@ class StudioActions {
241
238
) ;
242
239
}
243
240
244
- private constructMenu ( menu , contextOnly = false ) : any [ ] {
241
+ private constructMenu ( menu , contextMenu = false ) : any [ ] {
245
242
return menu
246
- . filter ( menuGroup => ! ( contextOnly && menuGroup . type === "main" ) )
243
+ . filter ( menuGroup => ! ( contextMenu == ( menuGroup . type === "main" ) ) )
247
244
. reduce (
248
245
( list , sub ) =>
249
246
list . concat (
@@ -260,20 +257,13 @@ class StudioActions {
260
257
} ) )
261
258
) ,
262
259
[ ]
263
- )
264
- . sort ( ( el1 , el2 ) => ( el1 . type === "main" && el2 . type !== el1 . type ? - 1 : 1 ) )
265
- . filter ( ( item : any , index : number , self : any ) => {
266
- if ( item && item . type === "main" ) {
267
- return true ;
268
- }
269
- return self . findIndex ( ( el ) : boolean => el . itemId === item . itemId ) === index ;
270
- } ) ;
260
+ ) ;
271
261
}
272
262
273
263
public getMenu ( menuType : string , contextOnly = false ) : Thenable < any > {
274
264
let selectedText = "" ;
275
265
const editor = vscode . window . activeTextEditor ;
276
- if ( this . uri && editor ) {
266
+ if ( this . uri && editor ) {
277
267
const selection = editor . selection ;
278
268
selectedText = editor . document . getText ( selection ) ;
279
269
}
@@ -286,22 +276,25 @@ class StudioActions {
286
276
. then ( data => data . result . content )
287
277
. then ( menu => this . constructMenu ( menu , contextOnly ) )
288
278
. then ( menuItems => {
289
- return vscode . window . showQuickPick < StudioAction > ( menuItems , { canPickMany : false } ) ;
279
+ return vscode . window . showQuickPick < StudioAction > ( menuItems , {
280
+ canPickMany : false ,
281
+ placeHolder : `Pick server-side action to perform${ this . name ? " on " + this . name : "" } ` ,
282
+ } ) ;
290
283
} )
291
284
. then ( action => this . userAction ( action ) ) ;
292
285
}
293
286
294
287
public fireOtherStudioAction ( action : OtherStudioAction ) {
295
288
const actionObject = {
296
289
id : action . toString ( ) ,
297
- label : getOtherStudioActionLabel ( action )
290
+ label : getOtherStudioActionLabel ( action ) ,
298
291
} ;
299
- if ( action === OtherStudioAction . AttemptedEdit ) {
292
+ if ( action === OtherStudioAction . AttemptedEdit ) {
300
293
const query = "select * from %Atelier_v1_Utils.Extension_GetStatus(?)" ;
301
294
this . api . actionQuery ( query , [ this . name ] ) . then ( statusObj => {
302
295
const docStatus = statusObj . result . content . pop ( ) ;
303
- if ( ! docStatus . editable ) {
304
- vscode . commands . executeCommand ( ' undo' ) ;
296
+ if ( ! docStatus . editable ) {
297
+ vscode . commands . executeCommand ( " undo" ) ;
305
298
this . userAction ( actionObject , false , "" , "" , 1 ) ;
306
299
}
307
300
} ) ;
@@ -313,7 +306,7 @@ class StudioActions {
313
306
private async processSaveFlag ( saveFlag : number ) {
314
307
const bitString = saveFlag . toString ( ) . padStart ( 3 , "0" ) ;
315
308
const saveAndCompile = async ( document : vscode . TextDocument ) => {
316
- if ( document . isDirty ) {
309
+ if ( document . isDirty ) {
317
310
// Prevent onDidSave from compiling the file
318
311
// in order to await the importAndCompile function
319
312
documentBeingProcessed = document ;
@@ -324,22 +317,22 @@ class StudioActions {
324
317
} ;
325
318
326
319
// Save the current document
327
- if ( bitString . charAt ( 0 ) === "1" ) {
320
+ if ( bitString . charAt ( 0 ) === "1" ) {
328
321
await saveAndCompile ( vscode . window . activeTextEditor . document ) ;
329
322
}
330
323
331
324
// Save all documents
332
- if ( bitString . charAt ( 2 ) === "1" ) {
333
- for ( const document of vscode . workspace . textDocuments ) {
325
+ if ( bitString . charAt ( 2 ) === "1" ) {
326
+ for ( const document of vscode . workspace . textDocuments ) {
334
327
await saveAndCompile ( document ) ;
335
328
}
336
329
}
337
330
}
338
331
}
339
332
340
- export async function mainMenu ( uri : vscode . Uri ) {
333
+ export async function mainMenu ( uri ? : vscode . Uri ) {
341
334
uri = uri || vscode . window . activeTextEditor ?. document . uri ;
342
- if ( ! uri || uri . scheme !== FILESYSTEM_SCHEMA ) {
335
+ if ( uri && uri . scheme !== FILESYSTEM_SCHEMA ) {
343
336
return ;
344
337
}
345
338
const studioActions = new StudioActions ( uri ) ;
@@ -362,19 +355,25 @@ export async function fireOtherStudioAction(action: OtherStudioAction, uri?: vsc
362
355
363
356
function getOtherStudioActionLabel ( action : OtherStudioAction ) : string {
364
357
let label = "" ;
365
- switch ( action ) {
358
+ switch ( action ) {
366
359
case OtherStudioAction . AttemptedEdit :
367
360
label = "Attempted Edit" ;
361
+ break ;
368
362
case OtherStudioAction . CreatedNewDocument :
369
363
label = "Created New Document" ;
364
+ break ;
370
365
case OtherStudioAction . DeletedDocument :
371
366
label = "Deleted Document" ;
367
+ break ;
372
368
case OtherStudioAction . OpenedDocument :
373
369
label = "Opened Document" ;
370
+ break ;
374
371
case OtherStudioAction . ClosedDocument :
375
372
label = "Closed Document" ;
373
+ break ;
376
374
case OtherStudioAction . ConnectedToNewNamespace :
377
375
label = "Changed Namespace" ;
376
+ break ;
378
377
case OtherStudioAction . FirstTimeDocumentSave :
379
378
label = "Saved Document to Server for the First Time" ;
380
379
}
0 commit comments