@@ -52,7 +52,7 @@ import { UTF8 } from '../common/encodings';
52
52
import { EnvVariablesServer } from '../common/env-variables' ;
53
53
import { AuthenticationService } from './authentication-service' ;
54
54
import { FormatType , Saveable , SaveOptions } from './saveable' ;
55
- import { QuickInputService , QuickPickItem , QuickPickItemOrSeparator } from './quick-input' ;
55
+ import { QuickInputService , QuickPickItem , QuickPickItemOrSeparator , QuickPickSeparator } from './quick-input' ;
56
56
import { AsyncLocalizationProvider } from '../common/i18n/localization' ;
57
57
import { nls } from '../common/nls' ;
58
58
import { CurrentWidgetCommandAdapter } from './shell/current-widget-command-adapter' ;
@@ -69,6 +69,7 @@ import { LanguageQuickPickService } from './i18n/language-quick-pick-service';
69
69
export namespace CommonMenus {
70
70
71
71
export const FILE = [ ...MAIN_MENU_BAR , '1_file' ] ;
72
+ export const FILE_NEW_TEXT = [ ...FILE , '1_new_text' ] ;
72
73
export const FILE_NEW = [ ...FILE , '1_new' ] ;
73
74
export const FILE_OPEN = [ ...FILE , '2_open' ] ;
74
75
export const FILE_SAVE = [ ...FILE , '3_save' ] ;
@@ -79,6 +80,8 @@ export namespace CommonMenus {
79
80
export const FILE_SETTINGS_SUBMENU_THEME = [ ...FILE_SETTINGS_SUBMENU , '2_settings_submenu_theme' ] ;
80
81
export const FILE_CLOSE = [ ...FILE , '6_close' ] ;
81
82
83
+ export const FILE_NEW_CONTRIBUTIONS = 'file/newFile' ;
84
+
82
85
export const EDIT = [ ...MAIN_MENU_BAR , '2_edit' ] ;
83
86
export const EDIT_UNDO = [ ...EDIT , '1_undo' ] ;
84
87
export const EDIT_CLIPBOARD = [ ...EDIT , '2_clipboard' ] ;
@@ -108,6 +111,7 @@ export namespace CommonCommands {
108
111
109
112
export const FILE_CATEGORY = 'File' ;
110
113
export const VIEW_CATEGORY = 'View' ;
114
+ export const CREATE_CATEGORY = 'Create' ;
111
115
export const PREFERENCES_CATEGORY = 'Preferences' ;
112
116
export const FILE_CATEGORY_KEY = nls . getDefaultKey ( FILE_CATEGORY ) ;
113
117
export const VIEW_CATEGORY_KEY = nls . getDefaultKey ( VIEW_CATEGORY ) ;
@@ -272,11 +276,16 @@ export namespace CommonCommands {
272
276
category : VIEW_CATEGORY ,
273
277
label : 'Toggle Menu Bar'
274
278
} ) ;
275
- export const NEW_UNTITLED_FILE = Command . toDefaultLocalizedCommand ( {
276
- id : 'workbench.action.files.newUntitledFile ' ,
279
+ export const NEW_UNTITLED_TEXT_FILE = Command . toDefaultLocalizedCommand ( {
280
+ id : 'workbench.action.files.newUntitledTextFile ' ,
277
281
category : FILE_CATEGORY ,
278
282
label : 'New Untitled Text File'
279
283
} ) ;
284
+ export const NEW_UNTITLED_FILE = Command . toDefaultLocalizedCommand ( {
285
+ id : 'workbench.action.files.newUntitledFile' ,
286
+ category : CREATE_CATEGORY ,
287
+ label : 'New File...'
288
+ } ) ;
280
289
export const SAVE = Command . toDefaultLocalizedCommand ( {
281
290
id : 'core.save' ,
282
291
category : FILE_CATEGORY ,
@@ -371,6 +380,9 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
371
380
@inject ( CommandRegistry )
372
381
protected readonly commandRegistry : CommandRegistry ;
373
382
383
+ @inject ( MenuModelRegistry )
384
+ protected readonly menuRegistry : MenuModelRegistry ;
385
+
374
386
@inject ( StorageService )
375
387
protected readonly storageService : StorageService ;
376
388
@@ -545,6 +557,9 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
545
557
registry . registerSubmenu ( CommonMenus . VIEW , nls . localizeByDefault ( 'View' ) ) ;
546
558
registry . registerSubmenu ( CommonMenus . HELP , nls . localizeByDefault ( 'Help' ) ) ;
547
559
560
+ // For plugins contributing create new file commands/menu-actions
561
+ registry . registerIndependentSubmenu ( CommonMenus . FILE_NEW_CONTRIBUTIONS , nls . localizeByDefault ( 'New File...' ) ) ;
562
+
548
563
registry . registerMenuAction ( CommonMenus . FILE_SAVE , {
549
564
commandId : CommonCommands . SAVE . id
550
565
} ) ;
@@ -693,10 +708,16 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
693
708
694
709
registry . registerSubmenu ( CommonMenus . VIEW_APPEARANCE_SUBMENU , nls . localizeByDefault ( 'Appearance' ) ) ;
695
710
696
- registry . registerMenuAction ( CommonMenus . FILE_NEW , {
711
+ registry . registerMenuAction ( CommonMenus . FILE_NEW_TEXT , {
712
+ commandId : CommonCommands . NEW_UNTITLED_TEXT_FILE . id ,
713
+ label : nls . localizeByDefault ( 'New Text File' ) ,
714
+ order : 'a'
715
+ } ) ;
716
+
717
+ registry . registerMenuAction ( CommonMenus . FILE_NEW_TEXT , {
697
718
commandId : CommonCommands . NEW_UNTITLED_FILE . id ,
698
719
label : nls . localizeByDefault ( 'New File...' ) ,
699
- order : 'a '
720
+ order : 'a1 '
700
721
} ) ;
701
722
}
702
723
@@ -941,13 +962,17 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
941
962
execute : ( ) => this . toggleBreadcrumbs ( ) ,
942
963
isToggled : ( ) => this . isBreadcrumbsEnabled ( ) ,
943
964
} ) ;
944
- commandRegistry . registerCommand ( CommonCommands . NEW_UNTITLED_FILE , {
965
+ commandRegistry . registerCommand ( CommonCommands . NEW_UNTITLED_TEXT_FILE , {
945
966
execute : async ( ) => {
946
967
const untitledUri = this . untitledResourceResolver . createUntitledURI ( '' , await this . workingDirProvider . getUserWorkingDir ( ) ) ;
947
968
this . untitledResourceResolver . resolve ( untitledUri ) ;
948
969
return open ( this . openerService , untitledUri ) ;
949
970
}
950
971
} ) ;
972
+ commandRegistry . registerCommand ( CommonCommands . NEW_UNTITLED_FILE , {
973
+ execute : async ( ) => this . showNewFilePicker ( )
974
+ } ) ;
975
+
951
976
for ( const [ index , ordinal ] of this . getOrdinalNumbers ( ) . entries ( ) ) {
952
977
commandRegistry . registerCommand ( { id : `workbench.action.focus${ ordinal } EditorGroup` , label : index === 0 ? nls . localizeByDefault ( 'Focus First Editor Group' ) : '' , category : nls . localize ( CommonCommands . VIEW_CATEGORY_KEY , CommonCommands . VIEW_CATEGORY ) } , {
953
978
isEnabled : ( ) => this . shell . mainAreaTabBars . length > index ,
@@ -1097,8 +1122,12 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
1097
1122
when : 'activeEditorIsPinned'
1098
1123
} ,
1099
1124
{
1100
- command : CommonCommands . NEW_UNTITLED_FILE . id ,
1125
+ command : CommonCommands . NEW_UNTITLED_TEXT_FILE . id ,
1101
1126
keybinding : this . isElectron ( ) ? 'ctrlcmd+n' : 'alt+n' ,
1127
+ } ,
1128
+ {
1129
+ command : CommonCommands . NEW_UNTITLED_FILE . id ,
1130
+ keybinding : 'ctrlcmd+alt+n'
1102
1131
}
1103
1132
) ;
1104
1133
for ( const [ index , ordinal ] of this . getOrdinalNumbers ( ) . entries ( ) ) {
@@ -1294,6 +1323,43 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
1294
1323
} ) ;
1295
1324
}
1296
1325
1326
+ /**
1327
+ * @todo https://github.com/eclipse-theia/theia/issues/12824
1328
+ */
1329
+ protected async showNewFilePicker ( ) : Promise < void > {
1330
+ const newFileContributions = this . menuRegistry . getMenuNode ( CommonMenus . FILE_NEW_CONTRIBUTIONS ) ; // Add menus
1331
+ const items : QuickPickItemOrSeparator [ ] = [
1332
+ {
1333
+ label : nls . localizeByDefault ( 'New Text File' ) ,
1334
+ execute : async ( ) => this . commandRegistry . executeCommand ( CommonCommands . NEW_UNTITLED_TEXT_FILE . id )
1335
+ } ,
1336
+ ...newFileContributions . children
1337
+ . flatMap ( node => {
1338
+ if ( node . children && node . children . length > 0 ) {
1339
+ return node . children ;
1340
+ }
1341
+ return node ;
1342
+ } )
1343
+ . filter ( node => node . role || node . command )
1344
+ . map ( node => {
1345
+ if ( node . role ) {
1346
+ return { type : 'separator' } as QuickPickSeparator ;
1347
+ }
1348
+ const command = this . commandRegistry . getCommand ( node . command ! ) ;
1349
+ return {
1350
+ label : command ! . label ! ,
1351
+ execute : async ( ) => this . commandRegistry . executeCommand ( command ! . id ! )
1352
+ } ;
1353
+
1354
+ } )
1355
+ ] ;
1356
+ this . quickInputService . showQuickPick ( items , {
1357
+ title : nls . localizeByDefault ( 'New File...' ) ,
1358
+ placeholder : nls . localizeByDefault ( 'Select File Type or Enter File Name...' ) ,
1359
+ canSelectMany : false
1360
+ } ) ;
1361
+ }
1362
+
1297
1363
registerColors ( colors : ColorRegistry ) : void {
1298
1364
colors . register (
1299
1365
// Base Colors should be aligned with https://code.visualstudio.com/api/references/theme-color#base-colors
0 commit comments