Browse Source

Fixed SD2-1206: New "Wait" Dialog appears if the search has already finished.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2154 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
1a245bf728
  1. 4
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs
  2. 2
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchToolbarCommands.cs
  3. 4
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs
  4. 57
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs
  5. 7
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.cs
  6. 36
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs

4
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs

@ -43,7 +43,7 @@ namespace SearchAndReplace
public override void Run() public override void Run()
{ {
if (SearchOptions.CurrentFindPattern.Length > 0) { if (SearchOptions.CurrentFindPattern.Length > 0) {
SearchReplaceManager.FindNext(); SearchReplaceManager.FindNext(null);
} else { } else {
Find find = new Find(); Find find = new Find();
find.Run(); find.Run();
@ -96,7 +96,7 @@ namespace SearchAndReplace
if (SearchOptions.DocumentIteratorType == DocumentIteratorType.CurrentSelection) { if (SearchOptions.DocumentIteratorType == DocumentIteratorType.CurrentSelection) {
SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument; SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
} }
SearchReplaceManager.FindNext(); SearchReplaceManager.FindNext(null);
} }
} }
} }

2
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchToolbarCommands.cs

@ -44,7 +44,7 @@ namespace SearchAndReplace
LoggingService.Debug("FindComboBox.CommitSearch()"); LoggingService.Debug("FindComboBox.CommitSearch()");
SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument; SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
SearchOptions.FindPattern = comboBox.Text; SearchOptions.FindPattern = comboBox.Text;
SearchReplaceManager.FindNext(); SearchReplaceManager.FindNext(null);
comboBox.Focus(); comboBox.Focus();
} }
} }

4
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs

@ -69,7 +69,7 @@ namespace SearchAndReplace
} }
} }
public static void FindAll() public static void FindAll(IProgressMonitor monitor)
{ {
if (!InitializeSearchInFiles()) { if (!InitializeSearchInFiles()) {
return; return;
@ -86,7 +86,7 @@ namespace SearchAndReplace
FinishSearchInFiles(results); FinishSearchInFiles(results);
} }
public static void FindAll(int offset, int length) public static void FindAll(int offset, int length, IProgressMonitor monitor)
{ {
if (!InitializeSearchInFiles()) { if (!InitializeSearchInFiles()) {
return; return;

57
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs

@ -35,7 +35,7 @@ namespace SearchAndReplace
find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType); find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType);
} }
public static void Replace() public static void Replace(IProgressMonitor monitor)
{ {
SetSearchOptions(); SetSearchOptions();
if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) {
@ -59,18 +59,18 @@ namespace SearchAndReplace
} }
} }
} }
FindNext(); FindNext(monitor);
} }
static TextSelection textSelection; static TextSelection textSelection;
public static void ReplaceFirstInSelection(int offset, int length) public static void ReplaceFirstInSelection(int offset, int length, IProgressMonitor monitor)
{ {
SetSearchOptions(); SetSearchOptions();
FindFirstInSelection(offset, length); FindFirstInSelection(offset, length, monitor);
} }
public static bool ReplaceNextInSelection() public static bool ReplaceNextInSelection(IProgressMonitor monitor)
{ {
if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) {
ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent as ITextEditorControlProvider; ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent as ITextEditorControlProvider;
@ -95,10 +95,10 @@ namespace SearchAndReplace
} }
} }
} }
return FindNextInSelection(); return FindNextInSelection(monitor);
} }
public static void MarkAll() public static void MarkAll(IProgressMonitor monitor)
{ {
SetSearchOptions(); SetSearchOptions();
ClearSelection(); ClearSelection();
@ -120,10 +120,10 @@ namespace SearchAndReplace
foreach (TextEditorControl ctl in textAreas) { foreach (TextEditorControl ctl in textAreas) {
ctl.Refresh(); ctl.Refresh();
} }
ShowMarkDoneMessage(count); ShowMarkDoneMessage(count, monitor);
} }
public static void MarkAll(int offset, int length) public static void MarkAll(int offset, int length, IProgressMonitor monitor)
{ {
SetSearchOptions(); SetSearchOptions();
find.Reset(); find.Reset();
@ -145,7 +145,7 @@ namespace SearchAndReplace
foreach (TextEditorControl ctl in textAreas) { foreach (TextEditorControl ctl in textAreas) {
ctl.Refresh(); ctl.Refresh();
} }
ShowMarkDoneMessage(count); ShowMarkDoneMessage(count, monitor);
} }
static void MarkResult(List<TextEditorControl> textAreas, SearchResult result) static void MarkResult(List<TextEditorControl> textAreas, SearchResult result)
@ -164,25 +164,29 @@ namespace SearchAndReplace
} }
} }
static void ShowMarkDoneMessage(int count) static void ShowMarkDoneMessage(int count, IProgressMonitor monitor)
{ {
if (count == 0) { if (count == 0) {
ShowNotFoundMessage(); ShowNotFoundMessage(monitor);
} else { } else {
if (monitor != null) monitor.ShowingDialog = true;
MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.MarkAllDone}", "${res:Global.FinishedCaptionText}"); MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.MarkAllDone}", "${res:Global.FinishedCaptionText}");
if (monitor != null) monitor.ShowingDialog = false;
} }
} }
static void ShowReplaceDoneMessage(int count) static void ShowReplaceDoneMessage(int count, IProgressMonitor monitor)
{ {
if (count == 0) { if (count == 0) {
ShowNotFoundMessage(); ShowNotFoundMessage(monitor);
} else { } else {
if (monitor != null) monitor.ShowingDialog = true;
MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.ReplaceAllDone}", "${res:Global.FinishedCaptionText}"); MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.ReplaceAllDone}", "${res:Global.FinishedCaptionText}");
if (monitor != null) monitor.ShowingDialog = false;
} }
} }
public static void ReplaceAll() public static void ReplaceAll(IProgressMonitor monitor)
{ {
SetSearchOptions(); SetSearchOptions();
ClearSelection(); ClearSelection();
@ -202,7 +206,7 @@ namespace SearchAndReplace
ta.Refresh(); ta.Refresh();
} }
} }
ShowReplaceDoneMessage(count); ShowReplaceDoneMessage(count, monitor);
find.Reset(); find.Reset();
return; return;
} else { } else {
@ -230,7 +234,7 @@ namespace SearchAndReplace
} }
} }
public static void ReplaceAll(int offset, int length) public static void ReplaceAll(int offset, int length, IProgressMonitor monitor)
{ {
SetSearchOptions(); SetSearchOptions();
find.Reset(); find.Reset();
@ -241,7 +245,7 @@ namespace SearchAndReplace
for (int count = 0;; count++) { for (int count = 0;; count++) {
SearchResult result = find.FindNext(offset, length); SearchResult result = find.FindNext(offset, length);
if (result == null) { if (result == null) {
ShowReplaceDoneMessage(count); ShowReplaceDoneMessage(count, monitor);
return; return;
} }
@ -260,7 +264,8 @@ namespace SearchAndReplace
} }
static SearchResult lastResult = null; static SearchResult lastResult = null;
public static void FindNext()
public static void FindNext(IProgressMonitor monitor)
{ {
SetSearchOptions(); SetSearchOptions();
if (find == null || if (find == null ||
@ -279,7 +284,7 @@ namespace SearchAndReplace
while (textArea == null) { while (textArea == null) {
SearchResult result = find.FindNext(); SearchResult result = find.FindNext();
if (result == null) { if (result == null) {
ShowNotFoundMessage(); ShowNotFoundMessage(monitor);
find.Reset(); find.Reset();
lastResult = null; lastResult = null;
return; return;
@ -302,7 +307,7 @@ namespace SearchAndReplace
static bool foundAtLeastOneItem = false; static bool foundAtLeastOneItem = false;
public static void FindFirstInSelection(int offset, int length) public static void FindFirstInSelection(int offset, int length, IProgressMonitor monitor)
{ {
foundAtLeastOneItem = false; foundAtLeastOneItem = false;
textSelection = null; textSelection = null;
@ -321,17 +326,17 @@ namespace SearchAndReplace
} }
textSelection = new TextSelection(offset, length); textSelection = new TextSelection(offset, length);
FindNextInSelection(); FindNextInSelection(monitor);
} }
public static bool FindNextInSelection() public static bool FindNextInSelection(IProgressMonitor monitor)
{ {
TextEditorControl textArea = null; TextEditorControl textArea = null;
while (textArea == null) { while (textArea == null) {
SearchResult result = find.FindNext(textSelection.Offset, textSelection.Length); SearchResult result = find.FindNext(textSelection.Offset, textSelection.Length);
if (result == null) { if (result == null) {
if (!foundAtLeastOneItem) { if (!foundAtLeastOneItem) {
ShowNotFoundMessage(); ShowNotFoundMessage(monitor);
} }
find.Reset(); find.Reset();
lastResult = null; lastResult = null;
@ -354,13 +359,15 @@ namespace SearchAndReplace
return true; return true;
} }
static void ShowNotFoundMessage() static void ShowNotFoundMessage(IProgressMonitor monitor)
{ {
if (monitor != null) monitor.ShowingDialog = true;
MessageBox.Show((Form)WorkbenchSingleton.Workbench, MessageBox.Show((Form)WorkbenchSingleton.Workbench,
ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound"), ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound"),
ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound.Title"), ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound.Title"),
MessageBoxButtons.OK, MessageBoxButtons.OK,
MessageBoxIcon.Information); MessageBoxIcon.Information);
if (monitor != null) monitor.ShowingDialog = false;
} }
static TextEditorControl OpenTextArea(string fileName) static TextEditorControl OpenTextArea(string fileName)

7
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/AsynchronousWaitDialog.cs

@ -244,7 +244,12 @@ namespace SearchAndReplace
if (value) { if (value) {
dlg.BeginInvoke(new MethodInvoker(dlg.Hide)); dlg.BeginInvoke(new MethodInvoker(dlg.Hide));
} else { } else {
dlg.BeginInvoke(new MethodInvoker(dlg.Show)); dlg.BeginInvoke(new MethodInvoker(delegate {
Thread.Sleep(100);
if (showingDialog) {
dlg.Show();
}
}));
} }
} }
} }

36
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs

@ -94,9 +94,9 @@ namespace SearchAndReplace
FindNextInSelection(); FindNextInSelection();
} }
} else { } else {
using (AsynchronousWaitDialog.ShowWaitDialog("Search")) using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
{ {
SearchReplaceManager.FindNext(); SearchReplaceManager.FindNext(monitor);
} }
} }
Focus(); Focus();
@ -110,9 +110,9 @@ namespace SearchAndReplace
RunAllInSelection(0); RunAllInSelection(0);
} }
} else { } else {
using (AsynchronousWaitDialog.ShowWaitDialog("Search")) using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
{ {
SearchInFilesManager.FindAll(); SearchInFilesManager.FindAll(monitor);
} }
} }
} }
@ -125,9 +125,9 @@ namespace SearchAndReplace
RunAllInSelection(1); RunAllInSelection(1);
} }
} else { } else {
using (AsynchronousWaitDialog.ShowWaitDialog("Search")) using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
{ {
SearchReplaceManager.MarkAll(); SearchReplaceManager.MarkAll(monitor);
} }
} }
} }
@ -140,9 +140,9 @@ namespace SearchAndReplace
RunAllInSelection(2); RunAllInSelection(2);
} }
} else { } else {
using (AsynchronousWaitDialog.ShowWaitDialog("Search")) using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
{ {
SearchReplaceManager.ReplaceAll(); SearchReplaceManager.ReplaceAll(monitor);
} }
} }
} }
@ -155,9 +155,9 @@ namespace SearchAndReplace
ReplaceInSelection(); ReplaceInSelection();
} }
} else { } else {
using (AsynchronousWaitDialog.ShowWaitDialog("Search")) using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
{ {
SearchReplaceManager.Replace(); SearchReplaceManager.Replace(monitor);
} }
} }
Focus(); Focus();
@ -311,9 +311,9 @@ namespace SearchAndReplace
ignoreSelectionChanges = true; ignoreSelectionChanges = true;
if (findFirst) { if (findFirst) {
findFirst = false; findFirst = false;
SearchReplaceManager.FindFirstInSelection(startOffset, endOffset - startOffset); SearchReplaceManager.FindFirstInSelection(startOffset, endOffset - startOffset, null);
} else { } else {
findFirst = !SearchReplaceManager.FindNextInSelection(); findFirst = !SearchReplaceManager.FindNextInSelection(null);
if (findFirst) { if (findFirst) {
SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset); SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
} }
@ -409,6 +409,8 @@ namespace SearchAndReplace
/// </summary> /// </summary>
void RunAllInSelection(int action) void RunAllInSelection(int action)
{ {
const IProgressMonitor monitor = null;
int startOffset = Math.Min(selection.Offset, selection.EndOffset); int startOffset = Math.Min(selection.Offset, selection.EndOffset);
int endOffset = Math.Max(selection.Offset, selection.EndOffset); int endOffset = Math.Max(selection.Offset, selection.EndOffset);
@ -418,11 +420,11 @@ namespace SearchAndReplace
try { try {
ignoreSelectionChanges = true; ignoreSelectionChanges = true;
if (action == 0) if (action == 0)
SearchInFilesManager.FindAll(startOffset, endOffset - startOffset); SearchInFilesManager.FindAll(startOffset, endOffset - startOffset, monitor);
else if (action == 1) else if (action == 1)
SearchReplaceManager.MarkAll(startOffset, endOffset - startOffset); SearchReplaceManager.MarkAll(startOffset, endOffset - startOffset, monitor);
else if (action == 2) else if (action == 2)
SearchReplaceManager.ReplaceAll(startOffset, endOffset - startOffset); SearchReplaceManager.ReplaceAll(startOffset, endOffset - startOffset, monitor);
SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset); SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
} finally { } finally {
ignoreSelectionChanges = false; ignoreSelectionChanges = false;
@ -442,9 +444,9 @@ namespace SearchAndReplace
ignoreSelectionChanges = true; ignoreSelectionChanges = true;
if (findFirst) { if (findFirst) {
findFirst = false; findFirst = false;
SearchReplaceManager.ReplaceFirstInSelection(startOffset, endOffset - startOffset); SearchReplaceManager.ReplaceFirstInSelection(startOffset, endOffset - startOffset, null);
} else { } else {
findFirst = !SearchReplaceManager.ReplaceNextInSelection(); findFirst = !SearchReplaceManager.ReplaceNextInSelection(null);
if (findFirst) { if (findFirst) {
SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset); SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
} }

Loading…
Cancel
Save