Merge pull request #170889 from microsoft/sbatten/cheerful-swift

move isHiddenByDefault
This commit is contained in:
Daniel Imms 2023-01-10 06:57:55 -08:00 committed by GitHub
commit b535afbd27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View file

@ -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>;

View file

@ -23,6 +23,7 @@ export interface IMenuItem {
when?: ContextKeyExpression;
group?: 'navigation' | string;
order?: number;
isHiddenByDefault?: boolean;
}
export interface ISubmenuItem {

View file

@ -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);
@ -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}`,
@ -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); }
});