-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
common-frontend-contribution.ts
2680 lines (2536 loc) · 128 KB
/
common-frontend-contribution.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// *****************************************************************************
// Copyright (C) 2017 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
/* eslint-disable max-len, @typescript-eslint/indent */
import debounce = require('lodash.debounce');
import { injectable, inject, optional } from 'inversify';
import { MAIN_MENU_BAR, MANAGE_MENU, MenuContribution, MenuModelRegistry, ACCOUNTS_MENU } from '../common/menu';
import { KeybindingContribution, KeybindingRegistry } from './keybinding';
import { FrontendApplication } from './frontend-application';
import { FrontendApplicationContribution, OnWillStopAction } from './frontend-application-contribution';
import { CommandContribution, CommandRegistry, Command } from '../common/command';
import { UriAwareCommandHandler } from '../common/uri-command-handler';
import { SelectionService } from '../common/selection-service';
import { MessageService } from '../common/message-service';
import { OpenerService, open } from '../browser/opener-service';
import { ApplicationShell } from './shell/application-shell';
import { SHELL_TABBAR_CONTEXT_CLOSE, SHELL_TABBAR_CONTEXT_COPY, SHELL_TABBAR_CONTEXT_PIN, SHELL_TABBAR_CONTEXT_SPLIT } from './shell/tab-bars';
import { AboutDialog } from './about-dialog';
import * as browser from './browser';
import URI from '../common/uri';
import { ContextKey, ContextKeyService } from './context-key-service';
import { OS, isOSX, isWindows, EOL } from '../common/os';
import { ResourceContextKey } from './resource-context-key';
import { UriSelection } from '../common/selection';
import { StorageService } from './storage-service';
import { Navigatable, NavigatableWidget } from './navigatable';
import { QuickViewService } from './quick-input/quick-view-service';
import { environment } from '@theia/application-package/lib/environment';
import { IconTheme, IconThemeService } from './icon-theme-service';
import { ColorContribution } from './color-application-contribution';
import { ColorRegistry } from './color-registry';
import { Color } from '../common/color';
import { CoreConfiguration, CorePreferences } from './core-preferences';
import { ThemeService } from './theming';
import { PreferenceService, PreferenceChangeEvent, PreferenceScope } from './preferences';
import { ClipboardService } from './clipboard-service';
import { EncodingRegistry } from './encoding-registry';
import { UTF8 } from '../common/encodings';
import { EnvVariablesServer } from '../common/env-variables';
import { AuthenticationService } from './authentication-service';
import { FormatType, Saveable, SaveOptions } from './saveable';
import { QuickInputService, QuickPickItem, QuickPickItemOrSeparator, QuickPickSeparator } from './quick-input';
import { AsyncLocalizationProvider } from '../common/i18n/localization';
import { nls } from '../common/nls';
import { CurrentWidgetCommandAdapter } from './shell/current-widget-command-adapter';
import { ConfirmDialog, confirmExit, ConfirmSaveDialog, Dialog } from './dialogs';
import { WindowService } from './window/window-service';
import { FrontendApplicationConfigProvider } from './frontend-application-config-provider';
import { DecorationStyle } from './decoration-style';
import { codicon, isPinned, Title, togglePinned, Widget } from './widgets';
import { SaveableService } from './saveable-service';
import { UserWorkingDirectoryProvider } from './user-working-directory-provider';
import { UNTITLED_SCHEME, UntitledResourceResolver } from '../common';
import { LanguageQuickPickService } from './i18n/language-quick-pick-service';
import { SidebarMenu } from './shell/sidebar-menu-widget';
import { UndoRedoHandlerService } from './undo-redo-handler';
export namespace CommonMenus {
export const FILE = [...MAIN_MENU_BAR, '1_file'];
export const FILE_NEW_TEXT = [...FILE, '1_new_text'];
export const FILE_NEW = [...FILE, '1_new'];
export const FILE_OPEN = [...FILE, '2_open'];
export const FILE_SAVE = [...FILE, '3_save'];
export const FILE_AUTOSAVE = [...FILE, '4_autosave'];
export const FILE_SETTINGS = [...FILE, '5_settings'];
export const FILE_SETTINGS_SUBMENU = [...FILE_SETTINGS, '1_settings_submenu'];
export const FILE_SETTINGS_SUBMENU_OPEN = [...FILE_SETTINGS_SUBMENU, '1_settings_submenu_open'];
export const FILE_SETTINGS_SUBMENU_THEME = [...FILE_SETTINGS_SUBMENU, '2_settings_submenu_theme'];
export const FILE_CLOSE = [...FILE, '6_close'];
export const FILE_NEW_CONTRIBUTIONS = 'file/newFile';
export const EDIT = [...MAIN_MENU_BAR, '2_edit'];
export const EDIT_UNDO = [...EDIT, '1_undo'];
export const EDIT_CLIPBOARD = [...EDIT, '2_clipboard'];
export const EDIT_FIND = [...EDIT, '3_find'];
export const VIEW = [...MAIN_MENU_BAR, '4_view'];
export const VIEW_PRIMARY = [...VIEW, '0_primary'];
export const VIEW_APPEARANCE = [...VIEW, '1_appearance'];
export const VIEW_APPEARANCE_SUBMENU = [...VIEW_APPEARANCE, '1_appearance_submenu'];
export const VIEW_APPEARANCE_SUBMENU_SCREEN = [...VIEW_APPEARANCE_SUBMENU, '2_appearance_submenu_screen'];
export const VIEW_APPEARANCE_SUBMENU_BAR = [...VIEW_APPEARANCE_SUBMENU, '3_appearance_submenu_bar'];
export const VIEW_EDITOR_SUBMENU = [...VIEW_APPEARANCE, '2_editor_submenu'];
export const VIEW_EDITOR_SUBMENU_SPLIT = [...VIEW_EDITOR_SUBMENU, '1_editor_submenu_split'];
export const VIEW_EDITOR_SUBMENU_ORTHO = [...VIEW_EDITOR_SUBMENU, '2_editor_submenu_ortho'];
export const VIEW_VIEWS = [...VIEW, '2_views'];
export const VIEW_LAYOUT = [...VIEW, '3_layout'];
export const VIEW_TOGGLE = [...VIEW, '4_toggle'];
export const MANAGE_GENERAL = [...MANAGE_MENU, '1_manage_general'];
export const MANAGE_SETTINGS = [...MANAGE_MENU, '2_manage_settings'];
export const MANAGE_SETTINGS_THEMES = [...MANAGE_SETTINGS, '1_manage_settings_themes'];
// last menu item
export const HELP = [...MAIN_MENU_BAR, '9_help'];
}
export namespace CommonCommands {
export const FILE_CATEGORY = 'File';
export const VIEW_CATEGORY = 'View';
export const CREATE_CATEGORY = 'Create';
export const PREFERENCES_CATEGORY = 'Preferences';
export const MANAGE_CATEGORY = 'Manage';
export const FILE_CATEGORY_KEY = nls.getDefaultKey(FILE_CATEGORY);
export const VIEW_CATEGORY_KEY = nls.getDefaultKey(VIEW_CATEGORY);
export const PREFERENCES_CATEGORY_KEY = nls.getDefaultKey(PREFERENCES_CATEGORY);
export const OPEN: Command = {
id: 'core.open',
};
export const CUT = Command.toDefaultLocalizedCommand({
id: 'core.cut',
label: 'Cut'
});
export const COPY = Command.toDefaultLocalizedCommand({
id: 'core.copy',
label: 'Copy'
});
export const PASTE = Command.toDefaultLocalizedCommand({
id: 'core.paste',
label: 'Paste'
});
export const COPY_PATH = Command.toDefaultLocalizedCommand({
id: 'core.copy.path',
label: 'Copy Path'
});
export const UNDO = Command.toDefaultLocalizedCommand({
id: 'core.undo',
label: 'Undo'
});
export const REDO = Command.toDefaultLocalizedCommand({
id: 'core.redo',
label: 'Redo'
});
export const SELECT_ALL = Command.toDefaultLocalizedCommand({
id: 'core.selectAll',
label: 'Select All'
});
export const FIND = Command.toDefaultLocalizedCommand({
id: 'core.find',
label: 'Find'
});
export const REPLACE = Command.toDefaultLocalizedCommand({
id: 'core.replace',
label: 'Replace'
});
export const NEXT_TAB = Command.toDefaultLocalizedCommand({
id: 'core.nextTab',
category: VIEW_CATEGORY,
label: 'Show Next Tab'
});
export const PREVIOUS_TAB = Command.toDefaultLocalizedCommand({
id: 'core.previousTab',
category: VIEW_CATEGORY,
label: 'Show Previous Tab'
});
export const NEXT_TAB_IN_GROUP = Command.toLocalizedCommand({
id: 'core.nextTabInGroup',
category: VIEW_CATEGORY,
label: 'Switch to Next Tab in Group'
}, 'theia/core/common/showNextTabInGroup', VIEW_CATEGORY_KEY);
export const PREVIOUS_TAB_IN_GROUP = Command.toLocalizedCommand({
id: 'core.previousTabInGroup',
category: VIEW_CATEGORY,
label: 'Switch to Previous Tab in Group'
}, 'theia/core/common/showPreviousTabInGroup', VIEW_CATEGORY_KEY);
export const NEXT_TAB_GROUP = Command.toLocalizedCommand({
id: 'core.nextTabGroup',
category: VIEW_CATEGORY,
label: 'Switch to Next Tab Group'
}, 'theia/core/common/showNextTabGroup', VIEW_CATEGORY_KEY);
export const PREVIOUS_TAB_GROUP = Command.toLocalizedCommand({
id: 'core.previousTabBar',
category: VIEW_CATEGORY,
label: 'Switch to Previous Tab Group'
}, 'theia/core/common/showPreviousTabGroup', VIEW_CATEGORY_KEY);
export const CLOSE_TAB = Command.toLocalizedCommand({
id: 'core.close.tab',
category: VIEW_CATEGORY,
label: 'Close Tab'
}, 'theia/core/common/closeTab', VIEW_CATEGORY_KEY);
export const CLOSE_OTHER_TABS = Command.toLocalizedCommand({
id: 'core.close.other.tabs',
category: VIEW_CATEGORY,
label: 'Close Other Tabs'
}, 'theia/core/common/closeOthers', VIEW_CATEGORY_KEY);
export const CLOSE_SAVED_TABS = Command.toDefaultLocalizedCommand({
id: 'workbench.action.closeUnmodifiedEditors',
category: VIEW_CATEGORY,
label: 'Close Saved Editors in Group',
});
export const CLOSE_RIGHT_TABS = Command.toLocalizedCommand({
id: 'core.close.right.tabs',
category: VIEW_CATEGORY,
label: 'Close Tabs to the Right'
}, 'theia/core/common/closeRight', VIEW_CATEGORY_KEY);
export const CLOSE_ALL_TABS = Command.toLocalizedCommand({
id: 'core.close.all.tabs',
category: VIEW_CATEGORY,
label: 'Close All Tabs'
}, 'theia/core/common/closeAll', VIEW_CATEGORY_KEY);
export const CLOSE_MAIN_TAB = Command.toLocalizedCommand({
id: 'core.close.main.tab',
category: VIEW_CATEGORY,
label: 'Close Tab in Main Area'
}, 'theia/core/common/closeTabMain', VIEW_CATEGORY_KEY);
export const CLOSE_OTHER_MAIN_TABS = Command.toLocalizedCommand({
id: 'core.close.other.main.tabs',
category: VIEW_CATEGORY,
label: 'Close Other Tabs in Main Area'
}, 'theia/core/common/closeOtherTabMain', VIEW_CATEGORY_KEY);
export const CLOSE_ALL_MAIN_TABS = Command.toLocalizedCommand({
id: 'core.close.all.main.tabs',
category: VIEW_CATEGORY,
label: 'Close All Tabs in Main Area'
}, 'theia/core/common/closeAllTabMain', VIEW_CATEGORY_KEY);
export const COLLAPSE_PANEL = Command.toLocalizedCommand({
id: 'core.collapse.tab',
category: VIEW_CATEGORY,
label: 'Collapse Side Panel'
}, 'theia/core/common/collapseTab', VIEW_CATEGORY_KEY);
export const COLLAPSE_ALL_PANELS = Command.toLocalizedCommand({
id: 'core.collapse.all.tabs',
category: VIEW_CATEGORY,
label: 'Collapse All Side Panels'
}, 'theia/core/common/collapseAllTabs', VIEW_CATEGORY_KEY);
export const TOGGLE_BOTTOM_PANEL = Command.toLocalizedCommand({
id: 'core.toggle.bottom.panel',
category: VIEW_CATEGORY,
label: 'Toggle Bottom Panel'
}, 'theia/core/common/collapseBottomPanel', VIEW_CATEGORY_KEY);
export const TOGGLE_STATUS_BAR = Command.toDefaultLocalizedCommand({
id: 'workbench.action.toggleStatusbarVisibility',
category: VIEW_CATEGORY,
label: 'Toggle Status Bar Visibility'
});
export const PIN_TAB = Command.toDefaultLocalizedCommand({
id: 'workbench.action.pinEditor',
category: VIEW_CATEGORY,
label: 'Pin Editor'
});
export const UNPIN_TAB = Command.toDefaultLocalizedCommand({
id: 'workbench.action.unpinEditor',
category: VIEW_CATEGORY,
label: 'Unpin Editor'
});
export const TOGGLE_MAXIMIZED = Command.toLocalizedCommand({
id: 'core.toggleMaximized',
category: VIEW_CATEGORY,
label: 'Toggle Maximized'
}, 'theia/core/common/toggleMaximized', VIEW_CATEGORY_KEY);
export const OPEN_VIEW = Command.toDefaultLocalizedCommand({
id: 'core.openView',
category: VIEW_CATEGORY,
label: 'Open View...'
});
export const SHOW_MENU_BAR = Command.toDefaultLocalizedCommand({
id: 'window.menuBarVisibility',
category: VIEW_CATEGORY,
label: 'Toggle Menu Bar'
});
/**
* Command Parameters:
* - `fileName`: string
* - `directory`: URI
*/
export const NEW_FILE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.files.newFile',
category: FILE_CATEGORY
});
export const NEW_UNTITLED_TEXT_FILE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.files.newUntitledTextFile',
category: FILE_CATEGORY,
label: 'New Untitled Text File'
});
export const NEW_UNTITLED_FILE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.files.newUntitledFile',
category: CREATE_CATEGORY,
label: 'New File...'
});
export const SAVE = Command.toDefaultLocalizedCommand({
id: 'core.save',
category: FILE_CATEGORY,
label: 'Save',
});
export const SAVE_AS = Command.toDefaultLocalizedCommand({
id: 'file.saveAs',
category: FILE_CATEGORY,
label: 'Save As...',
});
export const SAVE_WITHOUT_FORMATTING = Command.toDefaultLocalizedCommand({
id: 'core.saveWithoutFormatting',
category: FILE_CATEGORY,
label: 'Save without Formatting',
});
export const SAVE_ALL = Command.toDefaultLocalizedCommand({
id: 'core.saveAll',
category: FILE_CATEGORY,
label: 'Save All',
});
export const AUTO_SAVE = Command.toDefaultLocalizedCommand({
id: 'textEditor.commands.autosave',
category: FILE_CATEGORY,
label: 'Auto Save',
});
export const ABOUT_COMMAND = Command.toDefaultLocalizedCommand({
id: 'core.about',
label: 'About'
});
export const OPEN_PREFERENCES = Command.toDefaultLocalizedCommand({
id: 'preferences:open',
category: PREFERENCES_CATEGORY,
label: 'Open Settings (UI)',
});
export const SELECT_COLOR_THEME = Command.toDefaultLocalizedCommand({
id: 'workbench.action.selectTheme',
label: 'Color Theme',
category: PREFERENCES_CATEGORY
});
export const SELECT_ICON_THEME = Command.toDefaultLocalizedCommand({
id: 'workbench.action.selectIconTheme',
label: 'File Icon Theme',
category: PREFERENCES_CATEGORY
});
export const CONFIGURE_DISPLAY_LANGUAGE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.configureLanguage',
label: 'Configure Display Language'
});
export const TOGGLE_BREADCRUMBS = Command.toDefaultLocalizedCommand({
id: 'breadcrumbs.toggle',
label: 'Toggle Breadcrumbs',
category: VIEW_CATEGORY
});
}
export const supportCut = environment.electron.is() || document.queryCommandSupported('cut');
export const supportCopy = environment.electron.is() || document.queryCommandSupported('copy');
// Chrome incorrectly returns true for document.queryCommandSupported('paste')
// when the paste feature is available but the calling script has insufficient
// privileges to actually perform the action
export const supportPaste = environment.electron.is() || (!browser.isChrome && document.queryCommandSupported('paste'));
export const RECENT_COMMANDS_STORAGE_KEY = 'commands';
export const CLASSNAME_OS_MAC = 'mac';
export const CLASSNAME_OS_WINDOWS = 'windows';
export const CLASSNAME_OS_LINUX = 'linux';
@injectable()
export class CommonFrontendContribution implements FrontendApplicationContribution, MenuContribution, CommandContribution, KeybindingContribution, ColorContribution {
protected commonDecorationsStyleSheet: CSSStyleSheet = DecorationStyle.createStyleSheet('coreCommonDecorationsStyle');
constructor(
@inject(ApplicationShell) protected readonly shell: ApplicationShell,
@inject(SelectionService) protected readonly selectionService: SelectionService,
@inject(MessageService) protected readonly messageService: MessageService,
@inject(OpenerService) protected readonly openerService: OpenerService,
@inject(AboutDialog) protected readonly aboutDialog: AboutDialog,
@inject(AsyncLocalizationProvider) protected readonly localizationProvider: AsyncLocalizationProvider,
@inject(SaveableService) protected readonly saveResourceService: SaveableService,
) { }
@inject(ContextKeyService)
protected readonly contextKeyService: ContextKeyService;
@inject(ResourceContextKey)
protected readonly resourceContextKey: ResourceContextKey;
@inject(CommandRegistry)
protected readonly commandRegistry: CommandRegistry;
@inject(MenuModelRegistry)
protected readonly menuRegistry: MenuModelRegistry;
@inject(StorageService)
protected readonly storageService: StorageService;
@inject(QuickInputService) @optional()
protected readonly quickInputService: QuickInputService;
@inject(IconThemeService)
protected readonly iconThemes: IconThemeService;
@inject(ThemeService)
protected readonly themeService: ThemeService;
@inject(CorePreferences)
protected readonly preferences: CorePreferences;
@inject(PreferenceService)
protected readonly preferenceService: PreferenceService;
@inject(ClipboardService)
protected readonly clipboardService: ClipboardService;
@inject(EncodingRegistry)
protected readonly encodingRegistry: EncodingRegistry;
@inject(EnvVariablesServer)
protected readonly environments: EnvVariablesServer;
@inject(AuthenticationService)
protected readonly authenticationService: AuthenticationService;
@inject(WindowService)
protected readonly windowService: WindowService;
@inject(UserWorkingDirectoryProvider)
protected readonly workingDirProvider: UserWorkingDirectoryProvider;
@inject(LanguageQuickPickService)
protected readonly languageQuickPickService: LanguageQuickPickService;
@inject(UntitledResourceResolver)
protected readonly untitledResourceResolver: UntitledResourceResolver;
@inject(UndoRedoHandlerService)
protected readonly undoRedoHandlerService: UndoRedoHandlerService;
protected pinnedKey: ContextKey<boolean>;
protected inputFocus: ContextKey<boolean>;
async configure(app: FrontendApplication): Promise<void> {
// FIXME: This request blocks valuable startup time (~200ms).
const configDirUri = await this.environments.getConfigDirUri();
// Global settings
this.encodingRegistry.registerOverride({
encoding: UTF8,
parent: new URI(configDirUri)
});
this.contextKeyService.createKey<boolean>('isLinux', OS.type() === OS.Type.Linux);
this.contextKeyService.createKey<boolean>('isMac', OS.type() === OS.Type.OSX);
this.contextKeyService.createKey<boolean>('isWindows', OS.type() === OS.Type.Windows);
this.contextKeyService.createKey<boolean>('isWeb', !this.isElectron());
this.inputFocus = this.contextKeyService.createKey<boolean>('inputFocus', false);
this.updateInputFocus();
browser.onDomEvent(document, 'focusin', () => this.updateInputFocus());
this.pinnedKey = this.contextKeyService.createKey<boolean>('activeEditorIsPinned', false);
this.updatePinnedKey();
this.shell.onDidChangeActiveWidget(() => this.updatePinnedKey());
this.initResourceContextKeys();
this.registerCtrlWHandling();
this.setOsClass();
this.updateStyles();
this.preferences.ready.then(() => this.setSashProperties());
this.preferences.onPreferenceChanged(e => this.handlePreferenceChange(e, app));
app.shell.leftPanelHandler.addBottomMenu({
id: 'settings-menu',
iconClass: codicon('settings-gear'),
title: nls.localizeByDefault(CommonCommands.MANAGE_CATEGORY),
menuPath: MANAGE_MENU,
order: 0,
});
const accountsMenu: SidebarMenu = {
id: 'accounts-menu',
iconClass: codicon('account'),
title: nls.localizeByDefault('Accounts'),
menuPath: ACCOUNTS_MENU,
order: 1,
onDidBadgeChange: this.authenticationService.onDidUpdateSignInCount
};
this.authenticationService.onDidRegisterAuthenticationProvider(() => {
app.shell.leftPanelHandler.addBottomMenu(accountsMenu);
});
this.authenticationService.onDidUnregisterAuthenticationProvider(() => {
if (this.authenticationService.getProviderIds().length === 0) {
app.shell.leftPanelHandler.removeBottomMenu(accountsMenu.id);
}
});
}
protected setOsClass(): void {
if (isOSX) {
document.body.classList.add(CLASSNAME_OS_MAC);
} else if (isWindows) {
document.body.classList.add(CLASSNAME_OS_WINDOWS);
} else {
document.body.classList.add(CLASSNAME_OS_LINUX);
}
}
protected updateStyles(): void {
document.body.classList.remove('theia-editor-highlightModifiedTabs');
if (this.preferences['workbench.editor.highlightModifiedTabs']) {
document.body.classList.add('theia-editor-highlightModifiedTabs');
}
}
protected updateInputFocus(): void {
const activeElement = document.activeElement;
if (activeElement) {
const isInput = activeElement.tagName?.toLowerCase() === 'input'
|| activeElement.tagName?.toLowerCase() === 'textarea';
this.inputFocus.set(isInput);
}
}
protected updatePinnedKey(): void {
const activeTab = this.shell.findTabBar();
const pinningTarget = activeTab && this.shell.findTitle(activeTab);
const value = pinningTarget && isPinned(pinningTarget);
this.pinnedKey.set(value);
}
protected handlePreferenceChange(e: PreferenceChangeEvent<CoreConfiguration>, app: FrontendApplication): void {
switch (e.preferenceName) {
case 'workbench.editor.highlightModifiedTabs': {
this.updateStyles();
break;
}
case 'window.menuBarVisibility': {
const { newValue } = e;
const mainMenuId = 'main-menu';
if (newValue === 'compact') {
this.shell.leftPanelHandler.addTopMenu({
id: mainMenuId,
iconClass: `theia-compact-menu ${codicon('menu')}`,
title: nls.localizeByDefault('Application Menu'),
menuPath: MAIN_MENU_BAR,
order: 0,
});
} else {
app.shell.leftPanelHandler.removeTopMenu(mainMenuId);
}
break;
}
case 'workbench.sash.hoverDelay':
case 'workbench.sash.size': {
this.setSashProperties();
break;
}
}
}
protected setSashProperties(): void {
const sashRule = `:root {
--theia-sash-hoverDelay: ${this.preferences['workbench.sash.hoverDelay']}ms;
--theia-sash-width: ${this.preferences['workbench.sash.size']}px;
}`;
DecorationStyle.deleteStyleRule(':root', this.commonDecorationsStyleSheet);
this.commonDecorationsStyleSheet.insertRule(sashRule);
}
onStart(): void {
this.storageService.getData<{ recent: Command[] }>(RECENT_COMMANDS_STORAGE_KEY, { recent: [] })
.then(tasks => this.commandRegistry.recent = tasks.recent);
}
onStop(): void {
const recent = this.commandRegistry.recent;
this.storageService.setData<{ recent: Command[] }>(RECENT_COMMANDS_STORAGE_KEY, { recent });
window.localStorage.setItem(IconThemeService.STORAGE_KEY, this.iconThemes.current);
window.localStorage.setItem(ThemeService.STORAGE_KEY, this.themeService.getCurrentTheme().id);
}
protected initResourceContextKeys(): void {
const updateContextKeys = () => {
const selection = this.selectionService.selection;
const resourceUri = Navigatable.is(selection) && selection.getResourceUri() || UriSelection.getUri(selection);
this.resourceContextKey.set(resourceUri);
};
updateContextKeys();
this.selectionService.onSelectionChanged(updateContextKeys);
}
registerMenus(registry: MenuModelRegistry): void {
registry.registerSubmenu(CommonMenus.FILE, nls.localizeByDefault('File'));
registry.registerSubmenu(CommonMenus.EDIT, nls.localizeByDefault('Edit'));
registry.registerSubmenu(CommonMenus.VIEW, nls.localizeByDefault('View'));
registry.registerSubmenu(CommonMenus.HELP, nls.localizeByDefault('Help'));
// For plugins contributing create new file commands/menu-actions
registry.registerIndependentSubmenu(CommonMenus.FILE_NEW_CONTRIBUTIONS, nls.localizeByDefault('New File...'));
registry.registerMenuAction(CommonMenus.FILE_SAVE, {
commandId: CommonCommands.SAVE.id
});
registry.registerMenuAction(CommonMenus.FILE_SAVE, {
commandId: CommonCommands.SAVE_ALL.id
});
registry.registerMenuAction(CommonMenus.FILE_AUTOSAVE, {
commandId: CommonCommands.AUTO_SAVE.id
});
registry.registerSubmenu(CommonMenus.FILE_SETTINGS_SUBMENU, nls.localizeByDefault(CommonCommands.PREFERENCES_CATEGORY));
registry.registerMenuAction(CommonMenus.EDIT_UNDO, {
commandId: CommonCommands.UNDO.id,
order: '0'
});
registry.registerMenuAction(CommonMenus.EDIT_UNDO, {
commandId: CommonCommands.REDO.id,
order: '1'
});
registry.registerMenuAction(CommonMenus.EDIT_FIND, {
commandId: CommonCommands.FIND.id,
order: '0'
});
registry.registerMenuAction(CommonMenus.EDIT_FIND, {
commandId: CommonCommands.REPLACE.id,
order: '1'
});
registry.registerMenuAction(CommonMenus.EDIT_CLIPBOARD, {
commandId: CommonCommands.CUT.id,
order: '0'
});
registry.registerMenuAction(CommonMenus.EDIT_CLIPBOARD, {
commandId: CommonCommands.COPY.id,
order: '1'
});
registry.registerMenuAction(CommonMenus.EDIT_CLIPBOARD, {
commandId: CommonCommands.PASTE.id,
order: '2'
});
registry.registerMenuAction(CommonMenus.EDIT_CLIPBOARD, {
commandId: CommonCommands.COPY_PATH.id,
order: '3'
});
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, {
commandId: CommonCommands.TOGGLE_BOTTOM_PANEL.id,
order: '1'
});
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, {
commandId: CommonCommands.TOGGLE_STATUS_BAR.id,
order: '2',
label: nls.localizeByDefault('Toggle Status Bar Visibility')
});
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, {
commandId: CommonCommands.COLLAPSE_ALL_PANELS.id,
order: '3'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_CLOSE, {
commandId: CommonCommands.CLOSE_TAB.id,
label: nls.localizeByDefault('Close'),
order: '0'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_CLOSE, {
commandId: CommonCommands.CLOSE_OTHER_TABS.id,
label: nls.localizeByDefault('Close Others'),
order: '1'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_CLOSE, {
commandId: CommonCommands.CLOSE_RIGHT_TABS.id,
label: nls.localizeByDefault('Close to the Right'),
order: '2'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_CLOSE, {
commandId: CommonCommands.CLOSE_SAVED_TABS.id,
label: nls.localizeByDefault('Close Saved'),
order: '3',
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_CLOSE, {
commandId: CommonCommands.CLOSE_ALL_TABS.id,
label: nls.localizeByDefault('Close All'),
order: '4'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_SPLIT, {
commandId: CommonCommands.COLLAPSE_PANEL.id,
label: CommonCommands.COLLAPSE_PANEL.label,
order: '5'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_SPLIT, {
commandId: CommonCommands.TOGGLE_MAXIMIZED.id,
label: CommonCommands.TOGGLE_MAXIMIZED.label,
order: '6'
});
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_SCREEN, {
commandId: CommonCommands.TOGGLE_MAXIMIZED.id,
label: CommonCommands.TOGGLE_MAXIMIZED.label,
order: '6'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_COPY, {
commandId: CommonCommands.COPY_PATH.id,
label: CommonCommands.COPY_PATH.label,
order: '1',
});
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, {
commandId: CommonCommands.SHOW_MENU_BAR.id,
label: nls.localizeByDefault('Toggle Menu Bar'),
order: '0'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_PIN, {
commandId: CommonCommands.PIN_TAB.id,
label: nls.localizeByDefault('Pin'),
order: '7'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_PIN, {
commandId: CommonCommands.UNPIN_TAB.id,
label: nls.localizeByDefault('Unpin'),
order: '8'
});
registry.registerMenuAction(CommonMenus.HELP, {
commandId: CommonCommands.ABOUT_COMMAND.id,
label: CommonCommands.ABOUT_COMMAND.label,
order: '9'
});
registry.registerMenuAction(CommonMenus.VIEW_PRIMARY, {
commandId: CommonCommands.OPEN_VIEW.id
});
registry.registerMenuAction(CommonMenus.FILE_SETTINGS_SUBMENU_THEME, {
commandId: CommonCommands.SELECT_COLOR_THEME.id
});
registry.registerMenuAction(CommonMenus.FILE_SETTINGS_SUBMENU_THEME, {
commandId: CommonCommands.SELECT_ICON_THEME.id
});
registry.registerSubmenu(CommonMenus.MANAGE_SETTINGS_THEMES, nls.localizeByDefault('Themes'), { order: 'a50' });
registry.registerMenuAction(CommonMenus.MANAGE_SETTINGS_THEMES, {
commandId: CommonCommands.SELECT_COLOR_THEME.id,
order: '0'
});
registry.registerMenuAction(CommonMenus.MANAGE_SETTINGS_THEMES, {
commandId: CommonCommands.SELECT_ICON_THEME.id,
order: '1'
});
registry.registerSubmenu(CommonMenus.VIEW_APPEARANCE_SUBMENU, nls.localizeByDefault('Appearance'));
registry.registerMenuAction(CommonMenus.FILE_NEW_TEXT, {
commandId: CommonCommands.NEW_UNTITLED_TEXT_FILE.id,
label: nls.localizeByDefault('New Text File'),
order: 'a'
});
registry.registerMenuAction(CommonMenus.FILE_NEW_TEXT, {
commandId: CommonCommands.NEW_UNTITLED_FILE.id,
label: nls.localizeByDefault('New File...'),
order: 'a1'
});
}
registerCommands(commandRegistry: CommandRegistry): void {
commandRegistry.registerCommand(CommonCommands.OPEN, UriAwareCommandHandler.MultiSelect(this.selectionService, {
execute: uris => uris.map(uri => open(this.openerService, uri)),
}));
commandRegistry.registerCommand(CommonCommands.CUT, {
execute: () => {
if (supportCut) {
document.execCommand('cut');
} else {
this.messageService.warn(nls.localize('theia/core/cutWarn', "Please use the browser's cut command or shortcut."));
}
}
});
commandRegistry.registerCommand(CommonCommands.COPY, {
execute: () => {
if (supportCopy) {
document.execCommand('copy');
} else {
this.messageService.warn(nls.localize('theia/core/copyWarn', "Please use the browser's copy command or shortcut."));
}
}
});
commandRegistry.registerCommand(CommonCommands.PASTE, {
execute: () => {
if (supportPaste) {
document.execCommand('paste');
} else {
this.messageService.warn(nls.localize('theia/core/pasteWarn', "Please use the browser's paste command or shortcut."));
}
}
});
commandRegistry.registerCommand(CommonCommands.COPY_PATH, UriAwareCommandHandler.MultiSelect(this.selectionService, {
isVisible: uris => Array.isArray(uris) && uris.some(uri => uri instanceof URI),
isEnabled: uris => Array.isArray(uris) && uris.some(uri => uri instanceof URI),
execute: async uris => {
if (uris.length) {
const lineDelimiter = EOL;
const text = uris.map(resource => resource.path.fsPath()).join(lineDelimiter);
await this.clipboardService.writeText(text);
} else {
await this.messageService.info(nls.localize('theia/core/copyInfo', 'Open a file first to copy its path'));
}
}
}));
commandRegistry.registerCommand(CommonCommands.UNDO, {
execute: () => {
this.undoRedoHandlerService.undo();
}
});
commandRegistry.registerCommand(CommonCommands.REDO, {
execute: () => {
this.undoRedoHandlerService.redo();
}
});
commandRegistry.registerCommand(CommonCommands.SELECT_ALL, {
execute: () => document.execCommand('selectAll')
});
commandRegistry.registerCommand(CommonCommands.FIND, {
execute: () => { /* no-op */ }
});
commandRegistry.registerCommand(CommonCommands.REPLACE, {
execute: () => { /* no-op */ }
});
commandRegistry.registerCommand(CommonCommands.NEXT_TAB, {
isEnabled: () => this.shell.currentTabBar !== undefined,
execute: () => this.shell.activateNextTab()
});
commandRegistry.registerCommand(CommonCommands.PREVIOUS_TAB, {
isEnabled: () => this.shell.currentTabBar !== undefined,
execute: () => this.shell.activatePreviousTab()
});
commandRegistry.registerCommand(CommonCommands.NEXT_TAB_IN_GROUP, {
isEnabled: () => this.shell.nextTabIndexInTabBar() !== -1,
execute: () => this.shell.activateNextTabInTabBar()
});
commandRegistry.registerCommand(CommonCommands.PREVIOUS_TAB_IN_GROUP, {
isEnabled: () => this.shell.previousTabIndexInTabBar() !== -1,
execute: () => this.shell.activatePreviousTabInTabBar()
});
commandRegistry.registerCommand(CommonCommands.NEXT_TAB_GROUP, {
isEnabled: () => this.shell.nextTabBar() !== undefined,
execute: () => this.shell.activateNextTabBar()
});
commandRegistry.registerCommand(CommonCommands.PREVIOUS_TAB_GROUP, {
isEnabled: () => this.shell.previousTabBar() !== undefined,
execute: () => this.shell.activatePreviousTabBar()
});
commandRegistry.registerCommand(CommonCommands.CLOSE_TAB, new CurrentWidgetCommandAdapter(this.shell, {
isEnabled: title => Boolean(title?.closable),
execute: (title, tabBar) => tabBar && this.shell.closeTabs(tabBar, candidate => candidate === title),
}));
commandRegistry.registerCommand(CommonCommands.CLOSE_OTHER_TABS, new CurrentWidgetCommandAdapter(this.shell, {
isEnabled: (title, tabbar) => Boolean(tabbar?.titles.some(candidate => candidate !== title && candidate.closable)),
execute: (title, tabbar) => tabbar && this.shell.closeTabs(tabbar, candidate => candidate !== title && candidate.closable),
}));
commandRegistry.registerCommand(CommonCommands.CLOSE_SAVED_TABS, new CurrentWidgetCommandAdapter(this.shell, {
isEnabled: (_title, tabbar) => Boolean(tabbar?.titles.some(candidate => candidate.closable && !Saveable.isDirty(candidate.owner))),
execute: (_title, tabbar) => tabbar && this.shell.closeTabs(tabbar, candidate => candidate.closable && !Saveable.isDirty(candidate.owner)),
}));
commandRegistry.registerCommand(CommonCommands.CLOSE_RIGHT_TABS, new CurrentWidgetCommandAdapter(this.shell, {
isEnabled: (title, tabbar) => {
let targetSeen = false;
return Boolean(tabbar?.titles.some(candidate => {
if (targetSeen && candidate.closable) { return true; };
if (candidate === title) { targetSeen = true; };
}));
},
isVisible: (_title, tabbar) => {
const area = (tabbar && this.shell.getAreaFor(tabbar)) ?? this.shell.currentTabArea;
return area !== undefined && area !== 'left' && area !== 'right';
},
execute: (title, tabbar) => {
if (tabbar) {
let targetSeen = false;
this.shell.closeTabs(tabbar, candidate => {
if (targetSeen && candidate.closable) { return true; };
if (candidate === title) { targetSeen = true; };
return false;
});
}
}
}));
commandRegistry.registerCommand(CommonCommands.CLOSE_ALL_TABS, new CurrentWidgetCommandAdapter(this.shell, {
isEnabled: (_title, tabbar) => Boolean(tabbar?.titles.some(title => title.closable)),
execute: (_title, tabbar) => tabbar && this.shell.closeTabs(tabbar, candidate => candidate.closable),
}));
commandRegistry.registerCommand(CommonCommands.CLOSE_MAIN_TAB, {
isEnabled: () => {
const currentWidget = this.shell.getCurrentWidget('main');
return currentWidget !== undefined && currentWidget.title.closable;
},
execute: () => this.shell.getCurrentWidget('main')!.close()
});
commandRegistry.registerCommand(CommonCommands.CLOSE_OTHER_MAIN_TABS, {
isEnabled: () => {
const currentWidget = this.shell.getCurrentWidget('main');
return currentWidget !== undefined &&
this.shell.mainAreaTabBars.some(tb => tb.titles.some(title => title.owner !== currentWidget && title.closable));
},
execute: () => {
const currentWidget = this.shell.getCurrentWidget('main');
this.shell.closeTabs('main', title => title.owner !== currentWidget && title.closable);
}
});
commandRegistry.registerCommand(CommonCommands.CLOSE_ALL_MAIN_TABS, {
isEnabled: () => this.shell.mainAreaTabBars.some(tb => tb.titles.some(title => title.closable)),
execute: () => this.shell.closeTabs('main', title => title.closable)
});
commandRegistry.registerCommand(CommonCommands.COLLAPSE_PANEL, new CurrentWidgetCommandAdapter(this.shell, {
isEnabled: (_title, tabbar) => Boolean(tabbar && ApplicationShell.isSideArea(this.shell.getAreaFor(tabbar))),
isVisible: (_title, tabbar) => Boolean(tabbar && ApplicationShell.isSideArea(this.shell.getAreaFor(tabbar))),
execute: (_title, tabbar) => tabbar && this.shell.collapsePanel(this.shell.getAreaFor(tabbar)!)
}));
commandRegistry.registerCommand(CommonCommands.COLLAPSE_ALL_PANELS, {
execute: () => {
this.shell.collapsePanel('left');
this.shell.collapsePanel('right');
this.shell.collapsePanel('bottom');
}
});
commandRegistry.registerCommand(CommonCommands.TOGGLE_BOTTOM_PANEL, {
isEnabled: () => this.shell.getWidgets('bottom').length > 0,
execute: () => {
if (this.shell.isExpanded('bottom')) {
this.shell.collapsePanel('bottom');
} else {
this.shell.expandPanel('bottom');
}
}
});
commandRegistry.registerCommand(CommonCommands.TOGGLE_STATUS_BAR, {
execute: () => this.preferenceService.updateValue('workbench.statusBar.visible', !this.preferences['workbench.statusBar.visible'])
});
commandRegistry.registerCommand(CommonCommands.TOGGLE_MAXIMIZED, new CurrentWidgetCommandAdapter(this.shell, {
isEnabled: title => Boolean(title?.owner && this.shell.canToggleMaximized(title?.owner)),
isVisible: title => Boolean(title?.owner && this.shell.canToggleMaximized(title?.owner)),
execute: title => title?.owner && this.shell.toggleMaximized(title?.owner),
}));
commandRegistry.registerCommand(CommonCommands.SHOW_MENU_BAR, {
isEnabled: () => !isOSX,
isVisible: () => !isOSX,
execute: () => {
const menuBarVisibility = 'window.menuBarVisibility';
const visibility = this.preferences[menuBarVisibility];
if (visibility !== 'compact') {
this.preferenceService.updateValue(menuBarVisibility, 'compact');
} else {
this.preferenceService.updateValue(menuBarVisibility, 'classic');
}
}
});
commandRegistry.registerCommand(CommonCommands.SAVE, {
execute: () => this.save({ formatType: FormatType.ON })
});
commandRegistry.registerCommand(CommonCommands.SAVE_AS, {
isEnabled: () => this.saveResourceService.canSaveAs(this.shell.currentWidget),
execute: () => {
const { currentWidget } = this.shell;
// No clue what could have happened between `isEnabled` and `execute`
// when fetching currentWidget, so better to double-check:
if (this.saveResourceService.canSaveAs(currentWidget)) {
this.saveResourceService.saveAs(currentWidget);
} else {
this.messageService.error(nls.localize('theia/workspace/failSaveAs', 'Cannot run "{0}" for the current widget.', CommonCommands.SAVE_AS.label!));
}
},
});
commandRegistry.registerCommand(CommonCommands.SAVE_WITHOUT_FORMATTING, {
execute: () => this.save({ formatType: FormatType.OFF })
});
commandRegistry.registerCommand(CommonCommands.SAVE_ALL, {
execute: () => this.shell.saveAll({ formatType: FormatType.DIRTY })
});
commandRegistry.registerCommand(CommonCommands.ABOUT_COMMAND, {
execute: () => this.openAbout()
});
commandRegistry.registerCommand(CommonCommands.OPEN_VIEW, {
execute: () => this.quickInputService?.open(QuickViewService.PREFIX)
});
commandRegistry.registerCommand(CommonCommands.SELECT_COLOR_THEME, {
execute: () => this.selectColorTheme()