44 *--------------------------------------------------------------------------------------------*/
55
66import 'vs/css!./media/titlebarpart' ;
7- import { dirname , posix } from 'vs/base/common/path' ;
87import * as resources from 'vs/base/common/resources' ;
98import { Part } from 'vs/workbench/browser/part' ;
109import { ITitleService , ITitleProperties } from 'vs/workbench/services/title/common/titleService' ;
1110import { getZoomFactor } from 'vs/base/browser/browser' ;
12- import { IWindowService , IWindowsService , MenuBarVisibility , getTitleBarStyle } from 'vs/platform/windows/common/windows' ;
11+ import { IWindowService , MenuBarVisibility , getTitleBarStyle } from 'vs/platform/windows/common/windows' ;
1312import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
1413import { StandardMouseEvent } from 'vs/base/browser/mouseEvent' ;
15- import { IAction , Action } from 'vs/base/common/actions' ;
14+ import { IAction } from 'vs/base/common/actions' ;
1615import { IConfigurationService , IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration' ;
1716import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
18- import { DisposableStore } from 'vs/base/common/lifecycle' ;
17+ import { DisposableStore , dispose } from 'vs/base/common/lifecycle' ;
1918import * as nls from 'vs/nls' ;
2019import { EditorInput , toResource , Verbosity , SideBySideEditor } from 'vs/workbench/common/editor' ;
2120import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
@@ -29,14 +28,17 @@ import { trim } from 'vs/base/common/strings';
2928import { EventType , EventHelper , Dimension , isAncestor , hide , show , removeClass , addClass , append , $ , addDisposableListener , runAtThisOrScheduleAtNextAnimationFrame } from 'vs/base/browser/dom' ;
3029import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl' ;
3130import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
32- import { template , getBaseLabel } from 'vs/base/common/labels' ;
31+ import { template } from 'vs/base/common/labels' ;
3332import { ILabelService } from 'vs/platform/label/common/label' ;
3433import { Event , Emitter } from 'vs/base/common/event' ;
3534import { IStorageService } from 'vs/platform/storage/common/storage' ;
3635import { Parts , IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService' ;
3736import { RunOnceScheduler } from 'vs/base/common/async' ;
3837import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
3938import { Schemas } from 'vs/base/common/network' ;
39+ import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
40+ import { IMenuService , IMenu , MenuId } from 'vs/platform/actions/common/actions' ;
41+ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
4042
4143export class TitlebarPart extends Part implements ITitleService {
4244
@@ -71,7 +73,6 @@ export class TitlebarPart extends Part implements ITitleService {
7173 private lastLayoutDimensions : Dimension ;
7274
7375 private pendingTitle : string ;
74- private representedFileName : string ;
7576
7677 private isInactive : boolean ;
7778
@@ -80,22 +81,27 @@ export class TitlebarPart extends Part implements ITitleService {
8081
8182 private titleUpdater : RunOnceScheduler = this . _register ( new RunOnceScheduler ( ( ) => this . doUpdateTitle ( ) , 0 ) ) ;
8283
84+ private contextMenu : IMenu ;
85+
8386 constructor (
8487 @IContextMenuService private readonly contextMenuService : IContextMenuService ,
8588 @IWindowService private readonly windowService : IWindowService ,
8689 @IConfigurationService private readonly configurationService : IConfigurationService ,
87- @IWindowsService private readonly windowsService : IWindowsService ,
8890 @IEditorService private readonly editorService : IEditorService ,
8991 @IWorkbenchEnvironmentService private readonly environmentService : IWorkbenchEnvironmentService ,
9092 @IWorkspaceContextService private readonly contextService : IWorkspaceContextService ,
9193 @IInstantiationService private readonly instantiationService : IInstantiationService ,
9294 @IThemeService themeService : IThemeService ,
9395 @ILabelService private readonly labelService : ILabelService ,
9496 @IStorageService storageService : IStorageService ,
95- @IWorkbenchLayoutService layoutService : IWorkbenchLayoutService
97+ @IWorkbenchLayoutService layoutService : IWorkbenchLayoutService ,
98+ @IMenuService menuService : IMenuService ,
99+ @IContextKeyService contextKeyService : IContextKeyService
96100 ) {
97101 super ( Parts . TITLEBAR_PART , { hasTitle : false } , themeService , storageService , layoutService ) ;
98102
103+ this . contextMenu = this . _register ( menuService . createMenu ( MenuId . TitleBarContext , contextKeyService ) ) ;
104+
99105 this . registerListeners ( ) ;
100106 }
101107
@@ -181,9 +187,6 @@ export class TitlebarPart extends Part implements ITitleService {
181187
182188 // Apply to window
183189 this . windowService . setRepresentedFilename ( path ) ;
184-
185- // Keep for context menu
186- this . representedFileName = path ;
187190 }
188191
189192 private doUpdateTitle ( ) : void {
@@ -502,44 +505,16 @@ export class TitlebarPart extends Part implements ITitleService {
502505 const event = new StandardMouseEvent ( e ) ;
503506 const anchor = { x : event . posx , y : event . posy } ;
504507
505- // Show menu
506- const actions = this . getContextMenuActions ( ) ;
507- if ( actions . length ) {
508- this . contextMenuService . showContextMenu ( {
509- getAnchor : ( ) => anchor ,
510- getActions : ( ) => actions ,
511- onHide : ( ) => actions . forEach ( a => a . dispose ( ) )
512- } ) ;
513- }
514- }
515-
516- private getContextMenuActions ( ) : IAction [ ] {
508+ // Fill in contributed actions
517509 const actions : IAction [ ] = [ ] ;
510+ const actionsDisposable = createAndFillInContextMenuActions ( this . contextMenu , undefined , actions , this . contextMenuService ) ;
518511
519- if ( this . representedFileName ) {
520- const segments = this . representedFileName . split ( posix . sep ) ;
521- for ( let i = segments . length ; i > 0 ; i -- ) {
522- const isFile = ( i === segments . length ) ;
523-
524- let pathOffset = i ;
525- if ( ! isFile ) {
526- pathOffset ++ ; // for segments which are not the file name we want to open the folder
527- }
528-
529- const path = segments . slice ( 0 , pathOffset ) . join ( posix . sep ) ;
530-
531- let label : string ;
532- if ( ! isFile ) {
533- label = getBaseLabel ( dirname ( path ) ) ;
534- } else {
535- label = getBaseLabel ( path ) ;
536- }
537-
538- actions . push ( new ShowItemInFolderAction ( path , label || posix . sep , this . windowsService ) ) ;
539- }
540- }
541-
542- return actions ;
512+ // Show it
513+ this . contextMenuService . showContextMenu ( {
514+ getAnchor : ( ) => anchor ,
515+ getActions : ( ) => actions ,
516+ onHide : ( ) => dispose ( actionsDisposable )
517+ } ) ;
543518 }
544519
545520 private adjustTitleMarginToCenter ( ) : void {
@@ -604,19 +579,6 @@ export class TitlebarPart extends Part implements ITitleService {
604579 }
605580}
606581
607- class ShowItemInFolderAction extends Action {
608-
609- constructor ( private path : string , label : string , private windowsService : IWindowsService ) {
610- super ( 'showItemInFolder.action.id' , label ) ;
611- }
612-
613- run ( ) : Promise < void > {
614- if ( this . path && this . windowsService ) { }
615- return Promise . resolve ( ) ;
616- // return this.windowsService.showItemInFolder(URI.file(this.path));
617- }
618- }
619-
620582registerThemingParticipant ( ( theme : ITheme , collector : ICssStyleCollector ) => {
621583 const titlebarActiveFg = theme . getColor ( TITLE_BAR_ACTIVE_FOREGROUND ) ;
622584 if ( titlebarActiveFg ) {
0 commit comments