@@ -13,16 +13,16 @@ import { TPromise } from 'vs/base/common/winjs.base';
1313import { Builder , $ } from 'vs/base/browser/builder' ;
1414import { DelayedDragHandler } from 'vs/base/browser/dnd' ;
1515import { Action } from 'vs/base/common/actions' ;
16- import { BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar' ;
17- import { ProgressBadge , TextBadge , NumberBadge , IconBadge , IBadge } from 'vs/workbench/services/activity/common/activityService ' ;
16+ import { BaseActionItem , Separator } from 'vs/base/browser/ui/actionbar/actionbar' ;
17+ import { IActivityBarService , ProgressBadge , TextBadge , NumberBadge , IconBadge , IBadge } from 'vs/workbench/services/activity/common/activityBarService ' ;
1818import Event , { Emitter } from 'vs/base/common/event' ;
1919import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
2020import { ICommandService } from 'vs/platform/commands/common/commands' ;
2121import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
2222import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
2323import { ViewletDescriptor } from 'vs/workbench/browser/viewlet' ;
2424import { dispose , IDisposable } from 'vs/base/common/lifecycle' ;
25- import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet' ;
25+ import { IViewletService , } from 'vs/workbench/services/viewlet/browser/viewlet' ;
2626import { IPartService , Parts } from 'vs/workbench/services/part/common/partService' ;
2727
2828export class ActivityAction extends Action {
@@ -105,7 +105,6 @@ export class ViewletActivityAction extends ActivityAction {
105105export class ViewletOverflowActivityAction extends ActivityAction {
106106
107107 constructor (
108- private viewlets : ViewletDescriptor [ ] ,
109108 private showMenu : ( ) => void
110109 ) {
111110 super ( 'activitybar.additionalViewlets.action' , nls . localize ( 'additionalViewlets' , "Additional Viewlets" ) , 'toggle-more' ) ;
@@ -126,7 +125,7 @@ export class ViewletOverflowActivityActionItem extends BaseActionItem {
126125
127126 constructor (
128127 action : ActivityAction ,
129- private viewlets : ViewletDescriptor [ ] ,
128+ private getOverflowingViewlets : ( ) => ViewletDescriptor [ ] ,
130129 private getBadge : ( viewlet : ViewletDescriptor ) => IBadge ,
131130 @IInstantiationService private instantiationService : IInstantiationService ,
132131 @IViewletService private viewletService : IViewletService ,
@@ -136,7 +135,6 @@ export class ViewletOverflowActivityActionItem extends BaseActionItem {
136135
137136 this . cssClass = action . class ;
138137 this . name = action . label ;
139- this . actions = viewlets . map ( viewlet => this . instantiationService . createInstance ( OpenViewletAction , viewlet ) ) ;
140138 }
141139
142140 public render ( container : HTMLElement ) : void {
@@ -151,18 +149,24 @@ export class ViewletOverflowActivityActionItem extends BaseActionItem {
151149 }
152150
153151 public showMenu ( ) : void {
154- this . updateActions ( ) ;
152+ if ( this . actions ) {
153+ dispose ( this . actions ) ;
154+ }
155+
156+ this . actions = this . getActions ( ) ;
155157
156158 this . contextMenuService . showContextMenu ( {
157159 getAnchor : ( ) => this . builder . getHTMLElement ( ) ,
158- getActions : ( ) => TPromise . as ( this . actions )
160+ getActions : ( ) => TPromise . as ( this . actions ) ,
161+ onHide : ( ) => dispose ( this . actions )
159162 } ) ;
160163 }
161164
162- private updateActions ( ) : void {
165+ private getActions ( ) : OpenViewletAction [ ] {
163166 const activeViewlet = this . viewletService . getActiveViewlet ( ) ;
164167
165- this . actions . forEach ( action => {
168+ return this . getOverflowingViewlets ( ) . map ( viewlet => {
169+ const action = this . instantiationService . createInstance ( OpenViewletAction , viewlet ) ;
166170 action . radio = activeViewlet && activeViewlet . getId ( ) === action . id ;
167171
168172 const badge = this . getBadge ( action . viewlet ) ;
@@ -178,6 +182,8 @@ export class ViewletOverflowActivityActionItem extends BaseActionItem {
178182 } else {
179183 action . label = action . viewlet . name ;
180184 }
185+
186+ return action ;
181187 } ) ;
182188 }
183189
@@ -188,8 +194,11 @@ export class ViewletOverflowActivityActionItem extends BaseActionItem {
188194 }
189195}
190196
191- let manageExtensionAction : ManageExtensionAction ;
192197export class ActivityActionItem extends BaseActionItem {
198+
199+ private static manageExtensionAction : ManageExtensionAction ;
200+ private static toggleViewletPinnedAction : ToggleViewletPinnedAction ;
201+
193202 private $e : Builder ;
194203 private name : string ;
195204 private _keybinding : string ;
@@ -202,6 +211,8 @@ export class ActivityActionItem extends BaseActionItem {
202211 action : ActivityAction ,
203212 private viewlet : ViewletDescriptor ,
204213 @IContextMenuService private contextMenuService : IContextMenuService ,
214+ @IViewletService private viewletService : IViewletService ,
215+ @IActivityBarService private activityBarService : IActivityBarService ,
205216 @IKeybindingService private keybindingService : IKeybindingService ,
206217 @IInstantiationService instantiationService : IInstantiationService
207218 ) {
@@ -212,8 +223,12 @@ export class ActivityActionItem extends BaseActionItem {
212223 this . _keybinding = this . getKeybindingLabel ( viewlet . id ) ;
213224 action . onDidChangeBadge ( this . handleBadgeChangeEvenet , this , this . _callOnDispose ) ;
214225
215- if ( ! manageExtensionAction ) {
216- manageExtensionAction = instantiationService . createInstance ( ManageExtensionAction ) ;
226+ if ( ! ActivityActionItem . manageExtensionAction ) {
227+ ActivityActionItem . manageExtensionAction = instantiationService . createInstance ( ManageExtensionAction ) ;
228+ }
229+
230+ if ( ! ActivityActionItem . toggleViewletPinnedAction ) {
231+ ActivityActionItem . toggleViewletPinnedAction = instantiationService . createInstance ( ToggleViewletPinnedAction , void 0 ) ;
217232 }
218233 }
219234
@@ -234,17 +249,11 @@ export class ActivityActionItem extends BaseActionItem {
234249 role : 'button'
235250 } ) . appendTo ( this . builder ) ;
236251
237- if ( this . viewlet . extensionId ) {
238- $ ( container ) . on ( 'contextmenu' , e => {
239- DOM . EventHelper . stop ( e , true ) ;
240-
241- this . contextMenuService . showContextMenu ( {
242- getAnchor : ( ) => container ,
243- getActionsContext : ( ) => this . viewlet . extensionId ,
244- getActions : ( ) => TPromise . as ( [ manageExtensionAction ] )
245- } ) ;
246- } , this . toDispose ) ;
247- }
252+ $ ( container ) . on ( 'contextmenu' , e => {
253+ DOM . EventHelper . stop ( e , true ) ;
254+
255+ this . showContextMenu ( container ) ;
256+ } , this . toDispose ) ;
248257
249258 if ( this . cssClass ) {
250259 this . $e . addClass ( this . cssClass ) ;
@@ -266,6 +275,27 @@ export class ActivityActionItem extends BaseActionItem {
266275 } ) ) ;
267276 }
268277
278+ private showContextMenu ( container : HTMLElement ) : void {
279+ const actions : Action [ ] = [ ActivityActionItem . toggleViewletPinnedAction ] ;
280+ if ( this . viewlet . extensionId ) {
281+ actions . push ( new Separator ( ) ) ;
282+ actions . push ( ActivityActionItem . manageExtensionAction ) ;
283+ }
284+
285+ const isPinned = this . activityBarService . isPinned ( this . viewlet . id ) ;
286+ if ( isPinned ) {
287+ ActivityActionItem . toggleViewletPinnedAction . label = nls . localize ( 'removeFromActivityBar' , "Remove from Activity Bar" ) ;
288+ } else {
289+ ActivityActionItem . toggleViewletPinnedAction . label = nls . localize ( 'keepInActivityBar' , "Keep in Activity Bar" ) ;
290+ }
291+
292+ this . contextMenuService . showContextMenu ( {
293+ getAnchor : ( ) => container ,
294+ getActionsContext : ( ) => this . viewlet ,
295+ getActions : ( ) => TPromise . as ( actions )
296+ } ) ;
297+ }
298+
269299 public focus ( ) : void {
270300 this . $e . domFocus ( ) ;
271301 }
@@ -376,8 +406,8 @@ class ManageExtensionAction extends Action {
376406 super ( 'activitybar.manage.extension' , nls . localize ( 'manageExtension' , "Manage Extension" ) ) ;
377407 }
378408
379- public run ( extensionId : string ) : TPromise < any > {
380- return this . commandService . executeCommand ( '_extensions.manage' , extensionId ) ;
409+ public run ( viewlet : ViewletDescriptor ) : TPromise < any > {
410+ return this . commandService . executeCommand ( '_extensions.manage' , viewlet . extensionId ) ;
381411 }
382412}
383413
@@ -402,6 +432,30 @@ class OpenViewletAction extends Action {
402432 this . viewletService . openViewlet ( this . viewlet . id , true ) . done ( null , errors . onUnexpectedError ) ;
403433 }
404434
435+ return TPromise . as ( true ) ;
436+ }
437+ }
438+
439+ export class ToggleViewletPinnedAction extends Action {
440+
441+ constructor (
442+ private viewlet : ViewletDescriptor ,
443+ @IActivityBarService private activityBarService : IActivityBarService
444+ ) {
445+ super ( 'activitybar.show.toggleViewletPinned' , viewlet ? viewlet . name : nls . localize ( 'toggle' , "Toggle Viewlet Pinned" ) ) ;
446+
447+ this . checked = this . viewlet && this . activityBarService . isPinned ( this . viewlet . id ) ;
448+ }
449+
450+ public run ( context ?: ViewletDescriptor ) : TPromise < any > {
451+ const viewlet = this . viewlet || context ;
452+
453+ if ( this . activityBarService . isPinned ( viewlet . id ) ) {
454+ this . activityBarService . unpin ( viewlet . id ) ;
455+ } else {
456+ this . activityBarService . pin ( viewlet . id ) ;
457+ }
458+
405459 return TPromise . as ( true ) ;
406460 }
407461}
0 commit comments