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

merge viewletService into sidebarPart

fixes #63145
上级 d3b5c854
...@@ -8,7 +8,7 @@ import * as nls from 'vs/nls'; ...@@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions'; import { Action } from 'vs/base/common/actions';
import { CompositePart } from 'vs/workbench/browser/parts/compositePart'; 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 { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
...@@ -20,7 +20,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; ...@@ -20,7 +20,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; 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 { IThemeService } from 'vs/platform/theme/common/themeService';
import { contrastBorder } from 'vs/platform/theme/common/colorRegistry'; 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'; 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 ...@@ -29,16 +29,21 @@ import { Dimension, EventType, addDisposableListener, trackFocus } from 'vs/base
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent'; import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview'; 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>('sideBarFocus', false);
export const SidebarFocusContext = new RawContextKey<boolean>(SideBarFocusContextId, 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'; static readonly activeViewletSettingsKey = 'workbench.sidebar.activeviewletid';
private viewletRegistry: ViewletRegistry;
private sideBarFocusContextKey: IContextKey<boolean>; private sideBarFocusContextKey: IContextKey<boolean>;
private activeViewletContextKey: IContextKey<string>;
private blockOpeningViewlet: boolean; private blockOpeningViewlet: boolean;
private _onDidViewletEnable = new Emitter<{ id: string, enabled: boolean }>();
constructor( constructor(
id: string, id: string,
...@@ -51,6 +56,7 @@ export class SidebarPart extends CompositePart<Viewlet> { ...@@ -51,6 +56,7 @@ export class SidebarPart extends CompositePart<Viewlet> {
@IInstantiationService instantiationService: IInstantiationService, @IInstantiationService instantiationService: IInstantiationService,
@IThemeService themeService: IThemeService, @IThemeService themeService: IThemeService,
@IContextKeyService contextKeyService: IContextKeyService, @IContextKeyService contextKeyService: IContextKeyService,
@IExtensionService private extensionService: IExtensionService
) { ) {
super( super(
notificationService, notificationService,
...@@ -72,7 +78,22 @@ export class SidebarPart extends CompositePart<Viewlet> { ...@@ -72,7 +78,22 @@ export class SidebarPart extends CompositePart<Viewlet> {
); );
this.sideBarFocusContextKey = SidebarFocusContext.bindTo(contextKeyService); 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> { get onDidViewletOpen(): Event<IViewlet> {
return Event.map(this._onDidCompositeOpen.event, compositeEvent => <IViewlet>compositeEvent.composite); return Event.map(this._onDidCompositeOpen.event, compositeEvent => <IViewlet>compositeEvent.composite);
...@@ -124,24 +145,16 @@ export class SidebarPart extends CompositePart<Viewlet> { ...@@ -124,24 +145,16 @@ export class SidebarPart extends CompositePart<Viewlet> {
container.style.borderLeftColor = !isPositionLeft ? borderColor : null; container.style.borderLeftColor = !isPositionLeft ? borderColor : null;
} }
openViewlet(id: string, focus?: boolean): Viewlet { layout(dimension: Dimension): Dimension[] {
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)) { if (!this.partService.isVisible(Parts.SIDEBAR_PART)) {
try { return [dimension];
this.blockOpeningViewlet = true;
this.partService.setSideBarHidden(false);
} finally {
this.blockOpeningViewlet = false;
}
} }
return this.openComposite(id, focus) as Viewlet; return super.layout(dimension);
} }
// Viewlet service
getActiveViewlet(): IViewlet { getActiveViewlet(): IViewlet {
return <IViewlet>this.getActiveComposite(); return <IViewlet>this.getActiveComposite();
} }
...@@ -154,12 +167,61 @@ export class SidebarPart extends CompositePart<Viewlet> { ...@@ -154,12 +167,61 @@ export class SidebarPart extends CompositePart<Viewlet> {
this.hideActiveComposite(); 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)) { 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 { protected getTitleAreaDropDownAnchorAlignment(): AnchorAlignment {
......
...@@ -50,7 +50,6 @@ import { IKeybindingEditingService, KeybindingsEditingService } from 'vs/workben ...@@ -50,7 +50,6 @@ import { IKeybindingEditingService, KeybindingsEditingService } from 'vs/workben
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IActivityService } from 'vs/workbench/services/activity/common/activity'; import { IActivityService } from 'vs/workbench/services/activity/common/activity';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; 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 { RemoteFileService } from 'vs/workbench/services/files/electron-browser/remoteFileService';
import { IFileService } from 'vs/platform/files/common/files'; import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
...@@ -192,7 +191,6 @@ export class Workbench extends Disposable implements IPartService { ...@@ -192,7 +191,6 @@ export class Workbench extends Disposable implements IPartService {
private editorService: EditorService; private editorService: EditorService;
private editorGroupService: IEditorGroupsService; private editorGroupService: IEditorGroupsService;
private viewletService: IViewletService;
private contextViewService: ContextViewService; private contextViewService: ContextViewService;
private contextKeyService: IContextKeyService; private contextKeyService: IContextKeyService;
private keybindingService: IKeybindingService; private keybindingService: IKeybindingService;
...@@ -368,8 +366,7 @@ export class Workbench extends Disposable implements IPartService { ...@@ -368,8 +366,7 @@ export class Workbench extends Disposable implements IPartService {
this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART); this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
// Viewlet service // Viewlet service
this.viewletService = this.instantiationService.createInstance(ViewletService, this.sidebarPart); serviceCollection.set(IViewletService, this.sidebarPart);
serviceCollection.set(IViewletService, this.viewletService);
// Panel service (panel part) // Panel service (panel part)
this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART); this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
...@@ -737,12 +734,12 @@ export class Workbench extends Disposable implements IPartService { ...@@ -737,12 +734,12 @@ export class Workbench extends Disposable implements IPartService {
} }
if (!viewletIdToRestore) { if (!viewletIdToRestore) {
viewletIdToRestore = this.viewletService.getDefaultViewletId(); viewletIdToRestore = this.sidebarPart.getDefaultViewletId();
} }
perf.mark('willRestoreViewlet'); perf.mark('willRestoreViewlet');
restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore) restorePromises.push(this.sidebarPart.openViewlet(viewletIdToRestore)
.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId())) .then(viewlet => viewlet || this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId()))
.then(() => perf.mark('didRestoreViewlet'))); .then(() => perf.mark('didRestoreViewlet')));
} }
...@@ -1382,9 +1379,9 @@ export class Workbench extends Disposable implements IPartService { ...@@ -1382,9 +1379,9 @@ export class Workbench extends Disposable implements IPartService {
else if (!hidden && !this.sidebarPart.getActiveViewlet()) { else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
const viewletToOpen = this.sidebarPart.getLastActiveViewletId(); const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
if (viewletToOpen) { if (viewletToOpen) {
const viewlet = this.viewletService.openViewlet(viewletToOpen, true); const viewlet = this.sidebarPart.openViewlet(viewletToOpen, true);
if (!viewlet) { 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.
先完成此消息的编辑!
想要评论请 注册