From 35546c034882bd2c3cfd4da17212eac9f54e6b60 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Tue, 24 Oct 2006 18:44:50 +0000 Subject: [PATCH] Fixed SD2-998 - Find or replace all in all open documents hangs SharpDevelop if two or more text files are open. The new docking library does not set the ActiveWorkbenchWindow until certain windows messages have been processed which caused the AllOpenDocumentIterator class to not be able to change the active window and kept the search stuck in an infinite loop. The AllOpenDocumentIterator class has been modified to use an index to determine the currently searched document window rather than relying on the ActiveWorkbenchWindow. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1941 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../AllOpenDocumentIterator.cs | 72 +++++++++++-------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/AllOpenDocumentIterator.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/AllOpenDocumentIterator.cs index 52beed88ff..b47d330419 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/AllOpenDocumentIterator.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/AllOpenDocumentIterator.cs @@ -18,7 +18,8 @@ namespace SearchAndReplace public class AllOpenDocumentIterator : IDocumentIterator { int startIndex = -1; - bool resetted = true; + int curIndex = -1; + bool resetted = true; public AllOpenDocumentIterator() { @@ -27,45 +28,60 @@ namespace SearchAndReplace public string CurrentFileName { get { - if (!SearchReplaceUtilities.IsTextAreaSelected) { - return null; + IViewContent viewContent = GetCurrentTextEditorViewContent(); + if (viewContent != null) { + if (viewContent.FileName == null) { + return viewContent.UntitledName; + } + return viewContent.FileName; } - - if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.FileName == null) { - return WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.UntitledName; + return null; + } + } + + IViewContent GetCurrentTextEditorViewContent() + { + GetCurIndex(); + if (curIndex >= 0) { + IViewContent viewContent = WorkbenchSingleton.Workbench.ViewContentCollection[curIndex]; + if (viewContent is ITextEditorControlProvider) { + return viewContent; } - - return WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.FileName; } + return null; } public ProvidedDocumentInformation Current { get { - if (!SearchReplaceUtilities.IsTextAreaSelected) { - return null; + IViewContent viewContent = GetCurrentTextEditorViewContent(); + if (viewContent != null) { + TextEditorControl textEditor = (((ITextEditorControlProvider)viewContent).TextEditorControl); + IDocument document = textEditor.Document; + return new ProvidedDocumentInformation(document, + CurrentFileName, + textEditor.ActiveTextAreaControl); } - TextEditorControl textEditor = (((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl); - - IDocument document = textEditor.Document; - return new ProvidedDocumentInformation(document, - CurrentFileName, - textEditor.ActiveTextAreaControl); + return null; } } - int GetCurIndex() + void GetCurIndex() { - for (int i = 0; i < WorkbenchSingleton.Workbench.ViewContentCollection.Count; ++i) { - if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent == WorkbenchSingleton.Workbench.ViewContentCollection[i]) { - return i; + int viewCount = WorkbenchSingleton.Workbench.ViewContentCollection.Count; + if (curIndex == -1 || curIndex >= viewCount) { + for (int i = 0; i < viewCount; ++i) { + if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent == WorkbenchSingleton.Workbench.ViewContentCollection[i]) { + curIndex = i; + return; + } } + curIndex = -1; } - return -1; } public bool MoveForward() { - int curIndex = GetCurIndex(); + GetCurIndex(); if (curIndex < 0) { return false; } @@ -75,17 +91,16 @@ namespace SearchAndReplace return true; } - int nextIndex = (curIndex + 1) % WorkbenchSingleton.Workbench.ViewContentCollection.Count; - if (nextIndex == startIndex) { + curIndex = (curIndex + 1) % WorkbenchSingleton.Workbench.ViewContentCollection.Count; + if (curIndex == startIndex) { return false; } - WorkbenchSingleton.Workbench.ViewContentCollection[nextIndex].WorkbenchWindow.SelectWindow(); return true; } public bool MoveBackward() { - int curIndex = GetCurIndex(); + GetCurIndex(); if (curIndex < 0) { return false; } @@ -100,7 +115,6 @@ namespace SearchAndReplace if (curIndex > 0) { --curIndex; - WorkbenchSingleton.Workbench.ViewContentCollection[curIndex].WorkbenchWindow.SelectWindow(); return true; } return false; @@ -108,7 +122,9 @@ namespace SearchAndReplace public void Reset() { - startIndex = GetCurIndex(); + curIndex = -1; + GetCurIndex(); + startIndex = curIndex; resetted = true; } }