awa
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Emitter } from '../../../base/common/event.js';
|
||||
import { registerSingleton } from '../../instantiation/common/extensions.js';
|
||||
import { createDecorator } from '../../instantiation/common/instantiation.js';
|
||||
import { MenuId } from '../common/actions.js';
|
||||
export const IActionViewItemService = createDecorator('IActionViewItemService');
|
||||
class ActionViewItemService {
|
||||
constructor() {
|
||||
this._providers = new Map();
|
||||
this._onDidChange = new Emitter();
|
||||
this.onDidChange = this._onDidChange.event;
|
||||
}
|
||||
dispose() {
|
||||
this._onDidChange.dispose();
|
||||
}
|
||||
lookUp(menu, commandOrMenuId) {
|
||||
return this._providers.get(this._makeKey(menu, commandOrMenuId));
|
||||
}
|
||||
_makeKey(menu, commandOrMenuId) {
|
||||
return `${menu.id}/${(commandOrMenuId instanceof MenuId ? commandOrMenuId.id : commandOrMenuId)}`;
|
||||
}
|
||||
}
|
||||
registerSingleton(IActionViewItemService, ActionViewItemService, 1 /* InstantiationType.Delayed */);
|
||||
//# sourceMappingURL=actionViewItemService.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
.monaco-action-bar .action-item.menu-entry .action-label.icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 50%;
|
||||
background-size: 16px;
|
||||
}
|
||||
|
||||
.monaco-action-bar .action-item.menu-entry.text-only .action-label {
|
||||
color: var(--vscode-descriptionForeground);
|
||||
overflow: hidden;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.monaco-action-bar .action-item.menu-entry.text-only.use-comma:not(:last-of-type) .action-label::after {
|
||||
content: ', ';
|
||||
}
|
||||
|
||||
.monaco-action-bar .action-item.menu-entry.text-only + .action-item:not(.text-only) > .monaco-dropdown .action-label {
|
||||
color: var(--vscode-descriptionForeground);
|
||||
}
|
||||
|
||||
.monaco-dropdown-with-default {
|
||||
display: flex !important;
|
||||
flex-direction: row;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.monaco-dropdown-with-default > .action-container > .action-label {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.monaco-dropdown-with-default > .action-container.menu-entry > .action-label.icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 50%;
|
||||
background-size: 16px;
|
||||
}
|
||||
|
||||
.monaco-dropdown-with-default:hover {
|
||||
background-color: var(--vscode-toolbar-hoverBackground);
|
||||
}
|
||||
|
||||
.monaco-dropdown-with-default > .dropdown-action-container > .monaco-dropdown > .dropdown-label .codicon[class*='codicon-'] {
|
||||
font-size: 12px;
|
||||
padding-left: 0px;
|
||||
padding-right: 0px;
|
||||
line-height: 16px;
|
||||
margin-left: -3px;
|
||||
}
|
||||
|
||||
.monaco-dropdown-with-default > .dropdown-action-container > .monaco-dropdown > .dropdown-label > .action-label {
|
||||
display: block;
|
||||
background-size: 16px;
|
||||
background-position: center center;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
@@ -0,0 +1,499 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import { asCSSUrl } from '../../../base/browser/cssValue.js';
|
||||
import { $, addDisposableListener, append, EventType, ModifierKeyEmitter, prepend } from '../../../base/browser/dom.js';
|
||||
import { StandardKeyboardEvent } from '../../../base/browser/keyboardEvent.js';
|
||||
import { ActionViewItem, BaseActionViewItem, SelectActionViewItem } from '../../../base/browser/ui/actionbar/actionViewItems.js';
|
||||
import { DropdownMenuActionViewItem } from '../../../base/browser/ui/dropdown/dropdownActionViewItem.js';
|
||||
import { ActionRunner, Separator, SubmenuAction } from '../../../base/common/actions.js';
|
||||
import { UILabelProvider } from '../../../base/common/keybindingLabels.js';
|
||||
import { combinedDisposable, DisposableStore, MutableDisposable, toDisposable } from '../../../base/common/lifecycle.js';
|
||||
import { isLinux, isWindows, OS } from '../../../base/common/platform.js';
|
||||
import { ThemeIcon } from '../../../base/common/themables.js';
|
||||
import { assertType } from '../../../base/common/types.js';
|
||||
import { localize } from '../../../nls.js';
|
||||
import { IAccessibilityService } from '../../accessibility/common/accessibility.js';
|
||||
import { isICommandActionToggleInfo } from '../../action/common/action.js';
|
||||
import { IConfigurationService } from '../../configuration/common/configuration.js';
|
||||
import { IContextKeyService } from '../../contextkey/common/contextkey.js';
|
||||
import { IContextMenuService, IContextViewService } from '../../contextview/browser/contextView.js';
|
||||
import { IInstantiationService } from '../../instantiation/common/instantiation.js';
|
||||
import { IKeybindingService } from '../../keybinding/common/keybinding.js';
|
||||
import { INotificationService } from '../../notification/common/notification.js';
|
||||
import { IStorageService } from '../../storage/common/storage.js';
|
||||
import { defaultSelectBoxStyles } from '../../theme/browser/defaultStyles.js';
|
||||
import { asCssVariable, selectBorder } from '../../theme/common/colorRegistry.js';
|
||||
import { isDark } from '../../theme/common/theme.js';
|
||||
import { IThemeService } from '../../theme/common/themeService.js';
|
||||
import { hasNativeContextMenu } from '../../window/common/window.js';
|
||||
import { IMenuService, MenuItemAction, SubmenuItemAction } from '../common/actions.js';
|
||||
import './menuEntryActionViewItem.css';
|
||||
export function getFlatContextMenuActions(groups, primaryGroup) {
|
||||
const target = [];
|
||||
getContextMenuActionsImpl(groups, target, primaryGroup);
|
||||
return target;
|
||||
}
|
||||
function getContextMenuActionsImpl(groups, target, primaryGroup) {
|
||||
const modifierKeyEmitter = ModifierKeyEmitter.getInstance();
|
||||
const useAlternativeActions = modifierKeyEmitter.keyStatus.altKey || ((isWindows || isLinux) && modifierKeyEmitter.keyStatus.shiftKey);
|
||||
fillInActions(groups, target, useAlternativeActions, primaryGroup ? actionGroup => actionGroup === primaryGroup : actionGroup => actionGroup === 'navigation');
|
||||
}
|
||||
export function getActionBarActions(groups, primaryGroup, shouldInlineSubmenu, useSeparatorsInPrimaryActions) {
|
||||
const target = { primary: [], secondary: [] };
|
||||
fillInActionBarActions(groups, target, primaryGroup, shouldInlineSubmenu, useSeparatorsInPrimaryActions);
|
||||
return target;
|
||||
}
|
||||
export function getFlatActionBarActions(groups, primaryGroup, shouldInlineSubmenu, useSeparatorsInPrimaryActions) {
|
||||
const target = [];
|
||||
fillInActionBarActions(groups, target, primaryGroup, shouldInlineSubmenu, useSeparatorsInPrimaryActions);
|
||||
return target;
|
||||
}
|
||||
export function fillInActionBarActions(groups, target, primaryGroup, shouldInlineSubmenu, useSeparatorsInPrimaryActions) {
|
||||
const isPrimaryAction = typeof primaryGroup === 'string' ? (actionGroup) => actionGroup === primaryGroup : primaryGroup;
|
||||
// Action bars handle alternative actions on their own so the alternative actions should be ignored
|
||||
fillInActions(groups, target, false, isPrimaryAction, shouldInlineSubmenu, useSeparatorsInPrimaryActions);
|
||||
}
|
||||
function fillInActions(groups, target, useAlternativeActions, isPrimaryAction = actionGroup => actionGroup === 'navigation', shouldInlineSubmenu = () => false, useSeparatorsInPrimaryActions = false) {
|
||||
let primaryBucket;
|
||||
let secondaryBucket;
|
||||
if (Array.isArray(target)) {
|
||||
primaryBucket = target;
|
||||
secondaryBucket = target;
|
||||
}
|
||||
else {
|
||||
primaryBucket = target.primary;
|
||||
secondaryBucket = target.secondary;
|
||||
}
|
||||
const submenuInfo = new Set();
|
||||
for (const [group, actions] of groups) {
|
||||
let target;
|
||||
if (isPrimaryAction(group)) {
|
||||
target = primaryBucket;
|
||||
if (target.length > 0 && useSeparatorsInPrimaryActions) {
|
||||
target.push(new Separator());
|
||||
}
|
||||
}
|
||||
else {
|
||||
target = secondaryBucket;
|
||||
if (target.length > 0) {
|
||||
target.push(new Separator());
|
||||
}
|
||||
}
|
||||
for (let action of actions) {
|
||||
if (useAlternativeActions) {
|
||||
action = action instanceof MenuItemAction && action.alt ? action.alt : action;
|
||||
}
|
||||
const newLen = target.push(action);
|
||||
// keep submenu info for later inlining
|
||||
if (action instanceof SubmenuAction) {
|
||||
submenuInfo.add({ group, action, index: newLen - 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
// ask the outside if submenu should be inlined or not. only ask when
|
||||
// there would be enough space
|
||||
for (const { group, action, index } of submenuInfo) {
|
||||
const target = isPrimaryAction(group) ? primaryBucket : secondaryBucket;
|
||||
// inlining submenus with length 0 or 1 is easy,
|
||||
// larger submenus need to be checked with the overall limit
|
||||
const submenuActions = action.actions;
|
||||
if (shouldInlineSubmenu(action, group, target.length)) {
|
||||
target.splice(index, 1, ...submenuActions);
|
||||
}
|
||||
}
|
||||
}
|
||||
let MenuEntryActionViewItem = class MenuEntryActionViewItem extends ActionViewItem {
|
||||
constructor(action, _options, _keybindingService, _notificationService, _contextKeyService, _themeService, _contextMenuService, _accessibilityService) {
|
||||
super(undefined, action, { icon: !!(action.class || action.item.icon), label: !action.class && !action.item.icon, draggable: _options?.draggable, keybinding: _options?.keybinding, hoverDelegate: _options?.hoverDelegate, keybindingNotRenderedWithLabel: _options?.keybindingNotRenderedWithLabel });
|
||||
this._options = _options;
|
||||
this._keybindingService = _keybindingService;
|
||||
this._notificationService = _notificationService;
|
||||
this._contextKeyService = _contextKeyService;
|
||||
this._themeService = _themeService;
|
||||
this._contextMenuService = _contextMenuService;
|
||||
this._accessibilityService = _accessibilityService;
|
||||
this._wantsAltCommand = false;
|
||||
this._itemClassDispose = this._register(new MutableDisposable());
|
||||
this._altKey = ModifierKeyEmitter.getInstance();
|
||||
}
|
||||
get _menuItemAction() {
|
||||
return this._action;
|
||||
}
|
||||
get _commandAction() {
|
||||
return this._wantsAltCommand && this._menuItemAction.alt || this._menuItemAction;
|
||||
}
|
||||
async onClick(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
try {
|
||||
await this.actionRunner.run(this._commandAction, this._context);
|
||||
}
|
||||
catch (err) {
|
||||
this._notificationService.error(err);
|
||||
}
|
||||
}
|
||||
render(container) {
|
||||
super.render(container);
|
||||
container.classList.add('menu-entry');
|
||||
if (this.options.icon) {
|
||||
this._updateItemClass(this._menuItemAction.item);
|
||||
}
|
||||
if (this._menuItemAction.alt) {
|
||||
let isMouseOver = false;
|
||||
const updateAltState = () => {
|
||||
const wantsAltCommand = !!this._menuItemAction.alt?.enabled &&
|
||||
(!this._accessibilityService.isMotionReduced() || isMouseOver) && (this._altKey.keyStatus.altKey ||
|
||||
(this._altKey.keyStatus.shiftKey && isMouseOver));
|
||||
if (wantsAltCommand !== this._wantsAltCommand) {
|
||||
this._wantsAltCommand = wantsAltCommand;
|
||||
this.updateLabel();
|
||||
this.updateTooltip();
|
||||
this.updateClass();
|
||||
}
|
||||
};
|
||||
this._register(this._altKey.event(updateAltState));
|
||||
this._register(addDisposableListener(container, 'mouseleave', _ => {
|
||||
isMouseOver = false;
|
||||
updateAltState();
|
||||
}));
|
||||
this._register(addDisposableListener(container, 'mouseenter', _ => {
|
||||
isMouseOver = true;
|
||||
updateAltState();
|
||||
}));
|
||||
updateAltState();
|
||||
}
|
||||
}
|
||||
updateLabel() {
|
||||
if (this.options.label && this.label) {
|
||||
this.label.textContent = this._commandAction.label;
|
||||
}
|
||||
}
|
||||
getTooltip() {
|
||||
const keybinding = this._keybindingService.lookupKeybinding(this._commandAction.id, this._contextKeyService);
|
||||
const keybindingLabel = keybinding && keybinding.getLabel();
|
||||
const tooltip = this._commandAction.tooltip || this._commandAction.label;
|
||||
let title = keybindingLabel
|
||||
? localize(1629, "{0} ({1})", tooltip, keybindingLabel)
|
||||
: tooltip;
|
||||
if (!this._wantsAltCommand && this._menuItemAction.alt?.enabled) {
|
||||
const altTooltip = this._menuItemAction.alt.tooltip || this._menuItemAction.alt.label;
|
||||
const altKeybinding = this._keybindingService.lookupKeybinding(this._menuItemAction.alt.id, this._contextKeyService);
|
||||
const altKeybindingLabel = altKeybinding && altKeybinding.getLabel();
|
||||
const altTitleSection = altKeybindingLabel
|
||||
? localize(1630, "{0} ({1})", altTooltip, altKeybindingLabel)
|
||||
: altTooltip;
|
||||
title = localize(1631, "{0}\n[{1}] {2}", title, UILabelProvider.modifierLabels[OS].altKey, altTitleSection);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
updateClass() {
|
||||
if (this.options.icon) {
|
||||
if (this._commandAction !== this._menuItemAction) {
|
||||
if (this._menuItemAction.alt) {
|
||||
this._updateItemClass(this._menuItemAction.alt.item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._updateItemClass(this._menuItemAction.item);
|
||||
}
|
||||
}
|
||||
}
|
||||
_updateItemClass(item) {
|
||||
this._itemClassDispose.value = undefined;
|
||||
const { element, label } = this;
|
||||
if (!element || !label) {
|
||||
return;
|
||||
}
|
||||
const icon = this._commandAction.checked && isICommandActionToggleInfo(item.toggled) && item.toggled.icon ? item.toggled.icon : item.icon;
|
||||
if (!icon) {
|
||||
return;
|
||||
}
|
||||
if (ThemeIcon.isThemeIcon(icon)) {
|
||||
// theme icons
|
||||
const iconClasses = ThemeIcon.asClassNameArray(icon);
|
||||
label.classList.add(...iconClasses);
|
||||
this._itemClassDispose.value = toDisposable(() => {
|
||||
label.classList.remove(...iconClasses);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// icon path/url
|
||||
label.style.backgroundImage = (isDark(this._themeService.getColorTheme().type)
|
||||
? asCSSUrl(icon.dark)
|
||||
: asCSSUrl(icon.light));
|
||||
label.classList.add('icon');
|
||||
this._itemClassDispose.value = combinedDisposable(toDisposable(() => {
|
||||
label.style.backgroundImage = '';
|
||||
label.classList.remove('icon');
|
||||
}), this._themeService.onDidColorThemeChange(() => {
|
||||
// refresh when the theme changes in case we go between dark <-> light
|
||||
this.updateClass();
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
MenuEntryActionViewItem = __decorate([
|
||||
__param(2, IKeybindingService),
|
||||
__param(3, INotificationService),
|
||||
__param(4, IContextKeyService),
|
||||
__param(5, IThemeService),
|
||||
__param(6, IContextMenuService),
|
||||
__param(7, IAccessibilityService)
|
||||
], MenuEntryActionViewItem);
|
||||
export { MenuEntryActionViewItem };
|
||||
export class TextOnlyMenuEntryActionViewItem extends MenuEntryActionViewItem {
|
||||
render(container) {
|
||||
this.options.label = true;
|
||||
this.options.icon = false;
|
||||
super.render(container);
|
||||
container.classList.add('text-only');
|
||||
container.classList.toggle('use-comma', this._options?.useComma ?? false);
|
||||
}
|
||||
updateLabel() {
|
||||
const kb = this._keybindingService.lookupKeybinding(this._action.id, this._contextKeyService);
|
||||
if (!kb) {
|
||||
return super.updateLabel();
|
||||
}
|
||||
if (this.label) {
|
||||
const kb2 = TextOnlyMenuEntryActionViewItem._symbolPrintEnter(kb);
|
||||
if (this._options?.conversational) {
|
||||
this.label.textContent = localize(1632, '{1} to {0}', this._action.label, kb2);
|
||||
}
|
||||
else {
|
||||
this.label.textContent = localize(1633, '{0} ({1})', this._action.label, kb2);
|
||||
}
|
||||
}
|
||||
}
|
||||
static _symbolPrintEnter(kb) {
|
||||
return kb.getLabel()
|
||||
?.replace(/\benter\b/gi, '\u23CE')
|
||||
.replace(/\bEscape\b/gi, 'Esc');
|
||||
}
|
||||
}
|
||||
let SubmenuEntryActionViewItem = class SubmenuEntryActionViewItem extends DropdownMenuActionViewItem {
|
||||
constructor(action, options, _keybindingService, _contextMenuService, _themeService) {
|
||||
const dropdownOptions = {
|
||||
...options,
|
||||
menuAsChild: options?.menuAsChild ?? false,
|
||||
classNames: options?.classNames ?? (ThemeIcon.isThemeIcon(action.item.icon) ? ThemeIcon.asClassName(action.item.icon) : undefined),
|
||||
keybindingProvider: options?.keybindingProvider ?? (action => _keybindingService.lookupKeybinding(action.id))
|
||||
};
|
||||
super(action, { getActions: () => action.actions }, _contextMenuService, dropdownOptions);
|
||||
this._keybindingService = _keybindingService;
|
||||
this._contextMenuService = _contextMenuService;
|
||||
this._themeService = _themeService;
|
||||
}
|
||||
render(container) {
|
||||
super.render(container);
|
||||
assertType(this.element);
|
||||
container.classList.add('menu-entry');
|
||||
const action = this._action;
|
||||
const { icon } = action.item;
|
||||
if (icon && !ThemeIcon.isThemeIcon(icon)) {
|
||||
this.element.classList.add('icon');
|
||||
const setBackgroundImage = () => {
|
||||
if (this.element) {
|
||||
this.element.style.backgroundImage = (isDark(this._themeService.getColorTheme().type)
|
||||
? asCSSUrl(icon.dark)
|
||||
: asCSSUrl(icon.light));
|
||||
}
|
||||
};
|
||||
setBackgroundImage();
|
||||
this._register(this._themeService.onDidColorThemeChange(() => {
|
||||
// refresh when the theme changes in case we go between dark <-> light
|
||||
setBackgroundImage();
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
SubmenuEntryActionViewItem = __decorate([
|
||||
__param(2, IKeybindingService),
|
||||
__param(3, IContextMenuService),
|
||||
__param(4, IThemeService)
|
||||
], SubmenuEntryActionViewItem);
|
||||
export { SubmenuEntryActionViewItem };
|
||||
let DropdownWithDefaultActionViewItem = class DropdownWithDefaultActionViewItem extends BaseActionViewItem {
|
||||
constructor(submenuAction, options, _keybindingService, _notificationService, _contextMenuService, _menuService, _instaService, _storageService) {
|
||||
super(null, submenuAction);
|
||||
this._keybindingService = _keybindingService;
|
||||
this._notificationService = _notificationService;
|
||||
this._contextMenuService = _contextMenuService;
|
||||
this._menuService = _menuService;
|
||||
this._instaService = _instaService;
|
||||
this._storageService = _storageService;
|
||||
this._defaultActionDisposables = this._register(new DisposableStore());
|
||||
this._container = null;
|
||||
this._options = options;
|
||||
this._storageKey = `${submenuAction.item.submenu.id}_lastActionId`;
|
||||
// determine default action
|
||||
let defaultAction;
|
||||
const defaultActionId = options?.persistLastActionId ? _storageService.get(this._storageKey, 1 /* StorageScope.WORKSPACE */) : undefined;
|
||||
if (defaultActionId) {
|
||||
defaultAction = submenuAction.actions.find(a => defaultActionId === a.id);
|
||||
}
|
||||
if (!defaultAction) {
|
||||
defaultAction = submenuAction.actions[0];
|
||||
}
|
||||
this._defaultAction = this._defaultActionDisposables.add(this._instaService.createInstance(MenuEntryActionViewItem, defaultAction, { keybinding: this._getDefaultActionKeybindingLabel(defaultAction) }));
|
||||
const dropdownOptions = {
|
||||
keybindingProvider: action => this._keybindingService.lookupKeybinding(action.id),
|
||||
...options,
|
||||
menuAsChild: options?.menuAsChild ?? true,
|
||||
classNames: options?.classNames ?? ['codicon', 'codicon-chevron-down'],
|
||||
actionRunner: options?.actionRunner ?? this._register(new ActionRunner()),
|
||||
};
|
||||
this._dropdown = this._register(new DropdownMenuActionViewItem(submenuAction, submenuAction.actions, this._contextMenuService, dropdownOptions));
|
||||
this._register(this._dropdown.actionRunner.onDidRun((e) => {
|
||||
if (e.action instanceof MenuItemAction) {
|
||||
this.update(e.action);
|
||||
}
|
||||
}));
|
||||
}
|
||||
update(lastAction) {
|
||||
if (this._options?.persistLastActionId) {
|
||||
this._storageService.store(this._storageKey, lastAction.id, 1 /* StorageScope.WORKSPACE */, 1 /* StorageTarget.MACHINE */);
|
||||
}
|
||||
this._defaultActionDisposables.clear();
|
||||
this._defaultAction = this._defaultActionDisposables.add(this._instaService.createInstance(MenuEntryActionViewItem, lastAction, { keybinding: this._getDefaultActionKeybindingLabel(lastAction) }));
|
||||
this._defaultAction.actionRunner = this._defaultActionDisposables.add(new class extends ActionRunner {
|
||||
async runAction(action, context) {
|
||||
await action.run(undefined);
|
||||
}
|
||||
}());
|
||||
if (this._container) {
|
||||
this._defaultAction.render(prepend(this._container, $('.action-container')));
|
||||
}
|
||||
}
|
||||
_getDefaultActionKeybindingLabel(defaultAction) {
|
||||
let defaultActionKeybinding;
|
||||
if (this._options?.renderKeybindingWithDefaultActionLabel) {
|
||||
const kb = this._keybindingService.lookupKeybinding(defaultAction.id);
|
||||
if (kb) {
|
||||
defaultActionKeybinding = `(${kb.getLabel()})`;
|
||||
}
|
||||
}
|
||||
return defaultActionKeybinding;
|
||||
}
|
||||
setActionContext(newContext) {
|
||||
super.setActionContext(newContext);
|
||||
this._defaultAction.setActionContext(newContext);
|
||||
this._dropdown.setActionContext(newContext);
|
||||
}
|
||||
render(container) {
|
||||
this._container = container;
|
||||
super.render(this._container);
|
||||
this._container.classList.add('monaco-dropdown-with-default');
|
||||
const primaryContainer = $('.action-container');
|
||||
this._defaultAction.render(append(this._container, primaryContainer));
|
||||
this._register(addDisposableListener(primaryContainer, EventType.KEY_DOWN, (e) => {
|
||||
const event = new StandardKeyboardEvent(e);
|
||||
if (event.equals(17 /* KeyCode.RightArrow */)) {
|
||||
this._defaultAction.element.tabIndex = -1;
|
||||
this._dropdown.focus();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}));
|
||||
const dropdownContainer = $('.dropdown-action-container');
|
||||
this._dropdown.render(append(this._container, dropdownContainer));
|
||||
this._register(addDisposableListener(dropdownContainer, EventType.KEY_DOWN, (e) => {
|
||||
const event = new StandardKeyboardEvent(e);
|
||||
if (event.equals(15 /* KeyCode.LeftArrow */)) {
|
||||
this._defaultAction.element.tabIndex = 0;
|
||||
this._dropdown.setFocusable(false);
|
||||
this._defaultAction.element?.focus();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}));
|
||||
}
|
||||
focus(fromRight) {
|
||||
if (fromRight) {
|
||||
this._dropdown.focus();
|
||||
}
|
||||
else {
|
||||
this._defaultAction.element.tabIndex = 0;
|
||||
this._defaultAction.element.focus();
|
||||
}
|
||||
}
|
||||
blur() {
|
||||
this._defaultAction.element.tabIndex = -1;
|
||||
this._dropdown.blur();
|
||||
this._container.blur();
|
||||
}
|
||||
setFocusable(focusable) {
|
||||
if (focusable) {
|
||||
this._defaultAction.element.tabIndex = 0;
|
||||
}
|
||||
else {
|
||||
this._defaultAction.element.tabIndex = -1;
|
||||
this._dropdown.setFocusable(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
DropdownWithDefaultActionViewItem = __decorate([
|
||||
__param(2, IKeybindingService),
|
||||
__param(3, INotificationService),
|
||||
__param(4, IContextMenuService),
|
||||
__param(5, IMenuService),
|
||||
__param(6, IInstantiationService),
|
||||
__param(7, IStorageService)
|
||||
], DropdownWithDefaultActionViewItem);
|
||||
export { DropdownWithDefaultActionViewItem };
|
||||
let SubmenuEntrySelectActionViewItem = class SubmenuEntrySelectActionViewItem extends SelectActionViewItem {
|
||||
constructor(action, contextViewService, configurationService) {
|
||||
super(null, action, action.actions.map(a => ({
|
||||
text: a.id === Separator.ID ? '\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' : a.label,
|
||||
isDisabled: !a.enabled,
|
||||
})), 0, contextViewService, defaultSelectBoxStyles, { ariaLabel: action.tooltip, optionsAsChildren: true, useCustomDrawn: !hasNativeContextMenu(configurationService) });
|
||||
this.select(Math.max(0, action.actions.findIndex(a => a.checked)));
|
||||
}
|
||||
render(container) {
|
||||
super.render(container);
|
||||
container.style.borderColor = asCssVariable(selectBorder);
|
||||
}
|
||||
runAction(option, index) {
|
||||
const action = this.action.actions[index];
|
||||
if (action) {
|
||||
this.actionRunner.run(action);
|
||||
}
|
||||
}
|
||||
};
|
||||
SubmenuEntrySelectActionViewItem = __decorate([
|
||||
__param(1, IContextViewService),
|
||||
__param(2, IConfigurationService)
|
||||
], SubmenuEntrySelectActionViewItem);
|
||||
/**
|
||||
* Creates action view items for menu actions or submenu actions.
|
||||
*/
|
||||
export function createActionViewItem(instaService, action, options) {
|
||||
if (action instanceof MenuItemAction) {
|
||||
return instaService.createInstance(MenuEntryActionViewItem, action, options);
|
||||
}
|
||||
else if (action instanceof SubmenuItemAction) {
|
||||
if (action.item.isSelection) {
|
||||
return instaService.createInstance(SubmenuEntrySelectActionViewItem, action);
|
||||
}
|
||||
else {
|
||||
if (action.item.rememberDefaultAction) {
|
||||
return instaService.createInstance(DropdownWithDefaultActionViewItem, action, { ...options, persistLastActionId: true });
|
||||
}
|
||||
else {
|
||||
return instaService.createInstance(SubmenuEntryActionViewItem, action, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=menuEntryActionViewItem.js.map
|
||||
File diff suppressed because one or more lines are too long
280
_internal/editor/esm/vs/platform/actions/browser/toolbar.js
Normal file
280
_internal/editor/esm/vs/platform/actions/browser/toolbar.js
Normal file
@@ -0,0 +1,280 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import { addDisposableListener, getWindow } from '../../../base/browser/dom.js';
|
||||
import { StandardMouseEvent } from '../../../base/browser/mouseEvent.js';
|
||||
import { ToggleMenuAction, ToolBar } from '../../../base/browser/ui/toolbar/toolbar.js';
|
||||
import { Separator, toAction } from '../../../base/common/actions.js';
|
||||
import { coalesceInPlace } from '../../../base/common/arrays.js';
|
||||
import { intersection } from '../../../base/common/collections.js';
|
||||
import { BugIndicatingError } from '../../../base/common/errors.js';
|
||||
import { Emitter } from '../../../base/common/event.js';
|
||||
import { Iterable } from '../../../base/common/iterator.js';
|
||||
import { DisposableStore } from '../../../base/common/lifecycle.js';
|
||||
import { localize } from '../../../nls.js';
|
||||
import { createActionViewItem, getActionBarActions } from './menuEntryActionViewItem.js';
|
||||
import { IMenuService, MenuItemAction, SubmenuItemAction } from '../common/actions.js';
|
||||
import { createConfigureKeybindingAction } from '../common/menuService.js';
|
||||
import { ICommandService } from '../../commands/common/commands.js';
|
||||
import { IContextKeyService } from '../../contextkey/common/contextkey.js';
|
||||
import { IContextMenuService } from '../../contextview/browser/contextView.js';
|
||||
import { IKeybindingService } from '../../keybinding/common/keybinding.js';
|
||||
import { ITelemetryService } from '../../telemetry/common/telemetry.js';
|
||||
import { IActionViewItemService } from './actionViewItemService.js';
|
||||
import { IInstantiationService } from '../../instantiation/common/instantiation.js';
|
||||
/**
|
||||
* The `WorkbenchToolBar` does
|
||||
* - support hiding of menu items
|
||||
* - lookup keybindings for each actions automatically
|
||||
* - send `workbenchActionExecuted`-events for each action
|
||||
*
|
||||
* See {@link MenuWorkbenchToolBar} for a toolbar that is backed by a menu.
|
||||
*/
|
||||
let WorkbenchToolBar = class WorkbenchToolBar extends ToolBar {
|
||||
constructor(container, _options, _menuService, _contextKeyService, _contextMenuService, _keybindingService, _commandService, telemetryService) {
|
||||
super(container, _contextMenuService, {
|
||||
// defaults
|
||||
getKeyBinding: (action) => _keybindingService.lookupKeybinding(action.id) ?? undefined,
|
||||
// options (override defaults)
|
||||
..._options,
|
||||
// mandatory (overide options)
|
||||
allowContextMenu: true,
|
||||
skipTelemetry: typeof _options?.telemetrySource === 'string',
|
||||
});
|
||||
this._options = _options;
|
||||
this._menuService = _menuService;
|
||||
this._contextKeyService = _contextKeyService;
|
||||
this._contextMenuService = _contextMenuService;
|
||||
this._keybindingService = _keybindingService;
|
||||
this._commandService = _commandService;
|
||||
this._sessionDisposables = this._store.add(new DisposableStore());
|
||||
// telemetry logic
|
||||
const telemetrySource = _options?.telemetrySource;
|
||||
if (telemetrySource) {
|
||||
this._store.add(this.actionBar.onDidRun(e => telemetryService.publicLog2('workbenchActionExecuted', { id: e.action.id, from: telemetrySource })));
|
||||
}
|
||||
}
|
||||
setActions(_primary, _secondary = [], menuIds) {
|
||||
this._sessionDisposables.clear();
|
||||
const primary = _primary.slice(); // for hiding and overflow we set some items to undefined
|
||||
const secondary = _secondary.slice();
|
||||
const toggleActions = [];
|
||||
let toggleActionsCheckedCount = 0;
|
||||
const extraSecondary = [];
|
||||
let someAreHidden = false;
|
||||
// unless disabled, move all hidden items to secondary group or ignore them
|
||||
if (this._options?.hiddenItemStrategy !== -1 /* HiddenItemStrategy.NoHide */) {
|
||||
for (let i = 0; i < primary.length; i++) {
|
||||
const action = primary[i];
|
||||
if (!(action instanceof MenuItemAction) && !(action instanceof SubmenuItemAction)) {
|
||||
// console.warn(`Action ${action.id}/${action.label} is not a MenuItemAction`);
|
||||
continue;
|
||||
}
|
||||
if (!action.hideActions) {
|
||||
continue;
|
||||
}
|
||||
// collect all toggle actions
|
||||
toggleActions.push(action.hideActions.toggle);
|
||||
if (action.hideActions.toggle.checked) {
|
||||
toggleActionsCheckedCount++;
|
||||
}
|
||||
// hidden items move into overflow or ignore
|
||||
if (action.hideActions.isHidden) {
|
||||
someAreHidden = true;
|
||||
primary[i] = undefined;
|
||||
if (this._options?.hiddenItemStrategy !== 0 /* HiddenItemStrategy.Ignore */) {
|
||||
extraSecondary[i] = action;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// count for max
|
||||
if (this._options?.overflowBehavior !== undefined) {
|
||||
const exemptedIds = intersection(new Set(this._options.overflowBehavior.exempted), Iterable.map(primary, a => a?.id));
|
||||
const maxItems = this._options.overflowBehavior.maxItems - exemptedIds.size;
|
||||
let count = 0;
|
||||
for (let i = 0; i < primary.length; i++) {
|
||||
const action = primary[i];
|
||||
if (!action) {
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
if (exemptedIds.has(action.id)) {
|
||||
continue;
|
||||
}
|
||||
if (count >= maxItems) {
|
||||
primary[i] = undefined;
|
||||
extraSecondary[i] = action;
|
||||
}
|
||||
}
|
||||
}
|
||||
// coalesce turns Array<IAction|undefined> into IAction[]
|
||||
coalesceInPlace(primary);
|
||||
coalesceInPlace(extraSecondary);
|
||||
super.setActions(primary, Separator.join(extraSecondary, secondary));
|
||||
// add context menu for toggle and configure keybinding actions
|
||||
if (toggleActions.length > 0 || primary.length > 0) {
|
||||
this._sessionDisposables.add(addDisposableListener(this.getElement(), 'contextmenu', e => {
|
||||
const event = new StandardMouseEvent(getWindow(this.getElement()), e);
|
||||
const action = this.getItemAction(event.target);
|
||||
if (!(action)) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const primaryActions = [];
|
||||
// -- Configure Keybinding Action --
|
||||
if (action instanceof MenuItemAction && action.menuKeybinding) {
|
||||
primaryActions.push(action.menuKeybinding);
|
||||
}
|
||||
else if (!(action instanceof SubmenuItemAction || action instanceof ToggleMenuAction)) {
|
||||
// only enable the configure keybinding action for actions that support keybindings
|
||||
const supportsKeybindings = !!this._keybindingService.lookupKeybinding(action.id);
|
||||
primaryActions.push(createConfigureKeybindingAction(this._commandService, this._keybindingService, action.id, undefined, supportsKeybindings));
|
||||
}
|
||||
// -- Hide Actions --
|
||||
if (toggleActions.length > 0) {
|
||||
let noHide = false;
|
||||
// last item cannot be hidden when using ignore strategy
|
||||
if (toggleActionsCheckedCount === 1 && this._options?.hiddenItemStrategy === 0 /* HiddenItemStrategy.Ignore */) {
|
||||
noHide = true;
|
||||
for (let i = 0; i < toggleActions.length; i++) {
|
||||
if (toggleActions[i].checked) {
|
||||
toggleActions[i] = toAction({
|
||||
id: action.id,
|
||||
label: action.label,
|
||||
checked: true,
|
||||
enabled: false,
|
||||
run() { }
|
||||
});
|
||||
break; // there is only one
|
||||
}
|
||||
}
|
||||
}
|
||||
// add "hide foo" actions
|
||||
if (!noHide && (action instanceof MenuItemAction || action instanceof SubmenuItemAction)) {
|
||||
if (!action.hideActions) {
|
||||
// no context menu for MenuItemAction instances that support no hiding
|
||||
// those are fake actions and need to be cleaned up
|
||||
return;
|
||||
}
|
||||
primaryActions.push(action.hideActions.hide);
|
||||
}
|
||||
else {
|
||||
primaryActions.push(toAction({
|
||||
id: 'label',
|
||||
label: localize(1634, "Hide"),
|
||||
enabled: false,
|
||||
run() { }
|
||||
}));
|
||||
}
|
||||
}
|
||||
const actions = Separator.join(primaryActions, toggleActions);
|
||||
// add "Reset Menu" action
|
||||
if (this._options?.resetMenu && !menuIds) {
|
||||
menuIds = [this._options.resetMenu];
|
||||
}
|
||||
if (someAreHidden && menuIds) {
|
||||
actions.push(new Separator());
|
||||
actions.push(toAction({
|
||||
id: 'resetThisMenu',
|
||||
label: localize(1635, "Reset Menu"),
|
||||
run: () => this._menuService.resetHiddenStates(menuIds)
|
||||
}));
|
||||
}
|
||||
if (actions.length === 0) {
|
||||
return;
|
||||
}
|
||||
this._contextMenuService.showContextMenu({
|
||||
getAnchor: () => event,
|
||||
getActions: () => actions,
|
||||
// add context menu actions (iff appicable)
|
||||
menuId: this._options?.contextMenu,
|
||||
menuActionOptions: { renderShortTitle: true, ...this._options?.menuOptions },
|
||||
skipTelemetry: typeof this._options?.telemetrySource === 'string',
|
||||
contextKeyService: this._contextKeyService,
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
WorkbenchToolBar = __decorate([
|
||||
__param(2, IMenuService),
|
||||
__param(3, IContextKeyService),
|
||||
__param(4, IContextMenuService),
|
||||
__param(5, IKeybindingService),
|
||||
__param(6, ICommandService),
|
||||
__param(7, ITelemetryService)
|
||||
], WorkbenchToolBar);
|
||||
export { WorkbenchToolBar };
|
||||
/**
|
||||
* A {@link WorkbenchToolBar workbench toolbar} that is purely driven from a {@link MenuId menu}-identifier.
|
||||
*
|
||||
* *Note* that Manual updates via `setActions` are NOT supported.
|
||||
*/
|
||||
let MenuWorkbenchToolBar = class MenuWorkbenchToolBar extends WorkbenchToolBar {
|
||||
get onDidChangeMenuItems() { return this._onDidChangeMenuItems.event; }
|
||||
constructor(container, menuId, options, menuService, contextKeyService, contextMenuService, keybindingService, commandService, telemetryService, actionViewService, instantiationService) {
|
||||
super(container, {
|
||||
resetMenu: menuId,
|
||||
...options,
|
||||
actionViewItemProvider: (action, opts) => {
|
||||
let provider = actionViewService.lookUp(menuId, action instanceof SubmenuItemAction ? action.item.submenu.id : action.id);
|
||||
if (!provider) {
|
||||
provider = options?.actionViewItemProvider;
|
||||
}
|
||||
const viewItem = provider?.(action, opts, instantiationService, getWindow(container).vscodeWindowId);
|
||||
if (viewItem) {
|
||||
return viewItem;
|
||||
}
|
||||
return createActionViewItem(instantiationService, action, opts);
|
||||
}
|
||||
}, menuService, contextKeyService, contextMenuService, keybindingService, commandService, telemetryService);
|
||||
this._onDidChangeMenuItems = this._store.add(new Emitter());
|
||||
// update logic
|
||||
const menu = this._store.add(menuService.createMenu(menuId, contextKeyService, { emitEventsForSubmenuChanges: true, eventDebounceDelay: options?.eventDebounceDelay }));
|
||||
const updateToolbar = () => {
|
||||
const { primary, secondary } = getActionBarActions(menu.getActions(options?.menuOptions), options?.toolbarOptions?.primaryGroup, options?.toolbarOptions?.shouldInlineSubmenu, options?.toolbarOptions?.useSeparatorsInPrimaryActions);
|
||||
container.classList.toggle('has-no-actions', primary.length === 0 && secondary.length === 0);
|
||||
super.setActions(primary, secondary);
|
||||
};
|
||||
this._store.add(menu.onDidChange(() => {
|
||||
updateToolbar();
|
||||
this._onDidChangeMenuItems.fire(this);
|
||||
}));
|
||||
this._store.add(actionViewService.onDidChange(e => {
|
||||
if (e === menuId) {
|
||||
updateToolbar();
|
||||
}
|
||||
}));
|
||||
updateToolbar();
|
||||
}
|
||||
/**
|
||||
* @deprecated The WorkbenchToolBar does not support this method because it works with menus.
|
||||
*/
|
||||
setActions() {
|
||||
throw new BugIndicatingError('This toolbar is populated from a menu.');
|
||||
}
|
||||
};
|
||||
MenuWorkbenchToolBar = __decorate([
|
||||
__param(3, IMenuService),
|
||||
__param(4, IContextKeyService),
|
||||
__param(5, IContextMenuService),
|
||||
__param(6, IKeybindingService),
|
||||
__param(7, ICommandService),
|
||||
__param(8, ITelemetryService),
|
||||
__param(9, IActionViewItemService),
|
||||
__param(10, IInstantiationService)
|
||||
], MenuWorkbenchToolBar);
|
||||
export { MenuWorkbenchToolBar };
|
||||
//# sourceMappingURL=toolbar.js.map
|
||||
File diff suppressed because one or more lines are too long
478
_internal/editor/esm/vs/platform/actions/common/actions.js
Normal file
478
_internal/editor/esm/vs/platform/actions/common/actions.js
Normal file
@@ -0,0 +1,478 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var MenuItemAction_1;
|
||||
import { SubmenuAction } from '../../../base/common/actions.js';
|
||||
import { MicrotaskEmitter } from '../../../base/common/event.js';
|
||||
import { DisposableStore, dispose, markAsSingleton, toDisposable } from '../../../base/common/lifecycle.js';
|
||||
import { LinkedList } from '../../../base/common/linkedList.js';
|
||||
import { ThemeIcon } from '../../../base/common/themables.js';
|
||||
import { CommandsRegistry, ICommandService } from '../../commands/common/commands.js';
|
||||
import { ContextKeyExpr, IContextKeyService } from '../../contextkey/common/contextkey.js';
|
||||
import { createDecorator } from '../../instantiation/common/instantiation.js';
|
||||
import { KeybindingsRegistry } from '../../keybinding/common/keybindingsRegistry.js';
|
||||
export function isIMenuItem(item) {
|
||||
return item.command !== undefined;
|
||||
}
|
||||
export function isISubmenuItem(item) {
|
||||
return item.submenu !== undefined;
|
||||
}
|
||||
export class MenuId {
|
||||
static { this._instances = new Map(); }
|
||||
static { this.CommandPalette = new MenuId('CommandPalette'); }
|
||||
static { this.DebugBreakpointsContext = new MenuId('DebugBreakpointsContext'); }
|
||||
static { this.DebugCallStackContext = new MenuId('DebugCallStackContext'); }
|
||||
static { this.DebugConsoleContext = new MenuId('DebugConsoleContext'); }
|
||||
static { this.DebugVariablesContext = new MenuId('DebugVariablesContext'); }
|
||||
static { this.NotebookVariablesContext = new MenuId('NotebookVariablesContext'); }
|
||||
static { this.DebugHoverContext = new MenuId('DebugHoverContext'); }
|
||||
static { this.DebugWatchContext = new MenuId('DebugWatchContext'); }
|
||||
static { this.DebugToolBar = new MenuId('DebugToolBar'); }
|
||||
static { this.DebugToolBarStop = new MenuId('DebugToolBarStop'); }
|
||||
static { this.DebugDisassemblyContext = new MenuId('DebugDisassemblyContext'); }
|
||||
static { this.DebugCallStackToolbar = new MenuId('DebugCallStackToolbar'); }
|
||||
static { this.DebugCreateConfiguration = new MenuId('DebugCreateConfiguration'); }
|
||||
static { this.EditorContext = new MenuId('EditorContext'); }
|
||||
static { this.SimpleEditorContext = new MenuId('SimpleEditorContext'); }
|
||||
static { this.EditorContent = new MenuId('EditorContent'); }
|
||||
static { this.EditorLineNumberContext = new MenuId('EditorLineNumberContext'); }
|
||||
static { this.EditorContextCopy = new MenuId('EditorContextCopy'); }
|
||||
static { this.EditorContextPeek = new MenuId('EditorContextPeek'); }
|
||||
static { this.EditorContextShare = new MenuId('EditorContextShare'); }
|
||||
static { this.EditorTitle = new MenuId('EditorTitle'); }
|
||||
static { this.CompactWindowEditorTitle = new MenuId('CompactWindowEditorTitle'); }
|
||||
static { this.EditorTitleRun = new MenuId('EditorTitleRun'); }
|
||||
static { this.EditorTitleContext = new MenuId('EditorTitleContext'); }
|
||||
static { this.EditorTitleContextShare = new MenuId('EditorTitleContextShare'); }
|
||||
static { this.EmptyEditorGroup = new MenuId('EmptyEditorGroup'); }
|
||||
static { this.EmptyEditorGroupContext = new MenuId('EmptyEditorGroupContext'); }
|
||||
static { this.EditorTabsBarContext = new MenuId('EditorTabsBarContext'); }
|
||||
static { this.EditorTabsBarShowTabsSubmenu = new MenuId('EditorTabsBarShowTabsSubmenu'); }
|
||||
static { this.EditorTabsBarShowTabsZenModeSubmenu = new MenuId('EditorTabsBarShowTabsZenModeSubmenu'); }
|
||||
static { this.EditorActionsPositionSubmenu = new MenuId('EditorActionsPositionSubmenu'); }
|
||||
static { this.EditorSplitMoveSubmenu = new MenuId('EditorSplitMoveSubmenu'); }
|
||||
static { this.ExplorerContext = new MenuId('ExplorerContext'); }
|
||||
static { this.ExplorerContextShare = new MenuId('ExplorerContextShare'); }
|
||||
static { this.ExtensionContext = new MenuId('ExtensionContext'); }
|
||||
static { this.ExtensionEditorContextMenu = new MenuId('ExtensionEditorContextMenu'); }
|
||||
static { this.GlobalActivity = new MenuId('GlobalActivity'); }
|
||||
static { this.CommandCenter = new MenuId('CommandCenter'); }
|
||||
static { this.CommandCenterCenter = new MenuId('CommandCenterCenter'); }
|
||||
static { this.LayoutControlMenuSubmenu = new MenuId('LayoutControlMenuSubmenu'); }
|
||||
static { this.LayoutControlMenu = new MenuId('LayoutControlMenu'); }
|
||||
static { this.MenubarMainMenu = new MenuId('MenubarMainMenu'); }
|
||||
static { this.MenubarAppearanceMenu = new MenuId('MenubarAppearanceMenu'); }
|
||||
static { this.MenubarDebugMenu = new MenuId('MenubarDebugMenu'); }
|
||||
static { this.MenubarEditMenu = new MenuId('MenubarEditMenu'); }
|
||||
static { this.MenubarCopy = new MenuId('MenubarCopy'); }
|
||||
static { this.MenubarFileMenu = new MenuId('MenubarFileMenu'); }
|
||||
static { this.MenubarGoMenu = new MenuId('MenubarGoMenu'); }
|
||||
static { this.MenubarHelpMenu = new MenuId('MenubarHelpMenu'); }
|
||||
static { this.MenubarLayoutMenu = new MenuId('MenubarLayoutMenu'); }
|
||||
static { this.MenubarNewBreakpointMenu = new MenuId('MenubarNewBreakpointMenu'); }
|
||||
static { this.PanelAlignmentMenu = new MenuId('PanelAlignmentMenu'); }
|
||||
static { this.PanelPositionMenu = new MenuId('PanelPositionMenu'); }
|
||||
static { this.ActivityBarPositionMenu = new MenuId('ActivityBarPositionMenu'); }
|
||||
static { this.MenubarPreferencesMenu = new MenuId('MenubarPreferencesMenu'); }
|
||||
static { this.MenubarRecentMenu = new MenuId('MenubarRecentMenu'); }
|
||||
static { this.MenubarSelectionMenu = new MenuId('MenubarSelectionMenu'); }
|
||||
static { this.MenubarShare = new MenuId('MenubarShare'); }
|
||||
static { this.MenubarSwitchEditorMenu = new MenuId('MenubarSwitchEditorMenu'); }
|
||||
static { this.MenubarSwitchGroupMenu = new MenuId('MenubarSwitchGroupMenu'); }
|
||||
static { this.MenubarTerminalMenu = new MenuId('MenubarTerminalMenu'); }
|
||||
static { this.MenubarTerminalSuggestStatusMenu = new MenuId('MenubarTerminalSuggestStatusMenu'); }
|
||||
static { this.MenubarViewMenu = new MenuId('MenubarViewMenu'); }
|
||||
static { this.MenubarHomeMenu = new MenuId('MenubarHomeMenu'); }
|
||||
static { this.OpenEditorsContext = new MenuId('OpenEditorsContext'); }
|
||||
static { this.OpenEditorsContextShare = new MenuId('OpenEditorsContextShare'); }
|
||||
static { this.ProblemsPanelContext = new MenuId('ProblemsPanelContext'); }
|
||||
static { this.SCMInputBox = new MenuId('SCMInputBox'); }
|
||||
static { this.SCMChangeContext = new MenuId('SCMChangeContext'); }
|
||||
static { this.SCMResourceContext = new MenuId('SCMResourceContext'); }
|
||||
static { this.SCMResourceContextShare = new MenuId('SCMResourceContextShare'); }
|
||||
static { this.SCMResourceFolderContext = new MenuId('SCMResourceFolderContext'); }
|
||||
static { this.SCMResourceGroupContext = new MenuId('SCMResourceGroupContext'); }
|
||||
static { this.SCMSourceControl = new MenuId('SCMSourceControl'); }
|
||||
static { this.SCMSourceControlInline = new MenuId('SCMSourceControlInline'); }
|
||||
static { this.SCMSourceControlTitle = new MenuId('SCMSourceControlTitle'); }
|
||||
static { this.SCMHistoryTitle = new MenuId('SCMHistoryTitle'); }
|
||||
static { this.SCMHistoryItemContext = new MenuId('SCMHistoryItemContext'); }
|
||||
static { this.SCMHistoryItemChangeContext = new MenuId('SCMHistoryItemChangeContext'); }
|
||||
static { this.SCMHistoryItemHover = new MenuId('SCMHistoryItemHover'); }
|
||||
static { this.SCMHistoryItemRefContext = new MenuId('SCMHistoryItemRefContext'); }
|
||||
static { this.SCMQuickDiffDecorations = new MenuId('SCMQuickDiffDecorations'); }
|
||||
static { this.SCMTitle = new MenuId('SCMTitle'); }
|
||||
static { this.SearchContext = new MenuId('SearchContext'); }
|
||||
static { this.SearchActionMenu = new MenuId('SearchActionContext'); }
|
||||
static { this.StatusBarWindowIndicatorMenu = new MenuId('StatusBarWindowIndicatorMenu'); }
|
||||
static { this.StatusBarRemoteIndicatorMenu = new MenuId('StatusBarRemoteIndicatorMenu'); }
|
||||
static { this.StickyScrollContext = new MenuId('StickyScrollContext'); }
|
||||
static { this.TestItem = new MenuId('TestItem'); }
|
||||
static { this.TestItemGutter = new MenuId('TestItemGutter'); }
|
||||
static { this.TestProfilesContext = new MenuId('TestProfilesContext'); }
|
||||
static { this.TestMessageContext = new MenuId('TestMessageContext'); }
|
||||
static { this.TestMessageContent = new MenuId('TestMessageContent'); }
|
||||
static { this.TestPeekElement = new MenuId('TestPeekElement'); }
|
||||
static { this.TestPeekTitle = new MenuId('TestPeekTitle'); }
|
||||
static { this.TestCallStack = new MenuId('TestCallStack'); }
|
||||
static { this.TestCoverageFilterItem = new MenuId('TestCoverageFilterItem'); }
|
||||
static { this.TouchBarContext = new MenuId('TouchBarContext'); }
|
||||
static { this.TitleBar = new MenuId('TitleBar'); }
|
||||
static { this.TitleBarContext = new MenuId('TitleBarContext'); }
|
||||
static { this.TitleBarTitleContext = new MenuId('TitleBarTitleContext'); }
|
||||
static { this.TunnelContext = new MenuId('TunnelContext'); }
|
||||
static { this.TunnelPrivacy = new MenuId('TunnelPrivacy'); }
|
||||
static { this.TunnelProtocol = new MenuId('TunnelProtocol'); }
|
||||
static { this.TunnelPortInline = new MenuId('TunnelInline'); }
|
||||
static { this.TunnelTitle = new MenuId('TunnelTitle'); }
|
||||
static { this.TunnelLocalAddressInline = new MenuId('TunnelLocalAddressInline'); }
|
||||
static { this.TunnelOriginInline = new MenuId('TunnelOriginInline'); }
|
||||
static { this.ViewItemContext = new MenuId('ViewItemContext'); }
|
||||
static { this.ViewContainerTitle = new MenuId('ViewContainerTitle'); }
|
||||
static { this.ViewContainerTitleContext = new MenuId('ViewContainerTitleContext'); }
|
||||
static { this.ViewTitle = new MenuId('ViewTitle'); }
|
||||
static { this.ViewTitleContext = new MenuId('ViewTitleContext'); }
|
||||
static { this.CommentEditorActions = new MenuId('CommentEditorActions'); }
|
||||
static { this.CommentThreadTitle = new MenuId('CommentThreadTitle'); }
|
||||
static { this.CommentThreadActions = new MenuId('CommentThreadActions'); }
|
||||
static { this.CommentThreadAdditionalActions = new MenuId('CommentThreadAdditionalActions'); }
|
||||
static { this.CommentThreadTitleContext = new MenuId('CommentThreadTitleContext'); }
|
||||
static { this.CommentThreadCommentContext = new MenuId('CommentThreadCommentContext'); }
|
||||
static { this.CommentTitle = new MenuId('CommentTitle'); }
|
||||
static { this.CommentActions = new MenuId('CommentActions'); }
|
||||
static { this.CommentsViewThreadActions = new MenuId('CommentsViewThreadActions'); }
|
||||
static { this.InteractiveToolbar = new MenuId('InteractiveToolbar'); }
|
||||
static { this.InteractiveCellTitle = new MenuId('InteractiveCellTitle'); }
|
||||
static { this.InteractiveCellDelete = new MenuId('InteractiveCellDelete'); }
|
||||
static { this.InteractiveCellExecute = new MenuId('InteractiveCellExecute'); }
|
||||
static { this.InteractiveInputExecute = new MenuId('InteractiveInputExecute'); }
|
||||
static { this.InteractiveInputConfig = new MenuId('InteractiveInputConfig'); }
|
||||
static { this.ReplInputExecute = new MenuId('ReplInputExecute'); }
|
||||
static { this.IssueReporter = new MenuId('IssueReporter'); }
|
||||
static { this.NotebookToolbar = new MenuId('NotebookToolbar'); }
|
||||
static { this.NotebookToolbarContext = new MenuId('NotebookToolbarContext'); }
|
||||
static { this.NotebookStickyScrollContext = new MenuId('NotebookStickyScrollContext'); }
|
||||
static { this.NotebookCellTitle = new MenuId('NotebookCellTitle'); }
|
||||
static { this.NotebookCellDelete = new MenuId('NotebookCellDelete'); }
|
||||
static { this.NotebookCellInsert = new MenuId('NotebookCellInsert'); }
|
||||
static { this.NotebookCellBetween = new MenuId('NotebookCellBetween'); }
|
||||
static { this.NotebookCellListTop = new MenuId('NotebookCellTop'); }
|
||||
static { this.NotebookCellExecute = new MenuId('NotebookCellExecute'); }
|
||||
static { this.NotebookCellExecuteGoTo = new MenuId('NotebookCellExecuteGoTo'); }
|
||||
static { this.NotebookCellExecutePrimary = new MenuId('NotebookCellExecutePrimary'); }
|
||||
static { this.NotebookDiffCellInputTitle = new MenuId('NotebookDiffCellInputTitle'); }
|
||||
static { this.NotebookDiffDocumentMetadata = new MenuId('NotebookDiffDocumentMetadata'); }
|
||||
static { this.NotebookDiffCellMetadataTitle = new MenuId('NotebookDiffCellMetadataTitle'); }
|
||||
static { this.NotebookDiffCellOutputsTitle = new MenuId('NotebookDiffCellOutputsTitle'); }
|
||||
static { this.NotebookOutputToolbar = new MenuId('NotebookOutputToolbar'); }
|
||||
static { this.NotebookOutlineFilter = new MenuId('NotebookOutlineFilter'); }
|
||||
static { this.NotebookOutlineActionMenu = new MenuId('NotebookOutlineActionMenu'); }
|
||||
static { this.NotebookEditorLayoutConfigure = new MenuId('NotebookEditorLayoutConfigure'); }
|
||||
static { this.NotebookKernelSource = new MenuId('NotebookKernelSource'); }
|
||||
static { this.BulkEditTitle = new MenuId('BulkEditTitle'); }
|
||||
static { this.BulkEditContext = new MenuId('BulkEditContext'); }
|
||||
static { this.TimelineItemContext = new MenuId('TimelineItemContext'); }
|
||||
static { this.TimelineTitle = new MenuId('TimelineTitle'); }
|
||||
static { this.TimelineTitleContext = new MenuId('TimelineTitleContext'); }
|
||||
static { this.TimelineFilterSubMenu = new MenuId('TimelineFilterSubMenu'); }
|
||||
static { this.AccountsContext = new MenuId('AccountsContext'); }
|
||||
static { this.SidebarTitle = new MenuId('SidebarTitle'); }
|
||||
static { this.PanelTitle = new MenuId('PanelTitle'); }
|
||||
static { this.AuxiliaryBarTitle = new MenuId('AuxiliaryBarTitle'); }
|
||||
static { this.TerminalInstanceContext = new MenuId('TerminalInstanceContext'); }
|
||||
static { this.TerminalEditorInstanceContext = new MenuId('TerminalEditorInstanceContext'); }
|
||||
static { this.TerminalNewDropdownContext = new MenuId('TerminalNewDropdownContext'); }
|
||||
static { this.TerminalTabContext = new MenuId('TerminalTabContext'); }
|
||||
static { this.TerminalTabEmptyAreaContext = new MenuId('TerminalTabEmptyAreaContext'); }
|
||||
static { this.TerminalStickyScrollContext = new MenuId('TerminalStickyScrollContext'); }
|
||||
static { this.WebviewContext = new MenuId('WebviewContext'); }
|
||||
static { this.InlineCompletionsActions = new MenuId('InlineCompletionsActions'); }
|
||||
static { this.InlineEditsActions = new MenuId('InlineEditsActions'); }
|
||||
static { this.NewFile = new MenuId('NewFile'); }
|
||||
static { this.MergeInput1Toolbar = new MenuId('MergeToolbar1Toolbar'); }
|
||||
static { this.MergeInput2Toolbar = new MenuId('MergeToolbar2Toolbar'); }
|
||||
static { this.MergeBaseToolbar = new MenuId('MergeBaseToolbar'); }
|
||||
static { this.MergeInputResultToolbar = new MenuId('MergeToolbarResultToolbar'); }
|
||||
static { this.InlineSuggestionToolbar = new MenuId('InlineSuggestionToolbar'); }
|
||||
static { this.InlineEditToolbar = new MenuId('InlineEditToolbar'); }
|
||||
static { this.ChatContext = new MenuId('ChatContext'); }
|
||||
static { this.ChatCodeBlock = new MenuId('ChatCodeblock'); }
|
||||
static { this.ChatCompareBlock = new MenuId('ChatCompareBlock'); }
|
||||
static { this.ChatMessageTitle = new MenuId('ChatMessageTitle'); }
|
||||
static { this.ChatHistory = new MenuId('ChatHistory'); }
|
||||
static { this.ChatWelcomeHistoryContext = new MenuId('ChatWelcomeHistoryContext'); }
|
||||
static { this.ChatMessageFooter = new MenuId('ChatMessageFooter'); }
|
||||
static { this.ChatExecute = new MenuId('ChatExecute'); }
|
||||
static { this.ChatExecuteSecondary = new MenuId('ChatExecuteSecondary'); }
|
||||
static { this.ChatInput = new MenuId('ChatInput'); }
|
||||
static { this.ChatInputSide = new MenuId('ChatInputSide'); }
|
||||
static { this.ChatModePicker = new MenuId('ChatModePicker'); }
|
||||
static { this.ChatEditingWidgetToolbar = new MenuId('ChatEditingWidgetToolbar'); }
|
||||
static { this.ChatEditingEditorContent = new MenuId('ChatEditingEditorContent'); }
|
||||
static { this.ChatEditingEditorHunk = new MenuId('ChatEditingEditorHunk'); }
|
||||
static { this.ChatEditingDeletedNotebookCell = new MenuId('ChatEditingDeletedNotebookCell'); }
|
||||
static { this.ChatInputAttachmentToolbar = new MenuId('ChatInputAttachmentToolbar'); }
|
||||
static { this.ChatEditingWidgetModifiedFilesToolbar = new MenuId('ChatEditingWidgetModifiedFilesToolbar'); }
|
||||
static { this.ChatInputResourceAttachmentContext = new MenuId('ChatInputResourceAttachmentContext'); }
|
||||
static { this.ChatInputSymbolAttachmentContext = new MenuId('ChatInputSymbolAttachmentContext'); }
|
||||
static { this.ChatInlineResourceAnchorContext = new MenuId('ChatInlineResourceAnchorContext'); }
|
||||
static { this.ChatInlineSymbolAnchorContext = new MenuId('ChatInlineSymbolAnchorContext'); }
|
||||
static { this.ChatMessageCheckpoint = new MenuId('ChatMessageCheckpoint'); }
|
||||
static { this.ChatMessageRestoreCheckpoint = new MenuId('ChatMessageRestoreCheckpoint'); }
|
||||
static { this.ChatEditingCodeBlockContext = new MenuId('ChatEditingCodeBlockContext'); }
|
||||
static { this.ChatTitleBarMenu = new MenuId('ChatTitleBarMenu'); }
|
||||
static { this.ChatAttachmentsContext = new MenuId('ChatAttachmentsContext'); }
|
||||
static { this.ChatToolOutputResourceToolbar = new MenuId('ChatToolOutputResourceToolbar'); }
|
||||
static { this.ChatTextEditorMenu = new MenuId('ChatTextEditorMenu'); }
|
||||
static { this.ChatToolOutputResourceContext = new MenuId('ChatToolOutputResourceContext'); }
|
||||
static { this.ChatMultiDiffContext = new MenuId('ChatMultiDiffContext'); }
|
||||
static { this.ChatSessionsMenu = new MenuId('ChatSessionsMenu'); }
|
||||
static { this.ChatConfirmationMenu = new MenuId('ChatConfirmationMenu'); }
|
||||
static { this.AccessibleView = new MenuId('AccessibleView'); }
|
||||
static { this.MultiDiffEditorFileToolbar = new MenuId('MultiDiffEditorFileToolbar'); }
|
||||
static { this.DiffEditorHunkToolbar = new MenuId('DiffEditorHunkToolbar'); }
|
||||
static { this.DiffEditorSelectionToolbar = new MenuId('DiffEditorSelectionToolbar'); }
|
||||
/**
|
||||
* Create a new `MenuId` with the unique identifier. Will throw if a menu
|
||||
* with the identifier already exists, use `MenuId.for(ident)` or a unique
|
||||
* identifier
|
||||
*/
|
||||
constructor(identifier) {
|
||||
if (MenuId._instances.has(identifier)) {
|
||||
throw new TypeError(`MenuId with identifier '${identifier}' already exists. Use MenuId.for(ident) or a unique identifier`);
|
||||
}
|
||||
MenuId._instances.set(identifier, this);
|
||||
this.id = identifier;
|
||||
}
|
||||
}
|
||||
export const IMenuService = createDecorator('menuService');
|
||||
class MenuRegistryChangeEvent {
|
||||
static { this._all = new Map(); }
|
||||
static for(id) {
|
||||
let value = this._all.get(id);
|
||||
if (!value) {
|
||||
value = new MenuRegistryChangeEvent(id);
|
||||
this._all.set(id, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
static merge(events) {
|
||||
const ids = new Set();
|
||||
for (const item of events) {
|
||||
if (item instanceof MenuRegistryChangeEvent) {
|
||||
ids.add(item.id);
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
this.has = candidate => candidate === id;
|
||||
}
|
||||
}
|
||||
export const MenuRegistry = new class {
|
||||
constructor() {
|
||||
this._commands = new Map();
|
||||
this._menuItems = new Map();
|
||||
this._onDidChangeMenu = new MicrotaskEmitter({
|
||||
merge: MenuRegistryChangeEvent.merge
|
||||
});
|
||||
this.onDidChangeMenu = this._onDidChangeMenu.event;
|
||||
}
|
||||
addCommand(command) {
|
||||
this._commands.set(command.id, command);
|
||||
this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(MenuId.CommandPalette));
|
||||
return markAsSingleton(toDisposable(() => {
|
||||
if (this._commands.delete(command.id)) {
|
||||
this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(MenuId.CommandPalette));
|
||||
}
|
||||
}));
|
||||
}
|
||||
getCommand(id) {
|
||||
return this._commands.get(id);
|
||||
}
|
||||
getCommands() {
|
||||
const map = new Map();
|
||||
this._commands.forEach((value, key) => map.set(key, value));
|
||||
return map;
|
||||
}
|
||||
appendMenuItem(id, item) {
|
||||
let list = this._menuItems.get(id);
|
||||
if (!list) {
|
||||
list = new LinkedList();
|
||||
this._menuItems.set(id, list);
|
||||
}
|
||||
const rm = list.push(item);
|
||||
this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(id));
|
||||
return markAsSingleton(toDisposable(() => {
|
||||
rm();
|
||||
this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(id));
|
||||
}));
|
||||
}
|
||||
appendMenuItems(items) {
|
||||
const result = new DisposableStore();
|
||||
for (const { id, item } of items) {
|
||||
result.add(this.appendMenuItem(id, item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
getMenuItems(id) {
|
||||
let result;
|
||||
if (this._menuItems.has(id)) {
|
||||
result = [...this._menuItems.get(id)];
|
||||
}
|
||||
else {
|
||||
result = [];
|
||||
}
|
||||
if (id === MenuId.CommandPalette) {
|
||||
// CommandPalette is special because it shows
|
||||
// all commands by default
|
||||
this._appendImplicitItems(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
_appendImplicitItems(result) {
|
||||
const set = new Set();
|
||||
for (const item of result) {
|
||||
if (isIMenuItem(item)) {
|
||||
set.add(item.command.id);
|
||||
if (item.alt) {
|
||||
set.add(item.alt.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._commands.forEach((command, id) => {
|
||||
if (!set.has(id)) {
|
||||
result.push({ command });
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
export class SubmenuItemAction extends SubmenuAction {
|
||||
constructor(item, hideActions, actions) {
|
||||
super(`submenuitem.${item.submenu.id}`, typeof item.title === 'string' ? item.title : item.title.value, actions, 'submenu');
|
||||
this.item = item;
|
||||
this.hideActions = hideActions;
|
||||
}
|
||||
}
|
||||
// implements IAction, does NOT extend Action, so that no one
|
||||
// subscribes to events of Action or modified properties
|
||||
let MenuItemAction = MenuItemAction_1 = class MenuItemAction {
|
||||
static label(action, options) {
|
||||
return options?.renderShortTitle && action.shortTitle
|
||||
? (typeof action.shortTitle === 'string' ? action.shortTitle : action.shortTitle.value)
|
||||
: (typeof action.title === 'string' ? action.title : action.title.value);
|
||||
}
|
||||
constructor(item, alt, options, hideActions, menuKeybinding, contextKeyService, _commandService) {
|
||||
this.hideActions = hideActions;
|
||||
this.menuKeybinding = menuKeybinding;
|
||||
this._commandService = _commandService;
|
||||
this.id = item.id;
|
||||
this.label = MenuItemAction_1.label(item, options);
|
||||
this.tooltip = (typeof item.tooltip === 'string' ? item.tooltip : item.tooltip?.value) ?? '';
|
||||
this.enabled = !item.precondition || contextKeyService.contextMatchesRules(item.precondition);
|
||||
this.checked = undefined;
|
||||
let icon;
|
||||
if (item.toggled) {
|
||||
const toggled = (item.toggled.condition ? item.toggled : { condition: item.toggled });
|
||||
this.checked = contextKeyService.contextMatchesRules(toggled.condition);
|
||||
if (this.checked && toggled.tooltip) {
|
||||
this.tooltip = typeof toggled.tooltip === 'string' ? toggled.tooltip : toggled.tooltip.value;
|
||||
}
|
||||
if (this.checked && ThemeIcon.isThemeIcon(toggled.icon)) {
|
||||
icon = toggled.icon;
|
||||
}
|
||||
if (this.checked && toggled.title) {
|
||||
this.label = typeof toggled.title === 'string' ? toggled.title : toggled.title.value;
|
||||
}
|
||||
}
|
||||
if (!icon) {
|
||||
icon = ThemeIcon.isThemeIcon(item.icon) ? item.icon : undefined;
|
||||
}
|
||||
this.item = item;
|
||||
this.alt = alt ? new MenuItemAction_1(alt, undefined, options, hideActions, undefined, contextKeyService, _commandService) : undefined;
|
||||
this._options = options;
|
||||
this.class = icon && ThemeIcon.asClassName(icon);
|
||||
}
|
||||
run(...args) {
|
||||
let runArgs = [];
|
||||
if (this._options?.arg) {
|
||||
runArgs = [...runArgs, this._options.arg];
|
||||
}
|
||||
if (this._options?.shouldForwardArgs) {
|
||||
runArgs = [...runArgs, ...args];
|
||||
}
|
||||
return this._commandService.executeCommand(this.id, ...runArgs);
|
||||
}
|
||||
};
|
||||
MenuItemAction = MenuItemAction_1 = __decorate([
|
||||
__param(5, IContextKeyService),
|
||||
__param(6, ICommandService)
|
||||
], MenuItemAction);
|
||||
export { MenuItemAction };
|
||||
export class Action2 {
|
||||
constructor(desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
export function registerAction2(ctor) {
|
||||
const disposables = []; // not using `DisposableStore` to reduce startup perf cost
|
||||
const action = new ctor();
|
||||
const { f1, menu, keybinding, ...command } = action.desc;
|
||||
if (CommandsRegistry.getCommand(command.id)) {
|
||||
throw new Error(`Cannot register two commands with the same id: ${command.id}`);
|
||||
}
|
||||
// command
|
||||
disposables.push(CommandsRegistry.registerCommand({
|
||||
id: command.id,
|
||||
handler: (accessor, ...args) => action.run(accessor, ...args),
|
||||
metadata: command.metadata ?? { description: action.desc.title }
|
||||
}));
|
||||
// menu
|
||||
if (Array.isArray(menu)) {
|
||||
for (const item of menu) {
|
||||
disposables.push(MenuRegistry.appendMenuItem(item.id, { command: { ...command, precondition: item.precondition === null ? undefined : command.precondition }, ...item }));
|
||||
}
|
||||
}
|
||||
else if (menu) {
|
||||
disposables.push(MenuRegistry.appendMenuItem(menu.id, { command: { ...command, precondition: menu.precondition === null ? undefined : command.precondition }, ...menu }));
|
||||
}
|
||||
if (f1) {
|
||||
disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command, when: command.precondition }));
|
||||
disposables.push(MenuRegistry.addCommand(command));
|
||||
}
|
||||
// keybinding
|
||||
if (Array.isArray(keybinding)) {
|
||||
for (const item of keybinding) {
|
||||
disposables.push(KeybindingsRegistry.registerKeybindingRule({
|
||||
...item,
|
||||
id: command.id,
|
||||
when: command.precondition ? ContextKeyExpr.and(command.precondition, item.when) : item.when
|
||||
}));
|
||||
}
|
||||
}
|
||||
else if (keybinding) {
|
||||
disposables.push(KeybindingsRegistry.registerKeybindingRule({
|
||||
...keybinding,
|
||||
id: command.id,
|
||||
when: command.precondition ? ContextKeyExpr.and(command.precondition, keybinding.when) : keybinding.when
|
||||
}));
|
||||
}
|
||||
return {
|
||||
dispose() {
|
||||
dispose(disposables);
|
||||
}
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
//# sourceMappingURL=actions.js.map
|
||||
File diff suppressed because one or more lines are too long
435
_internal/editor/esm/vs/platform/actions/common/menuService.js
Normal file
435
_internal/editor/esm/vs/platform/actions/common/menuService.js
Normal file
@@ -0,0 +1,435 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var PersistedMenuHideState_1, MenuInfo_1;
|
||||
import { RunOnceScheduler } from '../../../base/common/async.js';
|
||||
import { DebounceEmitter, Emitter } from '../../../base/common/event.js';
|
||||
import { DisposableStore } from '../../../base/common/lifecycle.js';
|
||||
import { isIMenuItem, isISubmenuItem, MenuItemAction, MenuRegistry, SubmenuItemAction } from './actions.js';
|
||||
import { ICommandService } from '../../commands/common/commands.js';
|
||||
import { IContextKeyService } from '../../contextkey/common/contextkey.js';
|
||||
import { Separator, toAction } from '../../../base/common/actions.js';
|
||||
import { IStorageService } from '../../storage/common/storage.js';
|
||||
import { removeFastWithoutKeepingOrder } from '../../../base/common/arrays.js';
|
||||
import { localize } from '../../../nls.js';
|
||||
import { IKeybindingService } from '../../keybinding/common/keybinding.js';
|
||||
let MenuService = class MenuService {
|
||||
constructor(_commandService, _keybindingService, storageService) {
|
||||
this._commandService = _commandService;
|
||||
this._keybindingService = _keybindingService;
|
||||
this._hiddenStates = new PersistedMenuHideState(storageService);
|
||||
}
|
||||
createMenu(id, contextKeyService, options) {
|
||||
return new MenuImpl(id, this._hiddenStates, { emitEventsForSubmenuChanges: false, eventDebounceDelay: 50, ...options }, this._commandService, this._keybindingService, contextKeyService);
|
||||
}
|
||||
getMenuActions(id, contextKeyService, options) {
|
||||
const menu = new MenuImpl(id, this._hiddenStates, { emitEventsForSubmenuChanges: false, eventDebounceDelay: 50, ...options }, this._commandService, this._keybindingService, contextKeyService);
|
||||
const actions = menu.getActions(options);
|
||||
menu.dispose();
|
||||
return actions;
|
||||
}
|
||||
resetHiddenStates(ids) {
|
||||
this._hiddenStates.reset(ids);
|
||||
}
|
||||
};
|
||||
MenuService = __decorate([
|
||||
__param(0, ICommandService),
|
||||
__param(1, IKeybindingService),
|
||||
__param(2, IStorageService)
|
||||
], MenuService);
|
||||
export { MenuService };
|
||||
let PersistedMenuHideState = class PersistedMenuHideState {
|
||||
static { PersistedMenuHideState_1 = this; }
|
||||
static { this._key = 'menu.hiddenCommands'; }
|
||||
constructor(_storageService) {
|
||||
this._storageService = _storageService;
|
||||
this._disposables = new DisposableStore();
|
||||
this._onDidChange = new Emitter();
|
||||
this.onDidChange = this._onDidChange.event;
|
||||
this._ignoreChangeEvent = false;
|
||||
this._hiddenByDefaultCache = new Map();
|
||||
try {
|
||||
const raw = _storageService.get(PersistedMenuHideState_1._key, 0 /* StorageScope.PROFILE */, '{}');
|
||||
this._data = JSON.parse(raw);
|
||||
}
|
||||
catch (err) {
|
||||
this._data = Object.create(null);
|
||||
}
|
||||
this._disposables.add(_storageService.onDidChangeValue(0 /* StorageScope.PROFILE */, PersistedMenuHideState_1._key, this._disposables)(() => {
|
||||
if (!this._ignoreChangeEvent) {
|
||||
try {
|
||||
const raw = _storageService.get(PersistedMenuHideState_1._key, 0 /* StorageScope.PROFILE */, '{}');
|
||||
this._data = JSON.parse(raw);
|
||||
}
|
||||
catch (err) {
|
||||
console.log('FAILED to read storage after UPDATE', err);
|
||||
}
|
||||
}
|
||||
this._onDidChange.fire();
|
||||
}));
|
||||
}
|
||||
dispose() {
|
||||
this._onDidChange.dispose();
|
||||
this._disposables.dispose();
|
||||
}
|
||||
_isHiddenByDefault(menu, commandId) {
|
||||
return this._hiddenByDefaultCache.get(`${menu.id}/${commandId}`) ?? false;
|
||||
}
|
||||
setDefaultState(menu, commandId, hidden) {
|
||||
this._hiddenByDefaultCache.set(`${menu.id}/${commandId}`, hidden);
|
||||
}
|
||||
isHidden(menu, commandId) {
|
||||
const hiddenByDefault = this._isHiddenByDefault(menu, commandId);
|
||||
const state = this._data[menu.id]?.includes(commandId) ?? false;
|
||||
return hiddenByDefault ? !state : state;
|
||||
}
|
||||
updateHidden(menu, commandId, hidden) {
|
||||
const hiddenByDefault = this._isHiddenByDefault(menu, commandId);
|
||||
if (hiddenByDefault) {
|
||||
hidden = !hidden;
|
||||
}
|
||||
const entries = this._data[menu.id];
|
||||
if (!hidden) {
|
||||
// remove and cleanup
|
||||
if (entries) {
|
||||
const idx = entries.indexOf(commandId);
|
||||
if (idx >= 0) {
|
||||
removeFastWithoutKeepingOrder(entries, idx);
|
||||
}
|
||||
if (entries.length === 0) {
|
||||
delete this._data[menu.id];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// add unless already added
|
||||
if (!entries) {
|
||||
this._data[menu.id] = [commandId];
|
||||
}
|
||||
else {
|
||||
const idx = entries.indexOf(commandId);
|
||||
if (idx < 0) {
|
||||
entries.push(commandId);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._persist();
|
||||
}
|
||||
reset(menus) {
|
||||
if (menus === undefined) {
|
||||
// reset all
|
||||
this._data = Object.create(null);
|
||||
this._persist();
|
||||
}
|
||||
else {
|
||||
// reset only for a specific menu
|
||||
for (const { id } of menus) {
|
||||
if (this._data[id]) {
|
||||
delete this._data[id];
|
||||
}
|
||||
}
|
||||
this._persist();
|
||||
}
|
||||
}
|
||||
_persist() {
|
||||
try {
|
||||
this._ignoreChangeEvent = true;
|
||||
const raw = JSON.stringify(this._data);
|
||||
this._storageService.store(PersistedMenuHideState_1._key, raw, 0 /* StorageScope.PROFILE */, 0 /* StorageTarget.USER */);
|
||||
}
|
||||
finally {
|
||||
this._ignoreChangeEvent = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
PersistedMenuHideState = PersistedMenuHideState_1 = __decorate([
|
||||
__param(0, IStorageService)
|
||||
], PersistedMenuHideState);
|
||||
class MenuInfoSnapshot {
|
||||
constructor(_id, _collectContextKeysForSubmenus) {
|
||||
this._id = _id;
|
||||
this._collectContextKeysForSubmenus = _collectContextKeysForSubmenus;
|
||||
this._menuGroups = [];
|
||||
this._allMenuIds = new Set();
|
||||
this._structureContextKeys = new Set();
|
||||
this._preconditionContextKeys = new Set();
|
||||
this._toggledContextKeys = new Set();
|
||||
this.refresh();
|
||||
}
|
||||
get allMenuIds() {
|
||||
return this._allMenuIds;
|
||||
}
|
||||
get structureContextKeys() {
|
||||
return this._structureContextKeys;
|
||||
}
|
||||
get preconditionContextKeys() {
|
||||
return this._preconditionContextKeys;
|
||||
}
|
||||
get toggledContextKeys() {
|
||||
return this._toggledContextKeys;
|
||||
}
|
||||
refresh() {
|
||||
// reset
|
||||
this._menuGroups.length = 0;
|
||||
this._allMenuIds.clear();
|
||||
this._structureContextKeys.clear();
|
||||
this._preconditionContextKeys.clear();
|
||||
this._toggledContextKeys.clear();
|
||||
const menuItems = this._sort(MenuRegistry.getMenuItems(this._id));
|
||||
let group;
|
||||
for (const item of menuItems) {
|
||||
// group by groupId
|
||||
const groupName = item.group || '';
|
||||
if (!group || group[0] !== groupName) {
|
||||
group = [groupName, []];
|
||||
this._menuGroups.push(group);
|
||||
}
|
||||
group[1].push(item);
|
||||
// keep keys and submenu ids for eventing
|
||||
this._collectContextKeysAndSubmenuIds(item);
|
||||
}
|
||||
this._allMenuIds.add(this._id);
|
||||
}
|
||||
_sort(menuItems) {
|
||||
// no sorting needed in snapshot
|
||||
return menuItems;
|
||||
}
|
||||
_collectContextKeysAndSubmenuIds(item) {
|
||||
MenuInfoSnapshot._fillInKbExprKeys(item.when, this._structureContextKeys);
|
||||
if (isIMenuItem(item)) {
|
||||
// keep precondition keys for event if applicable
|
||||
if (item.command.precondition) {
|
||||
MenuInfoSnapshot._fillInKbExprKeys(item.command.precondition, this._preconditionContextKeys);
|
||||
}
|
||||
// keep toggled keys for event if applicable
|
||||
if (item.command.toggled) {
|
||||
const toggledExpression = item.command.toggled.condition || item.command.toggled;
|
||||
MenuInfoSnapshot._fillInKbExprKeys(toggledExpression, this._toggledContextKeys);
|
||||
}
|
||||
}
|
||||
else if (this._collectContextKeysForSubmenus) {
|
||||
// recursively collect context keys from submenus so that this
|
||||
// menu fires events when context key changes affect submenus
|
||||
MenuRegistry.getMenuItems(item.submenu).forEach(this._collectContextKeysAndSubmenuIds, this);
|
||||
this._allMenuIds.add(item.submenu);
|
||||
}
|
||||
}
|
||||
static _fillInKbExprKeys(exp, set) {
|
||||
if (exp) {
|
||||
for (const key of exp.keys()) {
|
||||
set.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let MenuInfo = MenuInfo_1 = class MenuInfo extends MenuInfoSnapshot {
|
||||
constructor(_id, _hiddenStates, _collectContextKeysForSubmenus, _commandService, _keybindingService, _contextKeyService) {
|
||||
super(_id, _collectContextKeysForSubmenus);
|
||||
this._hiddenStates = _hiddenStates;
|
||||
this._commandService = _commandService;
|
||||
this._keybindingService = _keybindingService;
|
||||
this._contextKeyService = _contextKeyService;
|
||||
this.refresh();
|
||||
}
|
||||
createActionGroups(options) {
|
||||
const result = [];
|
||||
for (const group of this._menuGroups) {
|
||||
const [id, items] = group;
|
||||
let activeActions;
|
||||
for (const item of items) {
|
||||
if (this._contextKeyService.contextMatchesRules(item.when)) {
|
||||
const isMenuItem = isIMenuItem(item);
|
||||
if (isMenuItem) {
|
||||
this._hiddenStates.setDefaultState(this._id, item.command.id, !!item.isHiddenByDefault);
|
||||
}
|
||||
const menuHide = createMenuHide(this._id, isMenuItem ? item.command : item, this._hiddenStates);
|
||||
if (isMenuItem) {
|
||||
// MenuItemAction
|
||||
const menuKeybinding = createConfigureKeybindingAction(this._commandService, this._keybindingService, item.command.id, item.when);
|
||||
(activeActions ??= []).push(new MenuItemAction(item.command, item.alt, options, menuHide, menuKeybinding, this._contextKeyService, this._commandService));
|
||||
}
|
||||
else {
|
||||
// SubmenuItemAction
|
||||
const groups = new MenuInfo_1(item.submenu, this._hiddenStates, this._collectContextKeysForSubmenus, this._commandService, this._keybindingService, this._contextKeyService).createActionGroups(options);
|
||||
const submenuActions = Separator.join(...groups.map(g => g[1]));
|
||||
if (submenuActions.length > 0) {
|
||||
(activeActions ??= []).push(new SubmenuItemAction(item, menuHide, submenuActions));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (activeActions && activeActions.length > 0) {
|
||||
result.push([id, activeActions]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
_sort(menuItems) {
|
||||
return menuItems.sort(MenuInfo_1._compareMenuItems);
|
||||
}
|
||||
static _compareMenuItems(a, b) {
|
||||
const aGroup = a.group;
|
||||
const bGroup = b.group;
|
||||
if (aGroup !== bGroup) {
|
||||
// Falsy groups come last
|
||||
if (!aGroup) {
|
||||
return 1;
|
||||
}
|
||||
else if (!bGroup) {
|
||||
return -1;
|
||||
}
|
||||
// 'navigation' group comes first
|
||||
if (aGroup === 'navigation') {
|
||||
return -1;
|
||||
}
|
||||
else if (bGroup === 'navigation') {
|
||||
return 1;
|
||||
}
|
||||
// lexical sort for groups
|
||||
const value = aGroup.localeCompare(bGroup);
|
||||
if (value !== 0) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
// sort on priority - default is 0
|
||||
const aPrio = a.order || 0;
|
||||
const bPrio = b.order || 0;
|
||||
if (aPrio < bPrio) {
|
||||
return -1;
|
||||
}
|
||||
else if (aPrio > bPrio) {
|
||||
return 1;
|
||||
}
|
||||
// sort on titles
|
||||
return MenuInfo_1._compareTitles(isIMenuItem(a) ? a.command.title : a.title, isIMenuItem(b) ? b.command.title : b.title);
|
||||
}
|
||||
static _compareTitles(a, b) {
|
||||
const aStr = typeof a === 'string' ? a : a.original;
|
||||
const bStr = typeof b === 'string' ? b : b.original;
|
||||
return aStr.localeCompare(bStr);
|
||||
}
|
||||
};
|
||||
MenuInfo = MenuInfo_1 = __decorate([
|
||||
__param(3, ICommandService),
|
||||
__param(4, IKeybindingService),
|
||||
__param(5, IContextKeyService)
|
||||
], MenuInfo);
|
||||
let MenuImpl = class MenuImpl {
|
||||
constructor(id, hiddenStates, options, commandService, keybindingService, contextKeyService) {
|
||||
this._disposables = new DisposableStore();
|
||||
this._menuInfo = new MenuInfo(id, hiddenStates, options.emitEventsForSubmenuChanges, commandService, keybindingService, contextKeyService);
|
||||
// Rebuild this menu whenever the menu registry reports an event for this MenuId.
|
||||
// This usually happen while code and extensions are loaded and affects the over
|
||||
// structure of the menu
|
||||
const rebuildMenuSoon = new RunOnceScheduler(() => {
|
||||
this._menuInfo.refresh();
|
||||
this._onDidChange.fire({ menu: this, isStructuralChange: true, isEnablementChange: true, isToggleChange: true });
|
||||
}, options.eventDebounceDelay);
|
||||
this._disposables.add(rebuildMenuSoon);
|
||||
this._disposables.add(MenuRegistry.onDidChangeMenu(e => {
|
||||
for (const id of this._menuInfo.allMenuIds) {
|
||||
if (e.has(id)) {
|
||||
rebuildMenuSoon.schedule();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
// When context keys or storage state changes we need to check if the menu also has changed. However,
|
||||
// we only do that when someone listens on this menu because (1) these events are
|
||||
// firing often and (2) menu are often leaked
|
||||
const lazyListener = this._disposables.add(new DisposableStore());
|
||||
const merge = (events) => {
|
||||
let isStructuralChange = false;
|
||||
let isEnablementChange = false;
|
||||
let isToggleChange = false;
|
||||
for (const item of events) {
|
||||
isStructuralChange = isStructuralChange || item.isStructuralChange;
|
||||
isEnablementChange = isEnablementChange || item.isEnablementChange;
|
||||
isToggleChange = isToggleChange || item.isToggleChange;
|
||||
if (isStructuralChange && isEnablementChange && isToggleChange) {
|
||||
// everything is TRUE, no need to continue iterating
|
||||
break;
|
||||
}
|
||||
}
|
||||
return { menu: this, isStructuralChange, isEnablementChange, isToggleChange };
|
||||
};
|
||||
const startLazyListener = () => {
|
||||
lazyListener.add(contextKeyService.onDidChangeContext(e => {
|
||||
const isStructuralChange = e.affectsSome(this._menuInfo.structureContextKeys);
|
||||
const isEnablementChange = e.affectsSome(this._menuInfo.preconditionContextKeys);
|
||||
const isToggleChange = e.affectsSome(this._menuInfo.toggledContextKeys);
|
||||
if (isStructuralChange || isEnablementChange || isToggleChange) {
|
||||
this._onDidChange.fire({ menu: this, isStructuralChange, isEnablementChange, isToggleChange });
|
||||
}
|
||||
}));
|
||||
lazyListener.add(hiddenStates.onDidChange(e => {
|
||||
this._onDidChange.fire({ menu: this, isStructuralChange: true, isEnablementChange: false, isToggleChange: false });
|
||||
}));
|
||||
};
|
||||
this._onDidChange = new DebounceEmitter({
|
||||
// start/stop context key listener
|
||||
onWillAddFirstListener: startLazyListener,
|
||||
onDidRemoveLastListener: lazyListener.clear.bind(lazyListener),
|
||||
delay: options.eventDebounceDelay,
|
||||
merge
|
||||
});
|
||||
this.onDidChange = this._onDidChange.event;
|
||||
}
|
||||
getActions(options) {
|
||||
return this._menuInfo.createActionGroups(options);
|
||||
}
|
||||
dispose() {
|
||||
this._disposables.dispose();
|
||||
this._onDidChange.dispose();
|
||||
}
|
||||
};
|
||||
MenuImpl = __decorate([
|
||||
__param(3, ICommandService),
|
||||
__param(4, IKeybindingService),
|
||||
__param(5, IContextKeyService)
|
||||
], MenuImpl);
|
||||
function createMenuHide(menu, command, states) {
|
||||
const id = isISubmenuItem(command) ? command.submenu.id : command.id;
|
||||
const title = typeof command.title === 'string' ? command.title : command.title.value;
|
||||
const hide = toAction({
|
||||
id: `hide/${menu.id}/${id}`,
|
||||
label: localize(1636, 'Hide \'{0}\'', title),
|
||||
run() { states.updateHidden(menu, id, true); }
|
||||
});
|
||||
const toggle = toAction({
|
||||
id: `toggle/${menu.id}/${id}`,
|
||||
label: title,
|
||||
get checked() { return !states.isHidden(menu, id); },
|
||||
run() { states.updateHidden(menu, id, !!this.checked); }
|
||||
});
|
||||
return {
|
||||
hide,
|
||||
toggle,
|
||||
get isHidden() { return !toggle.checked; },
|
||||
};
|
||||
}
|
||||
export function createConfigureKeybindingAction(commandService, keybindingService, commandId, when = undefined, enabled = true) {
|
||||
return toAction({
|
||||
id: `configureKeybinding/${commandId}`,
|
||||
label: localize(1637, "Configure Keybinding"),
|
||||
enabled,
|
||||
run() {
|
||||
// Only set the when clause when there is no keybinding
|
||||
// It is possible that the action and the keybinding have different when clauses
|
||||
const hasKeybinding = !!keybindingService.lookupKeybinding(commandId); // This may only be called inside the `run()` method as it can be expensive on startup. #210529
|
||||
const whenValue = !hasKeybinding && when ? when.serialize() : undefined;
|
||||
commandService.executeCommand('workbench.action.openGlobalKeybindings', `@command:${commandId}` + (whenValue ? ` +when:${whenValue}` : ''));
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=menuService.js.map
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user