mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 13:29:44 +00:00
Merge branch 'master' of https://github.com/microsoft/vscode
This commit is contained in:
commit
fbfb925b4d
|
@ -50,6 +50,7 @@ export class MenuId {
|
|||
static readonly SCMResourceGroupContext = new MenuId('12');
|
||||
static readonly SCMResourceContext = new MenuId('13');
|
||||
static readonly CommandPalette = new MenuId('14');
|
||||
static readonly ViewletTitle = new MenuId('15');
|
||||
|
||||
constructor(private _id: string) {
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace schema {
|
|||
case 'scm/title': return MenuId.SCMTitle;
|
||||
case 'scm/resourceGroup/context': return MenuId.SCMResourceGroupContext;
|
||||
case 'scm/resourceState/context': return MenuId.SCMResourceContext;
|
||||
case 'viewlet/title': return MenuId.ViewletTitle;
|
||||
}
|
||||
|
||||
return void 0;
|
||||
|
|
|
@ -42,7 +42,7 @@ class TreeExplorerNodeProvider implements InternalTreeExplorerNodeProvider {
|
|||
readonly _onRefresh: Emitter<InternalTreeExplorerNodeContent> = new Emitter<InternalTreeExplorerNodeContent>();
|
||||
readonly onRefresh: Event<InternalTreeExplorerNodeContent> = this._onRefresh.event;
|
||||
|
||||
constructor(private providerId: string, private rootNode: InternalTreeExplorerNodeContent, private _proxy: ExtHostTreeShape,
|
||||
constructor(public readonly id: string, private rootNode: InternalTreeExplorerNodeContent, private _proxy: ExtHostTreeShape,
|
||||
private messageService: IMessageService,
|
||||
private commandService: ICommandService
|
||||
) {
|
||||
|
@ -53,11 +53,11 @@ class TreeExplorerNodeProvider implements InternalTreeExplorerNodeProvider {
|
|||
}
|
||||
|
||||
resolveChildren(node: InternalTreeExplorerNodeContent): TPromise<InternalTreeExplorerNodeContent[]> {
|
||||
return this._proxy.$resolveChildren(this.providerId, node).then(children => children, err => this.messageService.show(Severity.Error, err));
|
||||
return this._proxy.$resolveChildren(this.id, node).then(children => children, err => this.messageService.show(Severity.Error, err));
|
||||
}
|
||||
|
||||
executeCommand(node: InternalTreeExplorerNodeContent): TPromise<any> {
|
||||
return this._proxy.$getInternalCommand(this.providerId, node).then(command => {
|
||||
return this._proxy.$getInternalCommand(this.id, node).then(command => {
|
||||
return this.commandService.executeCommand(command.id, ...command.arguments);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -42,22 +42,22 @@ class TreeExplorerNodeProvider implements InternalTreeExplorerNodeProvider {
|
|||
readonly _onRefresh: Emitter<InternalTreeExplorerNodeContent> = new Emitter<InternalTreeExplorerNodeContent>();
|
||||
readonly onRefresh: Event<InternalTreeExplorerNodeContent> = this._onRefresh.event;
|
||||
|
||||
constructor(private providerId: string, private _proxy: ExtHostTreeExplorersShape,
|
||||
constructor(public readonly id: string, private _proxy: ExtHostTreeExplorersShape,
|
||||
private messageService: IMessageService,
|
||||
private commandService: ICommandService
|
||||
) {
|
||||
}
|
||||
|
||||
provideRootNode(): TPromise<InternalTreeExplorerNodeContent> {
|
||||
return this._proxy.$provideRootNode(this.providerId).then(rootNode => rootNode, err => this.messageService.show(Severity.Error, err));
|
||||
return this._proxy.$provideRootNode(this.id).then(rootNode => rootNode, err => this.messageService.show(Severity.Error, err));
|
||||
}
|
||||
|
||||
resolveChildren(node: InternalTreeExplorerNodeContent): TPromise<InternalTreeExplorerNodeContent[]> {
|
||||
return this._proxy.$resolveChildren(this.providerId, node).then(children => children, err => this.messageService.show(Severity.Error, err));
|
||||
return this._proxy.$resolveChildren(this.id, node).then(children => children, err => this.messageService.show(Severity.Error, err));
|
||||
}
|
||||
|
||||
executeCommand(node: InternalTreeExplorerNodeContent): TPromise<any> {
|
||||
return this._proxy.$getInternalCommand(this.providerId, node).then(command => {
|
||||
return this._proxy.$getInternalCommand(this.id, node).then(command => {
|
||||
return this.commandService.executeCommand(command.id, ...command.arguments);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -440,7 +440,7 @@ export abstract class CollapsibleViewletView extends CollapsibleView implements
|
|||
collapsed: boolean,
|
||||
private viewName: string,
|
||||
protected messageService: IMessageService,
|
||||
private keybindingService: IKeybindingService,
|
||||
protected keybindingService: IKeybindingService,
|
||||
protected contextMenuService: IContextMenuService,
|
||||
headerSize?: number
|
||||
) {
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IDisposable, dispose, empty as EmptyDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
|
||||
import { ITreeExplorerService } from 'vs/workbench/parts/explorers/common/treeExplorerService';
|
||||
|
||||
|
||||
export class TreeExplorerMenus implements IDisposable {
|
||||
|
||||
private disposables: IDisposable[] = [];
|
||||
|
||||
private activeProviderId: string;
|
||||
private titleDisposable: IDisposable = EmptyDisposable;
|
||||
private titleActions: IAction[] = [];
|
||||
private titleSecondaryActions: IAction[] = [];
|
||||
|
||||
private _onDidChangeTitle = new Emitter<void>();
|
||||
get onDidChangeTitle(): Event<void> { return this._onDidChangeTitle.event; }
|
||||
|
||||
constructor(
|
||||
@IContextKeyService private contextKeyService: IContextKeyService,
|
||||
@ITreeExplorerService private treeExplorerService: ITreeExplorerService,
|
||||
@IMenuService private menuService: IMenuService
|
||||
) {
|
||||
this.setActiveProvider(this.treeExplorerService.activeProvider);
|
||||
this.treeExplorerService.onDidChangeProvider(this.setActiveProvider, this, this.disposables);
|
||||
}
|
||||
|
||||
private setActiveProvider(activeProvider: string | undefined): void {
|
||||
if (this.titleDisposable) {
|
||||
this.titleDisposable.dispose();
|
||||
this.titleDisposable = EmptyDisposable;
|
||||
}
|
||||
|
||||
if (!activeProvider) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.activeProviderId = activeProvider;
|
||||
|
||||
const titleMenu = this.menuService.createMenu(MenuId.ViewletTitle, this.contextKeyService);
|
||||
const updateActions = () => {
|
||||
this.titleActions = [];
|
||||
this.titleSecondaryActions = [];
|
||||
fillInActions(titleMenu, null, { primary: this.titleActions, secondary: this.titleSecondaryActions });
|
||||
this._onDidChangeTitle.fire();
|
||||
};
|
||||
|
||||
const listener = titleMenu.onDidChange(updateActions);
|
||||
updateActions();
|
||||
|
||||
this.titleDisposable = toDisposable(() => {
|
||||
listener.dispose();
|
||||
titleMenu.dispose();
|
||||
this.titleActions = [];
|
||||
this.titleSecondaryActions = [];
|
||||
});
|
||||
}
|
||||
|
||||
getTitleActions(): IAction[] {
|
||||
return this.titleActions;
|
||||
}
|
||||
|
||||
getTitleSecondaryActions(): IAction[] {
|
||||
return this.titleSecondaryActions;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposables = dispose(this.disposables);
|
||||
}
|
||||
}
|
|
@ -10,19 +10,47 @@ import { TPromise } from 'vs/base/common/winjs.base';
|
|||
import { IMessageService, Severity } from 'vs/platform/message/common/message';
|
||||
import { InternalTreeExplorerNode, InternalTreeExplorerNodeProvider } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
|
||||
import { ITreeExplorerService } from 'vs/workbench/parts/explorers/common/treeExplorerService';
|
||||
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
|
||||
export class TreeExplorerService implements ITreeExplorerService {
|
||||
public _serviceBrand: any;
|
||||
|
||||
private _activeProvider: string;
|
||||
private activeProviderContextKey: IContextKey<string | undefined>;
|
||||
|
||||
private _onDidChangeProvider = new Emitter<string>();
|
||||
get onDidChangeProvider(): Event<string> { return this._onDidChangeProvider.event; }
|
||||
|
||||
private _onTreeExplorerNodeProviderRegistered = new Emitter<String>();
|
||||
public get onTreeExplorerNodeProviderRegistered(): Event<string> { return this._onTreeExplorerNodeProviderRegistered.event; };
|
||||
|
||||
private _treeExplorerNodeProviders: { [providerId: string]: InternalTreeExplorerNodeProvider };
|
||||
|
||||
constructor(
|
||||
@IMessageService private messageService: IMessageService,
|
||||
@IContextKeyService private contextKeyService: IContextKeyService,
|
||||
@IMessageService private messageService: IMessageService
|
||||
) {
|
||||
this._treeExplorerNodeProviders = Object.create(null);
|
||||
this.activeProviderContextKey = this.contextKeyService.createKey<string | undefined>('treeExplorerProvider', void 0);
|
||||
}
|
||||
|
||||
get activeProvider(): string {
|
||||
return this._activeProvider;
|
||||
}
|
||||
|
||||
set activeProvider(provider: string) {
|
||||
if (!provider) {
|
||||
throw new Error('invalid provider');
|
||||
}
|
||||
|
||||
if (provider && !!this._treeExplorerNodeProviders[provider]) {
|
||||
throw new Error('Provider not registered');
|
||||
}
|
||||
|
||||
this._activeProvider = provider;
|
||||
this.activeProviderContextKey.set(provider ? provider : void 0);
|
||||
|
||||
this._onDidChangeProvider.fire(provider);
|
||||
}
|
||||
|
||||
public registerTreeExplorerNodeProvider(providerId: string, provider: InternalTreeExplorerNodeProvider): void {
|
||||
|
|
|
@ -10,8 +10,8 @@ import * as DOM from 'vs/base/browser/dom';
|
|||
import { Builder, $ } from 'vs/base/browser/builder';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { CollapsibleViewletView } from 'vs/workbench/browser/viewlet';
|
||||
import { IAction, IActionRunner } from 'vs/base/common/actions';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IAction, IActionRunner, IActionItem } from 'vs/base/common/actions';
|
||||
import { IMessageService } from 'vs/platform/message/common/message';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
|
||||
|
@ -21,13 +21,16 @@ import { ITreeExplorerService } from 'vs/workbench/parts/explorers/common/treeEx
|
|||
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
||||
import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
|
||||
import { TreeExplorerViewletState, TreeDataSource, TreeRenderer, TreeController } from 'vs/workbench/parts/explorers/browser/views/treeExplorerViewer';
|
||||
import { TreeExplorerMenus } from 'vs/workbench/parts/explorers/browser/treeExplorerMenus';
|
||||
import { RefreshViewExplorerAction } from 'vs/workbench/parts/explorers/browser/treeExplorerActions';
|
||||
import { attachListStyler } from "vs/platform/theme/common/styler";
|
||||
import { IThemeService } from "vs/platform/theme/common/themeService";
|
||||
import { createActionItem } from 'vs/platform/actions/browser/menuItemActionItem';
|
||||
|
||||
export class TreeExplorerView extends CollapsibleViewletView {
|
||||
|
||||
private providerDisposables = IDisposable[];
|
||||
private providerDisposables: IDisposable[];
|
||||
private menus: TreeExplorerMenus;
|
||||
|
||||
constructor(
|
||||
private viewletState: TreeExplorerViewletState,
|
||||
|
@ -44,7 +47,8 @@ export class TreeExplorerView extends CollapsibleViewletView {
|
|||
@IThemeService private themeService: IThemeService
|
||||
) {
|
||||
super(actionRunner, false, nls.localize('treeExplorerViewlet.tree', "Tree Explorer Section"), messageService, keybindingService, contextMenuService, headerSize);
|
||||
|
||||
this.treeExplorerService.activeProvider = treeNodeProviderId;
|
||||
this.menus = this.instantiationService.createInstance(TreeExplorerMenus);
|
||||
this.create();
|
||||
}
|
||||
|
||||
|
@ -74,10 +78,16 @@ export class TreeExplorerView extends CollapsibleViewletView {
|
|||
return tree;
|
||||
}
|
||||
|
||||
public getActions(): IAction[] {
|
||||
const refresh = this.instantiationService.createInstance(RefreshViewExplorerAction, this);
|
||||
getActions(): IAction[] {
|
||||
return [...this.menus.getTitleActions(), new RefreshViewExplorerAction(this)];
|
||||
}
|
||||
|
||||
return [refresh];
|
||||
getSecondaryActions(): IAction[] {
|
||||
return this.menus.getTitleSecondaryActions();
|
||||
}
|
||||
|
||||
getActionItem(action: IAction): IActionItem {
|
||||
return createActionItem(action, this.keybindingService, this.messageService);
|
||||
}
|
||||
|
||||
public create(): TPromise<void> {
|
||||
|
|
|
@ -14,8 +14,10 @@ export const ITreeExplorerService = createDecorator<ITreeExplorerService>('treeE
|
|||
export interface ITreeExplorerService {
|
||||
_serviceBrand: any;
|
||||
|
||||
onTreeExplorerNodeProviderRegistered: Event<String>;
|
||||
onDidChangeProvider: Event<string>;
|
||||
activeProvider: string;
|
||||
|
||||
onTreeExplorerNodeProviderRegistered: Event<String>;
|
||||
registerTreeExplorerNodeProvider(providerId: string, provider: InternalTreeExplorerNodeProvider): void;
|
||||
hasProvider(providerId: string): boolean;
|
||||
getProvider(providerId: string): InternalTreeExplorerNodeProvider;
|
||||
|
|
|
@ -18,6 +18,7 @@ export interface InternalTreeExplorerNode extends InternalTreeExplorerNodeConten
|
|||
}
|
||||
|
||||
export interface InternalTreeExplorerNodeProvider {
|
||||
id: string;
|
||||
provideRootNode(): Thenable<InternalTreeExplorerNodeContent>;
|
||||
resolveChildren(node: InternalTreeExplorerNodeContent): Thenable<InternalTreeExplorerNodeContent[]>;
|
||||
executeCommand(node: InternalTreeExplorerNodeContent): TPromise<any>;
|
||||
|
|
Loading…
Reference in a new issue