Skip to content

Commit

Permalink
fix #49465
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Oct 16, 2019
1 parent a97e8c3 commit 8a80677
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/vs/base/browser/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class ContextSubMenu extends SubmenuAction {
export interface IContextMenuDelegate {
getAnchor(): HTMLElement | { x: number; y: number; width?: number; height?: number; };
getActions(): ReadonlyArray<IAction | ContextSubMenu>;
getCheckedActionsRepresentation?(action: IAction): 'radio' | 'checkbox';
getActionViewItem?(action: IAction): IActionViewItem | undefined;
getActionsContext?(event?: IContextMenuEvent): any;
getKeyBinding?(action: IAction): ResolvedKeybinding | undefined;
Expand Down
1 change: 0 additions & 1 deletion src/vs/base/browser/ui/actionbar/actionbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ export class Separator extends Action {
constructor(label?: string) {
super(Separator.ID, label, label ? 'separator text' : 'separator');
this.checked = false;
this.radio = false;
this.enabled = false;
}
}
Expand Down
18 changes: 0 additions & 18 deletions src/vs/base/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export interface IAction extends IDisposable {
class: string | undefined;
enabled: boolean;
checked: boolean;
radio: boolean;
run(event?: any): Promise<any>;
}

Expand All @@ -54,7 +53,6 @@ export interface IActionChangeEvent {
readonly class?: string;
readonly enabled?: boolean;
readonly checked?: boolean;
readonly radio?: boolean;
}

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

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

get radio(): boolean {
return this._radio;
}

set radio(value: boolean) {
this._setRadio(value);
}

protected _setChecked(value: boolean): void {
if (this._checked !== value) {
this._checked = value;
this._onDidChange.fire({ checked: value });
}
}

protected _setRadio(value: boolean): void {
if (this._radio !== value) {
this._radio = value;
this._onDidChange.fire({ radio: value });
}
}

run(event?: any, _data?: ITelemetryData): Promise<any> {
if (this._actionCallback) {
return this._actionCallback(event);
Expand Down
11 changes: 6 additions & 5 deletions src/vs/workbench/browser/parts/compositeBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export interface ICompositeBarItem {
}

export interface ICompositeBarOptions {
icon: boolean;
orientation: ActionsOrientation;
colors: (theme: ITheme) => ICompositeBarColors;
compositeSize: number;
overflowActionSize: number;
readonly icon: boolean;
readonly orientation: ActionsOrientation;
readonly colors: (theme: ITheme) => ICompositeBarColors;
readonly compositeSize: number;
readonly overflowActionSize: number;

getActivityAction: (compositeId: string) => ActivityAction;
getCompositePinnedAction: (compositeId: string) => Action;
getOnCompositeClickAction: (compositeId: string) => Action;
Expand Down
7 changes: 4 additions & 3 deletions src/vs/workbench/browser/parts/compositeBarActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,15 @@ export class CompositeOverflowActivityActionViewItem extends ActivityActionViewI
this.contextMenuService.showContextMenu({
getAnchor: () => this.container,
getActions: () => this.actions,
getCheckedActionsRepresentation: () => 'radio',
onHide: () => dispose(this.actions)
});
}

private getActions(): Action[] {
return this.getOverflowingComposites().map(composite => {
const action = this.getCompositeOpenAction(composite.id);
action.radio = this.getActiveCompositeId() === action.id;
action.checked = this.getActiveCompositeId() === action.id;

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

this.contextMenuService.showContextMenu({
getAnchor: () => anchor,
getActionsContext: () => this.activity.id,
getActions: () => actions
getActions: () => actions,
getActionsContext: () => this.activity.id
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,19 @@ class NativeContextMenuService extends Disposable implements IContextMenuService

// Normal Menu Item
else {
let type: 'radio' | 'checkbox' | undefined = undefined;
if (!!entry.checked) {
if (typeof delegate.getCheckedActionsRepresentation === 'function') {
type = delegate.getCheckedActionsRepresentation(entry);
} else {
type = 'checkbox';
}
}

const item: IContextMenuItem = {
label: unmnemonicLabel(entry.label),
checked: !!entry.checked || !!entry.radio,
type: !!entry.checked ? 'checkbox' : !!entry.radio ? 'radio' : undefined,
checked: !!entry.checked,
type,
enabled: !!entry.enabled,
click: event => {

Expand Down Expand Up @@ -188,4 +197,4 @@ class NativeContextMenuService extends Disposable implements IContextMenuService
}
}

registerSingleton(IContextMenuService, ContextMenuService, true);
registerSingleton(IContextMenuService, ContextMenuService, true);

0 comments on commit 8a80677

Please sign in to comment.