@@ -10,7 +10,7 @@ import { ColorIdentifier } from 'vs/platform/theme/common/colorRegistry';
1010import { attachStyler , IColorMapping } from 'vs/platform/theme/common/styler' ;
1111import { SIDE_BAR_DRAG_AND_DROP_BACKGROUND , SIDE_BAR_SECTION_HEADER_FOREGROUND , SIDE_BAR_SECTION_HEADER_BACKGROUND , SIDE_BAR_SECTION_HEADER_BORDER } from 'vs/workbench/common/theme' ;
1212import { append , $ , trackFocus , toggleClass , EventType , isAncestor , Dimension , addDisposableListener } from 'vs/base/browser/dom' ;
13- import { IDisposable , combinedDisposable , dispose , toDisposable , Disposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
13+ import { IDisposable , combinedDisposable , dispose , toDisposable } from 'vs/base/common/lifecycle' ;
1414import { firstIndex } from 'vs/base/common/arrays' ;
1515import { IAction , IActionRunner , ActionRunner } from 'vs/base/common/actions' ;
1616import { IActionViewItem , ActionsOrientation , Separator } from 'vs/base/browser/ui/actionbar/actionbar' ;
@@ -25,7 +25,7 @@ import { PaneView, IPaneViewOptions, IPaneOptions, Pane, DefaultPaneDndControlle
2525import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
2626import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService' ;
2727import { StandardMouseEvent } from 'vs/base/browser/mouseEvent' ;
28- import { Extensions as ViewContainerExtensions , IView , FocusedViewContext , IViewContainersRegistry , IViewDescriptor , ViewContainer , IViewDescriptorService , Extensions as ViewsExtensions , ViewContainerLocation , IViewsService , IViewsRegistry } from 'vs/workbench/common/views' ;
28+ import { Extensions as ViewContainerExtensions , IView , FocusedViewContext , IViewContainersRegistry , IViewDescriptor , ViewContainer , IViewDescriptorService , ViewContainerLocation , IViewsService } from 'vs/workbench/common/views' ;
2929import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
3030import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
3131import { assertIsDefined } from 'vs/base/common/types' ;
@@ -36,8 +36,9 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
3636import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
3737import { IViewPaneContainer } from 'vs/workbench/common/viewPaneContainer' ;
3838import { Component } from 'vs/workbench/common/component' ;
39- import { IMenuService , MenuId , MenuItemAction } from 'vs/platform/actions/common/actions' ;
40- import { createAndFillInActionBarActions , ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
39+ import { MenuId , MenuItemAction } from 'vs/platform/actions/common/actions' ;
40+ import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
41+ import { ViewMenuActions } from 'vs/workbench/browser/parts/views/viewMenuActions' ;
4142
4243export interface IPaneColors extends IColorMapping {
4344 dropBackground ?: ColorIdentifier ;
@@ -76,7 +77,7 @@ export abstract class ViewPane extends Pane implements IView {
7677 readonly id : string ;
7778 title : string ;
7879
79- private readonly menuActions ? : ViewMenuActions ;
80+ private readonly menuActions : ViewMenuActions ;
8081
8182 protected actionRunner ?: IActionRunner ;
8283 protected toolbar ?: ToolBar ;
@@ -101,10 +102,8 @@ export abstract class ViewPane extends Pane implements IView {
101102 this . showActionsAlways = ! ! options . showActionsAlways ;
102103 this . focusedViewContextKey = FocusedViewContext . bindTo ( contextKeyService ) ;
103104
104- if ( options . titleMenuId !== undefined ) {
105- this . menuActions = this . _register ( instantiationService . createInstance ( ViewMenuActions , this . id , options . titleMenuId ) ) ;
106- this . _register ( this . menuActions . onDidChangeTitle ( ( ) => this . updateActions ( ) ) ) ;
107- }
105+ this . menuActions = this . _register ( instantiationService . createInstance ( ViewMenuActions , this . id , options . titleMenuId || MenuId . ViewTitle , MenuId . ViewTitleContext ) ) ;
106+ this . _register ( this . menuActions . onDidChangeTitle ( ( ) => this . updateActions ( ) ) ) ;
108107 }
109108
110109 setVisible ( visible : boolean ) : void {
@@ -225,6 +224,10 @@ export abstract class ViewPane extends Pane implements IView {
225224 return this . menuActions ? this . menuActions . getSecondaryActions ( ) : [ ] ;
226225 }
227226
227+ getContextMenuActions ( ) : IAction [ ] {
228+ return this . menuActions ? this . menuActions . getContextMenuActions ( ) : [ ] ;
229+ }
230+
228231 getActionViewItem ( action : IAction ) : IActionViewItem | undefined {
229232 if ( action instanceof MenuItemAction ) {
230233 return this . instantiationService . createInstance ( ContextAwareMenuEntryActionViewItem , action ) ;
@@ -391,55 +394,39 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
391394 }
392395
393396 getContextMenuActions ( viewDescriptor ?: IViewDescriptor ) : IAction [ ] {
397+ const result : IAction [ ] = [ ] ;
394398
395- if ( this . isViewMergedWithContainer ( ) ) {
396- const viewId = this . panes [ 0 ] . id ;
397- viewDescriptor = Registry . as < IViewsRegistry > ( ViewsExtensions . ViewsRegistry ) . getView ( viewId ) ! ;
399+ if ( ! viewDescriptor && this . isViewMergedWithContainer ( ) ) {
400+ viewDescriptor = this . viewDescriptorService . getViewDescriptor ( this . panes [ 0 ] . id ) || undefined ;
398401 }
399402
400- const viewContainerRegistry = Registry . as < IViewContainersRegistry > ( ViewsExtensions . ViewContainersRegistry ) ;
401- const currentLocation = viewContainerRegistry . getViewContainerLocation ( this . viewContainer ) ;
402-
403- const result : IAction [ ] = [ ] ;
404403 if ( viewDescriptor ) {
405- // For now, restrict any additional actions to the sidebar only
406- if ( ! this . isViewMergedWithContainer ( ) && currentLocation === ViewContainerLocation . Sidebar ) {
407- result . push ( < IAction > {
408- id : `${ viewDescriptor . id } .removeView` ,
409- label : nls . localize ( 'hideView' , "Hide" ) ,
410- enabled : viewDescriptor . canToggleVisibility ,
411- run : ( ) => this . toggleViewVisibility ( viewDescriptor ! . id )
412- } ) ;
413- }
414-
415- if ( viewDescriptor . canMoveView ) {
416- const newLocation = currentLocation === ViewContainerLocation . Panel ? ViewContainerLocation . Sidebar : ViewContainerLocation . Panel ;
417- result . push ( < IAction > {
418- id : `${ viewDescriptor . id } .moveView` ,
419- label : newLocation === ViewContainerLocation . Sidebar ? nls . localize ( 'moveViewToSidebar' , "Move to Sidebar" ) : nls . localize ( 'moveViewToPanel' , "Move to Panel" ) ,
420- enabled : true ,
421- run : ( ) => this . moveView ( viewDescriptor ! , newLocation )
422- } ) ;
404+ result . push ( < IAction > {
405+ id : `${ viewDescriptor . id } .removeView` ,
406+ label : nls . localize ( 'hideView' , "Hide" ) ,
407+ enabled : viewDescriptor . canToggleVisibility ,
408+ run : ( ) => this . toggleViewVisibility ( viewDescriptor ! . id )
409+ } ) ;
410+ const view = this . getView ( viewDescriptor . id ) ;
411+ if ( view ) {
412+ result . push ( ...view . getContextMenuActions ( ) ) ;
423413 }
424414 }
425415
426- // For now, restrict any additional actions to the sidebar only
427- if ( currentLocation === ViewContainerLocation . Sidebar ) {
428- const viewToggleActions = this . viewsModel . viewDescriptors . map ( viewDescriptor => ( < IAction > {
429- id : `${ viewDescriptor . id } .toggleVisibility` ,
430- label : viewDescriptor . name ,
431- checked : this . viewsModel . isVisible ( viewDescriptor . id ) ,
432- enabled : viewDescriptor . canToggleVisibility ,
433- run : ( ) => this . toggleViewVisibility ( viewDescriptor . id )
434- } ) ) ;
435-
436- if ( result . length && viewToggleActions . length ) {
437- result . push ( new Separator ( ) ) ;
438- }
416+ const viewToggleActions = this . viewsModel . viewDescriptors . map ( viewDescriptor => ( < IAction > {
417+ id : `${ viewDescriptor . id } .toggleVisibility` ,
418+ label : viewDescriptor . name ,
419+ checked : this . viewsModel . isVisible ( viewDescriptor . id ) ,
420+ enabled : viewDescriptor . canToggleVisibility ,
421+ run : ( ) => this . toggleViewVisibility ( viewDescriptor . id )
422+ } ) ) ;
439423
440- result . push ( ...viewToggleActions ) ;
424+ if ( result . length && viewToggleActions . length ) {
425+ result . push ( new Separator ( ) ) ;
441426 }
442427
428+ result . push ( ...viewToggleActions ) ;
429+
443430 return result ;
444431 }
445432
@@ -803,50 +790,3 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
803790 }
804791 }
805792}
806-
807-
808- class ViewMenuActions extends Disposable {
809-
810- private primaryActions : IAction [ ] = [ ] ;
811- private readonly titleActionsDisposable = this . _register ( new MutableDisposable ( ) ) ;
812- private secondaryActions : IAction [ ] = [ ] ;
813-
814- private _onDidChangeTitle = this . _register ( new Emitter < void > ( ) ) ;
815- readonly onDidChangeTitle : Event < void > = this . _onDidChangeTitle . event ;
816-
817- constructor (
818- viewId : string ,
819- menuId : MenuId ,
820- @IContextKeyService private readonly contextKeyService : IContextKeyService ,
821- @IMenuService private readonly menuService : IMenuService ,
822- ) {
823- super ( ) ;
824-
825- const scopedContextKeyService = this . _register ( this . contextKeyService . createScoped ( ) ) ;
826- scopedContextKeyService . createKey ( 'view' , viewId ) ;
827-
828- const menu = this . _register ( this . menuService . createMenu ( menuId , scopedContextKeyService ) ) ;
829- const updateActions = ( ) => {
830- this . primaryActions = [ ] ;
831- this . secondaryActions = [ ] ;
832- this . titleActionsDisposable . value = createAndFillInActionBarActions ( menu , undefined , { primary : this . primaryActions , secondary : this . secondaryActions } ) ;
833- this . _onDidChangeTitle . fire ( ) ;
834- } ;
835-
836- this . _register ( menu . onDidChange ( updateActions ) ) ;
837- updateActions ( ) ;
838-
839- this . _register ( toDisposable ( ( ) => {
840- this . primaryActions = [ ] ;
841- this . secondaryActions = [ ] ;
842- } ) ) ;
843- }
844-
845- getPrimaryActions ( ) : IAction [ ] {
846- return this . primaryActions ;
847- }
848-
849- getSecondaryActions ( ) : IAction [ ] {
850- return this . secondaryActions ;
851- }
852- }
0 commit comments