提交 6681c86c 编写于 作者: R Rob Lourens

Fix #31260 - implement 'replace all' button for folder match in search viewlet

上级 5c6a388c
......@@ -604,6 +604,30 @@ export class ReplaceAllAction extends AbstractSearchAndReplaceAction {
}
}
export class ReplaceAllInFolderAction extends AbstractSearchAndReplaceAction {
constructor(private viewer: ITree, private folderMatch: FolderMatch,
@IKeybindingService keyBindingService: IKeybindingService,
@ITelemetryService private telemetryService: ITelemetryService
) {
super(Constants.ReplaceAllInFileActionId, nls.localize('file.replaceAll.label', "Replace All"), 'action-replace-all');
}
public async run(): TPromise<any> {
/* __GDPR__
"replaceAllInFolder.action.selected" : {}
*/
this.telemetryService.publicLog('replaceAllInFolder.action.selected');
let nextFocusElement = this.getElementToFocusAfterRemoved(this.viewer, this.folderMatch);
await this.folderMatch.replaceAll();
if (nextFocusElement) {
this.viewer.setFocus(nextFocusElement);
}
this.viewer.DOMFocus();
}
}
export class ReplaceAction extends AbstractSearchAndReplaceAction {
constructor(private viewer: ITree, private element: Match, private viewlet: SearchViewlet,
......
......@@ -17,7 +17,7 @@ import { Match, SearchResult, FileMatch, FileMatchOrMatch, SearchModel, FolderMa
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { Range } from 'vs/editor/common/core/range';
import { SearchViewlet } from 'vs/workbench/parts/search/browser/searchViewlet';
import { RemoveAction, ReplaceAllAction, ReplaceAction } from 'vs/workbench/parts/search/browser/searchActions';
import { RemoveAction, ReplaceAllAction, ReplaceAction, ReplaceAllInFolderAction } from 'vs/workbench/parts/search/browser/searchActions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { attachBadgeStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
......@@ -251,7 +251,15 @@ export class SearchRenderer extends Disposable implements IRenderer {
templateData.badge.setTitleFormat(count > 1 ? nls.localize('searchFileMatches', "{0} files found", count) : nls.localize('searchFileMatch', "{0} file found", count));
templateData.actions.clear();
templateData.actions.push([new RemoveAction(tree, folderMatch)], { icon: true, label: false });
const input = <SearchResult>tree.getInput();
const actions: IAction[] = [];
if (input.searchModel.isReplaceActive() && count > 0) {
actions.push(this.instantiationService.createInstance(ReplaceAllInFolderAction, tree, folderMatch));
}
actions.push(new RemoveAction(tree, folderMatch));
templateData.actions.push(actions, { icon: true, label: false });
}
private renderFileMatch(tree: ITree, fileMatch: FileMatch, templateData: IFileMatchTemplate): void {
......
......@@ -422,6 +422,13 @@ export class FolderMatch extends Disposable {
});
}
public replaceAll(): TPromise<any> {
const matches = this.matches();
return this.replaceService.replace(matches).then(() => {
matches.forEach(match => this.doRemove(match, false, true));
});
}
public matches(): FileMatch[] {
return this._fileMatches.values();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册