Skip to content

Commit

Permalink
Allow 'Find in Folder...' with multiple folders at a time
Browse files Browse the repository at this point in the history
- allow users the ability to run the command `Find in Folder...` with multiple folders selected.

Signed-off-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto authored and lmcbout committed Nov 30, 2018
1 parent 705a376 commit 8012184
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,25 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut
})
});

commands.registerCommand(SearchInWorkspaceCommands.FIND_IN_FOLDER, this.newUriAwareCommandHandler({
execute: async fileUri => {
const widget: SearchInWorkspaceWidget = await this.openView({
activate: true
});
let uriStr = this.labelProvider.getLongName(fileUri);
const stat = await this.fileSystem.getFileStat(fileUri.toString());
if (stat) {
if (!stat.isDirectory) {
uriStr = this.labelProvider.getLongName(fileUri.parent);
commands.registerCommand(SearchInWorkspaceCommands.FIND_IN_FOLDER, this.newMultiUriAwareCommandHandler({
execute: async uris => {
const resources: string[] = [];
await Promise.all(uris.map(uri =>
this.fileSystem.getFileStat(uri.toString())
)).then(stats => {
for (const stat of stats) {
if (stat) {
const uri = new URI(stat.uri);
let uriStr = this.labelProvider.getLongName(uri);
if (stat && !stat.isDirectory) {
uriStr = this.labelProvider.getLongName(uri.parent);
}
resources.push(uriStr);
}
}
}
widget.findInFolder(uriStr);
});
const widget: SearchInWorkspaceWidget = await this.openView({ activate: true });
widget.findInFolder(resources);
}
}));
}
Expand All @@ -113,4 +119,8 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut
protected newUriAwareCommandHandler(handler: UriCommandHandler<URI>): UriAwareCommandHandler<URI> {
return new UriAwareCommandHandler(this.selectionService, handler);
}

protected newMultiUriAwareCommandHandler(handler: UriCommandHandler<URI[]>): UriAwareCommandHandler<URI[]> {
return new UriAwareCommandHandler(this.selectionService, handler, { multi: true });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge
this.refresh();
}

findInFolder(uri: string): void {
findInFolder(uris: string[]): void {
this.showSearchDetails = true;
const value = `${uri}/**`;
this.searchInWorkspaceOptions.include = [value];
const values = Array.from(new Set(uris.map(uri => `${uri}/**`)));
const value = values.join(', ');
this.searchInWorkspaceOptions.include = values;
const include = document.getElementById('include-glob-field');
if (include) {
(include as HTMLInputElement).value = value;
Expand Down

0 comments on commit 8012184

Please sign in to comment.