提交 09e10dd4 编写于 作者: J Joao Moreno

extract scm menus

上级 3467231a
/*---------------------------------------------------------------------------------------------
* 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<any> {
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);
}
}
......@@ -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<ISCMResourceGroup | ISCMResource>;
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<void> {
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册