@@ -15,7 +15,7 @@ import '@vaadin/confirm-dialog';
15
15
import '@vaadin/progress-bar' ;
16
16
import MarkdownIt from 'markdown-it' ;
17
17
import { unsafeHTML } from 'lit/directives/unsafe-html.js' ;
18
- import { dialogFooterRenderer , dialogRenderer } from '@vaadin/dialog/lit.js' ;
18
+ import { dialogHeaderRenderer , dialogFooterRenderer , dialogRenderer } from '@vaadin/dialog/lit.js' ;
19
19
import { observeState } from 'lit-element-state' ;
20
20
import { themeState } from 'theme-state' ;
21
21
import { notifier } from 'notifier' ;
@@ -83,11 +83,9 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
83
83
_filteredActions : { state : true } ,
84
84
_selectedWorkspaceItem : { state : true } ,
85
85
_changeToWorkspaceItem : { state : true } ,
86
- _actionResultContent : { state :true } ,
87
- _actionResultDisplay : { state :true } ,
88
- _actionResultDisplayType : { state :true } ,
86
+ _actionResult : { state : true } ,
89
87
_showActionProgress : { state : true } ,
90
- _confirmDialogOpened : { state : true }
88
+ _confirmDialogOpened : { state : true } ,
91
89
} ;
92
90
93
91
constructor ( ) {
@@ -122,9 +120,8 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
122
120
this . _workspaceActions = [ ] ;
123
121
this . _filteredActions = this . _workspaceActions ;
124
122
this . _clearActionResult ( ) ;
125
-
126
- this . _loadWorkspaceItems ( ) ;
127
123
this . _loadWorkspaceActions ( ) ;
124
+ this . _loadWorkspaceItems ( ) ;
128
125
}
129
126
130
127
disconnectedCallback ( ) {
@@ -193,14 +190,16 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
193
190
< vaadin-button title ="Copy " slot ="prefix " theme ="icon " aria-label ="Copy " @click ="${ this . _copySelectedWorkspaceItem } ">
194
191
< vaadin-icon icon ="font-awesome-solid:copy "> </ vaadin-icon >
195
192
</ vaadin-button >
193
+
194
+
195
+ ${ this . _renderActions ( ) }
196
+
196
197
< qui-ide-link slot ="suffix " title ="Open in IDE " style ="cursor: pointer; "
197
198
fileName ="${ this . _selectedWorkspaceItem . path } "
198
199
lineNumber ="0 "
199
200
noCheck >
200
201
< vaadin-icon icon ="font-awesome-solid:up-right-from-square "> </ vaadin-icon >
201
202
</ qui-ide-link >
202
-
203
- ${ this . _renderActions ( ) }
204
203
205
204
< vaadin-tabs slot ="tabs ">
206
205
< vaadin-tab id ="${ this . _selectedWorkspaceItem . path } " title ="${ this . _selectedWorkspaceItem . path } "> ${ this . _selectedWorkspaceItem . name . split ( '/' ) . pop ( ) } </ vaadin-tab >
@@ -217,7 +216,7 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
217
216
}
218
217
219
218
_renderResultSplitView ( ) {
220
- if ( this . _actionResultContent && this . _actionResultDisplay === "split" ) {
219
+ if ( this . _actionResult && this . _actionResult . content && this . _actionResult . display === "split" ) {
221
220
return html `< detail-content style ="width: 50%; ">
222
221
< div class ="actionSplitScreen ">
223
222
< div class ="actionButtonBar ">
@@ -233,36 +232,54 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
233
232
}
234
233
235
234
_renderResultDialog ( ) {
236
- if ( this . _actionResultContent && this . _actionResultDisplay === "dialog" ) {
237
- return html `< vaadin-dialog
235
+ if ( this . _actionResult && this . _actionResult . content && this . _actionResult . display === "dialog" ) {
236
+ return html `< vaadin-dialog style ="min-width=50vw; "
237
+ header-title ="${ this . _actionResult ?. name ?? this . _actionResult ?. path } "
238
238
resizable
239
239
draggable
240
- .opened =true
240
+ .opened =${ true }
241
+ ${ dialogHeaderRenderer (
242
+ ( ) => html `
243
+ < vaadin-button theme="tertiary " @click ="${ this . _clearActionResult } ">
244
+ < vaadin-icon icon ="font-awesome-solid:xmark "> </ vaadin-icon >
245
+ </ vaadin-button>
246
+ ` ,
247
+ [ ]
248
+ ) }
241
249
${ dialogRenderer ( this . _renderActionResult , [ ] ) }
250
+ ${ dialogFooterRenderer (
251
+ ( ) => html `
252
+ < vaadin-button theme ="primary " @click ="${ this . _saveActionResult } ">
253
+ Save
254
+ </ vaadin-button >
255
+ < vaadin-button theme ="tertiary " @click ="${ this . _copyActionResult } "> Copy</ vaadin-button >
256
+ ` ,
257
+ [ ]
258
+ ) }
242
259
> </ vaadin-dialog> ` ;
243
260
}
244
261
}
245
262
246
263
_renderActionResult ( ) {
247
- if ( this . _actionResultContent && this . _actionResultDisplayType === "raw" ) {
248
- return html `${ this . _actionResultContent } ` ;
249
- } else if ( this . _actionResultContent && this . _actionResultDisplayType === "code" ) {
264
+ if ( this . _actionResult && this . _actionResult . content && this . _actionResult . displayType === "raw" ) {
265
+ return html `${ this . _actionResult . content } ` ;
266
+ } else if ( this . _actionResult && this . _actionResult . content && this . _actionResult . displayType === "code" ) {
250
267
// TODO: We can not assume the mode is the same as the input
251
268
// Maybe return name|content ?
252
269
return html `< qui-code-block id ="code " class ='codeBlock '
253
- mode ='${ this . _getMode ( this . _selectedWorkspaceItem . name ) } '
270
+ mode ='${ this . _getMode ( this . _actionResult ? .name ?? this . _actionResult ?. path ) } '
254
271
theme ='${ themeState . theme . name } '
255
- .content ='${ this . _actionResultContent } '
272
+ .content ='${ this . _actionResult . content } '
256
273
showLineNumbers >
257
274
</ qui-code-block > ` ;
258
- } else if ( this . _actionResultContent && this . _actionResultDisplayType === "markdown" ) {
259
- const htmlContent = this . md . render ( this . _actionResultContent ) ;
275
+ } else if ( this . _actionResult && this . _actionResult . content && this . _actionResult . displayType === "markdown" ) {
276
+ const htmlContent = this . md . render ( this . _actionResult . content ) ;
260
277
return html `${ unsafeHTML ( htmlContent ) } ` ;
261
- } else if ( this . _actionResultContent && this . _actionResultDisplayType === "html" ) {
262
- return html `${ unsafeHTML ( this . _actionResultContent ) } ` ;
263
- } else if ( this . _actionResultContent && this . _actionResultDisplayType === "image" ) {
264
- let imgurl = `data:image/png;base64,${ this . _actionResultContent } ` ;
265
- return html `< img src ="${ imgurl } " alt ="${ this . _selectedWorkspaceItem . name } " style ="max-width: 100%; "/> ` ;
278
+ } else if ( this . _actionResult && this . _actionResult . content && this . _actionResult . displayType === "html" ) {
279
+ return html `${ unsafeHTML ( this . _actionResult . content ) } ` ;
280
+ } else if ( this . _actionResult && this . _actionResult . content && this . _actionResult . displayType === "image" ) {
281
+ let imgurl = `data:image/png;base64,${ this . _actionResult . content } ` ;
282
+ return html `< img src ="${ imgurl } " alt ="${ this . _actionResult ? .name ?? this . _actionResult ?. path } " style ="max-width: 100%; "/> ` ;
266
283
}
267
284
}
268
285
@@ -366,24 +383,25 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
366
383
if ( codeElement ) {
367
384
newWorkspaceItemValue = codeElement . getAttribute ( 'value' ) ;
368
385
}
369
-
370
386
this . jsonRpc . executeAction ( { actionId :actionId ,
371
387
name :this . _selectedWorkspaceItem . name ,
372
388
path :this . _selectedWorkspaceItem . path ,
373
389
content :newWorkspaceItemValue ,
374
390
type :this . _selectedWorkspaceItem . type } ) . then ( jsonRpcResponse => {
391
+
375
392
if ( e . detail . value . display === "notification" ) {
376
393
notifier . showInfoMessage ( jsonRpcResponse . result . result ) ;
377
394
} else if ( e . detail . value . display === "replace" ) {
378
- // TODO: This does not take Markdown into context....
379
- // TODO: Use result
380
- this . _selectedWorkspaceItem . content = jsonRpcResponse . result . result ;
395
+ this . _selectedWorkspaceItem . content = jsonRpcResponse . result . result . content ;
381
396
this . _selectedWorkspaceItem . type = e . detail . value . displayType ;
382
- //this._selectedWorkspaceItem.path =
397
+ this . _selectedWorkspaceItem . path = jsonRpcResponse . result . path ;
398
+ this . _selectedWorkspaceItem . isDirty = true ;
383
399
} else if ( e . detail . value . display !== "nothing" ) {
384
- this . _actionResultContent = jsonRpcResponse . result . result ;
385
- this . _actionResultDisplay = e . detail . value . display ;
386
- this . _actionResultDisplayType = e . detail . value . displayType ;
400
+ this . _actionResult = jsonRpcResponse . result . result ;
401
+ this . _actionResult . name = this . _actionResult . path ;
402
+ this . _actionResult . path = jsonRpcResponse . result . path ;
403
+ this . _actionResult . display = e . detail . value . display ;
404
+ this . _actionResult . displayType = e . detail . value . displayType ;
387
405
}
388
406
this . _showActionProgress = false ;
389
407
} ) ;
@@ -423,18 +441,9 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
423
441
}
424
442
425
443
_saveSelectedWorkspaceItem ( ) {
426
-
427
444
let newWorkspaceItemValue = this . _getChangedContent ( ) ;
428
445
if ( newWorkspaceItemValue ) {
429
- this . jsonRpc . saveWorkspaceItemContent ( { content :newWorkspaceItemValue , path :this . _selectedWorkspaceItem . path } ) . then ( jsonRpcResponse => {
430
- if ( jsonRpcResponse . result . success ) {
431
- notifier . showInfoMessage ( jsonRpcResponse . result . path + " saved successfully" ) ;
432
- this . _selectedWorkspaceItem = { ...this . _selectedWorkspaceItem , content : newWorkspaceItemValue , isDirty : false } ;
433
- super . forceRestart ( ) ;
434
- } else {
435
- notifier . showErrorMessage ( jsonRpcResponse . result . path + " NOT saved. " + jsonRpcResponse . result . errorMessage ) ;
436
- }
437
- } ) ;
446
+ this . _saveContent ( newWorkspaceItemValue , this . _selectedWorkspaceItem . path ) ;
438
447
}
439
448
}
440
449
@@ -445,6 +454,35 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
445
454
if ( changedContent ) content = changedContent ;
446
455
447
456
const path = this . _selectedWorkspaceItem ?. path ;
457
+ this . _copyContent ( content , path ) ;
458
+ }
459
+
460
+ _saveActionResult ( ) {
461
+ if ( this . _actionResult && this . _actionResult . content ) {
462
+ this . _saveContent ( this . _actionResult . content , this . _actionResult . path , false ) ;
463
+ }
464
+ }
465
+
466
+ _copyActionResult ( ) {
467
+ if ( this . _actionResult && this . _actionResult . content ) {
468
+ this . _copyContent ( this . _actionResult . content , this . _actionResult . path ) ;
469
+ }
470
+ }
471
+
472
+ _saveContent ( content , path , select = true ) {
473
+ this . jsonRpc . saveWorkspaceItemContent ( { content :content , path :path } ) . then ( jsonRpcResponse => {
474
+ if ( jsonRpcResponse . result . success ) {
475
+ notifier . showInfoMessage ( jsonRpcResponse . result . path + " saved successfully" ) ;
476
+ if ( select ) this . _selectedWorkspaceItem = { ...this . _selectedWorkspaceItem , content : content , isDirty : false } ;
477
+ //super.forceRestart();
478
+ } else {
479
+ notifier . showErrorMessage ( jsonRpcResponse . result . path + " NOT saved. " + jsonRpcResponse . result . errorMessage ) ;
480
+ }
481
+ } ) ;
482
+
483
+ }
484
+
485
+ _copyContent ( content , path ) {
448
486
if ( ! content ) {
449
487
notifier . showWarningMessage ( path + " has no content" ) ;
450
488
return ;
@@ -469,10 +507,7 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
469
507
}
470
508
471
509
_clearActionResult ( ) {
472
- this . _actionResultContent = null ;
473
- this . _actionResultDisplay = null ;
474
- this . _actionResultDisplayType = null ;
475
- this . _showActionProgress = false ;
510
+ this . _actionResult = null ;
476
511
}
477
512
478
513
_selectWorkspaceItem ( workspaceItem ) {
@@ -501,9 +536,11 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
501
536
this . _filterActions ( workspaceItem . name ) ;
502
537
503
538
this . _clearActionResult ( ) ;
539
+ this . _showActionProgress = false ;
504
540
}
505
541
506
542
shouldConfirmAwayNavigation ( ) {
543
+ if ( this . _selectedWorkspaceItem . isDirty ) return true ;
507
544
let changedContent = this . _getChangedContent ( ) ;
508
545
if ( changedContent ) {
509
546
return true ;
@@ -513,11 +550,15 @@ export class QwcWorkspace extends observeState(QwcHotReloadElement) {
513
550
514
551
_getChangedContent ( ) {
515
552
if ( this . _selectedWorkspaceItem . content ) {
516
- let codeElement = this . shadowRoot . getElementById ( 'code' ) ;
517
- if ( codeElement ) {
518
- let newWorkspaceItemValue = codeElement . getAttribute ( 'value' ) ;
519
- if ( newWorkspaceItemValue !== this . _selectedWorkspaceItem . content ) {
520
- return newWorkspaceItemValue ;
553
+ if ( this . _selectedWorkspaceItem . isDirty ) {
554
+ return this . _selectedWorkspaceItem . content ;
555
+ } else {
556
+ let codeElement = this . shadowRoot . getElementById ( 'code' ) ;
557
+ if ( codeElement ) {
558
+ let newWorkspaceItemValue = codeElement . getAttribute ( 'value' ) ;
559
+ if ( newWorkspaceItemValue !== this . _selectedWorkspaceItem . content ) {
560
+ return newWorkspaceItemValue ;
561
+ }
521
562
}
522
563
}
523
564
}
0 commit comments