UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

1,002 lines • 119 kB
"use strict"; // ***************************************************************************** // 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 WITH Classpath-exception-2.0 // ***************************************************************************** var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommonFrontendContribution = exports.RECENT_COMMANDS_STORAGE_KEY = exports.supportPaste = exports.supportCopy = exports.supportCut = exports.CommonCommands = exports.CommonMenus = void 0; /* eslint-disable max-len, @typescript-eslint/indent */ const debounce = require("lodash.debounce"); const inversify_1 = require("inversify"); const menu_1 = require("../common/menu"); const command_1 = require("../common/command"); const uri_command_handler_1 = require("../common/uri-command-handler"); const selection_service_1 = require("../common/selection-service"); const message_service_1 = require("../common/message-service"); const opener_service_1 = require("../browser/opener-service"); const application_shell_1 = require("./shell/application-shell"); const tab_bars_1 = require("./shell/tab-bars"); const about_dialog_1 = require("./about-dialog"); const browser = require("./browser"); const uri_1 = require("../common/uri"); const context_key_service_1 = require("./context-key-service"); const os_1 = require("../common/os"); const resource_context_key_1 = require("./resource-context-key"); const selection_1 = require("../common/selection"); const storage_service_1 = require("./storage-service"); const navigatable_1 = require("./navigatable"); const quick_view_service_1 = require("./quick-input/quick-view-service"); const environment_1 = require("@theia/application-package/lib/environment"); const icon_theme_service_1 = require("./icon-theme-service"); const color_1 = require("../common/color"); const core_preferences_1 = require("./core-preferences"); const theming_1 = require("./theming"); const preferences_1 = require("./preferences"); const clipboard_service_1 = require("./clipboard-service"); const encoding_registry_1 = require("./encoding-registry"); const encodings_1 = require("../common/encodings"); const env_variables_1 = require("../common/env-variables"); const authentication_service_1 = require("./authentication-service"); const saveable_1 = require("./saveable"); const quick_input_1 = require("./quick-input"); const localization_1 = require("../common/i18n/localization"); const nls_1 = require("../common/nls"); const current_widget_command_adapter_1 = require("./shell/current-widget-command-adapter"); const dialogs_1 = require("./dialogs"); const window_service_1 = require("./window/window-service"); const frontend_application_config_provider_1 = require("./frontend-application-config-provider"); const decoration_style_1 = require("./decoration-style"); const widgets_1 = require("./widgets"); const save_resource_service_1 = require("./save-resource-service"); const user_working_directory_provider_1 = require("./user-working-directory-provider"); const common_1 = require("../common"); const language_quick_pick_service_1 = require("./i18n/language-quick-pick-service"); var CommonMenus; (function (CommonMenus) { CommonMenus.FILE = [...menu_1.MAIN_MENU_BAR, '1_file']; CommonMenus.FILE_NEW = [...CommonMenus.FILE, '1_new']; CommonMenus.FILE_OPEN = [...CommonMenus.FILE, '2_open']; CommonMenus.FILE_SAVE = [...CommonMenus.FILE, '3_save']; CommonMenus.FILE_AUTOSAVE = [...CommonMenus.FILE, '4_autosave']; CommonMenus.FILE_SETTINGS = [...CommonMenus.FILE, '5_settings']; CommonMenus.FILE_SETTINGS_SUBMENU = [...CommonMenus.FILE_SETTINGS, '1_settings_submenu']; CommonMenus.FILE_SETTINGS_SUBMENU_OPEN = [...CommonMenus.FILE_SETTINGS_SUBMENU, '1_settings_submenu_open']; CommonMenus.FILE_SETTINGS_SUBMENU_THEME = [...CommonMenus.FILE_SETTINGS_SUBMENU, '2_settings_submenu_theme']; CommonMenus.FILE_CLOSE = [...CommonMenus.FILE, '6_close']; CommonMenus.EDIT = [...menu_1.MAIN_MENU_BAR, '2_edit']; CommonMenus.EDIT_UNDO = [...CommonMenus.EDIT, '1_undo']; CommonMenus.EDIT_CLIPBOARD = [...CommonMenus.EDIT, '2_clipboard']; CommonMenus.EDIT_FIND = [...CommonMenus.EDIT, '3_find']; CommonMenus.VIEW = [...menu_1.MAIN_MENU_BAR, '4_view']; CommonMenus.VIEW_PRIMARY = [...CommonMenus.VIEW, '0_primary']; CommonMenus.VIEW_APPEARANCE = [...CommonMenus.VIEW, '1_appearance']; CommonMenus.VIEW_APPEARANCE_SUBMENU = [...CommonMenus.VIEW_APPEARANCE, '1_appearance_submenu']; CommonMenus.VIEW_APPEARANCE_SUBMENU_SCREEN = [...CommonMenus.VIEW_APPEARANCE_SUBMENU, '2_appearance_submenu_screen']; CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR = [...CommonMenus.VIEW_APPEARANCE_SUBMENU, '3_appearance_submenu_bar']; CommonMenus.VIEW_EDITOR_SUBMENU = [...CommonMenus.VIEW_APPEARANCE, '2_editor_submenu']; CommonMenus.VIEW_EDITOR_SUBMENU_SPLIT = [...CommonMenus.VIEW_EDITOR_SUBMENU, '1_editor_submenu_split']; CommonMenus.VIEW_EDITOR_SUBMENU_ORTHO = [...CommonMenus.VIEW_EDITOR_SUBMENU, '2_editor_submenu_ortho']; CommonMenus.VIEW_VIEWS = [...CommonMenus.VIEW, '2_views']; CommonMenus.VIEW_LAYOUT = [...CommonMenus.VIEW, '3_layout']; CommonMenus.VIEW_TOGGLE = [...CommonMenus.VIEW, '4_toggle']; CommonMenus.SETTINGS_OPEN = [...menu_1.SETTINGS_MENU, '1_settings_open']; CommonMenus.SETTINGS__THEME = [...menu_1.SETTINGS_MENU, '2_settings_theme']; // last menu item CommonMenus.HELP = [...menu_1.MAIN_MENU_BAR, '9_help']; })(CommonMenus = exports.CommonMenus || (exports.CommonMenus = {})); var CommonCommands; (function (CommonCommands) { CommonCommands.FILE_CATEGORY = 'File'; CommonCommands.VIEW_CATEGORY = 'View'; CommonCommands.PREFERENCES_CATEGORY = 'Preferences'; CommonCommands.FILE_CATEGORY_KEY = nls_1.nls.getDefaultKey(CommonCommands.FILE_CATEGORY); CommonCommands.VIEW_CATEGORY_KEY = nls_1.nls.getDefaultKey(CommonCommands.VIEW_CATEGORY); CommonCommands.PREFERENCES_CATEGORY_KEY = nls_1.nls.getDefaultKey(CommonCommands.PREFERENCES_CATEGORY); CommonCommands.OPEN = { id: 'core.open', }; CommonCommands.CUT = command_1.Command.toDefaultLocalizedCommand({ id: 'core.cut', label: 'Cut' }); CommonCommands.COPY = command_1.Command.toDefaultLocalizedCommand({ id: 'core.copy', label: 'Copy' }); CommonCommands.PASTE = command_1.Command.toDefaultLocalizedCommand({ id: 'core.paste', label: 'Paste' }); CommonCommands.COPY_PATH = command_1.Command.toDefaultLocalizedCommand({ id: 'core.copy.path', label: 'Copy Path' }); CommonCommands.UNDO = command_1.Command.toDefaultLocalizedCommand({ id: 'core.undo', label: 'Undo' }); CommonCommands.REDO = command_1.Command.toDefaultLocalizedCommand({ id: 'core.redo', label: 'Redo' }); CommonCommands.SELECT_ALL = command_1.Command.toDefaultLocalizedCommand({ id: 'core.selectAll', label: 'Select All' }); CommonCommands.FIND = command_1.Command.toDefaultLocalizedCommand({ id: 'core.find', label: 'Find' }); CommonCommands.REPLACE = command_1.Command.toDefaultLocalizedCommand({ id: 'core.replace', label: 'Replace' }); CommonCommands.NEXT_TAB = command_1.Command.toDefaultLocalizedCommand({ id: 'core.nextTab', category: CommonCommands.VIEW_CATEGORY, label: 'Show Next Tab' }); CommonCommands.PREVIOUS_TAB = command_1.Command.toDefaultLocalizedCommand({ id: 'core.previousTab', category: CommonCommands.VIEW_CATEGORY, label: 'Show Previous Tab' }); CommonCommands.NEXT_TAB_IN_GROUP = command_1.Command.toLocalizedCommand({ id: 'core.nextTabInGroup', category: CommonCommands.VIEW_CATEGORY, label: 'Switch to Next Tab in Group' }, 'theia/core/common/showNextTabInGroup', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.PREVIOUS_TAB_IN_GROUP = command_1.Command.toLocalizedCommand({ id: 'core.previousTabInGroup', category: CommonCommands.VIEW_CATEGORY, label: 'Switch to Previous Tab in Group' }, 'theia/core/common/showPreviousTabInGroup', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.NEXT_TAB_GROUP = command_1.Command.toLocalizedCommand({ id: 'core.nextTabGroup', category: CommonCommands.VIEW_CATEGORY, label: 'Switch to Next Tab Group' }, 'theia/core/common/showNextTabGroup', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.PREVIOUS_TAB_GROUP = command_1.Command.toLocalizedCommand({ id: 'core.previousTabBar', category: CommonCommands.VIEW_CATEGORY, label: 'Switch to Previous Tab Group' }, 'theia/core/common/showPreviousTabGroup', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.CLOSE_TAB = command_1.Command.toLocalizedCommand({ id: 'core.close.tab', category: CommonCommands.VIEW_CATEGORY, label: 'Close Tab' }, 'theia/core/common/closeTab', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.CLOSE_OTHER_TABS = command_1.Command.toLocalizedCommand({ id: 'core.close.other.tabs', category: CommonCommands.VIEW_CATEGORY, label: 'Close Other Tabs' }, 'theia/core/common/closeOthers', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.CLOSE_SAVED_TABS = command_1.Command.toDefaultLocalizedCommand({ id: 'workbench.action.closeUnmodifiedEditors', category: CommonCommands.VIEW_CATEGORY, label: 'Close Saved Editors in Group', }); CommonCommands.CLOSE_RIGHT_TABS = command_1.Command.toLocalizedCommand({ id: 'core.close.right.tabs', category: CommonCommands.VIEW_CATEGORY, label: 'Close Tabs to the Right' }, 'theia/core/common/closeRight', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.CLOSE_ALL_TABS = command_1.Command.toLocalizedCommand({ id: 'core.close.all.tabs', category: CommonCommands.VIEW_CATEGORY, label: 'Close All Tabs' }, 'theia/core/common/closeAll', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.CLOSE_MAIN_TAB = command_1.Command.toLocalizedCommand({ id: 'core.close.main.tab', category: CommonCommands.VIEW_CATEGORY, label: 'Close Tab in Main Area' }, 'theia/core/common/closeTabMain', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.CLOSE_OTHER_MAIN_TABS = command_1.Command.toLocalizedCommand({ id: 'core.close.other.main.tabs', category: CommonCommands.VIEW_CATEGORY, label: 'Close Other Tabs in Main Area' }, 'theia/core/common/closeOtherTabMain', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.CLOSE_ALL_MAIN_TABS = command_1.Command.toLocalizedCommand({ id: 'core.close.all.main.tabs', category: CommonCommands.VIEW_CATEGORY, label: 'Close All Tabs in Main Area' }, 'theia/core/common/closeAllTabMain', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.COLLAPSE_PANEL = command_1.Command.toLocalizedCommand({ id: 'core.collapse.tab', category: CommonCommands.VIEW_CATEGORY, label: 'Collapse Side Panel' }, 'theia/core/common/collapseTab', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.COLLAPSE_ALL_PANELS = command_1.Command.toLocalizedCommand({ id: 'core.collapse.all.tabs', category: CommonCommands.VIEW_CATEGORY, label: 'Collapse All Side Panels' }, 'theia/core/common/collapseAllTabs', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.TOGGLE_BOTTOM_PANEL = command_1.Command.toLocalizedCommand({ id: 'core.toggle.bottom.panel', category: CommonCommands.VIEW_CATEGORY, label: 'Toggle Bottom Panel' }, 'theia/core/common/collapseBottomPanel', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.TOGGLE_STATUS_BAR = command_1.Command.toDefaultLocalizedCommand({ id: 'workbench.action.toggleStatusbarVisibility', category: CommonCommands.VIEW_CATEGORY, label: 'Toggle Status Bar Visibility' }); CommonCommands.PIN_TAB = command_1.Command.toDefaultLocalizedCommand({ id: 'workbench.action.pinEditor', category: CommonCommands.VIEW_CATEGORY, label: 'Pin Editor' }); CommonCommands.UNPIN_TAB = command_1.Command.toDefaultLocalizedCommand({ id: 'workbench.action.unpinEditor', category: CommonCommands.VIEW_CATEGORY, label: 'Unpin Editor' }); CommonCommands.TOGGLE_MAXIMIZED = command_1.Command.toLocalizedCommand({ id: 'core.toggleMaximized', category: CommonCommands.VIEW_CATEGORY, label: 'Toggle Maximized' }, 'theia/core/common/toggleMaximized', CommonCommands.VIEW_CATEGORY_KEY); CommonCommands.OPEN_VIEW = command_1.Command.toDefaultLocalizedCommand({ id: 'core.openView', category: CommonCommands.VIEW_CATEGORY, label: 'Open View...' }); CommonCommands.SHOW_MENU_BAR = command_1.Command.toDefaultLocalizedCommand({ id: 'window.menuBarVisibility', category: CommonCommands.VIEW_CATEGORY, label: 'Show Menu Bar' }); CommonCommands.NEW_UNTITLED_FILE = command_1.Command.toDefaultLocalizedCommand({ id: 'workbench.action.files.newUntitledFile', category: CommonCommands.FILE_CATEGORY, label: 'New Untitled File' }); CommonCommands.SAVE = command_1.Command.toDefaultLocalizedCommand({ id: 'core.save', category: CommonCommands.FILE_CATEGORY, label: 'Save', }); CommonCommands.SAVE_AS = command_1.Command.toDefaultLocalizedCommand({ id: 'file.saveAs', category: CommonCommands.FILE_CATEGORY, label: 'Save As...', }); CommonCommands.SAVE_WITHOUT_FORMATTING = command_1.Command.toDefaultLocalizedCommand({ id: 'core.saveWithoutFormatting', category: CommonCommands.FILE_CATEGORY, label: 'Save without Formatting', }); CommonCommands.SAVE_ALL = command_1.Command.toDefaultLocalizedCommand({ id: 'core.saveAll', category: CommonCommands.FILE_CATEGORY, label: 'Save All', }); CommonCommands.AUTO_SAVE = command_1.Command.toDefaultLocalizedCommand({ id: 'textEditor.commands.autosave', category: CommonCommands.FILE_CATEGORY, label: 'Auto Save', }); CommonCommands.ABOUT_COMMAND = command_1.Command.toDefaultLocalizedCommand({ id: 'core.about', label: 'About' }); CommonCommands.OPEN_PREFERENCES = command_1.Command.toDefaultLocalizedCommand({ id: 'preferences:open', category: CommonCommands.PREFERENCES_CATEGORY, label: 'Open Settings (UI)', }); CommonCommands.SELECT_COLOR_THEME = command_1.Command.toDefaultLocalizedCommand({ id: 'workbench.action.selectTheme', label: 'Color Theme', category: CommonCommands.PREFERENCES_CATEGORY }); CommonCommands.SELECT_ICON_THEME = command_1.Command.toDefaultLocalizedCommand({ id: 'workbench.action.selectIconTheme', label: 'File Icon Theme', category: CommonCommands.PREFERENCES_CATEGORY }); CommonCommands.CONFIGURE_DISPLAY_LANGUAGE = command_1.Command.toDefaultLocalizedCommand({ id: 'workbench.action.configureLanguage', label: 'Configure Display Language' }); CommonCommands.TOGGLE_BREADCRUMBS = command_1.Command.toDefaultLocalizedCommand({ id: 'breadcrumbs.toggle', label: 'Toggle Breadcrumbs', category: CommonCommands.VIEW_CATEGORY }); })(CommonCommands = exports.CommonCommands || (exports.CommonCommands = {})); exports.supportCut = browser.isNative || document.queryCommandSupported('cut'); exports.supportCopy = browser.isNative || 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 exports.supportPaste = browser.isNative || (!browser.isChrome && document.queryCommandSupported('paste')); exports.RECENT_COMMANDS_STORAGE_KEY = 'commands'; let CommonFrontendContribution = class CommonFrontendContribution { constructor(shell, selectionService, messageService, openerService, aboutDialog, localizationProvider, saveResourceService) { this.shell = shell; this.selectionService = selectionService; this.messageService = messageService; this.openerService = openerService; this.aboutDialog = aboutDialog; this.localizationProvider = localizationProvider; this.saveResourceService = saveResourceService; this.commonDecorationsStyleSheet = decoration_style_1.DecorationStyle.createStyleSheet('coreCommonDecorationsStyle'); this.shouldPreventClose = false; } async configure(app) { const configDirUri = await this.environments.getConfigDirUri(); // Global settings this.encodingRegistry.registerOverride({ encoding: encodings_1.UTF8, parent: new uri_1.default(configDirUri) }); this.contextKeyService.createKey('isLinux', os_1.OS.type() === os_1.OS.Type.Linux); this.contextKeyService.createKey('isMac', os_1.OS.type() === os_1.OS.Type.OSX); this.contextKeyService.createKey('isWindows', os_1.OS.type() === os_1.OS.Type.Windows); this.contextKeyService.createKey('isWeb', !this.isElectron()); this.pinnedKey = this.contextKeyService.createKey('activeEditorIsPinned', false); this.updatePinnedKey(); this.shell.onDidChangeActiveWidget(() => this.updatePinnedKey()); this.initResourceContextKeys(); this.registerCtrlWHandling(); 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 codicon-settings-gear', title: nls_1.nls.localizeByDefault(CommonCommands.PREFERENCES_CATEGORY), menuPath: menu_1.SETTINGS_MENU, order: 0, }); const accountsMenu = { id: 'accounts-menu', iconClass: 'codicon codicon-person', title: nls_1.nls.localizeByDefault('Accounts'), menuPath: menu_1.ACCOUNTS_MENU, order: 1, }; this.authenticationService.onDidRegisterAuthenticationProvider(() => { app.shell.leftPanelHandler.addBottomMenu(accountsMenu); }); this.authenticationService.onDidUnregisterAuthenticationProvider(() => { if (this.authenticationService.getProviderIds().length === 0) { app.shell.leftPanelHandler.removeBottomMenu(accountsMenu.id); } }); } updateStyles() { document.body.classList.remove('theia-editor-highlightModifiedTabs'); if (this.preferences['workbench.editor.highlightModifiedTabs']) { document.body.classList.add('theia-editor-highlightModifiedTabs'); } } updatePinnedKey() { const activeTab = this.shell.findTabBar(); const pinningTarget = activeTab && this.shell.findTitle(activeTab); const value = pinningTarget && (0, widgets_1.isPinned)(pinningTarget); this.pinnedKey.set(value); } handlePreferenceChange(e, app) { 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: 'codicon codicon-menu', title: nls_1.nls.localizeByDefault('Application Menu'), menuPath: menu_1.MAIN_MENU_BAR, order: 0, }); } else { app.shell.leftPanelHandler.removeTopMenu(mainMenuId); } break; } case 'workbench.sash.hoverDelay': case 'workbench.sash.size': { this.setSashProperties(); break; } } } setSashProperties() { const sashRule = `:root { --theia-sash-hoverDelay: ${this.preferences['workbench.sash.hoverDelay']}ms; --theia-sash-width: ${this.preferences['workbench.sash.size']}px; }`; decoration_style_1.DecorationStyle.deleteStyleRule(':root', this.commonDecorationsStyleSheet); this.commonDecorationsStyleSheet.insertRule(sashRule); } onStart() { this.storageService.getData(exports.RECENT_COMMANDS_STORAGE_KEY, { recent: [] }) .then(tasks => this.commandRegistry.recent = tasks.recent); } onStop() { const recent = this.commandRegistry.recent; this.storageService.setData(exports.RECENT_COMMANDS_STORAGE_KEY, { recent }); window.localStorage.setItem(icon_theme_service_1.IconThemeService.STORAGE_KEY, this.iconThemes.current); window.localStorage.setItem(theming_1.ThemeService.STORAGE_KEY, this.themeService.getCurrentTheme().id); } initResourceContextKeys() { const updateContextKeys = () => { const selection = this.selectionService.selection; const resourceUri = navigatable_1.Navigatable.is(selection) && selection.getResourceUri() || selection_1.UriSelection.getUri(selection); this.resourceContextKey.set(resourceUri); }; updateContextKeys(); this.selectionService.onSelectionChanged(updateContextKeys); } registerMenus(registry) { registry.registerSubmenu(CommonMenus.FILE, nls_1.nls.localizeByDefault('File')); registry.registerSubmenu(CommonMenus.EDIT, nls_1.nls.localizeByDefault('Edit')); registry.registerSubmenu(CommonMenus.VIEW, nls_1.nls.localizeByDefault('View')); registry.registerSubmenu(CommonMenus.HELP, nls_1.nls.localizeByDefault('Help')); 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_1.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_1.nls.localizeByDefault('Toggle Status Bar Visibility') }); registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, { commandId: CommonCommands.COLLAPSE_ALL_PANELS.id, order: '3' }); registry.registerMenuAction(tab_bars_1.SHELL_TABBAR_CONTEXT_CLOSE, { commandId: CommonCommands.CLOSE_TAB.id, label: nls_1.nls.localizeByDefault('Close'), order: '0' }); registry.registerMenuAction(tab_bars_1.SHELL_TABBAR_CONTEXT_CLOSE, { commandId: CommonCommands.CLOSE_OTHER_TABS.id, label: nls_1.nls.localizeByDefault('Close Others'), order: '1' }); registry.registerMenuAction(tab_bars_1.SHELL_TABBAR_CONTEXT_CLOSE, { commandId: CommonCommands.CLOSE_RIGHT_TABS.id, label: nls_1.nls.localizeByDefault('Close to the Right'), order: '2' }); registry.registerMenuAction(tab_bars_1.SHELL_TABBAR_CONTEXT_CLOSE, { commandId: CommonCommands.CLOSE_SAVED_TABS.id, label: nls_1.nls.localizeByDefault('Close Saved'), order: '3', }); registry.registerMenuAction(tab_bars_1.SHELL_TABBAR_CONTEXT_CLOSE, { commandId: CommonCommands.CLOSE_ALL_TABS.id, label: nls_1.nls.localizeByDefault('Close All'), order: '4' }); registry.registerMenuAction(tab_bars_1.SHELL_TABBAR_CONTEXT_SPLIT, { commandId: CommonCommands.COLLAPSE_PANEL.id, label: CommonCommands.COLLAPSE_PANEL.label, order: '5' }); registry.registerMenuAction(tab_bars_1.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(tab_bars_1.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_1.nls.localizeByDefault('Toggle Menu Bar'), order: '0' }); registry.registerMenuAction(tab_bars_1.SHELL_TABBAR_CONTEXT_PIN, { commandId: CommonCommands.PIN_TAB.id, label: nls_1.nls.localizeByDefault('Pin'), order: '7' }); registry.registerMenuAction(tab_bars_1.SHELL_TABBAR_CONTEXT_PIN, { commandId: CommonCommands.UNPIN_TAB.id, label: nls_1.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.registerMenuAction(CommonMenus.SETTINGS__THEME, { commandId: CommonCommands.SELECT_COLOR_THEME.id }); registry.registerMenuAction(CommonMenus.SETTINGS__THEME, { commandId: CommonCommands.SELECT_ICON_THEME.id }); registry.registerSubmenu(CommonMenus.VIEW_APPEARANCE_SUBMENU, nls_1.nls.localizeByDefault('Appearance')); registry.registerMenuAction(CommonMenus.FILE_NEW, { commandId: CommonCommands.NEW_UNTITLED_FILE.id, label: nls_1.nls.localizeByDefault('New File'), order: 'a' }); } registerCommands(commandRegistry) { commandRegistry.registerCommand(CommonCommands.OPEN, uri_command_handler_1.UriAwareCommandHandler.MultiSelect(this.selectionService, { execute: uris => uris.map(uri => (0, opener_service_1.open)(this.openerService, uri)), })); commandRegistry.registerCommand(CommonCommands.CUT, { execute: () => { if (exports.supportCut) { document.execCommand('cut'); } else { this.messageService.warn("Please use the browser's cut command or shortcut."); } } }); commandRegistry.registerCommand(CommonCommands.COPY, { execute: () => { if (exports.supportCopy) { document.execCommand('copy'); } else { this.messageService.warn("Please use the browser's copy command or shortcut."); } } }); commandRegistry.registerCommand(CommonCommands.PASTE, { execute: () => { if (exports.supportPaste) { document.execCommand('paste'); } else { this.messageService.warn("Please use the browser's paste command or shortcut."); } } }); commandRegistry.registerCommand(CommonCommands.COPY_PATH, uri_command_handler_1.UriAwareCommandHandler.MultiSelect(this.selectionService, { isVisible: uris => Array.isArray(uris) && uris.some(uri => uri instanceof uri_1.default), isEnabled: uris => Array.isArray(uris) && uris.some(uri => uri instanceof uri_1.default), execute: async (uris) => { if (uris.length) { const lineDelimiter = os_1.isWindows ? '\r\n' : '\n'; const text = uris.map(resource => resource.path.fsPath()).join(lineDelimiter); await this.clipboardService.writeText(text); } else { await this.messageService.info('Open a file first to copy its path'); } } })); commandRegistry.registerCommand(CommonCommands.UNDO, { execute: () => document.execCommand('undo') }); commandRegistry.registerCommand(CommonCommands.REDO, { execute: () => document.execCommand('redo') }); commandRegistry.registerCommand(CommonCommands.SELECT_ALL, { execute: () => document.execCommand('selectAll') }); commandRegistry.registerCommand(CommonCommands.FIND, { execute: () => { } }); commandRegistry.registerCommand(CommonCommands.REPLACE, { execute: () => { } }); 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 current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: title => Boolean(title === null || title === void 0 ? void 0 : title.closable), execute: (title, tabBar) => tabBar && this.shell.closeTabs(tabBar, candidate => candidate === title), })); commandRegistry.registerCommand(CommonCommands.CLOSE_OTHER_TABS, new current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: (title, tabbar) => Boolean(tabbar === null || tabbar === void 0 ? void 0 : 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 current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: (_title, tabbar) => Boolean(tabbar === null || tabbar === void 0 ? void 0 : tabbar.titles.some(candidate => candidate.closable && !saveable_1.Saveable.isDirty(candidate.owner))), execute: (_title, tabbar) => tabbar && this.shell.closeTabs(tabbar, candidate => candidate.closable && !saveable_1.Saveable.isDirty(candidate.owner)), })); commandRegistry.registerCommand(CommonCommands.CLOSE_RIGHT_TABS, new current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: (title, tabbar) => { let targetSeen = false; return Boolean(tabbar === null || tabbar === void 0 ? void 0 : tabbar.titles.some(candidate => { if (targetSeen && candidate.closable) { return true; } ; if (candidate === title) { targetSeen = true; } ; })); }, isVisible: (_title, tabbar) => { var _a; const area = (_a = (tabbar && this.shell.getAreaFor(tabbar))) !== null && _a !== void 0 ? _a : 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 current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: (_title, tabbar) => Boolean(tabbar === null || tabbar === void 0 ? void 0 : 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 current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: (_title, tabbar) => Boolean(tabbar && application_shell_1.ApplicationShell.isSideArea(this.shell.getAreaFor(tabbar))), isVisible: (_title, tabbar) => Boolean(tabbar && application_shell_1.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 current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: title => Boolean((title === null || title === void 0 ? void 0 : title.owner) && this.shell.canToggleMaximized(title === null || title === void 0 ? void 0 : title.owner)), isVisible: title => Boolean((title === null || title === void 0 ? void 0 : title.owner) && this.shell.canToggleMaximized(title === null || title === void 0 ? void 0 : title.owner)), execute: title => (title === null || title === void 0 ? void 0 : title.owner) && this.shell.toggleMaximized(title === null || title === void 0 ? void 0 : title.owner), })); commandRegistry.registerCommand(CommonCommands.SHOW_MENU_BAR, { isEnabled: () => !os_1.isOSX, isVisible: () => !os_1.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: 1 /* 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_1.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: 2 /* OFF */ }) }); commandRegistry.registerCommand(CommonCommands.SAVE_ALL, { execute: () => this.shell.saveAll({ formatType: 3 /* DIRTY */ }) }); commandRegistry.registerCommand(CommonCommands.ABOUT_COMMAND, { execute: () => this.openAbout() }); commandRegistry.registerCommand(CommonCommands.OPEN_VIEW, { execute: () => { var _a; return (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.open(quick_view_service_1.QuickViewService.PREFIX); } }); commandRegistry.registerCommand(CommonCommands.SELECT_COLOR_THEME, { execute: () => this.selectColorTheme() }); commandRegistry.registerCommand(CommonCommands.SELECT_ICON_THEME, { execute: () => this.selectIconTheme() }); commandRegistry.registerCommand(CommonCommands.PIN_TAB, new current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: title => Boolean(title && !(0, widgets_1.isPinned)(title)), execute: title => this.togglePinned(title), })); commandRegistry.registerCommand(CommonCommands.UNPIN_TAB, new current_widget_command_adapter_1.CurrentWidgetCommandAdapter(this.shell, { isEnabled: title => Boolean(title && (0, widgets_1.isPinned)(title)), execute: title => this.togglePinned(title), })); commandRegistry.registerCommand(CommonCommands.CONFIGURE_DISPLAY_LANGUAGE, { execute: () => this.configureDisplayLanguage() }); commandRegistry.registerCommand(CommonCommands.TOGGLE_BREADCRUMBS, { execute: () => this.toggleBreadcrumbs(), isToggled: () => this.isBreadcrumbsEnabled(), }); commandRegistry.registerCommand(CommonCommands.NEW_UNTITLED_FILE, { execute: async () => { const untitledUri = this.untitledResourceResolver.createUntitledURI('', await this.workingDirProvider.getUserWorkingDir()); this.untitledResourceResolver.resolve(untitledUri); return (0, opener_service_1.open)(this.openerService, untitledUri); } }); for (const [index, ordinal] of this.getOrdinalNumbers().entries()) { commandRegistry.registerCommand({ id: `workbench.action.focus${ordinal}EditorGroup`, label: index === 0 ? nls_1.nls.localizeByDefault('Focus First Editor Group') : '', category: nls_1.nls.localize(CommonCommands.VIEW_CATEGORY_KEY, CommonCommands.VIEW_CATEGORY) }, { isEnabled: () => this.shell.mainAreaTabBars.length > index, execute: () => { var _a, _b; const widget = (_b = (_a = this.shell.mainAreaTabBars[index]) === null || _a === void 0 ? void 0 : _a.currentTitle) === null || _b === void 0 ? void 0 : _b.owner; if (widget) { this.shell.activateWidget(widget.id); } } }); } } getOrdinalNumbers() { return ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth']; } isElectron() { return environment_1.environment.electron.is(); } togglePinned(title) { if (title) { (0, widgets_1.togglePinned)(title); this.updatePinnedKey(); } } registerKeybindings(registry) { if (exports.supportCut) { registry.registerKeybinding({ command: CommonCommands.CUT.id, keybinding: 'ctrlcmd+x' }); } if (exports.supportCopy) { registry.registerKeybinding({ command: CommonCommands.COPY.id, keybinding: 'ctrlcmd+c' }); } if (exports.supportPaste) { registry.registerKeybinding({ command: CommonCommands.PASTE.id, keybinding: 'ctrlcmd+v' }); } registry.registerKeybinding({ command: CommonCommands.COPY_PATH.id, keybinding: os_1.isWindows ? 'shift+alt+c' : 'ctrlcmd+alt+c', when: '!editorFocus' }); registry.registerKeybindings( // Edition { command: CommonCommands.UNDO.id, keybinding: 'ctrlcmd+z' }, { command: CommonCommands.REDO.id, keybinding: 'ctrlcmd+shift+z' }, { command: CommonCommands.SELECT_ALL.id, keybinding: 'ctrlcmd+a' }, { command: CommonCommands.FIND.id, keybinding: 'ctrlcmd+f' }, { command: CommonCommands.REPLACE.id, keybinding: 'ctrlcmd+alt+f' }, // Tabs { command: CommonCommands.NEXT_TAB.id, keybinding: 'ctrlcmd+tab' }, { command: CommonCommands.NEXT_TAB.id, keybinding: 'ctrlcmd+alt+d' }, { command: CommonCommands.PREVIOUS_TAB.id, keybinding: 'ctrlcmd+shift+tab' }, { command: CommonCommands.PREVIOUS_TAB.id, keybinding: 'ctrlcmd+alt+a' }, { command: CommonCommands.CLOSE_MAIN_TAB.id, keybinding: this.isElectron() ? (os_1.isWindows ? 'ctrl+f4' : 'ctrlcmd+w') : 'alt+w' }, { command: CommonCommands.CLOSE_OTHER_MAIN_TABS.id, keybinding: 'ctrlcmd+alt+t' }, { command: CommonCommands.CLOSE_ALL_MAIN_TABS.id, keybinding: this.isElectron() ? 'ctrlCmd+k ctrlCmd+w' : 'alt+shift+w' }, // Panels { command: CommonCommands.COLLAPSE_PANEL.id, keybinding: 'alt+c' }, { command: CommonCommands.TOGGLE_BOTTOM_PANEL.id, keybinding: 'ctrlcmd+j', }, { command: CommonCommands.COLLAPSE_ALL_PANELS.id, keybinding: 'alt+shift+c', }, { command: CommonCommands.TOGGLE_MAXIMIZED.id, keybinding: 'alt+m', }, // Saving { command: CommonCommands.SAVE.id, keybinding: 'ctrlcmd+s' }, { command: CommonCommands.SAVE_WITHOUT_FORMATTING.id, keybinding: 'ctrlcmd+k s' }, { command: CommonCommands.SAVE_ALL.id, keybinding: 'ctrlcmd+alt+s' }, // Theming { command: CommonCommands.SELECT_COLOR_THEME.id, keybinding: 'ctrlcmd+k ctrlcmd+t' }, { command: CommonCommands.PIN_TAB.id, keybinding: 'ctrlcmd+k shift+enter', when: '!activeEditorIsPinned' }, { command: CommonCommands.UNPIN_TAB.id, keybinding: 'ctrlcmd+k shift+enter', when: 'activeEditorIsPinned' }, { command: CommonCommands.NEW_UNTITLED_FILE.id, keybinding: this.isElectron() ? 'ctrlcmd+n' : 'alt+n', }); for (const [index, ordinal] of this.getO