Skip to content

Commit 8a80677

Browse files
author
Benjamin Pasero
committed
1 parent a97e8c3 commit 8a80677

6 files changed

Lines changed: 23 additions & 30 deletions

File tree

src/vs/base/browser/contextmenu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class ContextSubMenu extends SubmenuAction {
2525
export interface IContextMenuDelegate {
2626
getAnchor(): HTMLElement | { x: number; y: number; width?: number; height?: number; };
2727
getActions(): ReadonlyArray<IAction | ContextSubMenu>;
28+
getCheckedActionsRepresentation?(action: IAction): 'radio' | 'checkbox';
2829
getActionViewItem?(action: IAction): IActionViewItem | undefined;
2930
getActionsContext?(event?: IContextMenuEvent): any;
3031
getKeyBinding?(action: IAction): ResolvedKeybinding | undefined;

src/vs/base/browser/ui/actionbar/actionbar.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ export class Separator extends Action {
224224
constructor(label?: string) {
225225
super(Separator.ID, label, label ? 'separator text' : 'separator');
226226
this.checked = false;
227-
this.radio = false;
228227
this.enabled = false;
229228
}
230229
}

src/vs/base/common/actions.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export interface IAction extends IDisposable {
2929
class: string | undefined;
3030
enabled: boolean;
3131
checked: boolean;
32-
radio: boolean;
3332
run(event?: any): Promise<any>;
3433
}
3534

@@ -54,7 +53,6 @@ export interface IActionChangeEvent {
5453
readonly class?: string;
5554
readonly enabled?: boolean;
5655
readonly checked?: boolean;
57-
readonly radio?: boolean;
5856
}
5957

6058
export class Action extends Disposable implements IAction {
@@ -68,7 +66,6 @@ export class Action extends Disposable implements IAction {
6866
protected _cssClass: string | undefined;
6967
protected _enabled: boolean = true;
7068
protected _checked: boolean = false;
71-
protected _radio: boolean = false;
7269
protected readonly _actionCallback?: (event?: any) => Promise<any>;
7370

7471
constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: any) => Promise<any>) {
@@ -152,28 +149,13 @@ export class Action extends Disposable implements IAction {
152149
this._setChecked(value);
153150
}
154151

155-
get radio(): boolean {
156-
return this._radio;
157-
}
158-
159-
set radio(value: boolean) {
160-
this._setRadio(value);
161-
}
162-
163152
protected _setChecked(value: boolean): void {
164153
if (this._checked !== value) {
165154
this._checked = value;
166155
this._onDidChange.fire({ checked: value });
167156
}
168157
}
169158

170-
protected _setRadio(value: boolean): void {
171-
if (this._radio !== value) {
172-
this._radio = value;
173-
this._onDidChange.fire({ radio: value });
174-
}
175-
}
176-
177159
run(event?: any, _data?: ITelemetryData): Promise<any> {
178160
if (this._actionCallback) {
179161
return this._actionCallback(event);

src/vs/workbench/browser/parts/compositeBar.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ export interface ICompositeBarItem {
3030
}
3131

3232
export interface ICompositeBarOptions {
33-
icon: boolean;
34-
orientation: ActionsOrientation;
35-
colors: (theme: ITheme) => ICompositeBarColors;
36-
compositeSize: number;
37-
overflowActionSize: number;
33+
readonly icon: boolean;
34+
readonly orientation: ActionsOrientation;
35+
readonly colors: (theme: ITheme) => ICompositeBarColors;
36+
readonly compositeSize: number;
37+
readonly overflowActionSize: number;
38+
3839
getActivityAction: (compositeId: string) => ActivityAction;
3940
getCompositePinnedAction: (compositeId: string) => Action;
4041
getOnCompositeClickAction: (compositeId: string) => Action;

src/vs/workbench/browser/parts/compositeBarActions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,15 @@ export class CompositeOverflowActivityActionViewItem extends ActivityActionViewI
383383
this.contextMenuService.showContextMenu({
384384
getAnchor: () => this.container,
385385
getActions: () => this.actions,
386+
getCheckedActionsRepresentation: () => 'radio',
386387
onHide: () => dispose(this.actions)
387388
});
388389
}
389390

390391
private getActions(): Action[] {
391392
return this.getOverflowingComposites().map(composite => {
392393
const action = this.getCompositeOpenAction(composite.id);
393-
action.radio = this.getActiveCompositeId() === action.id;
394+
action.checked = this.getActiveCompositeId() === action.id;
394395

395396
const badge = this.getBadge(composite.id);
396397
let suffix: string | number | undefined;
@@ -614,8 +615,8 @@ export class CompositeActionViewItem extends ActivityActionViewItem {
614615

615616
this.contextMenuService.showContextMenu({
616617
getAnchor: () => anchor,
617-
getActionsContext: () => this.activity.id,
618-
getActions: () => actions
618+
getActions: () => actions,
619+
getActionsContext: () => this.activity.id
619620
});
620621
}
621622

src/vs/workbench/services/contextmenu/electron-browser/contextmenuService.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,19 @@ class NativeContextMenuService extends Disposable implements IContextMenuService
138138

139139
// Normal Menu Item
140140
else {
141+
let type: 'radio' | 'checkbox' | undefined = undefined;
142+
if (!!entry.checked) {
143+
if (typeof delegate.getCheckedActionsRepresentation === 'function') {
144+
type = delegate.getCheckedActionsRepresentation(entry);
145+
} else {
146+
type = 'checkbox';
147+
}
148+
}
149+
141150
const item: IContextMenuItem = {
142151
label: unmnemonicLabel(entry.label),
143-
checked: !!entry.checked || !!entry.radio,
144-
type: !!entry.checked ? 'checkbox' : !!entry.radio ? 'radio' : undefined,
152+
checked: !!entry.checked,
153+
type,
145154
enabled: !!entry.enabled,
146155
click: event => {
147156

@@ -188,4 +197,4 @@ class NativeContextMenuService extends Disposable implements IContextMenuService
188197
}
189198
}
190199

191-
registerSingleton(IContextMenuService, ContextMenuService, true);
200+
registerSingleton(IContextMenuService, ContextMenuService, true);

0 commit comments

Comments
 (0)