14
14
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
// *****************************************************************************
16
16
17
- import { QuickInputService } from '@theia/core/lib/browser' ;
17
+ import { ConfirmDialog , QuickInputService } from '@theia/core/lib/browser' ;
18
18
import {
19
19
Command , CommandContribution , CommandRegistry , MAIN_MENU_BAR ,
20
20
MenuContribution , MenuModelRegistry , MenuNode , MessageService , SubMenuOptions
@@ -29,6 +29,14 @@ const SampleCommand2: Command = {
29
29
id : 'sample-command2' ,
30
30
label : 'Sample Command2'
31
31
} ;
32
+ const SampleCommandConfirmDialog : Command = {
33
+ id : 'sample-command-confirm-dialog' ,
34
+ label : 'Sample Confirm Dialog'
35
+ } ;
36
+ const SampleComplexCommandConfirmDialog : Command = {
37
+ id : 'sample-command-complex-confirm-dialog' ,
38
+ label : 'Sample Complex Confirm Dialog'
39
+ } ;
32
40
const SampleCommandWithProgressMessage : Command = {
33
41
id : 'sample-command-with-progress' ,
34
42
label : 'Sample Command With Progress Message'
@@ -63,6 +71,38 @@ export class SampleCommandContribution implements CommandContribution {
63
71
alert ( 'This is sample command2!' ) ;
64
72
}
65
73
} ) ;
74
+ commands . registerCommand ( SampleCommandConfirmDialog , {
75
+ execute : async ( ) => {
76
+ const choice = await new ConfirmDialog ( {
77
+ title : 'Sample Confirm Dialog' ,
78
+ msg : 'This is a sample with lots of text:' + Array ( 100 )
79
+ . fill ( undefined )
80
+ . map ( ( element , index ) => `\n\nExtra line #${ index } ` )
81
+ . join ( '' )
82
+ } ) . open ( ) ;
83
+ this . messageService . info ( `Sample confirm dialog returned with: \`${ JSON . stringify ( choice ) } \`` ) ;
84
+ }
85
+ } ) ;
86
+ commands . registerCommand ( SampleComplexCommandConfirmDialog , {
87
+ execute : async ( ) => {
88
+ const mainDiv = document . createElement ( 'div' ) ;
89
+ for ( const color of [ '#FF00007F' , '#00FF007F' , '#0000FF7F' ] ) {
90
+ const innerDiv = document . createElement ( 'div' ) ;
91
+ innerDiv . textContent = 'This is a sample with lots of text:' + Array ( 50 )
92
+ . fill ( undefined )
93
+ . map ( ( _ , index ) => `\n\nExtra line #${ index } ` )
94
+ . join ( '' ) ;
95
+ innerDiv . style . backgroundColor = color ;
96
+ innerDiv . style . padding = '5px' ;
97
+ mainDiv . appendChild ( innerDiv ) ;
98
+ }
99
+ const choice = await new ConfirmDialog ( {
100
+ title : 'Sample Confirm Dialog' ,
101
+ msg : mainDiv
102
+ } ) . open ( ) ;
103
+ this . messageService . info ( `Sample confirm dialog returned with: \`${ JSON . stringify ( choice ) } \`` ) ;
104
+ }
105
+ } ) ;
66
106
commands . registerCommand ( SampleQuickInputCommand , {
67
107
execute : async ( ) => {
68
108
const result = await this . quickInputService . input ( {
0 commit comments