@theia/search-in-workspace 1.45.0 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +40 -40
  2. package/lib/browser/components/search-in-workspace-input.d.ts +39 -39
  3. package/lib/browser/components/search-in-workspace-input.js +123 -123
  4. package/lib/browser/components/search-in-workspace-textarea.d.ts +39 -39
  5. package/lib/browser/components/search-in-workspace-textarea.js +130 -130
  6. package/lib/browser/search-in-workspace-context-key-service.d.ts +23 -23
  7. package/lib/browser/search-in-workspace-context-key-service.js +90 -90
  8. package/lib/browser/search-in-workspace-factory.d.ts +10 -10
  9. package/lib/browser/search-in-workspace-factory.js +68 -68
  10. package/lib/browser/search-in-workspace-frontend-contribution.d.ts +57 -55
  11. package/lib/browser/search-in-workspace-frontend-contribution.d.ts.map +1 -1
  12. package/lib/browser/search-in-workspace-frontend-contribution.js +516 -482
  13. package/lib/browser/search-in-workspace-frontend-contribution.js.map +1 -1
  14. package/lib/browser/search-in-workspace-frontend-module.d.ts +6 -6
  15. package/lib/browser/search-in-workspace-frontend-module.js +71 -71
  16. package/lib/browser/search-in-workspace-label-provider.d.ts +9 -9
  17. package/lib/browser/search-in-workspace-label-provider.js +57 -57
  18. package/lib/browser/search-in-workspace-preferences.d.ts +17 -17
  19. package/lib/browser/search-in-workspace-preferences.js +87 -87
  20. package/lib/browser/search-in-workspace-result-tree-widget.d.ts +259 -255
  21. package/lib/browser/search-in-workspace-result-tree-widget.d.ts.map +1 -1
  22. package/lib/browser/search-in-workspace-result-tree-widget.js +1172 -1099
  23. package/lib/browser/search-in-workspace-result-tree-widget.js.map +1 -1
  24. package/lib/browser/search-in-workspace-service.d.ts +35 -35
  25. package/lib/browser/search-in-workspace-service.js +158 -158
  26. package/lib/browser/search-in-workspace-widget.d.ts +121 -121
  27. package/lib/browser/search-in-workspace-widget.js +629 -629
  28. package/lib/browser/search-layout-migrations.d.ts +5 -5
  29. package/lib/browser/search-layout-migrations.js +64 -64
  30. package/lib/common/search-in-workspace-interface.d.ts +116 -116
  31. package/lib/common/search-in-workspace-interface.js +35 -35
  32. package/lib/node/ripgrep-search-in-workspace-server.d.ts +94 -94
  33. package/lib/node/ripgrep-search-in-workspace-server.js +430 -430
  34. package/lib/node/ripgrep-search-in-workspace-server.js.map +1 -1
  35. package/lib/node/ripgrep-search-in-workspace-server.slow-spec.d.ts +1 -1
  36. package/lib/node/ripgrep-search-in-workspace-server.slow-spec.js +899 -899
  37. package/lib/node/ripgrep-search-in-workspace-server.slow-spec.js.map +1 -1
  38. package/lib/node/search-in-workspace-backend-module.d.ts +3 -3
  39. package/lib/node/search-in-workspace-backend-module.js +32 -32
  40. package/package.json +9 -9
  41. package/src/browser/components/search-in-workspace-input.tsx +139 -139
  42. package/src/browser/components/search-in-workspace-textarea.tsx +153 -153
  43. package/src/browser/search-in-workspace-context-key-service.ts +93 -93
  44. package/src/browser/search-in-workspace-factory.ts +59 -59
  45. package/src/browser/search-in-workspace-frontend-contribution.ts +510 -474
  46. package/src/browser/search-in-workspace-frontend-module.ts +83 -83
  47. package/src/browser/search-in-workspace-label-provider.ts +48 -48
  48. package/src/browser/search-in-workspace-preferences.ts +96 -96
  49. package/src/browser/search-in-workspace-result-tree-widget.tsx +1318 -1245
  50. package/src/browser/search-in-workspace-service.ts +152 -152
  51. package/src/browser/search-in-workspace-widget.tsx +727 -727
  52. package/src/browser/search-layout-migrations.ts +53 -53
  53. package/src/browser/styles/index.css +400 -400
  54. package/src/browser/styles/search.svg +6 -6
  55. package/src/common/search-in-workspace-interface.ts +153 -153
  56. package/src/node/ripgrep-search-in-workspace-server.slow-spec.ts +1073 -1073
  57. package/src/node/ripgrep-search-in-workspace-server.ts +490 -490
  58. package/src/node/search-in-workspace-backend-module.ts +33 -33
@@ -1,483 +1,517 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2018 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.SearchInWorkspaceFrontendContribution = exports.SearchInWorkspaceCommands = void 0;
28
- const browser_1 = require("@theia/core/lib/browser");
29
- const search_in_workspace_widget_1 = require("./search-in-workspace-widget");
30
- const inversify_1 = require("@theia/core/shared/inversify");
31
- const core_1 = require("@theia/core");
32
- const widgets_1 = require("@theia/core/lib/browser/widgets");
33
- const navigator_contribution_1 = require("@theia/navigator/lib/browser/navigator-contribution");
34
- const uri_command_handler_1 = require("@theia/core/lib/common/uri-command-handler");
35
- const browser_2 = require("@theia/workspace/lib/browser");
36
- const search_in_workspace_context_key_service_1 = require("./search-in-workspace-context-key-service");
37
- const editor_manager_1 = require("@theia/editor/lib/browser/editor-manager");
38
- const vscode_languageserver_protocol_1 = require("@theia/core/shared/vscode-languageserver-protocol");
39
- const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
40
- const search_in_workspace_factory_1 = require("./search-in-workspace-factory");
41
- const search_in_workspace_result_tree_widget_1 = require("./search-in-workspace-result-tree-widget");
42
- const tree_widget_selection_1 = require("@theia/core/lib/browser/tree/tree-widget-selection");
43
- const clipboard_service_1 = require("@theia/core/lib/browser/clipboard-service");
44
- const theme_1 = require("@theia/core/lib/common/theme");
45
- var SearchInWorkspaceCommands;
46
- (function (SearchInWorkspaceCommands) {
47
- const SEARCH_CATEGORY = 'Search';
48
- SearchInWorkspaceCommands.TOGGLE_SIW_WIDGET = {
49
- id: 'search-in-workspace.toggle'
50
- };
51
- SearchInWorkspaceCommands.OPEN_SIW_WIDGET = core_1.Command.toDefaultLocalizedCommand({
52
- id: 'search-in-workspace.open',
53
- category: SEARCH_CATEGORY,
54
- label: 'Find in Files'
55
- });
56
- SearchInWorkspaceCommands.REPLACE_IN_FILES = core_1.Command.toDefaultLocalizedCommand({
57
- id: 'search-in-workspace.replace',
58
- category: SEARCH_CATEGORY,
59
- label: 'Replace in Files'
60
- });
61
- SearchInWorkspaceCommands.FIND_IN_FOLDER = core_1.Command.toDefaultLocalizedCommand({
62
- id: 'search-in-workspace.in-folder',
63
- category: SEARCH_CATEGORY,
64
- label: 'Find in Folder...'
65
- });
66
- SearchInWorkspaceCommands.REFRESH_RESULTS = core_1.Command.toDefaultLocalizedCommand({
67
- id: 'search-in-workspace.refresh',
68
- category: SEARCH_CATEGORY,
69
- label: 'Refresh',
70
- iconClass: (0, widgets_1.codicon)('refresh')
71
- });
72
- SearchInWorkspaceCommands.CANCEL_SEARCH = core_1.Command.toDefaultLocalizedCommand({
73
- id: 'search-in-workspace.cancel',
74
- category: SEARCH_CATEGORY,
75
- label: 'Cancel Search',
76
- iconClass: (0, widgets_1.codicon)('search-stop')
77
- });
78
- SearchInWorkspaceCommands.COLLAPSE_ALL = core_1.Command.toDefaultLocalizedCommand({
79
- id: 'search-in-workspace.collapse-all',
80
- category: SEARCH_CATEGORY,
81
- label: 'Collapse All',
82
- iconClass: (0, widgets_1.codicon)('collapse-all')
83
- });
84
- SearchInWorkspaceCommands.EXPAND_ALL = core_1.Command.toDefaultLocalizedCommand({
85
- id: 'search-in-workspace.expand-all',
86
- category: SEARCH_CATEGORY,
87
- label: 'Expand All',
88
- iconClass: (0, widgets_1.codicon)('expand-all')
89
- });
90
- SearchInWorkspaceCommands.CLEAR_ALL = core_1.Command.toDefaultLocalizedCommand({
91
- id: 'search-in-workspace.clear-all',
92
- category: SEARCH_CATEGORY,
93
- label: 'Clear Search Results',
94
- iconClass: (0, widgets_1.codicon)('clear-all')
95
- });
96
- SearchInWorkspaceCommands.COPY_ALL = core_1.Command.toDefaultLocalizedCommand({
97
- id: 'search.action.copyAll',
98
- category: SEARCH_CATEGORY,
99
- label: 'Copy All',
100
- });
101
- SearchInWorkspaceCommands.COPY_ONE = core_1.Command.toDefaultLocalizedCommand({
102
- id: 'search.action.copyMatch',
103
- category: SEARCH_CATEGORY,
104
- label: 'Copy',
105
- });
106
- SearchInWorkspaceCommands.DISMISS_RESULT = core_1.Command.toDefaultLocalizedCommand({
107
- id: 'search.action.remove',
108
- category: SEARCH_CATEGORY,
109
- label: 'Dismiss',
110
- });
111
- SearchInWorkspaceCommands.REPLACE_RESULT = core_1.Command.toDefaultLocalizedCommand({
112
- id: 'search.action.replace',
113
- });
114
- SearchInWorkspaceCommands.REPLACE_ALL_RESULTS = core_1.Command.toDefaultLocalizedCommand({
115
- id: 'search.action.replaceAll'
116
- });
117
- })(SearchInWorkspaceCommands = exports.SearchInWorkspaceCommands || (exports.SearchInWorkspaceCommands = {}));
118
- let SearchInWorkspaceFrontendContribution = class SearchInWorkspaceFrontendContribution extends browser_1.AbstractViewContribution {
119
- constructor() {
120
- super({
121
- viewContainerId: search_in_workspace_factory_1.SEARCH_VIEW_CONTAINER_ID,
122
- widgetId: search_in_workspace_widget_1.SearchInWorkspaceWidget.ID,
123
- widgetName: search_in_workspace_widget_1.SearchInWorkspaceWidget.LABEL,
124
- defaultWidgetOptions: {
125
- area: 'left',
126
- rank: 200
127
- },
128
- toggleCommandId: SearchInWorkspaceCommands.TOGGLE_SIW_WIDGET.id
129
- });
130
- }
131
- init() {
132
- const updateFocusContextKey = () => this.contextKeyService.searchViewletFocus.set(this.shell.activeWidget instanceof search_in_workspace_widget_1.SearchInWorkspaceWidget);
133
- updateFocusContextKey();
134
- this.shell.onDidChangeActiveWidget(updateFocusContextKey);
135
- }
136
- async initializeLayout(app) {
137
- await this.openView({ activate: false });
138
- }
139
- async registerCommands(commands) {
140
- super.registerCommands(commands);
141
- commands.registerCommand(SearchInWorkspaceCommands.OPEN_SIW_WIDGET, {
142
- isEnabled: () => this.workspaceService.tryGetRoots().length > 0,
143
- execute: async () => {
144
- const widget = await this.openView({ activate: true });
145
- widget.updateSearchTerm(this.getSearchTerm());
146
- }
147
- });
148
- commands.registerCommand(SearchInWorkspaceCommands.REPLACE_IN_FILES, {
149
- isEnabled: () => this.workspaceService.tryGetRoots().length > 0,
150
- execute: async () => {
151
- const widget = await this.openView({ activate: true });
152
- widget.updateSearchTerm(this.getSearchTerm(), true);
153
- }
154
- });
155
- commands.registerCommand(SearchInWorkspaceCommands.FIND_IN_FOLDER, this.newMultiUriAwareCommandHandler({
156
- execute: async (uris) => {
157
- const resources = [];
158
- for (const { stat } of await this.fileService.resolveAll(uris.map(resource => ({ resource })))) {
159
- if (stat) {
160
- const uri = stat.resource;
161
- let uriStr = this.labelProvider.getLongName(uri);
162
- if (stat && !stat.isDirectory) {
163
- uriStr = this.labelProvider.getLongName(uri.parent);
164
- }
165
- resources.push(uriStr);
166
- }
167
- }
168
- const widget = await this.openView({ activate: true });
169
- widget.findInFolder(resources);
170
- }
171
- }));
172
- commands.registerCommand(SearchInWorkspaceCommands.CANCEL_SEARCH, {
173
- execute: w => this.withWidget(w, widget => widget.getCancelIndicator() && widget.getCancelIndicator().cancel()),
174
- isEnabled: w => this.withWidget(w, widget => widget.getCancelIndicator() !== undefined),
175
- isVisible: w => this.withWidget(w, widget => widget.getCancelIndicator() !== undefined)
176
- });
177
- commands.registerCommand(SearchInWorkspaceCommands.REFRESH_RESULTS, {
178
- execute: w => this.withWidget(w, widget => widget.refresh()),
179
- isEnabled: w => this.withWidget(w, widget => (widget.hasResultList() || widget.hasSearchTerm()) && this.workspaceService.tryGetRoots().length > 0),
180
- isVisible: w => this.withWidget(w, () => true)
181
- });
182
- commands.registerCommand(SearchInWorkspaceCommands.COLLAPSE_ALL, {
183
- execute: w => this.withWidget(w, widget => widget.collapseAll()),
184
- isEnabled: w => this.withWidget(w, widget => widget.hasResultList()),
185
- isVisible: w => this.withWidget(w, widget => !widget.areResultsCollapsed())
186
- });
187
- commands.registerCommand(SearchInWorkspaceCommands.EXPAND_ALL, {
188
- execute: w => this.withWidget(w, widget => widget.expandAll()),
189
- isEnabled: w => this.withWidget(w, widget => widget.hasResultList()),
190
- isVisible: w => this.withWidget(w, widget => widget.areResultsCollapsed())
191
- });
192
- commands.registerCommand(SearchInWorkspaceCommands.CLEAR_ALL, {
193
- execute: w => this.withWidget(w, widget => widget.clear()),
194
- isEnabled: w => this.withWidget(w, widget => widget.hasResultList()),
195
- isVisible: w => this.withWidget(w, () => true)
196
- });
197
- commands.registerCommand(SearchInWorkspaceCommands.DISMISS_RESULT, {
198
- isEnabled: () => this.withWidget(undefined, widget => {
199
- const { selection } = this.selectionService;
200
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
201
- }),
202
- isVisible: () => this.withWidget(undefined, widget => {
203
- const { selection } = this.selectionService;
204
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
205
- }),
206
- execute: () => this.withWidget(undefined, widget => {
207
- const { selection } = this.selectionService;
208
- if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
209
- selection.forEach(n => widget.resultTreeWidget.removeNode(n));
210
- }
211
- })
212
- });
213
- commands.registerCommand(SearchInWorkspaceCommands.REPLACE_RESULT, {
214
- isEnabled: () => this.withWidget(undefined, widget => {
215
- const { selection } = this.selectionService;
216
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0 && !search_in_workspace_result_tree_widget_1.SearchInWorkspaceFileNode.is(selection[0]);
217
- }),
218
- isVisible: () => this.withWidget(undefined, widget => {
219
- const { selection } = this.selectionService;
220
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0 && !search_in_workspace_result_tree_widget_1.SearchInWorkspaceFileNode.is(selection[0]);
221
- }),
222
- execute: () => this.withWidget(undefined, widget => {
223
- const { selection } = this.selectionService;
224
- if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
225
- selection.forEach(n => widget.resultTreeWidget.replace(n));
226
- }
227
- }),
228
- });
229
- commands.registerCommand(SearchInWorkspaceCommands.REPLACE_ALL_RESULTS, {
230
- isEnabled: () => this.withWidget(undefined, widget => {
231
- const { selection } = this.selectionService;
232
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0
233
- && search_in_workspace_result_tree_widget_1.SearchInWorkspaceFileNode.is(selection[0]);
234
- }),
235
- isVisible: () => this.withWidget(undefined, widget => {
236
- const { selection } = this.selectionService;
237
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0
238
- && search_in_workspace_result_tree_widget_1.SearchInWorkspaceFileNode.is(selection[0]);
239
- }),
240
- execute: () => this.withWidget(undefined, widget => {
241
- const { selection } = this.selectionService;
242
- if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
243
- selection.forEach(n => widget.resultTreeWidget.replace(n));
244
- }
245
- }),
246
- });
247
- commands.registerCommand(SearchInWorkspaceCommands.COPY_ONE, {
248
- isEnabled: () => this.withWidget(undefined, widget => {
249
- const { selection } = this.selectionService;
250
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
251
- }),
252
- isVisible: () => this.withWidget(undefined, widget => {
253
- const { selection } = this.selectionService;
254
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
255
- }),
256
- execute: () => this.withWidget(undefined, widget => {
257
- const { selection } = this.selectionService;
258
- if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
259
- const string = widget.resultTreeWidget.nodeToString(selection[0], true);
260
- if (string.length !== 0) {
261
- this.clipboardService.writeText(string);
262
- }
263
- }
264
- })
265
- });
266
- commands.registerCommand(SearchInWorkspaceCommands.COPY_ALL, {
267
- isEnabled: () => this.withWidget(undefined, widget => {
268
- const { selection } = this.selectionService;
269
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
270
- }),
271
- isVisible: () => this.withWidget(undefined, widget => {
272
- const { selection } = this.selectionService;
273
- return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
274
- }),
275
- execute: () => this.withWidget(undefined, widget => {
276
- const { selection } = this.selectionService;
277
- if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
278
- const string = widget.resultTreeWidget.treeToString();
279
- if (string.length !== 0) {
280
- this.clipboardService.writeText(string);
281
- }
282
- }
283
- })
284
- });
285
- }
286
- withWidget(widget = this.tryGetWidget(), fn) {
287
- if (widget instanceof search_in_workspace_widget_1.SearchInWorkspaceWidget && widget.id === search_in_workspace_widget_1.SearchInWorkspaceWidget.ID) {
288
- return fn(widget);
289
- }
290
- return false;
291
- }
292
- /**
293
- * Get the search term based on current editor selection.
294
- * @returns the selection if available.
295
- */
296
- getSearchTerm() {
297
- if (!this.editorManager.currentEditor) {
298
- return '';
299
- }
300
- // Get the current editor selection.
301
- const selection = this.editorManager.currentEditor.editor.selection;
302
- // Compute the selection range.
303
- const selectedRange = vscode_languageserver_protocol_1.Range.create(selection.start.line, selection.start.character, selection.end.line, selection.end.character);
304
- // Return the selection text if available, else return empty.
305
- return this.editorManager.currentEditor
306
- ? this.editorManager.currentEditor.editor.document.getText(selectedRange)
307
- : '';
308
- }
309
- registerKeybindings(keybindings) {
310
- super.registerKeybindings(keybindings);
311
- keybindings.registerKeybinding({
312
- command: SearchInWorkspaceCommands.OPEN_SIW_WIDGET.id,
313
- keybinding: 'ctrlcmd+shift+f'
314
- });
315
- keybindings.registerKeybinding({
316
- command: SearchInWorkspaceCommands.FIND_IN_FOLDER.id,
317
- keybinding: 'shift+alt+f',
318
- when: 'explorerResourceIsFolder'
319
- });
320
- keybindings.registerKeybinding({
321
- command: SearchInWorkspaceCommands.DISMISS_RESULT.id,
322
- keybinding: core_1.isOSX ? 'cmd+backspace' : 'del',
323
- when: 'searchViewletFocus && !inputBoxFocus'
324
- });
325
- keybindings.registerKeybinding({
326
- command: SearchInWorkspaceCommands.REPLACE_RESULT.id,
327
- keybinding: 'ctrlcmd+shift+1',
328
- when: 'searchViewletFocus && replaceActive',
329
- });
330
- keybindings.registerKeybinding({
331
- command: SearchInWorkspaceCommands.REPLACE_ALL_RESULTS.id,
332
- keybinding: 'ctrlcmd+shift+1',
333
- when: 'searchViewletFocus && replaceActive',
334
- });
335
- keybindings.registerKeybinding({
336
- command: SearchInWorkspaceCommands.COPY_ONE.id,
337
- keybinding: 'ctrlcmd+c',
338
- when: 'searchViewletFocus && !inputBoxFocus'
339
- });
340
- }
341
- registerMenus(menus) {
342
- super.registerMenus(menus);
343
- menus.registerMenuAction(navigator_contribution_1.NavigatorContextMenu.SEARCH, {
344
- commandId: SearchInWorkspaceCommands.FIND_IN_FOLDER.id,
345
- when: 'explorerResourceIsFolder'
346
- });
347
- menus.registerMenuAction(browser_1.CommonMenus.EDIT_FIND, {
348
- commandId: SearchInWorkspaceCommands.OPEN_SIW_WIDGET.id,
349
- order: '2'
350
- });
351
- menus.registerMenuAction(browser_1.CommonMenus.EDIT_FIND, {
352
- commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id,
353
- order: '3'
354
- });
355
- menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
356
- commandId: SearchInWorkspaceCommands.REPLACE_RESULT.id,
357
- label: core_1.nls.localizeByDefault('Replace'),
358
- order: '1',
359
- when: 'replaceActive',
360
- });
361
- menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
362
- commandId: SearchInWorkspaceCommands.REPLACE_ALL_RESULTS.id,
363
- label: core_1.nls.localizeByDefault('Replace All'),
364
- order: '1',
365
- when: 'replaceActive',
366
- });
367
- menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
368
- commandId: SearchInWorkspaceCommands.DISMISS_RESULT.id,
369
- order: '1'
370
- });
371
- menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.COPY, {
372
- commandId: SearchInWorkspaceCommands.COPY_ONE.id,
373
- order: '1',
374
- });
375
- menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.COPY, {
376
- commandId: browser_1.CommonCommands.COPY_PATH.id,
377
- order: '2',
378
- });
379
- menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.COPY, {
380
- commandId: SearchInWorkspaceCommands.COPY_ALL.id,
381
- order: '3',
382
- });
383
- menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.EXTERNAL, {
384
- commandId: navigator_contribution_1.FileNavigatorCommands.REVEAL_IN_NAVIGATOR.id,
385
- order: '1',
386
- });
387
- }
388
- async registerToolbarItems(toolbarRegistry) {
389
- const widget = await this.widget;
390
- const onDidChange = widget.onDidUpdate;
391
- toolbarRegistry.registerItem({
392
- id: SearchInWorkspaceCommands.CANCEL_SEARCH.id,
393
- command: SearchInWorkspaceCommands.CANCEL_SEARCH.id,
394
- tooltip: SearchInWorkspaceCommands.CANCEL_SEARCH.label,
395
- priority: 0,
396
- onDidChange
397
- });
398
- toolbarRegistry.registerItem({
399
- id: SearchInWorkspaceCommands.REFRESH_RESULTS.id,
400
- command: SearchInWorkspaceCommands.REFRESH_RESULTS.id,
401
- tooltip: SearchInWorkspaceCommands.REFRESH_RESULTS.label,
402
- priority: 1,
403
- onDidChange
404
- });
405
- toolbarRegistry.registerItem({
406
- id: SearchInWorkspaceCommands.CLEAR_ALL.id,
407
- command: SearchInWorkspaceCommands.CLEAR_ALL.id,
408
- tooltip: SearchInWorkspaceCommands.CLEAR_ALL.label,
409
- priority: 2,
410
- onDidChange
411
- });
412
- toolbarRegistry.registerItem({
413
- id: SearchInWorkspaceCommands.COLLAPSE_ALL.id,
414
- command: SearchInWorkspaceCommands.COLLAPSE_ALL.id,
415
- tooltip: SearchInWorkspaceCommands.COLLAPSE_ALL.label,
416
- priority: 3,
417
- onDidChange
418
- });
419
- toolbarRegistry.registerItem({
420
- id: SearchInWorkspaceCommands.EXPAND_ALL.id,
421
- command: SearchInWorkspaceCommands.EXPAND_ALL.id,
422
- tooltip: SearchInWorkspaceCommands.EXPAND_ALL.label,
423
- priority: 3,
424
- onDidChange
425
- });
426
- }
427
- newUriAwareCommandHandler(handler) {
428
- return uri_command_handler_1.UriAwareCommandHandler.MonoSelect(this.selectionService, handler);
429
- }
430
- newMultiUriAwareCommandHandler(handler) {
431
- return uri_command_handler_1.UriAwareCommandHandler.MultiSelect(this.selectionService, handler);
432
- }
433
- registerThemeStyle(theme, collector) {
434
- const contrastBorder = theme.getColor('contrastBorder');
435
- if (contrastBorder && (0, theme_1.isHighContrast)(theme.type)) {
436
- collector.addRule(`
437
- .t-siw-search-container .searchHeader .search-field-container {
438
- border-color: ${contrastBorder};
439
- }
440
- `);
441
- }
442
- }
443
- };
444
- __decorate([
445
- (0, inversify_1.inject)(core_1.SelectionService),
446
- __metadata("design:type", core_1.SelectionService)
447
- ], SearchInWorkspaceFrontendContribution.prototype, "selectionService", void 0);
448
- __decorate([
449
- (0, inversify_1.inject)(browser_1.LabelProvider),
450
- __metadata("design:type", browser_1.LabelProvider)
451
- ], SearchInWorkspaceFrontendContribution.prototype, "labelProvider", void 0);
452
- __decorate([
453
- (0, inversify_1.inject)(browser_2.WorkspaceService),
454
- __metadata("design:type", browser_2.WorkspaceService)
455
- ], SearchInWorkspaceFrontendContribution.prototype, "workspaceService", void 0);
456
- __decorate([
457
- (0, inversify_1.inject)(file_service_1.FileService),
458
- __metadata("design:type", file_service_1.FileService)
459
- ], SearchInWorkspaceFrontendContribution.prototype, "fileService", void 0);
460
- __decorate([
461
- (0, inversify_1.inject)(editor_manager_1.EditorManager),
462
- __metadata("design:type", editor_manager_1.EditorManager)
463
- ], SearchInWorkspaceFrontendContribution.prototype, "editorManager", void 0);
464
- __decorate([
465
- (0, inversify_1.inject)(clipboard_service_1.ClipboardService),
466
- __metadata("design:type", Object)
467
- ], SearchInWorkspaceFrontendContribution.prototype, "clipboardService", void 0);
468
- __decorate([
469
- (0, inversify_1.inject)(search_in_workspace_context_key_service_1.SearchInWorkspaceContextKeyService),
470
- __metadata("design:type", search_in_workspace_context_key_service_1.SearchInWorkspaceContextKeyService)
471
- ], SearchInWorkspaceFrontendContribution.prototype, "contextKeyService", void 0);
472
- __decorate([
473
- (0, inversify_1.postConstruct)(),
474
- __metadata("design:type", Function),
475
- __metadata("design:paramtypes", []),
476
- __metadata("design:returntype", void 0)
477
- ], SearchInWorkspaceFrontendContribution.prototype, "init", null);
478
- SearchInWorkspaceFrontendContribution = __decorate([
479
- (0, inversify_1.injectable)(),
480
- __metadata("design:paramtypes", [])
481
- ], SearchInWorkspaceFrontendContribution);
482
- exports.SearchInWorkspaceFrontendContribution = SearchInWorkspaceFrontendContribution;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2018 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.SearchInWorkspaceFrontendContribution = exports.SearchInWorkspaceCommands = void 0;
28
+ const browser_1 = require("@theia/core/lib/browser");
29
+ const search_in_workspace_widget_1 = require("./search-in-workspace-widget");
30
+ const inversify_1 = require("@theia/core/shared/inversify");
31
+ const core_1 = require("@theia/core");
32
+ const widgets_1 = require("@theia/core/lib/browser/widgets");
33
+ const navigator_contribution_1 = require("@theia/navigator/lib/browser/navigator-contribution");
34
+ const uri_command_handler_1 = require("@theia/core/lib/common/uri-command-handler");
35
+ const browser_2 = require("@theia/workspace/lib/browser");
36
+ const search_in_workspace_context_key_service_1 = require("./search-in-workspace-context-key-service");
37
+ const editor_manager_1 = require("@theia/editor/lib/browser/editor-manager");
38
+ const vscode_languageserver_protocol_1 = require("@theia/core/shared/vscode-languageserver-protocol");
39
+ const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
40
+ const search_in_workspace_factory_1 = require("./search-in-workspace-factory");
41
+ const search_in_workspace_result_tree_widget_1 = require("./search-in-workspace-result-tree-widget");
42
+ const tree_widget_selection_1 = require("@theia/core/lib/browser/tree/tree-widget-selection");
43
+ const clipboard_service_1 = require("@theia/core/lib/browser/clipboard-service");
44
+ const theme_1 = require("@theia/core/lib/common/theme");
45
+ var SearchInWorkspaceCommands;
46
+ (function (SearchInWorkspaceCommands) {
47
+ const SEARCH_CATEGORY = 'Search';
48
+ SearchInWorkspaceCommands.TOGGLE_SIW_WIDGET = {
49
+ id: 'search-in-workspace.toggle'
50
+ };
51
+ SearchInWorkspaceCommands.OPEN_SIW_WIDGET = core_1.Command.toDefaultLocalizedCommand({
52
+ id: 'search-in-workspace.open',
53
+ category: SEARCH_CATEGORY,
54
+ label: 'Find in Files'
55
+ });
56
+ SearchInWorkspaceCommands.REPLACE_IN_FILES = core_1.Command.toDefaultLocalizedCommand({
57
+ id: 'search-in-workspace.replace',
58
+ category: SEARCH_CATEGORY,
59
+ label: 'Replace in Files'
60
+ });
61
+ SearchInWorkspaceCommands.FIND_IN_FOLDER = core_1.Command.toDefaultLocalizedCommand({
62
+ id: 'search-in-workspace.in-folder',
63
+ category: SEARCH_CATEGORY,
64
+ label: 'Find in Folder...'
65
+ });
66
+ SearchInWorkspaceCommands.FOCUS_NEXT_RESULT = core_1.Command.toDefaultLocalizedCommand({
67
+ id: 'search.action.focusNextSearchResult',
68
+ category: SEARCH_CATEGORY,
69
+ label: 'Focus Next Search Result'
70
+ });
71
+ SearchInWorkspaceCommands.FOCUS_PREV_RESULT = core_1.Command.toDefaultLocalizedCommand({
72
+ id: 'search.action.focusPreviousSearchResult',
73
+ category: SEARCH_CATEGORY,
74
+ label: 'Focus Previous Search Result'
75
+ });
76
+ SearchInWorkspaceCommands.REFRESH_RESULTS = core_1.Command.toDefaultLocalizedCommand({
77
+ id: 'search-in-workspace.refresh',
78
+ category: SEARCH_CATEGORY,
79
+ label: 'Refresh',
80
+ iconClass: (0, widgets_1.codicon)('refresh')
81
+ });
82
+ SearchInWorkspaceCommands.CANCEL_SEARCH = core_1.Command.toDefaultLocalizedCommand({
83
+ id: 'search-in-workspace.cancel',
84
+ category: SEARCH_CATEGORY,
85
+ label: 'Cancel Search',
86
+ iconClass: (0, widgets_1.codicon)('search-stop')
87
+ });
88
+ SearchInWorkspaceCommands.COLLAPSE_ALL = core_1.Command.toDefaultLocalizedCommand({
89
+ id: 'search-in-workspace.collapse-all',
90
+ category: SEARCH_CATEGORY,
91
+ label: 'Collapse All',
92
+ iconClass: (0, widgets_1.codicon)('collapse-all')
93
+ });
94
+ SearchInWorkspaceCommands.EXPAND_ALL = core_1.Command.toDefaultLocalizedCommand({
95
+ id: 'search-in-workspace.expand-all',
96
+ category: SEARCH_CATEGORY,
97
+ label: 'Expand All',
98
+ iconClass: (0, widgets_1.codicon)('expand-all')
99
+ });
100
+ SearchInWorkspaceCommands.CLEAR_ALL = core_1.Command.toDefaultLocalizedCommand({
101
+ id: 'search-in-workspace.clear-all',
102
+ category: SEARCH_CATEGORY,
103
+ label: 'Clear Search Results',
104
+ iconClass: (0, widgets_1.codicon)('clear-all')
105
+ });
106
+ SearchInWorkspaceCommands.COPY_ALL = core_1.Command.toDefaultLocalizedCommand({
107
+ id: 'search.action.copyAll',
108
+ category: SEARCH_CATEGORY,
109
+ label: 'Copy All',
110
+ });
111
+ SearchInWorkspaceCommands.COPY_ONE = core_1.Command.toDefaultLocalizedCommand({
112
+ id: 'search.action.copyMatch',
113
+ category: SEARCH_CATEGORY,
114
+ label: 'Copy',
115
+ });
116
+ SearchInWorkspaceCommands.DISMISS_RESULT = core_1.Command.toDefaultLocalizedCommand({
117
+ id: 'search.action.remove',
118
+ category: SEARCH_CATEGORY,
119
+ label: 'Dismiss',
120
+ });
121
+ SearchInWorkspaceCommands.REPLACE_RESULT = core_1.Command.toDefaultLocalizedCommand({
122
+ id: 'search.action.replace',
123
+ });
124
+ SearchInWorkspaceCommands.REPLACE_ALL_RESULTS = core_1.Command.toDefaultLocalizedCommand({
125
+ id: 'search.action.replaceAll'
126
+ });
127
+ })(SearchInWorkspaceCommands = exports.SearchInWorkspaceCommands || (exports.SearchInWorkspaceCommands = {}));
128
+ let SearchInWorkspaceFrontendContribution = class SearchInWorkspaceFrontendContribution extends browser_1.AbstractViewContribution {
129
+ constructor() {
130
+ super({
131
+ viewContainerId: search_in_workspace_factory_1.SEARCH_VIEW_CONTAINER_ID,
132
+ widgetId: search_in_workspace_widget_1.SearchInWorkspaceWidget.ID,
133
+ widgetName: search_in_workspace_widget_1.SearchInWorkspaceWidget.LABEL,
134
+ defaultWidgetOptions: {
135
+ area: 'left',
136
+ rank: 200
137
+ },
138
+ toggleCommandId: SearchInWorkspaceCommands.TOGGLE_SIW_WIDGET.id
139
+ });
140
+ }
141
+ init() {
142
+ const updateFocusContextKey = () => this.contextKeyService.searchViewletFocus.set(this.shell.activeWidget instanceof search_in_workspace_widget_1.SearchInWorkspaceWidget);
143
+ updateFocusContextKey();
144
+ this.shell.onDidChangeActiveWidget(updateFocusContextKey);
145
+ }
146
+ async initializeLayout(app) {
147
+ await this.openView({ activate: false });
148
+ }
149
+ async registerCommands(commands) {
150
+ super.registerCommands(commands);
151
+ commands.registerCommand(SearchInWorkspaceCommands.OPEN_SIW_WIDGET, {
152
+ isEnabled: () => this.workspaceService.tryGetRoots().length > 0,
153
+ execute: async () => {
154
+ const widget = await this.openView({ activate: true });
155
+ widget.updateSearchTerm(this.getSearchTerm());
156
+ }
157
+ });
158
+ commands.registerCommand(SearchInWorkspaceCommands.REPLACE_IN_FILES, {
159
+ isEnabled: () => this.workspaceService.tryGetRoots().length > 0,
160
+ execute: async () => {
161
+ const widget = await this.openView({ activate: true });
162
+ widget.updateSearchTerm(this.getSearchTerm(), true);
163
+ }
164
+ });
165
+ commands.registerCommand(SearchInWorkspaceCommands.FOCUS_NEXT_RESULT, {
166
+ isEnabled: () => this.withWidget(undefined, widget => widget.hasResultList()),
167
+ execute: async () => {
168
+ const widget = await this.openView({ reveal: true });
169
+ widget.resultTreeWidget.selectNextResult();
170
+ }
171
+ });
172
+ commands.registerCommand(SearchInWorkspaceCommands.FOCUS_PREV_RESULT, {
173
+ isEnabled: () => this.withWidget(undefined, widget => widget.hasResultList()),
174
+ execute: async () => {
175
+ const widget = await this.openView({ reveal: true });
176
+ widget.resultTreeWidget.selectPreviousResult();
177
+ }
178
+ });
179
+ commands.registerCommand(SearchInWorkspaceCommands.FIND_IN_FOLDER, this.newMultiUriAwareCommandHandler({
180
+ execute: async (uris) => {
181
+ const resources = [];
182
+ for (const { stat } of await this.fileService.resolveAll(uris.map(resource => ({ resource })))) {
183
+ if (stat) {
184
+ const uri = stat.resource;
185
+ let uriStr = this.labelProvider.getLongName(uri);
186
+ if (stat && !stat.isDirectory) {
187
+ uriStr = this.labelProvider.getLongName(uri.parent);
188
+ }
189
+ resources.push(uriStr);
190
+ }
191
+ }
192
+ const widget = await this.openView({ activate: true });
193
+ widget.findInFolder(resources);
194
+ }
195
+ }));
196
+ commands.registerCommand(SearchInWorkspaceCommands.CANCEL_SEARCH, {
197
+ execute: w => this.withWidget(w, widget => widget.getCancelIndicator() && widget.getCancelIndicator().cancel()),
198
+ isEnabled: w => this.withWidget(w, widget => widget.getCancelIndicator() !== undefined),
199
+ isVisible: w => this.withWidget(w, widget => widget.getCancelIndicator() !== undefined)
200
+ });
201
+ commands.registerCommand(SearchInWorkspaceCommands.REFRESH_RESULTS, {
202
+ execute: w => this.withWidget(w, widget => widget.refresh()),
203
+ isEnabled: w => this.withWidget(w, widget => (widget.hasResultList() || widget.hasSearchTerm()) && this.workspaceService.tryGetRoots().length > 0),
204
+ isVisible: w => this.withWidget(w, () => true)
205
+ });
206
+ commands.registerCommand(SearchInWorkspaceCommands.COLLAPSE_ALL, {
207
+ execute: w => this.withWidget(w, widget => widget.collapseAll()),
208
+ isEnabled: w => this.withWidget(w, widget => widget.hasResultList()),
209
+ isVisible: w => this.withWidget(w, widget => !widget.areResultsCollapsed())
210
+ });
211
+ commands.registerCommand(SearchInWorkspaceCommands.EXPAND_ALL, {
212
+ execute: w => this.withWidget(w, widget => widget.expandAll()),
213
+ isEnabled: w => this.withWidget(w, widget => widget.hasResultList()),
214
+ isVisible: w => this.withWidget(w, widget => widget.areResultsCollapsed())
215
+ });
216
+ commands.registerCommand(SearchInWorkspaceCommands.CLEAR_ALL, {
217
+ execute: w => this.withWidget(w, widget => widget.clear()),
218
+ isEnabled: w => this.withWidget(w, widget => widget.hasResultList()),
219
+ isVisible: w => this.withWidget(w, () => true)
220
+ });
221
+ commands.registerCommand(SearchInWorkspaceCommands.DISMISS_RESULT, {
222
+ isEnabled: () => this.withWidget(undefined, widget => {
223
+ const { selection } = this.selectionService;
224
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
225
+ }),
226
+ isVisible: () => this.withWidget(undefined, widget => {
227
+ const { selection } = this.selectionService;
228
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
229
+ }),
230
+ execute: () => this.withWidget(undefined, widget => {
231
+ const { selection } = this.selectionService;
232
+ if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
233
+ selection.forEach(n => widget.resultTreeWidget.removeNode(n));
234
+ }
235
+ })
236
+ });
237
+ commands.registerCommand(SearchInWorkspaceCommands.REPLACE_RESULT, {
238
+ isEnabled: () => this.withWidget(undefined, widget => {
239
+ const { selection } = this.selectionService;
240
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0 && !search_in_workspace_result_tree_widget_1.SearchInWorkspaceFileNode.is(selection[0]);
241
+ }),
242
+ isVisible: () => this.withWidget(undefined, widget => {
243
+ const { selection } = this.selectionService;
244
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0 && !search_in_workspace_result_tree_widget_1.SearchInWorkspaceFileNode.is(selection[0]);
245
+ }),
246
+ execute: () => this.withWidget(undefined, widget => {
247
+ const { selection } = this.selectionService;
248
+ if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
249
+ selection.forEach(n => widget.resultTreeWidget.replace(n));
250
+ }
251
+ }),
252
+ });
253
+ commands.registerCommand(SearchInWorkspaceCommands.REPLACE_ALL_RESULTS, {
254
+ isEnabled: () => this.withWidget(undefined, widget => {
255
+ const { selection } = this.selectionService;
256
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0
257
+ && search_in_workspace_result_tree_widget_1.SearchInWorkspaceFileNode.is(selection[0]);
258
+ }),
259
+ isVisible: () => this.withWidget(undefined, widget => {
260
+ const { selection } = this.selectionService;
261
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0
262
+ && search_in_workspace_result_tree_widget_1.SearchInWorkspaceFileNode.is(selection[0]);
263
+ }),
264
+ execute: () => this.withWidget(undefined, widget => {
265
+ const { selection } = this.selectionService;
266
+ if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
267
+ selection.forEach(n => widget.resultTreeWidget.replace(n));
268
+ }
269
+ }),
270
+ });
271
+ commands.registerCommand(SearchInWorkspaceCommands.COPY_ONE, {
272
+ isEnabled: () => this.withWidget(undefined, widget => {
273
+ const { selection } = this.selectionService;
274
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
275
+ }),
276
+ isVisible: () => this.withWidget(undefined, widget => {
277
+ const { selection } = this.selectionService;
278
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
279
+ }),
280
+ execute: () => this.withWidget(undefined, widget => {
281
+ const { selection } = this.selectionService;
282
+ if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
283
+ const string = widget.resultTreeWidget.nodeToString(selection[0], true);
284
+ if (string.length !== 0) {
285
+ this.clipboardService.writeText(string);
286
+ }
287
+ }
288
+ })
289
+ });
290
+ commands.registerCommand(SearchInWorkspaceCommands.COPY_ALL, {
291
+ isEnabled: () => this.withWidget(undefined, widget => {
292
+ const { selection } = this.selectionService;
293
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
294
+ }),
295
+ isVisible: () => this.withWidget(undefined, widget => {
296
+ const { selection } = this.selectionService;
297
+ return tree_widget_selection_1.TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0;
298
+ }),
299
+ execute: () => this.withWidget(undefined, widget => {
300
+ const { selection } = this.selectionService;
301
+ if (tree_widget_selection_1.TreeWidgetSelection.is(selection)) {
302
+ const string = widget.resultTreeWidget.treeToString();
303
+ if (string.length !== 0) {
304
+ this.clipboardService.writeText(string);
305
+ }
306
+ }
307
+ })
308
+ });
309
+ }
310
+ withWidget(widget = this.tryGetWidget(), fn) {
311
+ if (widget instanceof search_in_workspace_widget_1.SearchInWorkspaceWidget && widget.id === search_in_workspace_widget_1.SearchInWorkspaceWidget.ID) {
312
+ return fn(widget);
313
+ }
314
+ return false;
315
+ }
316
+ /**
317
+ * Get the search term based on current editor selection.
318
+ * @returns the selection if available.
319
+ */
320
+ getSearchTerm() {
321
+ if (!this.editorManager.currentEditor) {
322
+ return '';
323
+ }
324
+ // Get the current editor selection.
325
+ const selection = this.editorManager.currentEditor.editor.selection;
326
+ // Compute the selection range.
327
+ const selectedRange = vscode_languageserver_protocol_1.Range.create(selection.start.line, selection.start.character, selection.end.line, selection.end.character);
328
+ // Return the selection text if available, else return empty.
329
+ return this.editorManager.currentEditor
330
+ ? this.editorManager.currentEditor.editor.document.getText(selectedRange)
331
+ : '';
332
+ }
333
+ registerKeybindings(keybindings) {
334
+ super.registerKeybindings(keybindings);
335
+ keybindings.registerKeybinding({
336
+ command: SearchInWorkspaceCommands.OPEN_SIW_WIDGET.id,
337
+ keybinding: 'ctrlcmd+shift+f'
338
+ });
339
+ keybindings.registerKeybinding({
340
+ command: SearchInWorkspaceCommands.FIND_IN_FOLDER.id,
341
+ keybinding: 'shift+alt+f',
342
+ when: 'explorerResourceIsFolder'
343
+ });
344
+ keybindings.registerKeybinding({
345
+ command: SearchInWorkspaceCommands.FOCUS_NEXT_RESULT.id,
346
+ keybinding: 'f4',
347
+ when: 'hasSearchResult'
348
+ });
349
+ keybindings.registerKeybinding({
350
+ command: SearchInWorkspaceCommands.FOCUS_PREV_RESULT.id,
351
+ keybinding: 'shift+f4',
352
+ when: 'hasSearchResult'
353
+ });
354
+ keybindings.registerKeybinding({
355
+ command: SearchInWorkspaceCommands.DISMISS_RESULT.id,
356
+ keybinding: core_1.isOSX ? 'cmd+backspace' : 'del',
357
+ when: 'searchViewletFocus && !inputBoxFocus'
358
+ });
359
+ keybindings.registerKeybinding({
360
+ command: SearchInWorkspaceCommands.REPLACE_RESULT.id,
361
+ keybinding: 'ctrlcmd+shift+1',
362
+ when: 'searchViewletFocus && replaceActive',
363
+ });
364
+ keybindings.registerKeybinding({
365
+ command: SearchInWorkspaceCommands.REPLACE_ALL_RESULTS.id,
366
+ keybinding: 'ctrlcmd+shift+1',
367
+ when: 'searchViewletFocus && replaceActive',
368
+ });
369
+ keybindings.registerKeybinding({
370
+ command: SearchInWorkspaceCommands.COPY_ONE.id,
371
+ keybinding: 'ctrlcmd+c',
372
+ when: 'searchViewletFocus && !inputBoxFocus'
373
+ });
374
+ }
375
+ registerMenus(menus) {
376
+ super.registerMenus(menus);
377
+ menus.registerMenuAction(navigator_contribution_1.NavigatorContextMenu.SEARCH, {
378
+ commandId: SearchInWorkspaceCommands.FIND_IN_FOLDER.id,
379
+ when: 'explorerResourceIsFolder'
380
+ });
381
+ menus.registerMenuAction(browser_1.CommonMenus.EDIT_FIND, {
382
+ commandId: SearchInWorkspaceCommands.OPEN_SIW_WIDGET.id,
383
+ order: '2'
384
+ });
385
+ menus.registerMenuAction(browser_1.CommonMenus.EDIT_FIND, {
386
+ commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id,
387
+ order: '3'
388
+ });
389
+ menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
390
+ commandId: SearchInWorkspaceCommands.REPLACE_RESULT.id,
391
+ label: core_1.nls.localizeByDefault('Replace'),
392
+ order: '1',
393
+ when: 'replaceActive',
394
+ });
395
+ menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
396
+ commandId: SearchInWorkspaceCommands.REPLACE_ALL_RESULTS.id,
397
+ label: core_1.nls.localizeByDefault('Replace All'),
398
+ order: '1',
399
+ when: 'replaceActive',
400
+ });
401
+ menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
402
+ commandId: SearchInWorkspaceCommands.DISMISS_RESULT.id,
403
+ order: '1'
404
+ });
405
+ menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.COPY, {
406
+ commandId: SearchInWorkspaceCommands.COPY_ONE.id,
407
+ order: '1',
408
+ });
409
+ menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.COPY, {
410
+ commandId: browser_1.CommonCommands.COPY_PATH.id,
411
+ order: '2',
412
+ });
413
+ menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.COPY, {
414
+ commandId: SearchInWorkspaceCommands.COPY_ALL.id,
415
+ order: '3',
416
+ });
417
+ menus.registerMenuAction(search_in_workspace_result_tree_widget_1.SearchInWorkspaceResultTreeWidget.Menus.EXTERNAL, {
418
+ commandId: navigator_contribution_1.FileNavigatorCommands.REVEAL_IN_NAVIGATOR.id,
419
+ order: '1',
420
+ });
421
+ }
422
+ async registerToolbarItems(toolbarRegistry) {
423
+ const widget = await this.widget;
424
+ const onDidChange = widget.onDidUpdate;
425
+ toolbarRegistry.registerItem({
426
+ id: SearchInWorkspaceCommands.CANCEL_SEARCH.id,
427
+ command: SearchInWorkspaceCommands.CANCEL_SEARCH.id,
428
+ tooltip: SearchInWorkspaceCommands.CANCEL_SEARCH.label,
429
+ priority: 0,
430
+ onDidChange
431
+ });
432
+ toolbarRegistry.registerItem({
433
+ id: SearchInWorkspaceCommands.REFRESH_RESULTS.id,
434
+ command: SearchInWorkspaceCommands.REFRESH_RESULTS.id,
435
+ tooltip: SearchInWorkspaceCommands.REFRESH_RESULTS.label,
436
+ priority: 1,
437
+ onDidChange
438
+ });
439
+ toolbarRegistry.registerItem({
440
+ id: SearchInWorkspaceCommands.CLEAR_ALL.id,
441
+ command: SearchInWorkspaceCommands.CLEAR_ALL.id,
442
+ tooltip: SearchInWorkspaceCommands.CLEAR_ALL.label,
443
+ priority: 2,
444
+ onDidChange
445
+ });
446
+ toolbarRegistry.registerItem({
447
+ id: SearchInWorkspaceCommands.COLLAPSE_ALL.id,
448
+ command: SearchInWorkspaceCommands.COLLAPSE_ALL.id,
449
+ tooltip: SearchInWorkspaceCommands.COLLAPSE_ALL.label,
450
+ priority: 3,
451
+ onDidChange
452
+ });
453
+ toolbarRegistry.registerItem({
454
+ id: SearchInWorkspaceCommands.EXPAND_ALL.id,
455
+ command: SearchInWorkspaceCommands.EXPAND_ALL.id,
456
+ tooltip: SearchInWorkspaceCommands.EXPAND_ALL.label,
457
+ priority: 3,
458
+ onDidChange
459
+ });
460
+ }
461
+ newUriAwareCommandHandler(handler) {
462
+ return uri_command_handler_1.UriAwareCommandHandler.MonoSelect(this.selectionService, handler);
463
+ }
464
+ newMultiUriAwareCommandHandler(handler) {
465
+ return uri_command_handler_1.UriAwareCommandHandler.MultiSelect(this.selectionService, handler);
466
+ }
467
+ registerThemeStyle(theme, collector) {
468
+ const contrastBorder = theme.getColor('contrastBorder');
469
+ if (contrastBorder && (0, theme_1.isHighContrast)(theme.type)) {
470
+ collector.addRule(`
471
+ .t-siw-search-container .searchHeader .search-field-container {
472
+ border-color: ${contrastBorder};
473
+ }
474
+ `);
475
+ }
476
+ }
477
+ };
478
+ __decorate([
479
+ (0, inversify_1.inject)(core_1.SelectionService),
480
+ __metadata("design:type", core_1.SelectionService)
481
+ ], SearchInWorkspaceFrontendContribution.prototype, "selectionService", void 0);
482
+ __decorate([
483
+ (0, inversify_1.inject)(browser_1.LabelProvider),
484
+ __metadata("design:type", browser_1.LabelProvider)
485
+ ], SearchInWorkspaceFrontendContribution.prototype, "labelProvider", void 0);
486
+ __decorate([
487
+ (0, inversify_1.inject)(browser_2.WorkspaceService),
488
+ __metadata("design:type", browser_2.WorkspaceService)
489
+ ], SearchInWorkspaceFrontendContribution.prototype, "workspaceService", void 0);
490
+ __decorate([
491
+ (0, inversify_1.inject)(file_service_1.FileService),
492
+ __metadata("design:type", file_service_1.FileService)
493
+ ], SearchInWorkspaceFrontendContribution.prototype, "fileService", void 0);
494
+ __decorate([
495
+ (0, inversify_1.inject)(editor_manager_1.EditorManager),
496
+ __metadata("design:type", editor_manager_1.EditorManager)
497
+ ], SearchInWorkspaceFrontendContribution.prototype, "editorManager", void 0);
498
+ __decorate([
499
+ (0, inversify_1.inject)(clipboard_service_1.ClipboardService),
500
+ __metadata("design:type", Object)
501
+ ], SearchInWorkspaceFrontendContribution.prototype, "clipboardService", void 0);
502
+ __decorate([
503
+ (0, inversify_1.inject)(search_in_workspace_context_key_service_1.SearchInWorkspaceContextKeyService),
504
+ __metadata("design:type", search_in_workspace_context_key_service_1.SearchInWorkspaceContextKeyService)
505
+ ], SearchInWorkspaceFrontendContribution.prototype, "contextKeyService", void 0);
506
+ __decorate([
507
+ (0, inversify_1.postConstruct)(),
508
+ __metadata("design:type", Function),
509
+ __metadata("design:paramtypes", []),
510
+ __metadata("design:returntype", void 0)
511
+ ], SearchInWorkspaceFrontendContribution.prototype, "init", null);
512
+ SearchInWorkspaceFrontendContribution = __decorate([
513
+ (0, inversify_1.injectable)(),
514
+ __metadata("design:paramtypes", [])
515
+ ], SearchInWorkspaceFrontendContribution);
516
+ exports.SearchInWorkspaceFrontendContribution = SearchInWorkspaceFrontendContribution;
483
517
  //# sourceMappingURL=search-in-workspace-frontend-contribution.js.map