Browse Source

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
shortcuts
Matt Ward 20 years ago
parent
commit
35546c0348
  1. 72
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/AllOpenDocumentIterator.cs

72
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/AllOpenDocumentIterator.cs

@ -18,7 +18,8 @@ namespace SearchAndReplace
public class AllOpenDocumentIterator : IDocumentIterator public class AllOpenDocumentIterator : IDocumentIterator
{ {
int startIndex = -1; int startIndex = -1;
bool resetted = true; int curIndex = -1;
bool resetted = true;
public AllOpenDocumentIterator() public AllOpenDocumentIterator()
{ {
@ -27,45 +28,60 @@ namespace SearchAndReplace
public string CurrentFileName { public string CurrentFileName {
get { get {
if (!SearchReplaceUtilities.IsTextAreaSelected) { IViewContent viewContent = GetCurrentTextEditorViewContent();
return null; if (viewContent != null) {
if (viewContent.FileName == null) {
return viewContent.UntitledName;
}
return viewContent.FileName;
} }
return null;
if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.FileName == null) { }
return WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.UntitledName; }
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 { public ProvidedDocumentInformation Current {
get { get {
if (!SearchReplaceUtilities.IsTextAreaSelected) { IViewContent viewContent = GetCurrentTextEditorViewContent();
return null; 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); return null;
IDocument document = textEditor.Document;
return new ProvidedDocumentInformation(document,
CurrentFileName,
textEditor.ActiveTextAreaControl);
} }
} }
int GetCurIndex() void GetCurIndex()
{ {
for (int i = 0; i < WorkbenchSingleton.Workbench.ViewContentCollection.Count; ++i) { int viewCount = WorkbenchSingleton.Workbench.ViewContentCollection.Count;
if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent == WorkbenchSingleton.Workbench.ViewContentCollection[i]) { if (curIndex == -1 || curIndex >= viewCount) {
return i; 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() public bool MoveForward()
{ {
int curIndex = GetCurIndex(); GetCurIndex();
if (curIndex < 0) { if (curIndex < 0) {
return false; return false;
} }
@ -75,17 +91,16 @@ namespace SearchAndReplace
return true; return true;
} }
int nextIndex = (curIndex + 1) % WorkbenchSingleton.Workbench.ViewContentCollection.Count; curIndex = (curIndex + 1) % WorkbenchSingleton.Workbench.ViewContentCollection.Count;
if (nextIndex == startIndex) { if (curIndex == startIndex) {
return false; return false;
} }
WorkbenchSingleton.Workbench.ViewContentCollection[nextIndex].WorkbenchWindow.SelectWindow();
return true; return true;
} }
public bool MoveBackward() public bool MoveBackward()
{ {
int curIndex = GetCurIndex(); GetCurIndex();
if (curIndex < 0) { if (curIndex < 0) {
return false; return false;
} }
@ -100,7 +115,6 @@ namespace SearchAndReplace
if (curIndex > 0) { if (curIndex > 0) {
--curIndex; --curIndex;
WorkbenchSingleton.Workbench.ViewContentCollection[curIndex].WorkbenchWindow.SelectWindow();
return true; return true;
} }
return false; return false;
@ -108,7 +122,9 @@ namespace SearchAndReplace
public void Reset() public void Reset()
{ {
startIndex = GetCurIndex(); curIndex = -1;
GetCurIndex();
startIndex = curIndex;
resetted = true; resetted = true;
} }
} }

Loading…
Cancel
Save