mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Merge pull request #170889 from microsoft/sbatten/cheerful-swift
move isHiddenByDefault
This commit is contained in:
commit
b535afbd27
|
@ -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>;
|
||||
|
|
|
@ -23,6 +23,7 @@ export interface IMenuItem {
|
|||
when?: ContextKeyExpression;
|
||||
group?: 'navigation' | string;
|
||||
order?: number;
|
||||
isHiddenByDefault?: boolean;
|
||||
}
|
||||
|
||||
export interface ISubmenuItem {
|
||||
|
|
|
@ -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); }
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue