Browse Source

Implemented SD2-1322: Cancelling an in progress search (based on patch by Siegfried Pammer)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3042 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
5c69217fcc
  1. 7
      src/AddIns/Misc/SearchAndReplace/Project/Engine/Search.cs
  2. 2
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceInFilesManager.cs
  3. 8
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceManager.cs
  4. 10
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs
  5. 26
      src/Main/Base/Project/Src/Gui/Dialogs/AsynchronousWaitDialog.cs

7
src/AddIns/Misc/SearchAndReplace/Project/Engine/Search.cs

@ -81,13 +81,16 @@ namespace SearchAndReplace @@ -81,13 +81,16 @@ namespace SearchAndReplace
}
}
public SearchResultMatch FindNext()
public SearchResultMatch FindNext(IProgressMonitor monitor)
{
// insanity check
Debug.Assert(searchStrategy != null);
Debug.Assert(documentIterator != null);
Debug.Assert(textIteratorBuilder != null);
if (monitor != null && monitor.IsCancelled)
return null;
if (info != null && textIterator != null && documentIterator.CurrentFileName != null) {
ProvidedDocumentInformation currentInfo = documentIterator.Current;
if (!info.Equals(currentInfo)) { // create new iterator, if document changed
@ -114,7 +117,7 @@ namespace SearchAndReplace @@ -114,7 +117,7 @@ namespace SearchAndReplace
textIterator = null;
}
return FindNext();
return FindNext(monitor);
}
return null;
}

2
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceInFilesManager.cs

@ -60,7 +60,7 @@ namespace SearchAndReplace @@ -60,7 +60,7 @@ namespace SearchAndReplace
List<SearchResultMatch> results = new List<SearchResultMatch>();
while (true) {
SearchResultMatch result = find.FindNext();
SearchResultMatch result = find.FindNext(monitor);
if (result == null) {
break;
}

8
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceManager.cs

@ -108,7 +108,7 @@ namespace SearchAndReplace @@ -108,7 +108,7 @@ namespace SearchAndReplace
List<TextEditorControl> textAreas = new List<TextEditorControl>();
int count;
for (count = 0;; count++) {
SearchResultMatch result = SearchReplaceManager.find.FindNext();
SearchResultMatch result = SearchReplaceManager.find.FindNext(monitor);
if (result == null) {
break;
@ -197,7 +197,7 @@ namespace SearchAndReplace @@ -197,7 +197,7 @@ namespace SearchAndReplace
List<TextEditorControl> textAreas = new List<TextEditorControl>();
TextEditorControl textArea = null;
for (int count = 0;; count++) {
SearchResultMatch result = SearchReplaceManager.find.FindNext();
SearchResultMatch result = SearchReplaceManager.find.FindNext(monitor);
if (result == null) {
if (count != 0) {
@ -282,7 +282,7 @@ namespace SearchAndReplace @@ -282,7 +282,7 @@ namespace SearchAndReplace
TextEditorControl textArea = null;
while (textArea == null) {
SearchResultMatch result = find.FindNext();
SearchResultMatch result = find.FindNext(monitor);
if (result == null) {
ShowNotFoundMessage(monitor);
find.Reset();
@ -361,6 +361,8 @@ namespace SearchAndReplace @@ -361,6 +361,8 @@ namespace SearchAndReplace
static void ShowNotFoundMessage(IProgressMonitor monitor)
{
if (monitor != null && monitor.IsCancelled)
return;
if (monitor != null) monitor.ShowingDialog = true;
MessageBox.Show(WorkbenchSingleton.MainForm,
ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound"),

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

@ -97,7 +97,7 @@ namespace SearchAndReplace @@ -97,7 +97,7 @@ namespace SearchAndReplace
FindNextInSelection();
}
} else {
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search", true))
{
SearchReplaceManager.FindNext(monitor);
}
@ -113,7 +113,7 @@ namespace SearchAndReplace @@ -113,7 +113,7 @@ namespace SearchAndReplace
RunAllInSelection(0);
}
} else {
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search", true))
{
SearchInFilesManager.FindAll(monitor);
}
@ -128,7 +128,7 @@ namespace SearchAndReplace @@ -128,7 +128,7 @@ namespace SearchAndReplace
RunAllInSelection(1);
}
} else {
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search", true))
{
SearchReplaceManager.MarkAll(monitor);
}
@ -143,7 +143,7 @@ namespace SearchAndReplace @@ -143,7 +143,7 @@ namespace SearchAndReplace
RunAllInSelection(2);
}
} else {
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search", true))
{
SearchReplaceManager.ReplaceAll(monitor);
}
@ -158,7 +158,7 @@ namespace SearchAndReplace @@ -158,7 +158,7 @@ namespace SearchAndReplace
ReplaceInSelection();
}
} else {
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search", true))
{
SearchReplaceManager.Replace(monitor);
}

26
src/Main/Base/Project/Src/Gui/Dialogs/AsynchronousWaitDialog.cs

@ -55,22 +55,38 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -55,22 +55,38 @@ namespace ICSharpCode.SharpDevelop.Gui
/// Shows a wait dialog.
/// </summary>
/// <param name="titleName">Title of the wait dialog</param>
/// <param name="taskName">Name of the current task</param>
/// <returns>WaitHandle object - you can use it to access the wait dialog's properties.
/// To close the wait dialog, call Dispose() on the WaitHandle</returns>
/// <returns>AsynchronousWaitDialog object - you can use it to access the wait dialog's properties.
/// To close the wait dialog, call Dispose() on the AsynchronousWaitDialog object</returns>
public static AsynchronousWaitDialog ShowWaitDialog(string titleName)
{
if (titleName == null)
throw new ArgumentNullException("titleName");
AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName);
AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, false);
h.Start();
return h;
}
private AsynchronousWaitDialog(string titleName)
/// <summary>
/// Shows a wait dialog.
/// </summary>
/// <param name="titleName">Title of the wait dialog</param>
/// <param name="allowCancel">Specifies whether a cancel button should be shown.</param>
/// <returns>AsynchronousWaitDialog object - you can use it to access the wait dialog's properties.
/// To close the wait dialog, call Dispose() on the AsynchronousWaitDialog object</returns>
public static AsynchronousWaitDialog ShowWaitDialog(string titleName, bool allowCancel)
{
if (titleName == null)
throw new ArgumentNullException("titleName");
AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, allowCancel);
h.Start();
return h;
}
private AsynchronousWaitDialog(string titleName, bool allowCancel)
{
this.titleName = titleName;
Done(); // set default values for titleName
this.allowCancel = allowCancel;
}
#region Start waiting thread

Loading…
Cancel
Save