提交 a890e1c8 编写于 作者: I isidor

viewlet, panel: remove notion of search.location, instead add api to enableViewlet enablePanel

上级 83d921a9
...@@ -203,6 +203,7 @@ export abstract class CompositeDescriptor<T extends Composite> { ...@@ -203,6 +203,7 @@ export abstract class CompositeDescriptor<T extends Composite> {
public cssClass: string; public cssClass: string;
public order: number; public order: number;
public keybindingId: string; public keybindingId: string;
public enabled: boolean;
private ctor: IConstructorSignature0<T>; private ctor: IConstructorSignature0<T>;
...@@ -212,6 +213,7 @@ export abstract class CompositeDescriptor<T extends Composite> { ...@@ -212,6 +213,7 @@ export abstract class CompositeDescriptor<T extends Composite> {
this.name = name; this.name = name;
this.cssClass = cssClass; this.cssClass = cssClass;
this.order = order; this.order = order;
this.enabled = true;
this.keybindingId = keybindingId; this.keybindingId = keybindingId;
} }
......
...@@ -29,8 +29,6 @@ import { ACTIVITY_BAR_BACKGROUND, ACTIVITY_BAR_BORDER, ACTIVITY_BAR_FOREGROUND, ...@@ -29,8 +29,6 @@ import { ACTIVITY_BAR_BACKGROUND, ACTIVITY_BAR_BORDER, ACTIVITY_BAR_FOREGROUND,
import { contrastBorder } from 'vs/platform/theme/common/colorRegistry'; import { contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { CompositeBar } from 'vs/workbench/browser/parts/compositebar/compositeBar'; import { CompositeBar } from 'vs/workbench/browser/parts/compositebar/compositeBar';
import { ToggleCompositePinnedAction } from 'vs/workbench/browser/parts/compositebar/compositeBarActions'; import { ToggleCompositePinnedAction } from 'vs/workbench/browser/parts/compositebar/compositeBarActions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ISearchConfiguration, VIEW_ID as SEARCH_VIEW_ID } from 'vs/platform/search/common/search';
export class ActivitybarPart extends Part { export class ActivitybarPart extends Part {
...@@ -58,8 +56,7 @@ export class ActivitybarPart extends Part { ...@@ -58,8 +56,7 @@ export class ActivitybarPart extends Part {
@IContextMenuService private contextMenuService: IContextMenuService, @IContextMenuService private contextMenuService: IContextMenuService,
@IInstantiationService private instantiationService: IInstantiationService, @IInstantiationService private instantiationService: IInstantiationService,
@IPartService private partService: IPartService, @IPartService private partService: IPartService,
@IThemeService themeService: IThemeService, @IThemeService themeService: IThemeService
@IConfigurationService private configurationService: IConfigurationService
) { ) {
super(id, { hasTitle: false }, themeService); super(id, { hasTitle: false }, themeService);
...@@ -89,15 +86,11 @@ export class ActivitybarPart extends Part { ...@@ -89,15 +86,11 @@ export class ActivitybarPart extends Part {
// Deactivate viewlet action on close // Deactivate viewlet action on close
this.toUnbind.push(this.viewletService.onDidViewletClose(viewlet => this.compositeBar.deactivateComposite(viewlet.getId()))); this.toUnbind.push(this.viewletService.onDidViewletClose(viewlet => this.compositeBar.deactivateComposite(viewlet.getId())));
this.toUnbind.push(this.compositeBar.onDidContextMenu(e => this.showContextMenu(e))); this.toUnbind.push(this.compositeBar.onDidContextMenu(e => this.showContextMenu(e)));
this.toUnbind.push(this.viewletService.onDidViewletEnable(({ id, enabled }) => {
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => { if (enabled) {
if (e.affectsConfiguration('search.location')) { this.compositeBar.addComposite(this.viewletService.getViewlet(id));
const location = this.configurationService.getValue<ISearchConfiguration>().search.location; } else {
if (location === 'sidebar') { this.compositeBar.removeComposite(id);
this.compositeBar.addComposite(this.viewletService.getViewlet(SEARCH_VIEW_ID));
} else {
this.compositeBar.removeComposite(SEARCH_VIEW_ID);
}
} }
})); }));
} }
......
...@@ -30,8 +30,6 @@ import { StandardMouseEvent } from 'vs/base/browser/mouseEvent'; ...@@ -30,8 +30,6 @@ import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { dispose, IDisposable } from 'vs/base/common/lifecycle'; import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { IBadge } from 'vs/workbench/services/activity/common/activity'; import { IBadge } from 'vs/workbench/services/activity/common/activity';
import { INotificationService } from 'vs/platform/notification/common/notification'; import { INotificationService } from 'vs/platform/notification/common/notification';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ISearchConfiguration, VIEW_ID as SEARCH_VIEW_ID } from 'vs/platform/search/common/search';
export class PanelPart extends CompositePart<Panel> implements IPanelService { export class PanelPart extends CompositePart<Panel> implements IPanelService {
...@@ -55,8 +53,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService { ...@@ -55,8 +53,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
@IPartService partService: IPartService, @IPartService partService: IPartService,
@IKeybindingService keybindingService: IKeybindingService, @IKeybindingService keybindingService: IKeybindingService,
@IInstantiationService instantiationService: IInstantiationService, @IInstantiationService instantiationService: IInstantiationService,
@IThemeService themeService: IThemeService, @IThemeService themeService: IThemeService
@IConfigurationService private configurationService: IConfigurationService
) { ) {
super( super(
notificationService, notificationService,
...@@ -113,16 +110,6 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService { ...@@ -113,16 +110,6 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
// Deactivate panel action on close // Deactivate panel action on close
this.toUnbind.push(this.onDidPanelClose(panel => this.compositeBar.deactivateComposite(panel.getId()))); this.toUnbind.push(this.onDidPanelClose(panel => this.compositeBar.deactivateComposite(panel.getId())));
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('search.location')) {
const location = this.configurationService.getValue<ISearchConfiguration>().search.location;
if (location === 'panel') {
this.compositeBar.addComposite(this.getPanel(SEARCH_VIEW_ID));
} else {
this.compositeBar.removeComposite(SEARCH_VIEW_ID);
}
}
}));
} }
public get onDidPanelOpen(): Event<IPanel> { public get onDidPanelOpen(): Event<IPanel> {
...@@ -183,13 +170,23 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService { ...@@ -183,13 +170,23 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
} }
public getPanels(): IPanelIdentifier[] { public getPanels(): IPanelIdentifier[] {
const searchConfig = this.configurationService.getValue<ISearchConfiguration>();
const excludeSearch = searchConfig.search.location !== 'panel';
return Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels() return Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels()
.filter(p => !(p.id === SEARCH_VIEW_ID && excludeSearch)) .filter(p => p.enabled)
.sort((v1, v2) => v1.order - v2.order); .sort((v1, v2) => v1.order - v2.order);
} }
public enablePanel(id: string, enabled: boolean): void {
const descriptor = Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels().filter(p => p.id === id).pop();
if (descriptor && descriptor.enabled !== enabled) {
descriptor.enabled = enabled;
if (enabled) {
this.compositeBar.addComposite(descriptor);
} else {
this.compositeBar.removeComposite(id);
}
}
}
protected getActions(): IAction[] { protected getActions(): IAction[] {
return [ return [
this.instantiationService.createInstance(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, ToggleMaximizedPanelAction.LABEL), this.instantiationService.createInstance(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, ToggleMaximizedPanelAction.LABEL),
......
...@@ -26,6 +26,10 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti ...@@ -26,6 +26,10 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IFileService } from 'vs/platform/files/common/files'; import { IFileService } from 'vs/platform/files/common/files';
import { ResourceTextEdit } from 'vs/editor/common/modes'; import { ResourceTextEdit } from 'vs/editor/common/modes';
import { createTextBufferFactoryFromSnapshot } from 'vs/editor/common/model/textModel'; import { createTextBufferFactoryFromSnapshot } from 'vs/editor/common/model/textModel';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ISearchConfiguration, VIEW_ID } from 'vs/platform/search/common/search';
const REPLACE_PREVIEW = 'replacePreview'; const REPLACE_PREVIEW = 'replacePreview';
...@@ -96,8 +100,30 @@ export class ReplaceService implements IReplaceService { ...@@ -96,8 +100,30 @@ export class ReplaceService implements IReplaceService {
constructor( constructor(
@IFileService private fileService: IFileService, @IFileService private fileService: IFileService,
@IEditorService private editorService: IWorkbenchEditorService, @IEditorService private editorService: IWorkbenchEditorService,
@ITextModelService private textModelResolverService: ITextModelService @ITextModelService private textModelResolverService: ITextModelService,
@IViewletService viewletService: IViewletService,
@IPanelService panelService: IPanelService,
@IConfigurationService configurationService: IConfigurationService
) { ) {
const updateSearchViewLocation = () => {
const config = configurationService.getValue<ISearchConfiguration>();
if (config.search.location === 'panel') {
viewletService.enableViewlet(VIEW_ID, false);
panelService.enablePanel(VIEW_ID, true);
}
if (config.search.location === 'sidebar') {
panelService.enablePanel(VIEW_ID, false);
viewletService.enableViewlet(VIEW_ID, true);
}
};
configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('search.location')) {
updateSearchViewLocation();
}
});
updateSearchViewLocation();
} }
public replace(match: Match): TPromise<any>; public replace(match: Match): TPromise<any>;
......
...@@ -37,4 +37,10 @@ export interface IPanelService { ...@@ -37,4 +37,10 @@ export interface IPanelService {
* Returns all enabled panels * Returns all enabled panels
*/ */
getPanels(): IPanelIdentifier[]; getPanels(): IPanelIdentifier[];
/**
* Enables or disables a panel. Disabled panels are completly hidden from UI.
* By default all panels are enabled.
*/
enablePanel(id: string, enabled: boolean): void;
} }
...@@ -24,9 +24,11 @@ class TestViewletService implements IViewletService { ...@@ -24,9 +24,11 @@ class TestViewletService implements IViewletService {
onDidViewletOpenEmitter = new Emitter<IViewlet>(); onDidViewletOpenEmitter = new Emitter<IViewlet>();
onDidViewletCloseEmitter = new Emitter<IViewlet>(); onDidViewletCloseEmitter = new Emitter<IViewlet>();
onDidViewletEnableEmitter = new Emitter<{ id: string, enabled: boolean }>();
onDidViewletOpen = this.onDidViewletOpenEmitter.event; onDidViewletOpen = this.onDidViewletOpenEmitter.event;
onDidViewletClose = this.onDidViewletCloseEmitter.event; onDidViewletClose = this.onDidViewletCloseEmitter.event;
onDidViewletEnable = this.onDidViewletEnableEmitter.event;
public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> { public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> {
return TPromise.as(null); return TPromise.as(null);
...@@ -39,6 +41,7 @@ class TestViewletService implements IViewletService { ...@@ -39,6 +41,7 @@ class TestViewletService implements IViewletService {
public getActiveViewlet(): IViewlet { public getActiveViewlet(): IViewlet {
return activeViewlet; return activeViewlet;
} }
public enableViewlet(id: string, enabled: boolean): void { }
public dispose() { public dispose() {
} }
...@@ -74,6 +77,8 @@ class TestPanelService implements IPanelService { ...@@ -74,6 +77,8 @@ class TestPanelService implements IPanelService {
return activeViewlet; return activeViewlet;
} }
public enablePanel(id: string, enabled: boolean): void { }
public dispose() { public dispose() {
} }
} }
......
...@@ -18,6 +18,7 @@ export interface IViewletService { ...@@ -18,6 +18,7 @@ export interface IViewletService {
onDidViewletOpen: Event<IViewlet>; onDidViewletOpen: Event<IViewlet>;
onDidViewletClose: Event<IViewlet>; onDidViewletClose: Event<IViewlet>;
onDidViewletEnable: Event<{ id: string, enabled: boolean }>;
/** /**
* Opens a viewlet with the given identifier and pass keyboard focus to it if specified. * Opens a viewlet with the given identifier and pass keyboard focus to it if specified.
...@@ -44,6 +45,12 @@ export interface IViewletService { ...@@ -44,6 +45,12 @@ export interface IViewletService {
*/ */
getViewlets(): ViewletDescriptor[]; getViewlets(): ViewletDescriptor[];
/**
* Enables or disables a viewlet. Disabled viewlets are completly hidden from UI.
* By default all viewlets are enabled.
*/
enableViewlet(id: string, enabled: boolean): void;
/** /**
* *
*/ */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import { TPromise, ValueCallback } from 'vs/base/common/winjs.base'; import { TPromise, ValueCallback } from 'vs/base/common/winjs.base';
import { IViewlet } from 'vs/workbench/common/viewlet'; import { IViewlet } from 'vs/workbench/common/viewlet';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import Event from 'vs/base/common/event'; import Event, { Emitter } from 'vs/base/common/event';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart'; import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { ViewletDescriptor, ViewletRegistry, Extensions as ViewletExtensions } from 'vs/workbench/browser/viewlet'; import { ViewletDescriptor, ViewletRegistry, Extensions as ViewletExtensions } from 'vs/workbench/browser/viewlet';
...@@ -15,8 +15,6 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten ...@@ -15,8 +15,6 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
import { IProgressService } from 'vs/platform/progress/common/progress'; import { IProgressService } from 'vs/platform/progress/common/progress';
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { dispose, IDisposable } from 'vs/base/common/lifecycle'; import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { ISearchConfiguration, VIEW_ID as SEARCH_VIEW_ID } from 'vs/platform/search/common/search';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
const ActiveViewletContextId = 'activeViewlet'; const ActiveViewletContextId = 'activeViewlet';
export const ActiveViewletContext = new RawContextKey<string>(ActiveViewletContextId, ''); export const ActiveViewletContext = new RawContextKey<string>(ActiveViewletContextId, '');
...@@ -32,16 +30,17 @@ export class ViewletService implements IViewletService { ...@@ -32,16 +30,17 @@ export class ViewletService implements IViewletService {
private extensionViewletsLoaded: TPromise<void>; private extensionViewletsLoaded: TPromise<void>;
private extensionViewletsLoadedPromiseComplete: ValueCallback; private extensionViewletsLoadedPromiseComplete: ValueCallback;
private activeViewletContextKey: IContextKey<string>; private activeViewletContextKey: IContextKey<string>;
private _onDidViewletEnable = new Emitter<{ id: string, enabled: boolean }>();
private disposables: IDisposable[] = []; private disposables: IDisposable[] = [];
public get onDidViewletOpen(): Event<IViewlet> { return this.sidebarPart.onDidViewletOpen; } public get onDidViewletOpen(): Event<IViewlet> { return this.sidebarPart.onDidViewletOpen; }
public get onDidViewletClose(): Event<IViewlet> { return this.sidebarPart.onDidViewletClose; } public get onDidViewletClose(): Event<IViewlet> { return this.sidebarPart.onDidViewletClose; }
public get onDidViewletEnable(): Event<{ id: string, enabled: boolean }> { return this._onDidViewletEnable.event; }
constructor( constructor(
sidebarPart: SidebarPart, sidebarPart: SidebarPart,
@IExtensionService private extensionService: IExtensionService, @IExtensionService private extensionService: IExtensionService,
@IContextKeyService contextKeyService: IContextKeyService, @IContextKeyService contextKeyService: IContextKeyService
@IConfigurationService private configurationService: IConfigurationService
) { ) {
this.sidebarPart = sidebarPart; this.sidebarPart = sidebarPart;
this.viewletRegistry = Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets); this.viewletRegistry = Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets);
...@@ -85,6 +84,14 @@ export class ViewletService implements IViewletService { ...@@ -85,6 +84,14 @@ export class ViewletService implements IViewletService {
}); });
} }
public enableViewlet(id: string, enabled: boolean): void {
const descriptor = this.getBuiltInViewlets().filter(desc => desc.id === id).pop();
if (descriptor && descriptor.enabled !== enabled) {
descriptor.enabled = enabled;
this._onDidViewletEnable.fire({ id, enabled });
}
}
public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> { public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> {
// Built in viewlets do not need to wait for extensions to be loaded // Built in viewlets do not need to wait for extensions to be loaded
...@@ -112,10 +119,8 @@ export class ViewletService implements IViewletService { ...@@ -112,10 +119,8 @@ export class ViewletService implements IViewletService {
public getViewlets(): ViewletDescriptor[] { public getViewlets(): ViewletDescriptor[] {
const builtInViewlets = this.getBuiltInViewlets(); const builtInViewlets = this.getBuiltInViewlets();
const viewlets = builtInViewlets.concat(this.extensionViewlets); const viewlets = builtInViewlets.concat(this.extensionViewlets);
const searchConfig = this.configurationService.getValue<ISearchConfiguration>();
const excludeSearch = searchConfig.search.location !== 'sidebar';
return viewlets.filter(v => !(v.id === SEARCH_VIEW_ID && excludeSearch)); return viewlets.filter(v => v.enabled);
} }
private getBuiltInViewlets(): ViewletDescriptor[] { private getBuiltInViewlets(): ViewletDescriptor[] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册