Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 99d94fd

Browse files
committed
Cancel currently running search when a new search is started.
1 parent c19a83f commit 99d94fd

6 files changed

Lines changed: 53 additions & 4 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ public Task FindReferencesAsync(SymbolSearchArgs args, Action<SearchedFile> call
7878
CancellationToken = cancellationToken
7979
},
8080
delegate (string fileName) {
81-
FindReferencesInFile(args, searchScope, FileName.Create(fileName), callback, cancellationToken);
81+
try {
82+
FindReferencesInFile(args, searchScope, FileName.Create(fileName), callback, cancellationToken);
83+
} catch (OperationCanceledException) {
84+
throw;
85+
} catch (Exception ex) {
86+
throw new ApplicationException("Error searching in file '" + fileName + "'", ex);
87+
}
8288
lock (progressLock)
8389
args.ProgressMonitor.Progress += workAmountInverse;
8490
});

src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ public virtual object GetControl()
5454
return resultsTreeViewInstance;
5555
}
5656

57-
static IList toolbarItems;
57+
public virtual void OnDeactivate()
58+
{
59+
}
60+
61+
static IList<object> toolbarItems;
5862

5963
public virtual IList GetToolbarItems()
6064
{
@@ -122,7 +126,8 @@ protected IList GetDefaultToolbarItems()
122126
collapseAll.Click += delegate { ExpandCollapseAll(false); };
123127
toolbarItems.Add(collapseAll);
124128
}
125-
return toolbarItems;
129+
// Copy the list to avoid modifications to the static list
130+
return new List<object>(toolbarItems);
126131
}
127132

128133
static void SetCheckedItem(MenuItem newTarget, ContextMenu menu)

src/AddIns/Misc/SearchAndReplace/Project/Gui/ObserverSearchResult.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public override object GetControl()
3737
return resultsTreeViewInstance;
3838
}
3939

40+
public override void OnDeactivate()
41+
{
42+
if (!finished)
43+
StopButtonClick(null, null);
44+
base.OnDeactivate();
45+
}
46+
4047
public override IList GetToolbarItems()
4148
{
4249
var items = base.GetToolbarItems();

src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ public sealed class SearchRootNode : SearchNode
1919
ObservableCollection<SearchFileNode> fileNodes;
2020
ObservableCollection<SearchProjectNode> projectNodes;
2121
ObservableCollection<SearchProjectNode> projectAndFileNodes;
22+
bool wasCancelled;
2223

2324
public string Title { get; private set; }
24-
public bool WasCancelled { get; set; }
25+
26+
public bool WasCancelled {
27+
get {
28+
return wasCancelled;
29+
}
30+
set {
31+
wasCancelled = value;
32+
InvalidateText();
33+
}
34+
}
2535

2636
public SearchRootNode(string title, IList<SearchResultMatch> results)
2737
{

src/Main/Base/Project/Editor/Search/ISearchResult.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public interface ISearchResult
2626
/// </summary>
2727
object GetControl();
2828

29+
/// <summary>
30+
/// Notifies the search that it is no longer active (another search result will be activated in the search results pad).
31+
/// GetControl() will be called if the search result is activated again.
32+
/// </summary>
33+
void OnDeactivate();
34+
2935
/// <summary>
3036
/// Gets the items for the toolbar that are visible only for this search result.
3137
/// </summary>

src/Main/Base/Project/Editor/Search/SearchResultsPad.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public override object Control {
6666
}
6767
}
6868

69+
ISearchResult activeSearchResult;
6970
List<ISearchResult> lastSearches = new List<ISearchResult>();
7071

7172
public IEnumerable<ISearchResult> LastSearches {
@@ -75,6 +76,10 @@ public IEnumerable<ISearchResult> LastSearches {
7576
public void ClearLastSearchesList()
7677
{
7778
lastSearches.Clear();
79+
if (activeSearchResult != null) {
80+
activeSearchResult.OnDeactivate();
81+
activeSearchResult = null;
82+
}
7883
SD.WinForms.SetContent(contentPlaceholder, null);
7984
}
8085

@@ -95,6 +100,12 @@ public void ShowSearchResults(ISearchResult result)
95100
while (lastSearches.Count > 15)
96101
lastSearches.RemoveAt(15);
97102

103+
if (activeSearchResult != result) {
104+
if (activeSearchResult != null) {
105+
activeSearchResult.OnDeactivate();
106+
}
107+
activeSearchResult = result;
108+
}
98109
SD.WinForms.SetContent(contentPlaceholder, result.GetControl());
99110

100111
toolBar.Items.Clear();
@@ -206,6 +217,10 @@ public IList GetToolbarItems()
206217
{
207218
return null;
208219
}
220+
221+
public void OnDeactivate()
222+
{
223+
}
209224
}
210225
}
211226
}

0 commit comments

Comments
 (0)