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

Support hiding navigation menu items by default #170727

Merged
merged 2 commits into from
Jan 9, 2023
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
2 changes: 2 additions & 0 deletions src/vs/platform/action/common/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export interface ICommandAction {
* or define toggle-info including an icon and a title that goes well with a checkmark.
*/
toggled?: ContextKeyExpression | ICommandActionToggleInfo;

isHiddenByDefault?: boolean;
}

export type ISerializableCommandAction = UriDto<ICommandAction>;
13 changes: 6 additions & 7 deletions src/vs/platform/actions/common/menuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ class PersistedMenuHideState {
this._disposables.dispose();
}

isHidden(menu: MenuId, commandId: string): boolean {
return this._data[menu.id]?.includes(commandId) ?? false;
isHidden(menu: MenuId, commandId: string, defaultState: boolean): boolean {
const state = this._data[menu.id]?.includes(commandId) ?? false;
return defaultState ? state : !state;
}

updateHidden(menu: MenuId, commandId: string, hidden: boolean): void {
Expand Down Expand Up @@ -400,6 +401,7 @@ function createMenuHide(menu: MenuId, command: ICommandAction | ISubmenuItem, st

const id = isISubmenuItem(command) ? command.submenu.id : command.id;
const title = typeof command.title === 'string' ? command.title : command.title.value;
const defaultState = isISubmenuItem(command) ? true : !command.isHiddenByDefault;

const hide = toAction({
id: `hide/${menu.id}/${id}`,
Expand All @@ -410,11 +412,8 @@ function createMenuHide(menu: MenuId, command: ICommandAction | ISubmenuItem, st
const toggle = toAction({
id: `toggle/${menu.id}/${id}`,
label: title,
get checked() { return !states.isHidden(menu, id); },
run() {
const newValue = !states.isHidden(menu, id);
states.updateHidden(menu, id, newValue);
}
get checked() { return !states.isHidden(menu, id, defaultState); },
run() { states.updateHidden(menu, id, !this.checked); }
});

return {
Expand Down