@@ -13,9 +13,9 @@ import * as arrays from 'vs/base/common/arrays';
1313import { illegalArgument } from 'vs/base/common/errors' ;
1414import { Builder , $ , Dimension } from 'vs/base/browser/builder' ;
1515import { Action } from 'vs/base/common/actions' ;
16- import { ActionsOrientation , ActionBar , IActionItem , Separator } from 'vs/base/browser/ui/actionbar/actionbar' ;
16+ import { ActionsOrientation , ActionBar , IActionItem , Separator , IBaseActionItemOptions } from 'vs/base/browser/ui/actionbar/actionbar' ;
1717import { ViewletDescriptor } from 'vs/workbench/browser/viewlet' ;
18- import { IActivity , ActivityExtensions , IActivityRegistry } from 'vs/workbench/browser/activity' ;
18+ import { IGlobalActivity , GlobalActivityExtensions , IGlobalActivityRegistry } from 'vs/workbench/browser/activity' ;
1919import { Registry } from 'vs/platform/platform' ;
2020import { Part } from 'vs/workbench/browser/part' ;
2121import { IViewlet } from 'vs/workbench/common/viewlet' ;
@@ -29,7 +29,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
2929import { Scope as MementoScope } from 'vs/workbench/common/memento' ;
3030import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
3131import { StandardMouseEvent } from 'vs/base/browser/mouseEvent' ;
32- import { dispose , IDisposable } from 'vs/base/common/lifecycle' ;
32+ import { dispose , IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
3333import { ToggleActivityBarVisibilityAction } from 'vs/workbench/browser/actions/toggleActivityBarVisibility' ;
3434import { IThemeService } from 'vs/platform/theme/common/themeService' ;
3535import { ACTIVITY_BAR_BACKGROUND , ACTIVITY_BAR_BORDER } from 'vs/workbench/common/theme' ;
@@ -42,17 +42,36 @@ interface IViewletActivity {
4242
4343class GlobalActivityAction extends ActivityAction {
4444
45- constructor ( activity : IActivity ) {
45+ constructor ( activity : IGlobalActivity ) {
4646 super ( activity ) ;
4747 }
4848}
4949
5050class GlobalActivityActionItem extends ActivityActionItem {
5151
52- onClick ( event : Event ) : void {
53- DOM . EventHelper . stop ( event , true ) ;
54- console . log ( 'hello world' ) ;
55- // fire up native menu around this.builder.getHTMLElement()
52+ constructor (
53+ action : GlobalActivityAction ,
54+ options : IBaseActionItemOptions ,
55+ @IThemeService themeService : IThemeService ,
56+ @IContextMenuService protected contextMenuService : IContextMenuService
57+ ) {
58+ super ( action , options , themeService ) ;
59+ }
60+
61+ onClick ( e : MouseEvent ) : void {
62+ const globalAction = this . _action as GlobalActivityAction ;
63+ const activity = globalAction . activity as IGlobalActivity ;
64+ const actions = activity . getActions ( ) ;
65+
66+ const event = new StandardMouseEvent ( e ) ;
67+ event . stopPropagation ( ) ;
68+ event . preventDefault ( ) ;
69+
70+ this . contextMenuService . showContextMenu ( {
71+ getAnchor : ( ) => ( { x : event . posx , y : event . posy } ) ,
72+ getActions : ( ) => TPromise . as ( actions ) ,
73+ onHide : ( ) => dispose ( actions )
74+ } ) ;
5675 }
5776}
5877
@@ -70,6 +89,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
7089 private viewletOverflowAction : ViewletOverflowActivityAction ;
7190 private viewletOverflowActionItem : ViewletOverflowActivityActionItem ;
7291
92+ private globalActivityIdToActions : { [ globalActivityId : string ] : GlobalActivityAction ; } ;
7393 private viewletIdToActions : { [ viewletId : string ] : ActivityAction ; } ;
7494 private viewletIdToActionItems : { [ viewletId : string ] : IActionItem ; } ;
7595 private viewletIdToActivityStack : { [ viewletId : string ] : IViewletActivity [ ] ; } ;
@@ -90,6 +110,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
90110 ) {
91111 super ( id , { hasTitle : false } , themeService ) ;
92112
113+ this . globalActivityIdToActions = Object . create ( null ) ;
93114 this . viewletIdToActionItems = Object . create ( null ) ;
94115 this . viewletIdToActions = Object . create ( null ) ;
95116 this . viewletIdToActivityStack = Object . create ( null ) ;
@@ -142,6 +163,21 @@ export class ActivitybarPart extends Part implements IActivityBarService {
142163 }
143164 }
144165
166+ public showGlobalActivity ( globalActivityId : string , badge : IBadge ) : IDisposable {
167+ if ( ! badge ) {
168+ throw illegalArgument ( 'badge' ) ;
169+ }
170+
171+ const action = this . globalActivityIdToActions [ globalActivityId ] ;
172+
173+ if ( ! action ) {
174+ throw illegalArgument ( 'globalActivityId' ) ;
175+ }
176+
177+ action . setBadge ( badge ) ;
178+ return toDisposable ( ( ) => action . setBadge ( undefined ) ) ;
179+ }
180+
145181 public showActivity ( viewletId : string , badge : IBadge , clazz ?: string ) : IDisposable {
146182 if ( ! badge ) {
147183 throw illegalArgument ( 'badge' ) ;
@@ -275,7 +311,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
275311 }
276312
277313 private createGlobalActivityActionBar ( container : HTMLElement ) : void {
278- const activityRegistry = Registry . as < IActivityRegistry > ( ActivityExtensions ) ;
314+ const activityRegistry = Registry . as < IGlobalActivityRegistry > ( GlobalActivityExtensions ) ;
279315 const descriptors = activityRegistry . getActivities ( ) ;
280316 const actions = descriptors
281317 . map ( d => this . instantiationService . createInstance ( d ) )
@@ -288,13 +324,10 @@ export class ActivitybarPart extends Part implements IActivityBarService {
288324 animated : false
289325 } ) ;
290326
291- actions . forEach ( a => this . activityActionBar . push ( a ) ) ;
292-
293- this . updateGlobalSwitcher ( ) ;
294- }
295-
296- private updateGlobalSwitcher ( ) : void {
297-
327+ actions . forEach ( a => {
328+ this . globalActivityIdToActions [ a . id ] = a ;
329+ this . activityActionBar . push ( a ) ;
330+ } ) ;
298331 }
299332
300333 private updateViewletSwitcher ( ) {
0 commit comments