Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable submenus rendered as dropdowns #109934

Merged
merged 2 commits into from Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/vs/base/browser/ui/dropdown/dropdown.css
Expand Up @@ -12,3 +12,7 @@
cursor: pointer;
height: 100%;
}

.monaco-dropdown > .dropdown-label > .action-label.disabled {
cursor: default;
}
11 changes: 11 additions & 0 deletions src/vs/base/browser/ui/dropdown/dropdownActionViewItem.ts
Expand Up @@ -35,6 +35,7 @@ export class DropdownMenuActionViewItem extends BaseActionViewItem {
private menuActionsOrProvider: readonly IAction[] | IActionProvider;
private dropdownMenu: DropdownMenu | undefined;
private contextMenuProvider: IContextMenuProvider;
private actionItem: HTMLElement | null = null;

private _onDidChangeVisibility = this._register(new Emitter<boolean>());
readonly onDidChangeVisibility = this._onDidChangeVisibility.event;
Expand All @@ -56,6 +57,8 @@ export class DropdownMenuActionViewItem extends BaseActionViewItem {
}

render(container: HTMLElement): void {
this.actionItem = container;

const labelRenderer: ILabelRenderer = (el: HTMLElement): IDisposable | null => {
this.element = append(el, $('a.action-label'));

Expand Down Expand Up @@ -115,6 +118,8 @@ export class DropdownMenuActionViewItem extends BaseActionViewItem {
}
};
}

this.updateEnabled();
}

setActionContext(newContext: unknown): void {
Expand All @@ -134,6 +139,12 @@ export class DropdownMenuActionViewItem extends BaseActionViewItem {
this.dropdownMenu.show();
}
}

protected updateEnabled(): void {
const disabled = !this.getAction().enabled;
this.actionItem?.classList.toggle('disabled', disabled);
this.element?.classList.toggle('disabled', disabled);
}
}

export interface IActionWithDropdownActionViewItemOptions extends IActionViewItemOptions {
Expand Down
6 changes: 6 additions & 0 deletions src/vs/base/browser/ui/menu/menu.ts
Expand Up @@ -777,6 +777,12 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
}));
}

updateEnabled(): void {
// override on submenu entry
// native menus do not observe enablement on sumbenus
// we mimic that behavior
}

open(selectFirst?: boolean): void {
this.cleanupExistingSubmenu(false);
this.createSubmenu(selectFirst);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/common/actions.ts
Expand Up @@ -242,7 +242,7 @@ export class SubmenuAction extends Action {
}

constructor(id: string, label: string, private _actions: IAction[], cssClass?: string) {
super(id, label, cssClass, true);
super(id, label, cssClass, !!_actions?.length);
}
}

Expand Down