未验证 提交 a4207f77 编写于 作者: B Benjamin Pasero 提交者: GitHub

web - allow to contribute navigation entries (#93467)

上级 12bdf225
......@@ -32,6 +32,7 @@ export interface IMenuBarOptions {
getKeybinding?: (action: IAction) => ResolvedKeybinding | undefined;
alwaysOnMnemonics?: boolean;
compactMode?: Direction;
getCompactMenuActions?: () => IAction[]
}
export interface MenuBarMenu {
......@@ -91,7 +92,7 @@ export class MenuBar extends Disposable {
private menuStyle: IMenuStyles | undefined;
private overflowLayoutScheduled: IDisposable | undefined = undefined;
constructor(private container: HTMLElement, private options: IMenuBarOptions = {}, private compactMenuActions?: IAction[]) {
constructor(private container: HTMLElement, private options: IMenuBarOptions = {}) {
super();
this.container.setAttribute('role', 'menubar');
......@@ -492,9 +493,10 @@ export class MenuBar extends Disposable {
this.overflowMenu.buttonElement.style.visibility = 'visible';
}
if (this.compactMenuActions && this.compactMenuActions.length) {
const compactMenuActions = this.options.getCompactMenuActions?.();
if (compactMenuActions && compactMenuActions.length) {
this.overflowMenu.actions.push(new Separator());
this.overflowMenu.actions.push(...this.compactMenuActions);
this.overflowMenu.actions.push(...compactMenuActions);
}
} else {
DOM.removeNode(this.overflowMenu.buttonElement);
......
......@@ -92,6 +92,7 @@ export class MenuId {
static readonly MenubarSwitchGroupMenu = new MenuId('MenubarSwitchGroupMenu');
static readonly MenubarTerminalMenu = new MenuId('MenubarTerminalMenu');
static readonly MenubarViewMenu = new MenuId('MenubarViewMenu');
static readonly MenubarWebNavigationMenu = new MenuId('MenubarWebNavigationMenu');
static readonly OpenEditorsContext = new MenuId('OpenEditorsContext');
static readonly ProblemsPanelContext = new MenuId('ProblemsPanelContext');
static readonly SCMChangeContext = new MenuId('SCMChangeContext');
......@@ -121,7 +122,6 @@ export class MenuId {
static readonly TimelineTitle = new MenuId('TimelineTitle');
static readonly TimelineTitleContext = new MenuId('TimelineTitleContext');
static readonly AccountsContext = new MenuId('AccountsContext');
static readonly WebMenuActions = new MenuId('MenubarWebMenu');
readonly id: number;
readonly _debugName: string;
......
......@@ -38,6 +38,7 @@ namespace schema {
case 'debug/toolbar': return MenuId.DebugToolBar;
case 'debug/toolBar': return MenuId.DebugToolBar;
case 'menuBar/file': return MenuId.MenubarFileMenu;
case 'menuBar/webNavigation': return MenuId.MenubarWebNavigationMenu;
case 'scm/title': return MenuId.SCMTitle;
case 'scm/sourceControl': return MenuId.SCMSourceControl;
case 'scm/resourceState/context': return MenuId.SCMResourceContext;
......@@ -64,6 +65,7 @@ namespace schema {
switch (menuId) {
case MenuId.StatusBarWindowIndicatorMenu:
case MenuId.MenubarFileMenu:
case MenuId.MenubarWebNavigationMenu:
return true;
}
return false;
......
......@@ -26,7 +26,7 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { MenuBar } from 'vs/base/browser/ui/menu/menubar';
import { MenuBar, IMenuBarOptions } from 'vs/base/browser/ui/menu/menubar';
import { SubmenuAction, Direction } from 'vs/base/browser/ui/menu/menu';
import { attachMenuStyler } from 'vs/platform/theme/common/styler';
import { assign } from 'vs/base/common/objects';
......@@ -509,30 +509,11 @@ export class CustomMenubarControl extends MenubarControl {
}
if (firstTime) {
const webActions = [];
const webMenu = this.menuService.createMenu(MenuId.WebMenuActions, this.contextKeyService);
for (const groups of webMenu.getActions()) {
const [, actions] = groups;
for (const action of actions) {
action.label = mnemonicMenuLabel(this.calculateActionLabel(action));
webActions.push(action);
}
}
this.menubar = this._register(new MenuBar(
this.container, {
enableMnemonics: this.currentEnableMenuBarMnemonics,
disableAltFocus: this.currentDisableMenuBarAltFocus,
visibility: this.currentMenubarVisibility,
getKeybinding: (action) => this.keybindingService.lookupKeybinding(action.id),
compactMode: this.currentCompactMenuMode
}, webActions.length > 0 ? webActions : undefined));
this.menubar = this._register(new MenuBar(this.container, this.getMenuBarOptions()));
this.accessibilityService.alwaysUnderlineAccessKeys().then(val => {
this.alwaysOnMnemonics = val;
if (this.menubar) {
this.menubar.update({ enableMnemonics: this.currentEnableMenuBarMnemonics, disableAltFocus: this.currentDisableMenuBarAltFocus, visibility: this.currentMenubarVisibility, getKeybinding: (action) => this.keybindingService.lookupKeybinding(action.id), alwaysOnMnemonics: this.alwaysOnMnemonics, compactMode: this.currentCompactMenuMode });
}
this.menubar?.update(this.getMenuBarOptions());
});
this._register(this.menubar.onFocusStateChange(focused => {
......@@ -558,9 +539,7 @@ export class CustomMenubarControl extends MenubarControl {
this._register(attachMenuStyler(this.menubar, this.themeService));
} else {
if (this.menubar) {
this.menubar.update({ enableMnemonics: this.currentEnableMenuBarMnemonics, disableAltFocus: this.currentDisableMenuBarAltFocus, visibility: this.currentMenubarVisibility, getKeybinding: (action) => this.keybindingService.lookupKeybinding(action.id), alwaysOnMnemonics: this.alwaysOnMnemonics, compactMode: this.currentCompactMenuMode });
}
this.menubar?.update(this.getMenuBarOptions());
}
// Update the menu actions
......@@ -631,6 +610,35 @@ export class CustomMenubarControl extends MenubarControl {
}
}
private getMenuBarOptions(): IMenuBarOptions {
return {
enableMnemonics: this.currentEnableMenuBarMnemonics,
disableAltFocus: this.currentDisableMenuBarAltFocus,
visibility: this.currentMenubarVisibility,
getKeybinding: (action) => this.keybindingService.lookupKeybinding(action.id),
alwaysOnMnemonics: this.alwaysOnMnemonics,
compactMode: this.currentCompactMenuMode,
getCompactMenuActions: () => {
if (!isWeb) {
return []; // only for web
}
const webNavigationActions: IAction[] = [];
const webNavigationMenu = this.menuService.createMenu(MenuId.MenubarWebNavigationMenu, this.contextKeyService);
for (const groups of webNavigationMenu.getActions()) {
const [, actions] = groups;
for (const action of actions) {
action.label = mnemonicMenuLabel(this.calculateActionLabel(action));
webNavigationActions.push(action);
}
}
webNavigationMenu.dispose();
return webNavigationActions;
}
};
}
protected onDidChangeWindowFocus(hasFocus: boolean): void {
super.onDidChangeWindowFocus(hasFocus);
......@@ -693,8 +701,6 @@ export class CustomMenubarControl extends MenubarControl {
this.container.style.height = `${dimension.height}px`;
}
if (this.menubar) {
this.menubar.update({ enableMnemonics: this.currentEnableMenuBarMnemonics, disableAltFocus: this.currentDisableMenuBarAltFocus, visibility: this.currentMenubarVisibility, getKeybinding: (action) => this.keybindingService.lookupKeybinding(action.id), alwaysOnMnemonics: this.alwaysOnMnemonics, compactMode: this.currentCompactMenuMode });
}
this.menubar?.update(this.getMenuBarOptions());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册