@ -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 next Index = ( curIndex + 1 ) % WorkbenchSingleton . Workbench . ViewContentCollection . Count ;
cur Index = ( curIndex + 1 ) % WorkbenchSingleton . Workbench . ViewContentCollection . Count ;
if ( next Index = = startIndex ) {
if ( cur Index = = 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 ;
}
}
}
}