Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search panel #43833

Merged
merged 9 commits into from
Feb 22, 2018
2 changes: 2 additions & 0 deletions src/vs/platform/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import { IDisposable } from 'vs/base/common/lifecycle';

export const ID = 'searchService';
export const VIEW_ID = 'workbench.view.search';

export const ISearchService = createDecorator<ISearchService>(ID);

Expand Down Expand Up @@ -178,6 +179,7 @@ export interface ISearchConfigurationProperties {
followSymlinks: boolean;
smartCase: boolean;
globalFindClipboard: boolean;
location: 'sidebar' | 'panel';
}

export interface ISearchConfiguration extends IFilesConfiguration {
Expand Down
16 changes: 15 additions & 1 deletion src/vs/workbench/browser/parts/activitybar/activitybarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { ACTIVITY_BAR_BACKGROUND, ACTIVITY_BAR_BORDER, ACTIVITY_BAR_FOREGROUND,
import { contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { CompositeBar } from 'vs/workbench/browser/parts/compositebar/compositeBar';
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 {

Expand Down Expand Up @@ -56,7 +58,8 @@ export class ActivitybarPart extends Part {
@IContextMenuService private contextMenuService: IContextMenuService,
@IInstantiationService private instantiationService: IInstantiationService,
@IPartService private partService: IPartService,
@IThemeService themeService: IThemeService
@IThemeService themeService: IThemeService,
@IConfigurationService private configurationService: IConfigurationService
) {
super(id, { hasTitle: false }, themeService);

Expand Down Expand Up @@ -86,6 +89,17 @@ export class ActivitybarPart extends Part {
// Deactivate viewlet action on close
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.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('search.location')) {
const location = this.configurationService.getValue<ISearchConfiguration>().search.location;
if (location === 'sidebar') {
this.compositeBar.addComposite(this.viewletService.getViewlet(SEARCH_VIEW_ID));
} else {
this.compositeBar.removeComposite(SEARCH_VIEW_ID);
}
}
}));
}

public showActivity(viewletOrActionId: string, badge: IBadge, clazz?: string, priority?: number): IDisposable {
Expand Down
18 changes: 18 additions & 0 deletions src/vs/workbench/browser/parts/compositebar/compositeBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ export class CompositeBar implements ICompositeBar {
return this._onDidContextMenu.event;
}

public addComposite(compositeData: { id: string; name: string }): void {
if (this.options.composites.filter(c => c.id === compositeData.id).length) {
return;
}

this.options.composites.push(compositeData);
this.pin(compositeData.id);
}

public removeComposite(id: string): void {
if (this.options.composites.filter(c => c.id === id).length === 0) {
return;
}

this.options.composites = this.options.composites.filter(c => c.id !== id);
this.unpin(id);
}

public activateComposite(id: string): void {
if (this.compositeIdToActions[id]) {
if (this.compositeIdToActions[this.activeCompositeId]) {
Expand Down
20 changes: 18 additions & 2 deletions src/vs/workbench/browser/parts/panel/panelPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { IBadge } from 'vs/workbench/services/activity/common/activity';
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 {

Expand All @@ -54,6 +56,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
@IKeybindingService keybindingService: IKeybindingService,
@IInstantiationService instantiationService: IInstantiationService,
@IThemeService themeService: IThemeService,
@IConfigurationService private configurationService: IConfigurationService
) {
super(
notificationService,
Expand Down Expand Up @@ -106,10 +109,20 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
// Need to relayout composite bar since different panels have different action bar width
this.layoutCompositeBar();
}));
this.toUnbind.push(this.compositeBar.onDidContextMenu(e => this.showContextMenu(e)));

// Deactivate panel action on close
this.toUnbind.push(this.onDidPanelClose(panel => this.compositeBar.deactivateComposite(panel.getId())));
this.toUnbind.push(this.compositeBar.onDidContextMenu(e => this.showContextMenu(e)));
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> {
Expand Down Expand Up @@ -155,7 +168,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
}

private getPanel(panelId: string): IPanelIdentifier {
return Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels().filter(p => p.id === panelId).pop();
return this.getPanels().filter(p => p.id === panelId).pop();
}

private showContextMenu(e: MouseEvent): void {
Expand All @@ -170,7 +183,10 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
}

public getPanels(): IPanelIdentifier[] {
const searchConfig = this.configurationService.getValue<ISearchConfiguration>();
const excludeSearch = searchConfig.search.location !== 'panel';
return Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels()
.filter(p => !(p.id === SEARCH_VIEW_ID && excludeSearch))
.sort((v1, v2) => v1.order - v2.order);
}

Expand Down
Loading