@@ -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 } from 'vs/workbench/common/views' ;
28+ import { Extensions as ViewContainerExtensions , IView , FocusedViewContext , IViewContainersRegistry , IViewDescriptor , ViewContainer , IViewDescriptorService } 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 ) ;
@@ -307,7 +310,8 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
307310 @IExtensionService protected extensionService : IExtensionService ,
308311 @IThemeService protected themeService : IThemeService ,
309312 @IStorageService protected storageService : IStorageService ,
310- @IWorkspaceContextService protected contextService : IWorkspaceContextService
313+ @IWorkspaceContextService protected contextService : IWorkspaceContextService ,
314+ @IViewDescriptorService protected viewDescriptorService : IViewDescriptorService
311315 ) {
312316
313317 super ( id , themeService , storageService ) ;
@@ -390,13 +394,22 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
390394
391395 getContextMenuActions ( viewDescriptor ?: IViewDescriptor ) : IAction [ ] {
392396 const result : IAction [ ] = [ ] ;
397+
398+ if ( ! viewDescriptor && this . isViewMergedWithContainer ( ) ) {
399+ viewDescriptor = this . viewDescriptorService . getViewDescriptor ( this . panes [ 0 ] . id ) || undefined ;
400+ }
401+
393402 if ( viewDescriptor ) {
394403 result . push ( < IAction > {
395404 id : `${ viewDescriptor . id } .removeView` ,
396405 label : nls . localize ( 'hideView' , "Hide" ) ,
397406 enabled : viewDescriptor . canToggleVisibility ,
398- run : ( ) => this . toggleViewVisibility ( viewDescriptor . id )
407+ run : ( ) => this . toggleViewVisibility ( viewDescriptor ! . id )
399408 } ) ;
409+ const view = this . getView ( viewDescriptor . id ) ;
410+ if ( view ) {
411+ result . push ( ...view . getContextMenuActions ( ) ) ;
412+ }
400413 }
401414
402415 const viewToggleActions = this . viewsModel . viewDescriptors . map ( viewDescriptor => ( < IAction > {
@@ -412,6 +425,7 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
412425 }
413426
414427 result . push ( ...viewToggleActions ) ;
428+
415429 return result ;
416430 }
417431
@@ -653,7 +667,6 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
653667 this . viewsModel . setVisible ( viewId , visible ) ;
654668 }
655669
656-
657670 private addPane ( pane : ViewPane , size : number , index = this . paneItems . length - 1 ) : void {
658671 const onDidFocus = pane . onDidFocus ( ( ) => this . lastFocusedPane = pane ) ;
659672 const onDidChangeTitleArea = pane . onDidChangeTitleArea ( ( ) => {
@@ -771,50 +784,3 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
771784 }
772785 }
773786}
774-
775-
776- class ViewMenuActions extends Disposable {
777-
778- private primaryActions : IAction [ ] = [ ] ;
779- private readonly titleActionsDisposable = this . _register ( new MutableDisposable ( ) ) ;
780- private secondaryActions : IAction [ ] = [ ] ;
781-
782- private _onDidChangeTitle = this . _register ( new Emitter < void > ( ) ) ;
783- readonly onDidChangeTitle : Event < void > = this . _onDidChangeTitle . event ;
784-
785- constructor (
786- viewId : string ,
787- menuId : MenuId ,
788- @IContextKeyService private readonly contextKeyService : IContextKeyService ,
789- @IMenuService private readonly menuService : IMenuService ,
790- ) {
791- super ( ) ;
792-
793- const scopedContextKeyService = this . _register ( this . contextKeyService . createScoped ( ) ) ;
794- scopedContextKeyService . createKey ( 'view' , viewId ) ;
795-
796- const menu = this . _register ( this . menuService . createMenu ( menuId , scopedContextKeyService ) ) ;
797- const updateActions = ( ) => {
798- this . primaryActions = [ ] ;
799- this . secondaryActions = [ ] ;
800- this . titleActionsDisposable . value = createAndFillInActionBarActions ( menu , undefined , { primary : this . primaryActions , secondary : this . secondaryActions } ) ;
801- this . _onDidChangeTitle . fire ( ) ;
802- } ;
803-
804- this . _register ( menu . onDidChange ( updateActions ) ) ;
805- updateActions ( ) ;
806-
807- this . _register ( toDisposable ( ( ) => {
808- this . primaryActions = [ ] ;
809- this . secondaryActions = [ ] ;
810- } ) ) ;
811- }
812-
813- getPrimaryActions ( ) : IAction [ ] {
814- return this . primaryActions ;
815- }
816-
817- getSecondaryActions ( ) : IAction [ ] {
818- return this . secondaryActions ;
819- }
820- }
0 commit comments