Skip to content

Commit 77b5058

Browse files
committed
web - change homeindicator to href instead of command
1 parent 63b766f commit 77b5058

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface IActionViewItem extends IDisposable {
3131
export interface IBaseActionViewItemOptions {
3232
draggable?: boolean;
3333
isMenu?: boolean;
34+
useEventAsContext?: boolean;
3435
}
3536

3637
export class BaseActionViewItem extends Disposable implements IActionViewItem {
@@ -178,7 +179,7 @@ export class BaseActionViewItem extends Disposable implements IActionViewItem {
178179
onClick(event: DOM.EventLike): void {
179180
DOM.EventHelper.stop(event, true);
180181

181-
const context = types.isUndefinedOrNull(this._context) ? undefined : this._context;
182+
const context = types.isUndefinedOrNull(this._context) ? this.options?.useEventAsContext ? event : undefined : this._context;
182183
this.actionRunner.run(this._action, context);
183184
}
184185

src/vs/workbench/browser/parts/activitybar/activitybarActions.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/bro
2626
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
2727
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2828
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
29-
import { ICommandService } from 'vs/platform/commands/common/commands';
3029
import { Codicon } from 'vs/base/common/codicons';
30+
import { ActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
31+
import { isMacintosh } from 'vs/base/common/platform';
3132

3233
export class ViewContainerActivityAction extends ActivityAction {
3334

@@ -288,16 +289,33 @@ export class NextSideBarViewAction extends SwitchSideBarViewAction {
288289
export class HomeAction extends Action {
289290

290291
constructor(
291-
private readonly command: string,
292+
private readonly href: string,
292293
name: string,
293-
icon: Codicon,
294-
@ICommandService private readonly commandService: ICommandService
294+
icon: Codicon
295295
) {
296296
super('workbench.action.home', name, icon.classNames);
297297
}
298298

299-
async run(): Promise<void> {
300-
this.commandService.executeCommand(this.command);
299+
async run(event: MouseEvent): Promise<void> {
300+
let openInNewWindow = false;
301+
if (isMacintosh) {
302+
openInNewWindow = event.metaKey;
303+
} else {
304+
openInNewWindow = event.ctrlKey;
305+
}
306+
307+
if (openInNewWindow) {
308+
DOM.windowOpenNoOpener(this.href);
309+
} else {
310+
window.location.href = this.href;
311+
}
312+
}
313+
}
314+
315+
export class HomeActionViewItem extends ActionViewItem {
316+
317+
constructor(action: IAction) {
318+
super(undefined, action, { icon: true, label: false, useEventAsContext: true });
301319
}
302320
}
303321

src/vs/workbench/browser/parts/activitybar/activitybarPart.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
88
import { ActionsOrientation, ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
99
import { GLOBAL_ACTIVITY_ID, IActivity, ACCOUNTS_ACTIIVTY_ID } from 'vs/workbench/common/activity';
1010
import { Part } from 'vs/workbench/browser/part';
11-
import { GlobalActivityActionViewItem, ViewContainerActivityAction, PlaceHolderToggleCompositePinnedAction, PlaceHolderViewContainerActivityAction, AccountsActionViewItem, HomeAction } from 'vs/workbench/browser/parts/activitybar/activitybarActions';
11+
import { GlobalActivityActionViewItem, ViewContainerActivityAction, PlaceHolderToggleCompositePinnedAction, PlaceHolderViewContainerActivityAction, AccountsActionViewItem, HomeAction, HomeActionViewItem } from 'vs/workbench/browser/parts/activitybar/activitybarActions';
1212
import { IBadge, NumberBadge } from 'vs/workbench/services/activity/common/activity';
1313
import { IWorkbenchLayoutService, Parts, Position as SideBarPosition } from 'vs/workbench/services/layout/browser/layoutService';
1414
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -362,7 +362,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
362362
console.warn(`Unknown home indicator icon ${homeIndicator.icon}`);
363363
codicon = Codicon.code;
364364
}
365-
this.createHomeBar(homeIndicator.command, homeIndicator.title, codicon);
365+
this.createHomeBar(homeIndicator.href, homeIndicator.title, codicon);
366366
}
367367

368368
// Install menubar if compact
@@ -383,22 +383,24 @@ export class ActivitybarPart extends Part implements IActivityBarService {
383383
return this.content;
384384
}
385385

386-
private createHomeBar(command: string, title: string, icon: Codicon): void {
386+
private createHomeBar(href: string, title: string, icon: Codicon): void {
387387
this.homeBarContainer = document.createElement('div');
388388
this.homeBarContainer.setAttribute('aria-label', nls.localize('homeIndicator', "Home"));
389389
this.homeBarContainer.setAttribute('role', 'toolbar');
390390
addClass(this.homeBarContainer, 'home-bar');
391391

392392
this.homeBar = this._register(new ActionBar(this.homeBarContainer, {
393393
orientation: ActionsOrientation.VERTICAL,
394-
animated: false
394+
animated: false,
395+
ariaLabel: nls.localize('home', "Home"),
396+
actionViewItemProvider: action => new HomeActionViewItem(action)
395397
}));
396398

397399
const homeBarIconBadge = document.createElement('div');
398400
addClass(homeBarIconBadge, 'home-bar-icon-badge');
399401
this.homeBarContainer.appendChild(homeBarIconBadge);
400402

401-
this.homeBar.push(this._register(this.instantiationService.createInstance(HomeAction, command, title, icon)), { icon: true, label: false });
403+
this.homeBar.push(this._register(this.instantiationService.createInstance(HomeAction, href, title, icon)));
402404

403405
const content = assertIsDefined(this.content);
404406
content.prepend(this.homeBarContainer);

src/vs/workbench/workbench.web.api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ interface ICommand {
8989
interface IHomeIndicator {
9090

9191
/**
92-
* The identifier of the command to run when clicking the home indicator.
92+
* The link to open when clicking the home indicator.
9393
*/
94-
command: string;
94+
href: string;
9595

9696
/**
9797
* The icon name for the home indicator. This needs to be one of the existing

0 commit comments

Comments
 (0)