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

move isHiddenByDefault #170889

Merged
merged 3 commits into from
Jan 10, 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: 0 additions & 2 deletions src/vs/platform/action/common/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ 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>;
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IMenuItem {
when?: ContextKeyExpression;
group?: 'navigation' | string;
order?: number;
isHiddenByDefault?: boolean;
}

export interface ISubmenuItem {
Expand Down
22 changes: 17 additions & 5 deletions src/vs/platform/actions/common/menuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,27 @@ class PersistedMenuHideState {
this._disposables.dispose();
}

isHidden(menu: MenuId, commandId: string, defaultState: boolean): boolean {
private _isHiddenByDefault(menu: MenuId, commandId: string) {
let hiddenByDefault = false;
for (const item of MenuRegistry.getMenuItems(menu)) {
if (isIMenuItem(item) && item.command.id === commandId) {
hiddenByDefault = Boolean(item.isHiddenByDefault);
break;
}
}
return hiddenByDefault;
}

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

updateHidden(menu: MenuId, commandId: string, hidden: boolean): void {
const hiddenByDefault = this._isHiddenByDefault(menu, commandId);
const entries = this._data[menu.id];
if (!hidden) {
if (hidden === !hiddenByDefault) {
// remove and cleanup
if (entries) {
const idx = entries.indexOf(commandId);
Expand Down Expand Up @@ -401,7 +414,6 @@ 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 @@ -412,7 +424,7 @@ 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, defaultState); },
get checked() { return !states.isHidden(menu, id); },
run() { states.updateHidden(menu, id, !this.checked); }
});

Expand Down