Skip to content

Commit ce1f35c

Browse files
committed
search and panel: support search.location setting
1 parent 879a409 commit ce1f35c

9 files changed

Lines changed: 31 additions & 17 deletions

File tree

src/vs/platform/search/common/search.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
1414
import { IDisposable } from 'vs/base/common/lifecycle';
1515

1616
export const ID = 'searchService';
17+
export const VIEW_ID = 'workbench.view.search';
1718

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

@@ -178,6 +179,7 @@ export interface ISearchConfigurationProperties {
178179
followSymlinks: boolean;
179180
smartCase: boolean;
180181
globalFindClipboard: boolean;
182+
location: 'sidebar' | 'panel';
181183
}
182184

183185
export interface ISearchConfiguration extends IFilesConfiguration {

src/vs/workbench/browser/parts/panel/panelPart.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
3030
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
3131
import { IBadge } from 'vs/workbench/services/activity/common/activity';
3232
import { INotificationService } from 'vs/platform/notification/common/notification';
33+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
34+
import { ISearchConfiguration, VIEW_ID as SEARCH_VIEW_ID } from 'vs/platform/search/common/search';
3335

3436
export class PanelPart extends CompositePart<Panel> implements IPanelService {
3537

@@ -54,6 +56,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
5456
@IKeybindingService keybindingService: IKeybindingService,
5557
@IInstantiationService instantiationService: IInstantiationService,
5658
@IThemeService themeService: IThemeService,
59+
@IConfigurationService private configurationService: IConfigurationService
5760
) {
5861
super(
5962
notificationService,
@@ -155,7 +158,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
155158
}
156159

157160
private getPanel(panelId: string): IPanelIdentifier {
158-
return Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels().filter(p => p.id === panelId).pop();
161+
return this.getPanels().filter(p => p.id === panelId).pop();
159162
}
160163

161164
private showContextMenu(e: MouseEvent): void {
@@ -170,7 +173,10 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
170173
}
171174

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

src/vs/workbench/parts/search/browser/searchActions.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation
2121
import { OS } from 'vs/base/common/platform';
2222
import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
2323
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
24+
import { VIEW_ID } from 'vs/platform/search/common/search';
2425

2526
export function isSearchViewletFocused(viewletService: IViewletService, panelService: IPanelService): boolean {
2627
let searchView = getSearchView(viewletService, panelService);
@@ -38,21 +39,21 @@ export function appendKeyBindingLabel(label: string, keyBinding: number | Resolv
3839
}
3940

4041
export function openSearchView(viewletService: IViewletService, panelService: IPanelService, focus?: boolean): TPromise<SearchView> {
41-
if (viewletService.getViewlets().filter(v => v.id === Constants.VIEW_ID).length) {
42-
return viewletService.openViewlet(Constants.VIEW_ID, focus).then(viewlet => <SearchView>viewlet);
42+
if (viewletService.getViewlets().filter(v => v.id === VIEW_ID).length) {
43+
return viewletService.openViewlet(VIEW_ID, focus).then(viewlet => <SearchView>viewlet);
4344
}
4445

45-
return panelService.openPanel(Constants.VIEW_ID, focus).then(panel => <SearchView>panel);
46+
return panelService.openPanel(VIEW_ID, focus).then(panel => <SearchView>panel);
4647
}
4748

4849
export function getSearchView(viewletService: IViewletService, panelService: IPanelService): SearchView {
4950
const activeViewlet = viewletService.getActiveViewlet();
50-
if (activeViewlet && activeViewlet.getId() === Constants.VIEW_ID) {
51+
if (activeViewlet && activeViewlet.getId() === VIEW_ID) {
5152
return <SearchView>activeViewlet;
5253
}
5354

5455
const activePanel = panelService.getActivePanel();
55-
if (activePanel && activePanel.getId() === Constants.VIEW_ID) {
56+
if (activePanel && activePanel.getId() === VIEW_ID) {
5657
return <SearchView>activePanel;
5758
}
5859

src/vs/workbench/parts/search/browser/searchViewlet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { FileChangeType, FileChangesEvent, IFileService } from 'vs/platform/file
2929
import { Match, FileMatch, SearchModel, FileMatchOrMatch, IChangeEvent, ISearchWorkbenchService, FolderMatch } from 'vs/workbench/parts/search/common/searchModel';
3030
import { QueryBuilder } from 'vs/workbench/parts/search/common/queryBuilder';
3131
import { MessageType } from 'vs/base/browser/ui/inputbox/inputBox';
32-
import { ISearchProgressItem, ISearchComplete, ISearchQuery, IQueryOptions, ISearchConfiguration, IPatternInfo } from 'vs/platform/search/common/search';
32+
import { ISearchProgressItem, ISearchComplete, ISearchQuery, IQueryOptions, ISearchConfiguration, IPatternInfo, VIEW_ID } from 'vs/platform/search/common/search';
3333
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
3434
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
3535
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -124,7 +124,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
124124
@IPreferencesService private preferencesService: IPreferencesService,
125125
@IThemeService protected themeService: IThemeService
126126
) {
127-
super(Constants.VIEW_ID, telemetryService, themeService);
127+
super(VIEW_ID, telemetryService, themeService);
128128

129129
this.viewletVisible = Constants.SearchViewletVisibleKey.bindTo(contextKeyService);
130130
this.inputBoxFocused = Constants.InputBoxFocusedKey.bindTo(this.contextKeyService);

src/vs/workbench/parts/search/common/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
77

8-
export const VIEW_ID = 'workbench.view.search';
9-
108
export const FindInFilesActionId = 'workbench.action.findInFiles';
119
export const FocusActiveEditorCommandId = 'search.action.focusActiveEditor';
1210

src/vs/workbench/parts/search/electron-browser/search.contribution.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { Schemas } from 'vs/base/common/network';
5454
import { PanelRegistry, Extensions as PanelExtensions, PanelDescriptor } from 'vs/workbench/browser/panel';
5555
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
5656
import { openSearchView, getSearchView, ReplaceAllInFolderAction, ReplaceAllAction, CloseReplaceAction, FocusNextInputAction, FocusPreviousInputAction, FocusNextSearchResultAction, FocusPreviousSearchResultAction, ReplaceInFilesAction, FindInFilesAction, FocusActiveEditorCommand, toggleCaseSensitiveCommand, ShowNextSearchTermAction, ShowPreviousSearchTermAction, toggleRegexCommand, ShowNextSearchExcludeAction, ShowPreviousSearchIncludeAction, ShowNextSearchIncludeAction, ShowPreviousSearchExcludeAction, CollapseDeepestExpandedLevelAction, toggleWholeWordCommand, RemoveAction, ReplaceAction } from 'vs/workbench/parts/search/browser/searchActions';
57+
import { VIEW_ID } from 'vs/platform/search/common/search';
5758

5859
registerSingleton(ISearchWorkbenchService, SearchWorkbenchService);
5960
replaceContributions();
@@ -282,7 +283,7 @@ class ShowAllSymbolsAction extends Action {
282283
// Register Viewlet
283284
Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets).registerViewlet(new ViewletDescriptor(
284285
SearchView,
285-
Constants.VIEW_ID,
286+
VIEW_ID,
286287
nls.localize('name', "Search"),
287288
'search',
288289
10
@@ -291,7 +292,7 @@ Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets).registerViewlet(new Vie
291292
// Register Viewlet
292293
Registry.as<PanelRegistry>(PanelExtensions.Panels).registerPanel(new PanelDescriptor(
293294
SearchView,
294-
Constants.VIEW_ID,
295+
VIEW_ID,
295296
nls.localize('name', "Search"),
296297
'search',
297298
10
@@ -301,7 +302,7 @@ Registry.as<PanelRegistry>(PanelExtensions.Panels).registerPanel(new PanelDescri
301302
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
302303
const category = nls.localize('search', "Search");
303304

304-
registry.registerWorkbenchAction(new SyncActionDescriptor(FindInFilesAction, Constants.VIEW_ID, nls.localize('showSearchViewlet', "Show Search"), { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F },
305+
registry.registerWorkbenchAction(new SyncActionDescriptor(FindInFilesAction, VIEW_ID, nls.localize('showSearchViewlet', "Show Search"), { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F },
305306
Constants.SearchViewletVisibleKey.toNegated()), 'View: Show Search', nls.localize('view', "View"));
306307
registry.registerWorkbenchAction(new SyncActionDescriptor(FindInFilesAction, Constants.FindInFilesActionId, nls.localize('findInFiles', "Find in Files"), { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F },
307308
Constants.SearchInputBoxFocusedKey.toNegated()), 'Find in Files', category);

src/vs/workbench/services/panel/common/panelService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface IPanelService {
3434
getActivePanel(): IPanel;
3535

3636
/**
37-
* Returns all registered panels
37+
* Returns all enabled panels
3838
*/
3939
getPanels(): IPanelIdentifier[];
4040
}

src/vs/workbench/services/viewlet/browser/viewlet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface IViewletService {
4040
getViewlet(id: string): ViewletDescriptor;
4141

4242
/**
43-
* Returns all registered viewlets
43+
* Returns all enabled viewlets
4444
*/
4545
getViewlets(): ViewletDescriptor[];
4646

src/vs/workbench/services/viewlet/browser/viewletService.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { IExtensionService } from 'vs/platform/extensions/common/extensions';
1515
import { IProgressService } from 'vs/platform/progress/common/progress';
1616
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
1717
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
18+
import { ISearchConfiguration, VIEW_ID as SEARCH_VIEW_ID } from 'vs/platform/search/common/search';
19+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1820

1921
const ActiveViewletContextId = 'activeViewlet';
2022
export const ActiveViewletContext = new RawContextKey<string>(ActiveViewletContextId, '');
@@ -38,7 +40,8 @@ export class ViewletService implements IViewletService {
3840
constructor(
3941
sidebarPart: SidebarPart,
4042
@IExtensionService private extensionService: IExtensionService,
41-
@IContextKeyService contextKeyService: IContextKeyService
43+
@IContextKeyService contextKeyService: IContextKeyService,
44+
@IConfigurationService private configurationService: IConfigurationService
4245
) {
4346
this.sidebarPart = sidebarPart;
4447
this.viewletRegistry = Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets);
@@ -108,8 +111,11 @@ export class ViewletService implements IViewletService {
108111

109112
public getViewlets(): ViewletDescriptor[] {
110113
const builtInViewlets = this.getBuiltInViewlets();
114+
const viewlets = builtInViewlets.concat(this.extensionViewlets);
115+
const searchConfig = this.configurationService.getValue<ISearchConfiguration>();
116+
const excludeSearch = searchConfig.search.location !== 'sidebar';
111117

112-
return builtInViewlets.concat(this.extensionViewlets);
118+
return viewlets.filter(v => !(v.id === SEARCH_VIEW_ID && excludeSearch));
113119
}
114120

115121
private getBuiltInViewlets(): ViewletDescriptor[] {

0 commit comments

Comments
 (0)