diff --git a/src/vs/workbench/parts/scm/browser/scmMenus.ts b/src/vs/workbench/parts/scm/browser/scmMenus.ts new file mode 100644 index 0000000000000000000000000000000000000000..fec6272ab75f9642399fb1ade2f84bd0c4edc319 --- /dev/null +++ b/src/vs/workbench/parts/scm/browser/scmMenus.ts @@ -0,0 +1,56 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import 'vs/css!./media/scmViewlet'; +import Event, { mapEvent } from 'vs/base/common/event'; +import { memoize } from 'vs/base/common/decorators'; +import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions'; +import { IAction } from 'vs/base/common/actions'; +import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem'; + +export class SCMMenus implements IDisposable { + + private titleMenu: IMenu; + + private _titleMenuActions: { primary: IAction[]; secondary: IAction[] }; + private get cachedTitleMenuActions() { + if (!this._titleMenuActions) { + this._titleMenuActions = { primary: [], secondary: [] }; + fillInActions(this.titleMenu, this._titleMenuActions); + } + return this._titleMenuActions; + } + + private disposables: IDisposable[] = []; + + constructor( + @IContextKeyService private contextKeyService: IContextKeyService, + @IMenuService private menuService: IMenuService + ) { + this.titleMenu = menuService.createMenu(MenuId.SCMTitle, contextKeyService); + this.disposables.push(this.titleMenu); + } + + @memoize + get onDidChangeTitleMenu(): Event { + return mapEvent(this.titleMenu.onDidChange, () => this._titleMenuActions = void 0); + } + + get titleMenuActions(): IAction[] { + return this.cachedTitleMenuActions.primary; + } + + get titleMenuSecondaryActions(): IAction[] { + return this.cachedTitleMenuActions.secondary; + } + + dispose(): void { + this.disposables = dispose(this.disposables); + } +} diff --git a/src/vs/workbench/parts/scm/browser/scmViewlet.ts b/src/vs/workbench/parts/scm/browser/scmViewlet.ts index e1608d65cfa70a02d45ccc602910cfd3605ddd53..734e3e8c72b80cd2e8fc414fc60dc571d0e78844 100644 --- a/src/vs/workbench/parts/scm/browser/scmViewlet.ts +++ b/src/vs/workbench/parts/scm/browser/scmViewlet.ts @@ -30,9 +30,10 @@ import { IMessageService } from 'vs/platform/message/common/message'; import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; -import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions'; +import { IMenuService } from 'vs/platform/actions/common/actions'; import { IAction, IActionItem } from 'vs/base/common/actions'; -import { createActionItem, fillInActions } from 'vs/platform/actions/browser/menuItemActionItem'; +import { createActionItem } from 'vs/platform/actions/browser/menuItemActionItem'; +import { SCMMenus } from './scmMenus'; // TODO@Joao remove import { GitSCMProvider } from 'vs/workbench/parts/git/browser/gitSCMProvider'; @@ -119,17 +120,7 @@ export class SCMViewlet extends Viewlet { private inputBox: InputBox; private listContainer: HTMLElement; private list: List; - - private titleMenu: IMenu; - private _titleMenuActions: { primary: IAction[]; secondary: IAction[] }; - private get titleMenuActions() { - if (!this._titleMenuActions) { - this._titleMenuActions = { primary: [], secondary: [] }; - fillInActions(this.titleMenu, this._titleMenuActions); - } - return this._titleMenuActions; - } - + private menus: SCMMenus; private disposables: IDisposable[] = []; constructor( @@ -147,10 +138,10 @@ export class SCMViewlet extends Viewlet { // TODO@Joao scmService.activeProvider = instantiationService.createInstance(GitSCMProvider); - this.titleMenu = menuService.createMenu(MenuId.SCMTitle, contextKeyService); + this.menus = this.instantiationService.createInstance(SCMMenus); + this.disposables.push(this.menus); - this.disposables.push(this.titleMenu); - this.titleMenu.onDidChange(this.onTitleMenuChange, this, this.disposables); + this.menus.onDidChangeTitleMenu(this.updateTitleArea, this, this.disposables); } create(parent: Builder): TPromise { @@ -238,17 +229,12 @@ export class SCMViewlet extends Viewlet { this.scmService.activeProvider.open(e); } - private onTitleMenuChange(): void { - this._titleMenuActions = void 0; - this.updateTitleArea(); - } - getActions(): IAction[] { - return this.titleMenuActions.primary; + return this.menus.titleMenuActions; } getSecondaryActions(): IAction[] { - return this.titleMenuActions.secondary; + return this.menus.titleMenuSecondaryActions; } getActionItem(action: IAction): IActionItem {