Browse Source

handle SearchPatternException in SearchAndReplacePanel

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
22ed6e1093
  1. 98
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs

98
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs

@ -85,66 +85,84 @@ namespace SearchAndReplace
void FindNextButtonClicked(object sender, EventArgs e) void FindNextButtonClicked(object sender, EventArgs e)
{ {
WritebackOptions(); try {
var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null); WritebackOptions();
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null);
lastMatch = SearchManager.FindNext(strategy, location); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
SearchManager.SelectResult(lastMatch); lastMatch = SearchManager.FindNext(strategy, location);
Focus(); SearchManager.SelectResult(lastMatch);
Focus();
} catch (SearchPatternException ex) {
MessageService.ShowError(ex.Message);
}
} }
void FindAllButtonClicked(object sender, EventArgs e) void FindAllButtonClicked(object sender, EventArgs e)
{ {
WritebackOptions(); WritebackOptions();
var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor(); using (var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor()) {
monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}");
try { try {
var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
var results = SearchManager.FindAllParallel(strategy, location, monitor); var results = SearchManager.FindAllParallel(strategy, location, monitor);
SearchManager.ShowSearchResults(SearchOptions.FindPattern, results); SearchManager.ShowSearchResults(SearchOptions.FindPattern, results);
} catch (OperationCanceledException) {} } catch (SearchPatternException ex) {
MessageService.ShowError(ex.Message);
} catch (OperationCanceledException) {}
}
} }
void BookmarkAllButtonClicked(object sender, EventArgs e) void BookmarkAllButtonClicked(object sender, EventArgs e)
{ {
WritebackOptions(); WritebackOptions();
var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor(); using (var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor()) {
monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}");
try { try {
var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
var results = SearchManager.FindAllParallel(strategy, location, monitor); var results = SearchManager.FindAllParallel(strategy, location, monitor);
SearchManager.MarkAll(results); SearchManager.MarkAll(results);
} catch (OperationCanceledException) {} } catch (SearchPatternException ex) {
MessageService.ShowError(ex.Message);
} catch (OperationCanceledException) {}
}
} }
void ReplaceAllButtonClicked(object sender, EventArgs e) void ReplaceAllButtonClicked(object sender, EventArgs e)
{ {
WritebackOptions(); WritebackOptions();
int count = -1; int count = -1;
AsynchronousWaitDialog.RunInCancellableWaitDialog( try {
StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"), null, AsynchronousWaitDialog.RunInCancellableWaitDialog(
monitor => { StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"), null,
var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null); monitor => {
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null);
var results = SearchManager.FindAll(strategy, location, monitor); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
count = SearchManager.ReplaceAll(results, SearchOptions.ReplacePattern, monitor.CancellationToken); var results = SearchManager.FindAll(strategy, location, monitor);
}); count = SearchManager.ReplaceAll(results, SearchOptions.ReplacePattern, monitor.CancellationToken);
if (count != -1) });
SearchManager.ShowReplaceDoneMessage(count); if (count != -1)
SearchManager.ShowReplaceDoneMessage(count);
} catch (SearchPatternException ex) {
MessageService.ShowError(ex.Message);
}
} }
void ReplaceButtonClicked(object sender, EventArgs e) void ReplaceButtonClicked(object sender, EventArgs e)
{ {
WritebackOptions(); try {
if (SearchManager.IsResultSelected(lastMatch)) WritebackOptions();
SearchManager.Replace(lastMatch, SearchOptions.ReplacePattern); if (SearchManager.IsResultSelected(lastMatch))
var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null); SearchManager.Replace(lastMatch, SearchOptions.ReplacePattern);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null);
lastMatch = SearchManager.FindNext(strategy, location); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
SearchManager.SelectResult(lastMatch); lastMatch = SearchManager.FindNext(strategy, location);
Focus(); SearchManager.SelectResult(lastMatch);
Focus();
} catch (SearchPatternException ex) {
MessageService.ShowError(ex.Message);
}
} }
void WritebackOptions() void WritebackOptions()

Loading…
Cancel
Save