提交 307037cc 编写于 作者: P Pine Wu

Add ViewletService as IViewletService

ViewletService -> handling viewlet enabling/disabling, etc.
SidebarService -> construct sidebar composite
ActivityService -> Badge, etc
上级 29346ad1
......@@ -25,7 +25,16 @@ import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import Event from 'vs/base/common/event';
export class SidebarPart extends CompositePart<Viewlet> implements IViewletService {
export interface ISidebar {
onDidViewletOpen: Event<IViewlet>;
onDidViewletClose: Event<IViewlet>;
openViewlet(id: string, focus?: boolean): TPromise<IViewlet>;
getActiveViewlet(): IViewlet;
getLastActiveViewletId(): string;
hideActiveViewlet(): TPromise<void>;
}
export class SidebarPart extends CompositePart<Viewlet> implements ISidebar {
public static activeViewletSettingsKey = 'workbench.sidebar.activeviewletid';
......
......@@ -53,6 +53,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ContextKeyExpr, RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IActivityService } from 'vs/workbench/services/activity/common/activityService';
import { IViewletService } from 'vs/workbench/services/viewlet/common/viewletService';
import { ViewletService } from 'vs/workbench/services/viewlet/browser/viewletService';
import { FileService } from 'vs/workbench/services/files/electron-browser/fileService';
import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
......@@ -125,6 +126,7 @@ export class Workbench implements IPartService {
private workbenchCreated: boolean;
private workbenchShutdown: boolean;
private editorService: WorkbenchEditorService;
private viewletService: IViewletService;
private contextKeyService: IContextKeyService;
private keybindingService: IKeybindingService;
private configurationEditingService: IConfigurationEditingService;
......@@ -368,11 +370,14 @@ export class Workbench implements IPartService {
// Menus/Actions
serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
// Viewlet service (sidebar part)
// Sidebar part
this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
this.toDispose.push(this.sidebarPart);
this.toShutdown.push(this.sidebarPart);
serviceCollection.set(IViewletService, this.sidebarPart);
// Viewlet service
this.viewletService = this.instantiationService.createInstance(ViewletService, this.sidebarPart);
serviceCollection.set(IViewletService, this.viewletService);
// Panel service (panel part)
this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
......
......@@ -11,7 +11,7 @@ import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/wor
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { Action } from 'vs/base/common/actions';
import { IQuickOpenService, IPickOpenEntry } from 'vs/workbench/services/quickopen/common/quickOpenService';
import { IActivityService } from 'vs/workbench/services/activity/common/activityService';
import { IViewletService } from 'vs/workbench/services/viewlet/common/viewletService';
import { toCustomViewletActionId } from 'vs/workbench/parts/explorers/common/treeExplorer';
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
......@@ -24,28 +24,35 @@ export class ToggleExtViewletAction extends Action {
id: string,
label: string,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IActivityService private activityService: IActivityService
@IViewletService private viewletService: IViewletService
) {
super(id, name);
}
run(): TPromise<any> {
const infoForExtViewlets = this.activityService.getInfoForExtViewlets();
const viewletDescriptors = this.viewletService.getViewletDescriptors();
const picks: IPickOpenEntry[] = [];
for (let viewletId in infoForExtViewlets) {
const { isEnabled, treeLabel } = infoForExtViewlets[viewletId];
const picks: IPickOpenEntry[] = viewletDescriptors.map((d) => {
return {
id: d.id,
label: d.name
};
});
viewletDescriptors.forEach(vd => {
const isEnabled = true;
const actionLabel = isEnabled ? localize('disable', 'Disable') : localize('enable', 'Enable');
picks.push({
id: viewletId,
label: `${actionLabel} ${treeLabel}`
id: vd.name,
label: `${actionLabel} ${vd.name}`
});
}
});
return TPromise.timeout(50 /* quick open is sensitive to being opened so soon after another */).then(() => {
this.quickOpenService.pick(picks, { placeHolder: 'Select Custom Explorer to toggle' }).then(pick => {
if (pick) {
this.activityService.toggleExtViewlet(pick.id);
this.viewletService.toggleViewlet(pick.id);
}
});
});
......
......@@ -71,19 +71,4 @@ export interface IActivityService {
* Clears activity shown in the activitybar for the given viewlet or panel.
*/
clearActivity(compositeId: string): void;
/**
* Get registered extension viewlets' info for populating 'Toggle Custom Explorer' command picks.
*/
getInfoForExtViewlets(): {
[viewletId: string]: {
isEnabled: boolean;
treeLabel: string;
}
};
/**
* Enable/disable an extension viewlet.
*/
toggleExtViewlet(viewletId: string): void;
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* 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 { TPromise } from 'vs/base/common/winjs.base';
import { IViewletService } from 'vs/workbench/services/viewlet/common/viewletService';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { ISidebar } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import Event from 'vs/base/common/event';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
export class ViewletService implements IViewletService {
public _serviceBrand: any;
private sidebarPart: ISidebar;
constructor(
sidebarPart: ISidebar
) {
this.sidebarPart = sidebarPart;
}
public get onDidViewletOpen(): Event<IViewlet> {
return this.sidebarPart.onDidViewletOpen;
}
public get onDidViewletClose(): Event<IViewlet> {
return this.sidebarPart.onDidViewletClose;
}
public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> {
return this.sidebarPart.openViewlet(id, focus);
}
public toggleViewlet(id: string): TPromise<IViewlet> {
return TPromise.as(null);
}
public getActiveViewlet(): IViewlet {
return this.sidebarPart.getActiveViewlet();
}
public getViewletDescriptors(): ViewletDescriptor[] {
return [];
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import Event from 'vs/base/common/event';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
export const IViewletService = createDecorator<IViewletService>('viewletService');
......@@ -24,7 +25,17 @@ export interface IViewletService {
openViewlet(id: string, focus?: boolean): TPromise<IViewlet>;
/**
* Returns the current active viewlet or null if none
* Toggles a viewlet with the given identifier.
*/
toggleViewlet(id: string): TPromise<IViewlet>;
/**
* Returns the current active viewlet or null if none.
*/
getActiveViewlet(): IViewlet;
}
\ No newline at end of file
/**
* Returns all registered viewlets.
*/
getViewletDescriptors(): ViewletDescriptor[];
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册