feat: 添加vscode编辑器
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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-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 > .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,441 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { $, addDisposableListener, append, asCSSUrl, EventType, ModifierKeyEmitter, prepend } from '../../../base/browser/dom.js';
|
||||
import { StandardKeyboardEvent } from '../../../base/browser/keyboardEvent.js';
|
||||
import { ActionViewItem, BaseActionViewItem } 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 './menuEntryActionViewItem.css';
|
||||
import { localize } from '../../../nls.js';
|
||||
import { IMenuService, MenuItemAction, SubmenuItemAction } from '../common/actions.js';
|
||||
import { IContextKeyService } from '../../contextkey/common/contextkey.js';
|
||||
import { IContextMenuService } 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 { IThemeService, ThemeIcon } from '../../theme/common/themeService.js';
|
||||
import { isDark } from '../../theme/common/theme.js';
|
||||
import { assertType } from '../../../base/common/types.js';
|
||||
export function createAndFillInActionBarActions(menu, options, target, primaryGroup, primaryMaxCount, shouldInlineSubmenu, useSeparatorsInPrimaryActions) {
|
||||
const groups = menu.getActions(options);
|
||||
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, primaryMaxCount, shouldInlineSubmenu, useSeparatorsInPrimaryActions);
|
||||
return asDisposable(groups);
|
||||
}
|
||||
function asDisposable(groups) {
|
||||
const disposables = new DisposableStore();
|
||||
for (const [, actions] of groups) {
|
||||
for (const action of actions) {
|
||||
disposables.add(action);
|
||||
}
|
||||
}
|
||||
return disposables;
|
||||
}
|
||||
function fillInActions(groups, target, useAlternativeActions, isPrimaryAction = actionGroup => actionGroup === 'navigation', primaryMaxCount = Number.MAX_SAFE_INTEGER, 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 ((submenuActions.length <= 1 || target.length + submenuActions.length - 2 <= primaryMaxCount) && shouldInlineSubmenu(action, group, target.length)) {
|
||||
target.splice(index, 1, ...submenuActions);
|
||||
}
|
||||
}
|
||||
// overflow items from the primary group into the secondary bucket
|
||||
if (primaryBucket !== secondaryBucket && primaryBucket.length > primaryMaxCount) {
|
||||
const overflow = primaryBucket.splice(primaryMaxCount, primaryBucket.length - primaryMaxCount);
|
||||
secondaryBucket.unshift(...overflow, new Separator());
|
||||
}
|
||||
}
|
||||
let MenuEntryActionViewItem = class MenuEntryActionViewItem extends ActionViewItem {
|
||||
constructor(action, options, _keybindingService, _notificationService, _contextKeyService, _themeService, _contextMenuService) {
|
||||
super(undefined, action, { icon: !!(action.class || action.item.icon), label: !action.class && !action.item.icon, draggable: options === null || options === void 0 ? void 0 : options.draggable, keybinding: options === null || options === void 0 ? void 0 : options.keybinding, hoverDelegate: options === null || options === void 0 ? void 0 : options.hoverDelegate });
|
||||
this._keybindingService = _keybindingService;
|
||||
this._notificationService = _notificationService;
|
||||
this._contextKeyService = _contextKeyService;
|
||||
this._themeService = _themeService;
|
||||
this._contextMenuService = _contextMenuService;
|
||||
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;
|
||||
}
|
||||
onClick(event) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
try {
|
||||
yield this.actionRunner.run(this._commandAction, this._context);
|
||||
}
|
||||
catch (err) {
|
||||
this._notificationService.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
render(container) {
|
||||
super.render(container);
|
||||
container.classList.add('menu-entry');
|
||||
this._updateItemClass(this._menuItemAction.item);
|
||||
let mouseOver = false;
|
||||
let alternativeKeyDown = this._altKey.keyStatus.altKey || ((isWindows || isLinux) && this._altKey.keyStatus.shiftKey);
|
||||
const updateAltState = () => {
|
||||
var _a;
|
||||
const wantsAltCommand = mouseOver && alternativeKeyDown && !!((_a = this._commandAction.alt) === null || _a === void 0 ? void 0 : _a.enabled);
|
||||
if (wantsAltCommand !== this._wantsAltCommand) {
|
||||
this._wantsAltCommand = wantsAltCommand;
|
||||
this.updateLabel();
|
||||
this.updateTooltip();
|
||||
this.updateClass();
|
||||
}
|
||||
};
|
||||
if (this._menuItemAction.alt) {
|
||||
this._register(this._altKey.event(value => {
|
||||
alternativeKeyDown = value.altKey || ((isWindows || isLinux) && value.shiftKey);
|
||||
updateAltState();
|
||||
}));
|
||||
}
|
||||
this._register(addDisposableListener(container, 'mouseleave', _ => {
|
||||
mouseOver = false;
|
||||
updateAltState();
|
||||
}));
|
||||
this._register(addDisposableListener(container, 'mouseenter', _ => {
|
||||
mouseOver = true;
|
||||
updateAltState();
|
||||
}));
|
||||
}
|
||||
updateLabel() {
|
||||
if (this.options.label && this.label) {
|
||||
this.label.textContent = this._commandAction.label;
|
||||
}
|
||||
}
|
||||
getTooltip() {
|
||||
var _a;
|
||||
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('titleAndKb', "{0} ({1})", tooltip, keybindingLabel)
|
||||
: tooltip;
|
||||
if (!this._wantsAltCommand && ((_a = this._menuItemAction.alt) === null || _a === void 0 ? void 0 : _a.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('titleAndKb', "{0} ({1})", altTooltip, altKeybindingLabel)
|
||||
: altTooltip;
|
||||
title = localize('titleAndKbAndAlt', "{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) {
|
||||
var _a;
|
||||
this._itemClassDispose.value = undefined;
|
||||
const { element, label } = this;
|
||||
if (!element || !label) {
|
||||
return;
|
||||
}
|
||||
const icon = this._commandAction.checked && ((_a = item.toggled) === null || _a === void 0 ? void 0 : _a.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)
|
||||
], MenuEntryActionViewItem);
|
||||
export { MenuEntryActionViewItem };
|
||||
let SubmenuEntryActionViewItem = class SubmenuEntryActionViewItem extends DropdownMenuActionViewItem {
|
||||
constructor(action, options, _contextMenuService, _themeService) {
|
||||
var _a, _b;
|
||||
const dropdownOptions = Object.assign({}, options !== null && options !== void 0 ? options : Object.create(null), {
|
||||
menuAsChild: (_a = options === null || options === void 0 ? void 0 : options.menuAsChild) !== null && _a !== void 0 ? _a : false,
|
||||
classNames: (_b = options === null || options === void 0 ? void 0 : options.classNames) !== null && _b !== void 0 ? _b : (ThemeIcon.isThemeIcon(action.item.icon) ? ThemeIcon.asClassName(action.item.icon) : undefined),
|
||||
});
|
||||
super(action, { getActions: () => action.actions }, _contextMenuService, dropdownOptions);
|
||||
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, IContextMenuService),
|
||||
__param(3, IThemeService)
|
||||
], SubmenuEntryActionViewItem);
|
||||
export { SubmenuEntryActionViewItem };
|
||||
let DropdownWithDefaultActionViewItem = class DropdownWithDefaultActionViewItem extends BaseActionViewItem {
|
||||
constructor(submenuAction, options, _keybindingService, _notificationService, _contextMenuService, _menuService, _instaService, _storageService) {
|
||||
var _a, _b, _c;
|
||||
super(null, submenuAction);
|
||||
this._keybindingService = _keybindingService;
|
||||
this._notificationService = _notificationService;
|
||||
this._contextMenuService = _contextMenuService;
|
||||
this._menuService = _menuService;
|
||||
this._instaService = _instaService;
|
||||
this._storageService = _storageService;
|
||||
this._container = null;
|
||||
this._options = options;
|
||||
this._storageKey = `${submenuAction.item.submenu.id}_lastActionId`;
|
||||
// determine default action
|
||||
let defaultAction;
|
||||
const defaultActionId = _storageService.get(this._storageKey, 1 /* StorageScope.WORKSPACE */);
|
||||
if (defaultActionId) {
|
||||
defaultAction = submenuAction.actions.find(a => defaultActionId === a.id);
|
||||
}
|
||||
if (!defaultAction) {
|
||||
defaultAction = submenuAction.actions[0];
|
||||
}
|
||||
this._defaultAction = this._instaService.createInstance(MenuEntryActionViewItem, defaultAction, { keybinding: this._getDefaultActionKeybindingLabel(defaultAction) });
|
||||
const dropdownOptions = Object.assign({}, options !== null && options !== void 0 ? options : Object.create(null), {
|
||||
menuAsChild: (_a = options === null || options === void 0 ? void 0 : options.menuAsChild) !== null && _a !== void 0 ? _a : true,
|
||||
classNames: (_b = options === null || options === void 0 ? void 0 : options.classNames) !== null && _b !== void 0 ? _b : ['codicon', 'codicon-chevron-down'],
|
||||
actionRunner: (_c = options === null || options === void 0 ? void 0 : options.actionRunner) !== null && _c !== void 0 ? _c : new ActionRunner()
|
||||
});
|
||||
this._dropdown = new DropdownMenuActionViewItem(submenuAction, submenuAction.actions, this._contextMenuService, dropdownOptions);
|
||||
this._dropdown.actionRunner.onDidRun((e) => {
|
||||
if (e.action instanceof MenuItemAction) {
|
||||
this.update(e.action);
|
||||
}
|
||||
});
|
||||
}
|
||||
update(lastAction) {
|
||||
this._storageService.store(this._storageKey, lastAction.id, 1 /* StorageScope.WORKSPACE */, 0 /* StorageTarget.USER */);
|
||||
this._defaultAction.dispose();
|
||||
this._defaultAction = this._instaService.createInstance(MenuEntryActionViewItem, lastAction, { keybinding: this._getDefaultActionKeybindingLabel(lastAction) });
|
||||
this._defaultAction.actionRunner = new class extends ActionRunner {
|
||||
runAction(action, context) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield action.run(undefined);
|
||||
});
|
||||
}
|
||||
}();
|
||||
if (this._container) {
|
||||
this._defaultAction.render(prepend(this._container, $('.action-container')));
|
||||
}
|
||||
}
|
||||
_getDefaultActionKeybindingLabel(defaultAction) {
|
||||
var _a;
|
||||
let defaultActionKeybinding;
|
||||
if ((_a = this._options) === null || _a === void 0 ? void 0 : _a.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) => {
|
||||
var _a;
|
||||
const event = new StandardKeyboardEvent(e);
|
||||
if (event.equals(15 /* KeyCode.LeftArrow */)) {
|
||||
this._defaultAction.element.tabIndex = 0;
|
||||
this._dropdown.setFocusable(false);
|
||||
(_a = this._defaultAction.element) === null || _a === void 0 ? void 0 : _a.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);
|
||||
}
|
||||
}
|
||||
dispose() {
|
||||
this._defaultAction.dispose();
|
||||
this._dropdown.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
};
|
||||
DropdownWithDefaultActionViewItem = __decorate([
|
||||
__param(2, IKeybindingService),
|
||||
__param(3, INotificationService),
|
||||
__param(4, IContextMenuService),
|
||||
__param(5, IMenuService),
|
||||
__param(6, IInstantiationService),
|
||||
__param(7, IStorageService)
|
||||
], DropdownWithDefaultActionViewItem);
|
||||
export { DropdownWithDefaultActionViewItem };
|
||||
/**
|
||||
* 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.rememberDefaultAction) {
|
||||
return instaService.createInstance(DropdownWithDefaultActionViewItem, action, options);
|
||||
}
|
||||
else {
|
||||
return instaService.createInstance(SubmenuEntryActionViewItem, action, options);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { Separator, SubmenuAction } from '../../../base/common/actions.js';
|
||||
import { CSSIcon } from '../../../base/common/codicons.js';
|
||||
import { Emitter } from '../../../base/common/event.js';
|
||||
import { Iterable } from '../../../base/common/iterator.js';
|
||||
import { toDisposable } from '../../../base/common/lifecycle.js';
|
||||
import { LinkedList } from '../../../base/common/linkedList.js';
|
||||
import { ICommandService } from '../../commands/common/commands.js';
|
||||
import { IContextKeyService } from '../../contextkey/common/contextkey.js';
|
||||
import { createDecorator } from '../../instantiation/common/instantiation.js';
|
||||
import { ThemeIcon } from '../../theme/common/themeService.js';
|
||||
export function isIMenuItem(item) {
|
||||
return item.command !== undefined;
|
||||
}
|
||||
export class MenuId {
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
MenuId._instances = new Map();
|
||||
MenuId.CommandPalette = new MenuId('CommandPalette');
|
||||
MenuId.DebugBreakpointsContext = new MenuId('DebugBreakpointsContext');
|
||||
MenuId.DebugCallStackContext = new MenuId('DebugCallStackContext');
|
||||
MenuId.DebugConsoleContext = new MenuId('DebugConsoleContext');
|
||||
MenuId.DebugVariablesContext = new MenuId('DebugVariablesContext');
|
||||
MenuId.DebugWatchContext = new MenuId('DebugWatchContext');
|
||||
MenuId.DebugToolBar = new MenuId('DebugToolBar');
|
||||
MenuId.DebugToolBarStop = new MenuId('DebugToolBarStop');
|
||||
MenuId.EditorContext = new MenuId('EditorContext');
|
||||
MenuId.SimpleEditorContext = new MenuId('SimpleEditorContext');
|
||||
MenuId.EditorContextCopy = new MenuId('EditorContextCopy');
|
||||
MenuId.EditorContextPeek = new MenuId('EditorContextPeek');
|
||||
MenuId.EditorContextShare = new MenuId('EditorContextShare');
|
||||
MenuId.EditorTitle = new MenuId('EditorTitle');
|
||||
MenuId.EditorTitleRun = new MenuId('EditorTitleRun');
|
||||
MenuId.EditorTitleContext = new MenuId('EditorTitleContext');
|
||||
MenuId.EmptyEditorGroup = new MenuId('EmptyEditorGroup');
|
||||
MenuId.EmptyEditorGroupContext = new MenuId('EmptyEditorGroupContext');
|
||||
MenuId.ExplorerContext = new MenuId('ExplorerContext');
|
||||
MenuId.ExtensionContext = new MenuId('ExtensionContext');
|
||||
MenuId.GlobalActivity = new MenuId('GlobalActivity');
|
||||
MenuId.CommandCenter = new MenuId('CommandCenter');
|
||||
MenuId.LayoutControlMenuSubmenu = new MenuId('LayoutControlMenuSubmenu');
|
||||
MenuId.LayoutControlMenu = new MenuId('LayoutControlMenu');
|
||||
MenuId.MenubarMainMenu = new MenuId('MenubarMainMenu');
|
||||
MenuId.MenubarAppearanceMenu = new MenuId('MenubarAppearanceMenu');
|
||||
MenuId.MenubarDebugMenu = new MenuId('MenubarDebugMenu');
|
||||
MenuId.MenubarEditMenu = new MenuId('MenubarEditMenu');
|
||||
MenuId.MenubarCopy = new MenuId('MenubarCopy');
|
||||
MenuId.MenubarFileMenu = new MenuId('MenubarFileMenu');
|
||||
MenuId.MenubarGoMenu = new MenuId('MenubarGoMenu');
|
||||
MenuId.MenubarHelpMenu = new MenuId('MenubarHelpMenu');
|
||||
MenuId.MenubarLayoutMenu = new MenuId('MenubarLayoutMenu');
|
||||
MenuId.MenubarNewBreakpointMenu = new MenuId('MenubarNewBreakpointMenu');
|
||||
MenuId.MenubarPanelAlignmentMenu = new MenuId('MenubarPanelAlignmentMenu');
|
||||
MenuId.MenubarPanelPositionMenu = new MenuId('MenubarPanelPositionMenu');
|
||||
MenuId.MenubarPreferencesMenu = new MenuId('MenubarPreferencesMenu');
|
||||
MenuId.MenubarRecentMenu = new MenuId('MenubarRecentMenu');
|
||||
MenuId.MenubarSelectionMenu = new MenuId('MenubarSelectionMenu');
|
||||
MenuId.MenubarShare = new MenuId('MenubarShare');
|
||||
MenuId.MenubarSwitchEditorMenu = new MenuId('MenubarSwitchEditorMenu');
|
||||
MenuId.MenubarSwitchGroupMenu = new MenuId('MenubarSwitchGroupMenu');
|
||||
MenuId.MenubarTerminalMenu = new MenuId('MenubarTerminalMenu');
|
||||
MenuId.MenubarViewMenu = new MenuId('MenubarViewMenu');
|
||||
MenuId.MenubarHomeMenu = new MenuId('MenubarHomeMenu');
|
||||
MenuId.OpenEditorsContext = new MenuId('OpenEditorsContext');
|
||||
MenuId.ProblemsPanelContext = new MenuId('ProblemsPanelContext');
|
||||
MenuId.SCMChangeContext = new MenuId('SCMChangeContext');
|
||||
MenuId.SCMResourceContext = new MenuId('SCMResourceContext');
|
||||
MenuId.SCMResourceFolderContext = new MenuId('SCMResourceFolderContext');
|
||||
MenuId.SCMResourceGroupContext = new MenuId('SCMResourceGroupContext');
|
||||
MenuId.SCMSourceControl = new MenuId('SCMSourceControl');
|
||||
MenuId.SCMTitle = new MenuId('SCMTitle');
|
||||
MenuId.SearchContext = new MenuId('SearchContext');
|
||||
MenuId.StatusBarWindowIndicatorMenu = new MenuId('StatusBarWindowIndicatorMenu');
|
||||
MenuId.StatusBarRemoteIndicatorMenu = new MenuId('StatusBarRemoteIndicatorMenu');
|
||||
MenuId.TestItem = new MenuId('TestItem');
|
||||
MenuId.TestItemGutter = new MenuId('TestItemGutter');
|
||||
MenuId.TestPeekElement = new MenuId('TestPeekElement');
|
||||
MenuId.TestPeekTitle = new MenuId('TestPeekTitle');
|
||||
MenuId.TouchBarContext = new MenuId('TouchBarContext');
|
||||
MenuId.TitleBarContext = new MenuId('TitleBarContext');
|
||||
MenuId.TitleBarTitleContext = new MenuId('TitleBarTitleContext');
|
||||
MenuId.TunnelContext = new MenuId('TunnelContext');
|
||||
MenuId.TunnelPrivacy = new MenuId('TunnelPrivacy');
|
||||
MenuId.TunnelProtocol = new MenuId('TunnelProtocol');
|
||||
MenuId.TunnelPortInline = new MenuId('TunnelInline');
|
||||
MenuId.TunnelTitle = new MenuId('TunnelTitle');
|
||||
MenuId.TunnelLocalAddressInline = new MenuId('TunnelLocalAddressInline');
|
||||
MenuId.TunnelOriginInline = new MenuId('TunnelOriginInline');
|
||||
MenuId.ViewItemContext = new MenuId('ViewItemContext');
|
||||
MenuId.ViewContainerTitle = new MenuId('ViewContainerTitle');
|
||||
MenuId.ViewContainerTitleContext = new MenuId('ViewContainerTitleContext');
|
||||
MenuId.ViewTitle = new MenuId('ViewTitle');
|
||||
MenuId.ViewTitleContext = new MenuId('ViewTitleContext');
|
||||
MenuId.CommentThreadTitle = new MenuId('CommentThreadTitle');
|
||||
MenuId.CommentThreadActions = new MenuId('CommentThreadActions');
|
||||
MenuId.CommentTitle = new MenuId('CommentTitle');
|
||||
MenuId.CommentActions = new MenuId('CommentActions');
|
||||
MenuId.InteractiveToolbar = new MenuId('InteractiveToolbar');
|
||||
MenuId.InteractiveCellTitle = new MenuId('InteractiveCellTitle');
|
||||
MenuId.InteractiveCellDelete = new MenuId('InteractiveCellDelete');
|
||||
MenuId.InteractiveCellExecute = new MenuId('InteractiveCellExecute');
|
||||
MenuId.InteractiveInputExecute = new MenuId('InteractiveInputExecute');
|
||||
MenuId.NotebookToolbar = new MenuId('NotebookToolbar');
|
||||
MenuId.NotebookCellTitle = new MenuId('NotebookCellTitle');
|
||||
MenuId.NotebookCellDelete = new MenuId('NotebookCellDelete');
|
||||
MenuId.NotebookCellInsert = new MenuId('NotebookCellInsert');
|
||||
MenuId.NotebookCellBetween = new MenuId('NotebookCellBetween');
|
||||
MenuId.NotebookCellListTop = new MenuId('NotebookCellTop');
|
||||
MenuId.NotebookCellExecute = new MenuId('NotebookCellExecute');
|
||||
MenuId.NotebookCellExecutePrimary = new MenuId('NotebookCellExecutePrimary');
|
||||
MenuId.NotebookDiffCellInputTitle = new MenuId('NotebookDiffCellInputTitle');
|
||||
MenuId.NotebookDiffCellMetadataTitle = new MenuId('NotebookDiffCellMetadataTitle');
|
||||
MenuId.NotebookDiffCellOutputsTitle = new MenuId('NotebookDiffCellOutputsTitle');
|
||||
MenuId.NotebookOutputToolbar = new MenuId('NotebookOutputToolbar');
|
||||
MenuId.NotebookEditorLayoutConfigure = new MenuId('NotebookEditorLayoutConfigure');
|
||||
MenuId.NotebookKernelSource = new MenuId('NotebookKernelSource');
|
||||
MenuId.BulkEditTitle = new MenuId('BulkEditTitle');
|
||||
MenuId.BulkEditContext = new MenuId('BulkEditContext');
|
||||
MenuId.TimelineItemContext = new MenuId('TimelineItemContext');
|
||||
MenuId.TimelineTitle = new MenuId('TimelineTitle');
|
||||
MenuId.TimelineTitleContext = new MenuId('TimelineTitleContext');
|
||||
MenuId.TimelineFilterSubMenu = new MenuId('TimelineFilterSubMenu');
|
||||
MenuId.AccountsContext = new MenuId('AccountsContext');
|
||||
MenuId.PanelTitle = new MenuId('PanelTitle');
|
||||
MenuId.AuxiliaryBarTitle = new MenuId('AuxiliaryBarTitle');
|
||||
MenuId.TerminalInstanceContext = new MenuId('TerminalInstanceContext');
|
||||
MenuId.TerminalEditorInstanceContext = new MenuId('TerminalEditorInstanceContext');
|
||||
MenuId.TerminalNewDropdownContext = new MenuId('TerminalNewDropdownContext');
|
||||
MenuId.TerminalTabContext = new MenuId('TerminalTabContext');
|
||||
MenuId.TerminalTabEmptyAreaContext = new MenuId('TerminalTabEmptyAreaContext');
|
||||
MenuId.TerminalInlineTabContext = new MenuId('TerminalInlineTabContext');
|
||||
MenuId.WebviewContext = new MenuId('WebviewContext');
|
||||
MenuId.InlineCompletionsActions = new MenuId('InlineCompletionsActions');
|
||||
MenuId.NewFile = new MenuId('NewFile');
|
||||
MenuId.MergeToolbar = new MenuId('MergeToolbar');
|
||||
MenuId.MergeInput1Toolbar = new MenuId('MergeToolbar1Toolbar');
|
||||
MenuId.MergeInput2Toolbar = new MenuId('MergeToolbar2Toolbar');
|
||||
export const IMenuService = createDecorator('menuService');
|
||||
export const MenuRegistry = new class {
|
||||
constructor() {
|
||||
this._commands = new Map();
|
||||
this._menuItems = new Map();
|
||||
this._onDidChangeMenu = new Emitter();
|
||||
this.onDidChangeMenu = this._onDidChangeMenu.event;
|
||||
this._commandPaletteChangeEvent = {
|
||||
has: id => id === MenuId.CommandPalette
|
||||
};
|
||||
}
|
||||
addCommand(command) {
|
||||
return this.addCommands(Iterable.single(command));
|
||||
}
|
||||
addCommands(commands) {
|
||||
for (const command of commands) {
|
||||
this._commands.set(command.id, command);
|
||||
}
|
||||
this._onDidChangeMenu.fire(this._commandPaletteChangeEvent);
|
||||
return toDisposable(() => {
|
||||
let didChange = false;
|
||||
for (const command of commands) {
|
||||
didChange = this._commands.delete(command.id) || didChange;
|
||||
}
|
||||
if (didChange) {
|
||||
this._onDidChangeMenu.fire(this._commandPaletteChangeEvent);
|
||||
}
|
||||
});
|
||||
}
|
||||
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) {
|
||||
return this.appendMenuItems(Iterable.single({ id, item }));
|
||||
}
|
||||
appendMenuItems(items) {
|
||||
const changedIds = new Set();
|
||||
const toRemove = new LinkedList();
|
||||
for (const { id, item } of items) {
|
||||
let list = this._menuItems.get(id);
|
||||
if (!list) {
|
||||
list = new LinkedList();
|
||||
this._menuItems.set(id, list);
|
||||
}
|
||||
toRemove.push(list.push(item));
|
||||
changedIds.add(id);
|
||||
}
|
||||
this._onDidChangeMenu.fire(changedIds);
|
||||
return toDisposable(() => {
|
||||
if (toRemove.size > 0) {
|
||||
for (const fn of toRemove) {
|
||||
fn();
|
||||
}
|
||||
this._onDidChangeMenu.fire(changedIds);
|
||||
toRemove.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
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, _menuService, _contextKeyService, _options) {
|
||||
super(`submenuitem.${item.submenu.id}`, typeof item.title === 'string' ? item.title : item.title.value, [], 'submenu');
|
||||
this.item = item;
|
||||
this._menuService = _menuService;
|
||||
this._contextKeyService = _contextKeyService;
|
||||
this._options = _options;
|
||||
}
|
||||
get actions() {
|
||||
const result = [];
|
||||
const menu = this._menuService.createMenu(this.item.submenu, this._contextKeyService);
|
||||
const groups = menu.getActions(this._options);
|
||||
menu.dispose();
|
||||
for (const [, actions] of groups) {
|
||||
if (actions.length > 0) {
|
||||
result.push(...actions);
|
||||
result.push(new Separator());
|
||||
}
|
||||
}
|
||||
if (result.length) {
|
||||
result.pop(); // remove last separator
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// implements IAction, does NOT extend Action, so that no one
|
||||
// subscribes to events of Action or modified properties
|
||||
let MenuItemAction = class MenuItemAction {
|
||||
constructor(item, alt, options, hideActions, contextKeyService, _commandService) {
|
||||
var _a, _b;
|
||||
this.hideActions = hideActions;
|
||||
this._commandService = _commandService;
|
||||
this.id = item.id;
|
||||
this.label = (options === null || options === void 0 ? void 0 : options.renderShortTitle) && item.shortTitle
|
||||
? (typeof item.shortTitle === 'string' ? item.shortTitle : item.shortTitle.value)
|
||||
: (typeof item.title === 'string' ? item.title : item.title.value);
|
||||
this.tooltip = (_b = (typeof item.tooltip === 'string' ? item.tooltip : (_a = item.tooltip) === null || _a === void 0 ? void 0 : _a.value)) !== null && _b !== void 0 ? _b : '';
|
||||
this.enabled = !item.precondition || contextKeyService.contextMatchesRules(item.precondition);
|
||||
this.checked = undefined;
|
||||
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 (toggled.title) {
|
||||
this.label = typeof toggled.title === 'string' ? toggled.title : toggled.title.value;
|
||||
}
|
||||
}
|
||||
this.item = item;
|
||||
this.alt = alt ? new MenuItemAction(alt, undefined, options, hideActions, contextKeyService, _commandService) : undefined;
|
||||
this._options = options;
|
||||
if (ThemeIcon.isThemeIcon(item.icon)) {
|
||||
this.class = CSSIcon.asClassName(item.icon);
|
||||
}
|
||||
}
|
||||
dispose() {
|
||||
// there is NOTHING to dispose and the MenuItemAction should
|
||||
// never have anything to dispose as it is a convenience type
|
||||
// to bridge into the rendering world.
|
||||
}
|
||||
run(...args) {
|
||||
var _a, _b;
|
||||
let runArgs = [];
|
||||
if ((_a = this._options) === null || _a === void 0 ? void 0 : _a.arg) {
|
||||
runArgs = [...runArgs, this._options.arg];
|
||||
}
|
||||
if ((_b = this._options) === null || _b === void 0 ? void 0 : _b.shouldForwardArgs) {
|
||||
runArgs = [...runArgs, ...args];
|
||||
}
|
||||
return this._commandService.executeCommand(this.id, ...runArgs);
|
||||
}
|
||||
};
|
||||
MenuItemAction = __decorate([
|
||||
__param(4, IContextKeyService),
|
||||
__param(5, ICommandService)
|
||||
], MenuItemAction);
|
||||
export { MenuItemAction };
|
||||
//#endregion
|
||||
@@ -0,0 +1,321 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { RunOnceScheduler } from '../../../base/common/async.js';
|
||||
import { Emitter } from '../../../base/common/event.js';
|
||||
import { DisposableStore } from '../../../base/common/lifecycle.js';
|
||||
import { IMenuService, isIMenuItem, MenuItemAction, MenuRegistry, SubmenuItemAction } from './actions.js';
|
||||
import { ICommandService } from '../../commands/common/commands.js';
|
||||
import { IContextKeyService } from '../../contextkey/common/contextkey.js';
|
||||
import { 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';
|
||||
let MenuService = class MenuService {
|
||||
constructor(_commandService, storageService) {
|
||||
this._commandService = _commandService;
|
||||
this._hiddenStates = new PersistedMenuHideState(storageService);
|
||||
}
|
||||
createMenu(id, contextKeyService, options) {
|
||||
return new Menu(id, this._hiddenStates, Object.assign({ emitEventsForSubmenuChanges: false, eventDebounceDelay: 50 }, options), this._commandService, contextKeyService, this);
|
||||
}
|
||||
};
|
||||
MenuService = __decorate([
|
||||
__param(0, ICommandService),
|
||||
__param(1, IStorageService)
|
||||
], MenuService);
|
||||
export { MenuService };
|
||||
let PersistedMenuHideState = class PersistedMenuHideState {
|
||||
constructor(_storageService) {
|
||||
this._storageService = _storageService;
|
||||
this._disposables = new DisposableStore();
|
||||
this._onDidChange = new Emitter();
|
||||
this.onDidChange = this._onDidChange.event;
|
||||
this._ignoreChangeEvent = false;
|
||||
try {
|
||||
const raw = _storageService.get(PersistedMenuHideState._key, 0 /* StorageScope.PROFILE */, '{}');
|
||||
this._data = JSON.parse(raw);
|
||||
}
|
||||
catch (err) {
|
||||
this._data = Object.create(null);
|
||||
}
|
||||
this._disposables.add(_storageService.onDidChangeValue(e => {
|
||||
if (e.key !== PersistedMenuHideState._key) {
|
||||
return;
|
||||
}
|
||||
if (!this._ignoreChangeEvent) {
|
||||
try {
|
||||
const raw = _storageService.get(PersistedMenuHideState._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();
|
||||
}
|
||||
isHidden(menu, commandId) {
|
||||
var _a, _b;
|
||||
return (_b = (_a = this._data[menu.id]) === null || _a === void 0 ? void 0 : _a.includes(commandId)) !== null && _b !== void 0 ? _b : false;
|
||||
}
|
||||
updateHidden(menu, commandId, 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();
|
||||
}
|
||||
_persist() {
|
||||
try {
|
||||
this._ignoreChangeEvent = true;
|
||||
const raw = JSON.stringify(this._data);
|
||||
this._storageService.store(PersistedMenuHideState._key, raw, 0 /* StorageScope.PROFILE */, 0 /* StorageTarget.USER */);
|
||||
}
|
||||
finally {
|
||||
this._ignoreChangeEvent = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
PersistedMenuHideState._key = 'menu.hiddenCommands';
|
||||
PersistedMenuHideState = __decorate([
|
||||
__param(0, IStorageService)
|
||||
], PersistedMenuHideState);
|
||||
let Menu = class Menu {
|
||||
constructor(_id, _hiddenStates, _options, _commandService, _contextKeyService, _menuService) {
|
||||
this._id = _id;
|
||||
this._hiddenStates = _hiddenStates;
|
||||
this._options = _options;
|
||||
this._commandService = _commandService;
|
||||
this._contextKeyService = _contextKeyService;
|
||||
this._menuService = _menuService;
|
||||
this._disposables = new DisposableStore();
|
||||
this._menuGroups = [];
|
||||
this._contextKeys = new Set();
|
||||
this._build();
|
||||
// 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._build();
|
||||
this._onDidChange.fire(this);
|
||||
}, _options.eventDebounceDelay);
|
||||
this._disposables.add(rebuildMenuSoon);
|
||||
this._disposables.add(MenuRegistry.onDidChangeMenu(e => {
|
||||
if (e.has(_id)) {
|
||||
rebuildMenuSoon.schedule();
|
||||
}
|
||||
}));
|
||||
// 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 startLazyListener = () => {
|
||||
const fireChangeSoon = new RunOnceScheduler(() => this._onDidChange.fire(this), _options.eventDebounceDelay);
|
||||
lazyListener.add(fireChangeSoon);
|
||||
lazyListener.add(_contextKeyService.onDidChangeContext(e => {
|
||||
if (e.affectsSome(this._contextKeys)) {
|
||||
fireChangeSoon.schedule();
|
||||
}
|
||||
}));
|
||||
lazyListener.add(_hiddenStates.onDidChange(() => {
|
||||
fireChangeSoon.schedule();
|
||||
}));
|
||||
};
|
||||
this._onDidChange = new Emitter({
|
||||
// start/stop context key listener
|
||||
onFirstListenerAdd: startLazyListener,
|
||||
onLastListenerRemove: lazyListener.clear.bind(lazyListener)
|
||||
});
|
||||
this.onDidChange = this._onDidChange.event;
|
||||
}
|
||||
dispose() {
|
||||
this._disposables.dispose();
|
||||
this._onDidChange.dispose();
|
||||
}
|
||||
_build() {
|
||||
// reset
|
||||
this._menuGroups.length = 0;
|
||||
this._contextKeys.clear();
|
||||
const menuItems = MenuRegistry.getMenuItems(this._id);
|
||||
let group;
|
||||
menuItems.sort(Menu._compareMenuItems);
|
||||
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 for eventing
|
||||
this._collectContextKeys(item);
|
||||
}
|
||||
}
|
||||
_collectContextKeys(item) {
|
||||
Menu._fillInKbExprKeys(item.when, this._contextKeys);
|
||||
if (isIMenuItem(item)) {
|
||||
// keep precondition keys for event if applicable
|
||||
if (item.command.precondition) {
|
||||
Menu._fillInKbExprKeys(item.command.precondition, this._contextKeys);
|
||||
}
|
||||
// keep toggled keys for event if applicable
|
||||
if (item.command.toggled) {
|
||||
const toggledExpression = item.command.toggled.condition || item.command.toggled;
|
||||
Menu._fillInKbExprKeys(toggledExpression, this._contextKeys);
|
||||
}
|
||||
}
|
||||
else if (this._options.emitEventsForSubmenuChanges) {
|
||||
// recursively collect context keys from submenus so that this
|
||||
// menu fires events when context key changes affect submenus
|
||||
MenuRegistry.getMenuItems(item.submenu).forEach(this._collectContextKeys, this);
|
||||
}
|
||||
}
|
||||
getActions(options) {
|
||||
const result = [];
|
||||
const allToggleActions = [];
|
||||
for (const group of this._menuGroups) {
|
||||
const [id, items] = group;
|
||||
const toggleActions = [];
|
||||
const activeActions = [];
|
||||
for (const item of items) {
|
||||
if (this._contextKeyService.contextMatchesRules(item.when)) {
|
||||
let action;
|
||||
const isMenuItem = isIMenuItem(item);
|
||||
if (isMenuItem) {
|
||||
const menuHide = createMenuHide(this._id, item.command, this._hiddenStates);
|
||||
action = new MenuItemAction(item.command, item.alt, options, menuHide, this._contextKeyService, this._commandService);
|
||||
}
|
||||
else {
|
||||
action = new SubmenuItemAction(item, this._menuService, this._contextKeyService, options);
|
||||
if (action.actions.length === 0) {
|
||||
action.dispose();
|
||||
action = undefined;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
activeActions.push(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (activeActions.length > 0) {
|
||||
result.push([id, activeActions]);
|
||||
}
|
||||
if (toggleActions.length > 0) {
|
||||
allToggleActions.push(toggleActions);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static _fillInKbExprKeys(exp, set) {
|
||||
if (exp) {
|
||||
for (const key of exp.keys()) {
|
||||
set.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
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 Menu._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);
|
||||
}
|
||||
};
|
||||
Menu = __decorate([
|
||||
__param(3, ICommandService),
|
||||
__param(4, IContextKeyService),
|
||||
__param(5, IMenuService)
|
||||
], Menu);
|
||||
function createMenuHide(menu, command, states) {
|
||||
const id = `${menu.id}/${command.id}`;
|
||||
const title = typeof command.title === 'string' ? command.title : command.title.value;
|
||||
const hide = toAction({
|
||||
id,
|
||||
label: localize('hide.label', 'Hide \'{0}\'', title),
|
||||
run() { states.updateHidden(menu, command.id, true); }
|
||||
});
|
||||
const toggle = toAction({
|
||||
id,
|
||||
label: title,
|
||||
get checked() { return !states.isHidden(menu, command.id); },
|
||||
run() {
|
||||
const newValue = !states.isHidden(menu, command.id);
|
||||
states.updateHidden(menu, command.id, newValue);
|
||||
}
|
||||
});
|
||||
return {
|
||||
hide,
|
||||
toggle,
|
||||
get isHidden() { return !toggle.checked; },
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user