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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save