Skip to content

Commit

Permalink
Merge pull request #170727 from microsoft/tyriar/hidden_by_default
Browse files Browse the repository at this point in the history
Support hiding navigation menu items by default
  • Loading branch information
Tyriar committed Jan 9, 2023
2 parents 5b043e8 + e3d7d52 commit 9df499d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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

0 comments on commit 9df499d

Please sign in to comment.