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

make checked optional on IAction to differentiate false from never checked #135605

Merged
merged 1 commit into from
Oct 22, 2021
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
4 changes: 2 additions & 2 deletions src/vs/base/browser/ui/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class CheckboxActionViewItem extends BaseActionViewItem {
super(context, action, options);
this.checkbox = this._register(new Checkbox({
actionClassName: this._action.class,
isChecked: this._action.checked,
isChecked: !!this._action.checked,
title: (<IActionViewItemOptions>this.options).keybinding ? `${this._action.label} (${(<IActionViewItemOptions>this.options).keybinding})` : this._action.label,
notFocusable: true
}));
Expand All @@ -70,7 +70,7 @@ export class CheckboxActionViewItem extends BaseActionViewItem {
}

override updateChecked(): void {
this.checkbox.checked = this._action.checked;
this.checkbox.checked = !!this._action.checked;
}

override focus(): void {
Expand Down
10 changes: 5 additions & 5 deletions src/vs/base/browser/ui/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,14 @@ class BaseMenuActionViewItem extends BaseActionViewItem {
return;
}

if (this.getAction().checked) {
this.item.classList.add('checked');
const checked = this.getAction().checked;
this.item.classList.toggle('checked', !!checked);
if (checked !== undefined) {
this.item.setAttribute('role', 'menuitemcheckbox');
this.item.setAttribute('aria-checked', 'true');
this.item.setAttribute('aria-checked', checked ? 'true' : 'false');
} else {
this.item.classList.remove('checked');
this.item.setAttribute('role', 'menuitem');
this.item.setAttribute('aria-checked', 'false');
this.item.setAttribute('aria-checked', '');
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/vs/base/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface IAction extends IDisposable {
tooltip: string;
class: string | undefined;
enabled: boolean;
checked: boolean;
checked?: boolean;
run(event?: unknown): unknown;
}

Expand Down Expand Up @@ -58,7 +58,7 @@ export class Action extends Disposable implements IAction {
protected _tooltip: string | undefined;
protected _cssClass: string | undefined;
protected _enabled: boolean = true;
protected _checked: boolean = false;
protected _checked?: boolean;
protected readonly _actionCallback?: (event?: unknown) => unknown;

constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: unknown) => unknown) {
Expand Down Expand Up @@ -134,15 +134,15 @@ export class Action extends Disposable implements IAction {
}
}

get checked(): boolean {
get checked(): boolean | undefined {
return this._checked;
}

set checked(value: boolean) {
set checked(value: boolean | undefined) {
this._setChecked(value);
}

protected _setChecked(value: boolean): void {
protected _setChecked(value: boolean | undefined): void {
if (this._checked !== value) {
this._checked = value;
this._onDidChange.fire({ checked: value });
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class MenuItemAction implements IAction {
readonly tooltip: string;
readonly class: string | undefined;
readonly enabled: boolean;
readonly checked: boolean;
readonly checked?: boolean;

constructor(
item: ICommandAction,
Expand All @@ -416,7 +416,7 @@ export class MenuItemAction implements IAction {
: (typeof item.title === 'string' ? item.title : item.title.value);
this.tooltip = (typeof item.tooltip === 'string' ? item.tooltip : item.tooltip?.value) ?? '';
this.enabled = !item.precondition || contextKeyService.contextMatchesRules(item.precondition);
this.checked = false;
this.checked = undefined;

if (item.toggled) {
const toggled = ((item.toggled as { condition: ContextKeyExpression }).condition ? item.toggled : { condition: item.toggled }) as {
Expand Down