提交 55cbf197 编写于 作者: I isidor

merge viewletService into sidebarPart

fixes #63145
上级 d3b5c854
......@@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { CompositePart } from 'vs/workbench/browser/parts/compositePart';
import { Viewlet, ViewletRegistry, Extensions as ViewletExtensions } from 'vs/workbench/browser/viewlet';
import { Viewlet, ViewletRegistry, Extensions as ViewletExtensions, ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
......@@ -20,7 +20,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Event } from 'vs/base/common/event';
import { Event, Emitter } from 'vs/base/common/event';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { SIDE_BAR_TITLE_FOREGROUND, SIDE_BAR_BACKGROUND, SIDE_BAR_FOREGROUND, SIDE_BAR_BORDER } from 'vs/workbench/common/theme';
......@@ -29,16 +29,21 @@ import { Dimension, EventType, addDisposableListener, trackFocus } from 'vs/base
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
const SideBarFocusContextId = 'sideBarFocus';
export const SidebarFocusContext = new RawContextKey<boolean>(SideBarFocusContextId, false);
export const SidebarFocusContext = new RawContextKey<boolean>('sideBarFocus', false);
export const ActiveViewletContext = new RawContextKey<string>('activeViewlet', '');
export class SidebarPart extends CompositePart<Viewlet> {
export class SidebarPart extends CompositePart<Viewlet> implements IViewletService {
_serviceBrand: any;
static readonly activeViewletSettingsKey = 'workbench.sidebar.activeviewletid';
private viewletRegistry: ViewletRegistry;
private sideBarFocusContextKey: IContextKey<boolean>;
private activeViewletContextKey: IContextKey<string>;
private blockOpeningViewlet: boolean;
private _onDidViewletEnable = new Emitter<{ id: string, enabled: boolean }>();
constructor(
id: string,
......@@ -51,6 +56,7 @@ export class SidebarPart extends CompositePart<Viewlet> {
@IInstantiationService instantiationService: IInstantiationService,
@IThemeService themeService: IThemeService,
@IContextKeyService contextKeyService: IContextKeyService,
@IExtensionService private extensionService: IExtensionService
) {
super(
notificationService,
......@@ -72,8 +78,23 @@ export class SidebarPart extends CompositePart<Viewlet> {
);
this.sideBarFocusContextKey = SidebarFocusContext.bindTo(contextKeyService);
this.viewletRegistry = Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets);
this.activeViewletContextKey = ActiveViewletContext.bindTo(contextKeyService);
this._register(this.onDidViewletOpen(viewlet => {
this.activeViewletContextKey.set(viewlet.getId());
}));
this._register(this.onDidViewletClose(viewlet => {
if (this.activeViewletContextKey.get() === viewlet.getId()) {
this.activeViewletContextKey.reset();
}
}));
}
get onDidViewletRegister(): Event<ViewletDescriptor> { return <Event<ViewletDescriptor>>this.viewletRegistry.onDidRegister; }
get onDidViewletEnablementChange(): Event<{ id: string, enabled: boolean }> { return this._onDidViewletEnable.event; }
get onDidViewletOpen(): Event<IViewlet> {
return Event.map(this._onDidCompositeOpen.event, compositeEvent => <IViewlet>compositeEvent.composite);
}
......@@ -124,24 +145,16 @@ export class SidebarPart extends CompositePart<Viewlet> {
container.style.borderLeftColor = !isPositionLeft ? borderColor : null;
}
openViewlet(id: string, focus?: boolean): Viewlet {
if (this.blockOpeningViewlet) {
return null; // Workaround against a potential race condition
}
// First check if sidebar is hidden and show if so
layout(dimension: Dimension): Dimension[] {
if (!this.partService.isVisible(Parts.SIDEBAR_PART)) {
try {
this.blockOpeningViewlet = true;
this.partService.setSideBarHidden(false);
} finally {
this.blockOpeningViewlet = false;
}
return [dimension];
}
return this.openComposite(id, focus) as Viewlet;
return super.layout(dimension);
}
// Viewlet service
getActiveViewlet(): IViewlet {
return <IViewlet>this.getActiveComposite();
}
......@@ -154,12 +167,61 @@ export class SidebarPart extends CompositePart<Viewlet> {
this.hideActiveComposite();
}
layout(dimension: Dimension): Dimension[] {
setViewletEnablement(id: string, enabled: boolean): void {
const descriptor = this.getAllViewlets().filter(desc => desc.id === id).pop();
if (descriptor && descriptor.enabled !== enabled) {
descriptor.enabled = enabled;
this._onDidViewletEnable.fire({ id, enabled });
}
}
openViewlet(id: string, focus?: boolean): Thenable<IViewlet> {
if (this.getViewlet(id)) {
return Promise.resolve(this.doOpenViewlet(id, focus));
}
return this.extensionService.whenInstalledExtensionsRegistered()
.then(() => {
if (this.getViewlet(id)) {
return this.doOpenViewlet(id, focus);
}
return null;
});
}
getViewlets(): ViewletDescriptor[] {
return this.getAllViewlets()
.filter(v => v.enabled);
}
getAllViewlets(): ViewletDescriptor[] {
return this.viewletRegistry.getViewlets()
.sort((v1, v2) => v1.order - v2.order);
}
getDefaultViewletId(): string {
return this.viewletRegistry.getDefaultViewletId();
}
getViewlet(id: string): ViewletDescriptor {
return this.getViewlets().filter(viewlet => viewlet.id === id)[0];
}
private doOpenViewlet(id: string, focus?: boolean): Viewlet {
if (this.blockOpeningViewlet) {
return null; // Workaround against a potential race condition
}
// First check if sidebar is hidden and show if so
if (!this.partService.isVisible(Parts.SIDEBAR_PART)) {
return [dimension];
try {
this.blockOpeningViewlet = true;
this.partService.setSideBarHidden(false);
} finally {
this.blockOpeningViewlet = false;
}
}
return super.layout(dimension);
return this.openComposite(id, focus) as Viewlet;
}
protected getTitleAreaDropDownAnchorAlignment(): AnchorAlignment {
......
......@@ -50,7 +50,6 @@ import { IKeybindingEditingService, KeybindingsEditingService } from 'vs/workben
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IActivityService } from 'vs/workbench/services/activity/common/activity';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ViewletService } from 'vs/workbench/services/viewlet/browser/viewletService';
import { RemoteFileService } from 'vs/workbench/services/files/electron-browser/remoteFileService';
import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
......@@ -192,7 +191,6 @@ export class Workbench extends Disposable implements IPartService {
private editorService: EditorService;
private editorGroupService: IEditorGroupsService;
private viewletService: IViewletService;
private contextViewService: ContextViewService;
private contextKeyService: IContextKeyService;
private keybindingService: IKeybindingService;
......@@ -368,8 +366,7 @@ export class Workbench extends Disposable implements IPartService {
this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
// Viewlet service
this.viewletService = this.instantiationService.createInstance(ViewletService, this.sidebarPart);
serviceCollection.set(IViewletService, this.viewletService);
serviceCollection.set(IViewletService, this.sidebarPart);
// Panel service (panel part)
this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
......@@ -737,12 +734,12 @@ export class Workbench extends Disposable implements IPartService {
}
if (!viewletIdToRestore) {
viewletIdToRestore = this.viewletService.getDefaultViewletId();
viewletIdToRestore = this.sidebarPart.getDefaultViewletId();
}
perf.mark('willRestoreViewlet');
restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore)
.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId()))
restorePromises.push(this.sidebarPart.openViewlet(viewletIdToRestore)
.then(viewlet => viewlet || this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId()))
.then(() => perf.mark('didRestoreViewlet')));
}
......@@ -1382,9 +1379,9 @@ export class Workbench extends Disposable implements IPartService {
else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
if (viewletToOpen) {
const viewlet = this.viewletService.openViewlet(viewletToOpen, true);
const viewlet = this.sidebarPart.openViewlet(viewletToOpen, true);
if (!viewlet) {
this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true);
this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId(), true);
}
}
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IViewlet } from 'vs/workbench/common/viewlet';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { Event, Emitter } from 'vs/base/common/event';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { Registry } from 'vs/platform/registry/common/platform';
import { ViewletDescriptor, ViewletRegistry, Extensions as ViewletExtensions } from 'vs/workbench/browser/viewlet';
import { IProgressService } from 'vs/platform/progress/common/progress';
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { Disposable } from 'vs/base/common/lifecycle';
const ActiveViewletContextId = 'activeViewlet';
export const ActiveViewletContext = new RawContextKey<string>(ActiveViewletContextId, '');
export class ViewletService extends Disposable implements IViewletService {
_serviceBrand: any;
private sidebarPart: SidebarPart;
private viewletRegistry: ViewletRegistry;
private activeViewletContextKey: IContextKey<string>;
private _onDidViewletEnable = new Emitter<{ id: string, enabled: boolean }>();
get onDidViewletRegister(): Event<ViewletDescriptor> { return <Event<ViewletDescriptor>>this.viewletRegistry.onDidRegister; }
get onDidViewletOpen(): Event<IViewlet> { return this.sidebarPart.onDidViewletOpen; }
get onDidViewletClose(): Event<IViewlet> { return this.sidebarPart.onDidViewletClose; }
get onDidViewletEnablementChange(): Event<{ id: string, enabled: boolean }> { return this._onDidViewletEnable.event; }
constructor(
sidebarPart: SidebarPart,
@IContextKeyService contextKeyService: IContextKeyService,
@IExtensionService private extensionService: IExtensionService
) {
super();
this.sidebarPart = sidebarPart;
this.viewletRegistry = Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets);
this.activeViewletContextKey = ActiveViewletContext.bindTo(contextKeyService);
this._register(this.onDidViewletOpen(this._onDidViewletOpen, this));
this._register(this.onDidViewletClose(this._onDidViewletClose, this));
}
private _onDidViewletOpen(viewlet: IViewlet): void {
this.activeViewletContextKey.set(viewlet.getId());
}
private _onDidViewletClose(viewlet: IViewlet): void {
const id = viewlet.getId();
if (this.activeViewletContextKey.get() === id) {
this.activeViewletContextKey.reset();
}
}
setViewletEnablement(id: string, enabled: boolean): void {
const descriptor = this.getAllViewlets().filter(desc => desc.id === id).pop();
if (descriptor && descriptor.enabled !== enabled) {
descriptor.enabled = enabled;
this._onDidViewletEnable.fire({ id, enabled });
}
}
openViewlet(id: string, focus?: boolean): Thenable<IViewlet> {
if (this.getViewlet(id)) {
return Promise.resolve(this.sidebarPart.openViewlet(id, focus));
}
return this.extensionService.whenInstalledExtensionsRegistered()
.then(() => {
if (this.getViewlet(id)) {
return this.sidebarPart.openViewlet(id, focus);
}
return null;
});
}
getActiveViewlet(): IViewlet {
return this.sidebarPart.getActiveViewlet();
}
getViewlets(): ViewletDescriptor[] {
return this.getAllViewlets()
.filter(v => v.enabled);
}
getAllViewlets(): ViewletDescriptor[] {
return this.viewletRegistry.getViewlets()
.sort((v1, v2) => v1.order - v2.order);
}
getDefaultViewletId(): string {
return this.viewletRegistry.getDefaultViewletId();
}
getViewlet(id: string): ViewletDescriptor {
return this.getViewlets().filter(viewlet => viewlet.id === id)[0];
}
getProgressIndicator(id: string): IProgressService {
return this.sidebarPart.getProgressIndicator(id);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册