diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/AllOpenDocumentIterator.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/AllOpenDocumentIterator.cs index bccf910092..032d23df69 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/AllOpenDocumentIterator.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/AllOpenDocumentIterator.cs @@ -5,15 +5,14 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Editor.Search; +using ICSharpCode.SharpDevelop.Editor; using System; using System.Linq; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Refactoring; -using ICSharpCode.TextEditor; -using ICSharpCode.TextEditor.Document; namespace SearchAndReplace { @@ -43,7 +42,7 @@ namespace SearchAndReplace GetCurIndex(); if (curIndex >= 0) { IViewContent viewContent = WorkbenchSingleton.Workbench.ViewContentCollection.ToList()[curIndex]; - if (viewContent is ITextEditorControlProvider) { + if (viewContent is ITextEditorProvider) { return viewContent; } } @@ -54,11 +53,10 @@ namespace SearchAndReplace get { IViewContent viewContent = GetCurrentTextEditorViewContent(); if (viewContent != null) { - TextEditorControl textEditor = (((ITextEditorControlProvider)viewContent).TextEditorControl); - TextEditorAdapter adapter = new TextEditorAdapter(textEditor); - return new ProvidedDocumentInformation(adapter.Document, + ITextEditor textEditor = (((ITextEditorProvider)viewContent).TextEditor); + return new ProvidedDocumentInformation(textEditor.Document, CurrentFileName, - adapter); + textEditor); } return null; } diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/CurrentDocumentIterator.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/CurrentDocumentIterator.cs index 301da49e33..3d6533bd96 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/CurrentDocumentIterator.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/CurrentDocumentIterator.cs @@ -11,7 +11,6 @@ using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Gui; -using ICSharpCode.TextEditor; namespace SearchAndReplace { diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/DirectoryDocumentIterator.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/DirectoryDocumentIterator.cs index 7ccfce3682..0fe848d565 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/DirectoryDocumentIterator.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/DirectoryDocumentIterator.cs @@ -5,15 +5,16 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Editor.Search; +using ICSharpCode.SharpDevelop; using System; using System.Collections.Generic; using System.IO; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Refactoring; -using ICSharpCode.TextEditor.Document; namespace SearchAndReplace { @@ -59,20 +60,20 @@ namespace SearchAndReplace foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { if (content.PrimaryFileName != null && FileUtility.IsEqualFileName(content.PrimaryFileName, fileName) && - content is ITextEditorControlProvider) { - document = ((ITextEditorControlProvider)content).TextEditorControl.Document; - return new ProvidedDocumentInformation(new TextEditorDocument(document), + content is ITextEditorProvider) { + document = ((ITextEditorProvider)content).TextEditor.Document; + return new ProvidedDocumentInformation(document, fileName, 0); } } - ITextBufferStrategy strategy = null; + string fileContent; try { - strategy = StringTextBufferStrategy.CreateTextBufferFromFile(fileName); + fileContent = ParserService.GetParseableFileContent(fileName); } catch (Exception) { return null; } - return new ProvidedDocumentInformation(strategy, + return new ProvidedDocumentInformation(fileContent, fileName, 0); } diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/WholeProjectDocumentIterator.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/WholeProjectDocumentIterator.cs index 24e9b02da3..cc4006aae3 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/WholeProjectDocumentIterator.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/WholeProjectDocumentIterator.cs @@ -5,16 +5,17 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Editor.Search; +using ICSharpCode.SharpDevelop; using System; using System.Collections; using System.IO; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Refactoring; -using ICSharpCode.TextEditor.Document; namespace SearchAndReplace { @@ -52,21 +53,21 @@ namespace SearchAndReplace foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { if (content.PrimaryFileName != null && FileUtility.IsEqualFileName(content.PrimaryFileName, fileName) && - content is ITextEditorControlProvider) + content is ITextEditorProvider) { - document = (((ITextEditorControlProvider)content).TextEditorControl).Document; - return new ProvidedDocumentInformation(new TextEditorDocument(document), + document = (((ITextEditorProvider)content).TextEditor).Document; + return new ProvidedDocumentInformation(document, fileName, 0); } } - ITextBufferStrategy strategy = null; + string fileContent; try { - strategy = StringTextBufferStrategy.CreateTextBufferFromFile(fileName); + fileContent = ParserService.GetParseableFileContent(fileName); } catch (Exception) { return null; } - return new ProvidedDocumentInformation(strategy, + return new ProvidedDocumentInformation(fileContent, fileName, 0); } diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/WholeSolutionDocumentIterator.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/WholeSolutionDocumentIterator.cs index 2bba40e69a..d906ba2fde 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/WholeSolutionDocumentIterator.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/DocumentIterator/WholeSolutionDocumentIterator.cs @@ -5,16 +5,17 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Editor.Search; +using ICSharpCode.SharpDevelop; using System; using System.Collections; using System.IO; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Refactoring; -using ICSharpCode.TextEditor.Document; namespace SearchAndReplace { @@ -52,21 +53,21 @@ namespace SearchAndReplace foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { if (content.PrimaryFileName != null && FileUtility.IsEqualFileName(content.PrimaryFileName, fileName) && - content is ITextEditorControlProvider) + content is ITextEditorProvider) { - document = (((ITextEditorControlProvider)content).TextEditorControl).Document; - return new ProvidedDocumentInformation(new TextEditorDocument(document), + document = (((ITextEditorProvider)content).TextEditor).Document; + return new ProvidedDocumentInformation(document, fileName, 0); } } - ITextBufferStrategy strategy = null; + string fileContent; try { - strategy = StringTextBufferStrategy.CreateTextBufferFromFile(fileName); + fileContent = ParserService.GetParseableFileContent(fileName); } catch (Exception) { return null; } - return new ProvidedDocumentInformation(strategy, + return new ProvidedDocumentInformation(fileContent, fileName, 0); } diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceManager.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceManager.cs index b00d5e29e0..dce7d8d22f 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceManager.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceManager.cs @@ -14,8 +14,6 @@ using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; -using ICSharpCode.TextEditor; -using ICSharpCode.TextEditor.Document; namespace SearchAndReplace { @@ -39,24 +37,21 @@ namespace SearchAndReplace public static void Replace(IProgressMonitor monitor) { SetSearchOptions(); - if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { - ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorControlProvider; + if (lastResult != null) { + ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; if (provider != null) { - TextEditorControl textarea = provider.TextEditorControl; - SelectionManager selectionManager = textarea.ActiveTextAreaControl.TextArea.SelectionManager; + ITextEditor textarea = provider.TextEditor; - if (selectionManager.SelectionCollection.Count == 1 - && selectionManager.SelectionCollection[0].Offset == lastResult.Offset - && selectionManager.SelectionCollection[0].Length == lastResult.Length + if (textarea.SelectionStart == lastResult.Offset + && textarea.SelectionLength == lastResult.Length && lastResult.FileName == textarea.FileName) { string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern); - textarea.BeginUpdate(); - selectionManager.ClearSelection(); - textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); - textarea.ActiveTextAreaControl.Caret.Position = textarea.Document.OffsetToPosition(lastResult.Offset + replacePattern.Length); - textarea.EndUpdate(); + using (textarea.Document.OpenUndoGroup()) { + textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); + textarea.Select(lastResult.Offset + replacePattern.Length, 0); // clear selection and set caret position + } } } } @@ -73,24 +68,21 @@ namespace SearchAndReplace public static bool ReplaceNextInSelection(IProgressMonitor monitor) { - if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { - ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorControlProvider; + if (lastResult != null) { + ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; if (provider != null) { - TextEditorControl textarea = provider.TextEditorControl; - SelectionManager selectionManager = textarea.ActiveTextAreaControl.TextArea.SelectionManager; + ITextEditor textarea = provider.TextEditor; - if (selectionManager.SelectionCollection.Count == 1 - && selectionManager.SelectionCollection[0].Offset == lastResult.Offset - && selectionManager.SelectionCollection[0].Length == lastResult.Length + if (textarea.SelectionStart == lastResult.Offset + && textarea.SelectionLength == lastResult.Length && lastResult.FileName == textarea.FileName) { string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern); - textarea.BeginUpdate(); - selectionManager.ClearSelection(); - textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); - textarea.ActiveTextAreaControl.Caret.Position = textarea.Document.OffsetToPosition(lastResult.Offset + replacePattern.Length); - textarea.EndUpdate(); + using (textarea.Document.OpenUndoGroup()) { + textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); + textarea.Select(lastResult.Offset + replacePattern.Length, 0); // clear selection and set caret position + } textSelection.Length -= lastResult.Length - replacePattern.Length; } @@ -386,11 +378,11 @@ namespace SearchAndReplace static void ClearSelection() { - if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { - ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorControlProvider; - if (provider != null) { - provider.TextEditorControl.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection(); - } + ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; + if (provider != null) { + ITextEditor editor = provider.TextEditor; + if (editor.SelectionLength > 0) + editor.Select(editor.Caret.Offset, 0); } } } diff --git a/src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj b/src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj index 1245c56e5a..3f0dbca36e 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj +++ b/src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj @@ -107,11 +107,6 @@ - - {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D} - ICSharpCode.TextEditor - False - {2748AD25-9C63-4E12-877B-4DCE96FBED54} ICSharpCode.SharpDevelop diff --git a/src/AddIns/Misc/SearchAndReplace/Test/FindNextWithCursorAtEndTestFixture.cs b/src/AddIns/Misc/SearchAndReplace/Test/FindNextWithCursorAtEndTestFixture.cs index e2b00e8ac1..d63217787b 100644 --- a/src/AddIns/Misc/SearchAndReplace/Test/FindNextWithCursorAtEndTestFixture.cs +++ b/src/AddIns/Misc/SearchAndReplace/Test/FindNextWithCursorAtEndTestFixture.cs @@ -8,7 +8,6 @@ using ICSharpCode.SharpDevelop.Editor.Search; using System; using ICSharpCode.Core; -using ICSharpCode.TextEditor.Document; using NUnit.Framework; using SearchAndReplace; using SearchAndReplace.Tests.Utils; diff --git a/src/AddIns/Misc/SearchAndReplace/Test/ForwardIteratorWithEmptyTextBufferTestFixture.cs b/src/AddIns/Misc/SearchAndReplace/Test/ForwardIteratorWithEmptyTextBufferTestFixture.cs index 36fa849f26..276fa9d96b 100644 --- a/src/AddIns/Misc/SearchAndReplace/Test/ForwardIteratorWithEmptyTextBufferTestFixture.cs +++ b/src/AddIns/Misc/SearchAndReplace/Test/ForwardIteratorWithEmptyTextBufferTestFixture.cs @@ -7,7 +7,6 @@ using ICSharpCode.SharpDevelop.Editor.Search; using System; -using ICSharpCode.TextEditor.Document; using NUnit.Framework; using SearchAndReplace; using SearchAndReplace.Tests.Utils; diff --git a/src/AddIns/Misc/SearchAndReplace/Test/ForwardTextIteratorPositionIsEndOffsetTestFixture.cs b/src/AddIns/Misc/SearchAndReplace/Test/ForwardTextIteratorPositionIsEndOffsetTestFixture.cs index 85e15eca44..bcf7331a74 100644 --- a/src/AddIns/Misc/SearchAndReplace/Test/ForwardTextIteratorPositionIsEndOffsetTestFixture.cs +++ b/src/AddIns/Misc/SearchAndReplace/Test/ForwardTextIteratorPositionIsEndOffsetTestFixture.cs @@ -7,7 +7,6 @@ using ICSharpCode.SharpDevelop.Editor.Search; using System; -using ICSharpCode.TextEditor.Document; using NUnit.Framework; using SearchAndReplace; using SearchAndReplace.Tests.Utils; diff --git a/src/AddIns/Misc/SearchAndReplace/Test/SearchAndReplace.Tests.csproj b/src/AddIns/Misc/SearchAndReplace/Test/SearchAndReplace.Tests.csproj index 8e11bc2028..b950f6c35a 100644 --- a/src/AddIns/Misc/SearchAndReplace/Test/SearchAndReplace.Tests.csproj +++ b/src/AddIns/Misc/SearchAndReplace/Test/SearchAndReplace.Tests.csproj @@ -47,10 +47,6 @@ - - {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D} - ICSharpCode.TextEditor - {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195} NRefactory diff --git a/src/Main/Base/Project/Src/Editor/Search/ProvidedDocumentInformation.cs b/src/Main/Base/Project/Src/Editor/Search/ProvidedDocumentInformation.cs index ab1647b88a..5adda7c4ce 100644 --- a/src/Main/Base/Project/Src/Editor/Search/ProvidedDocumentInformation.cs +++ b/src/Main/Base/Project/Src/Editor/Search/ProvidedDocumentInformation.cs @@ -5,6 +5,7 @@ // $Revision$ // +using ICSharpCode.AvalonEdit.Document; using System; using ICSharpCode.SharpDevelop.Refactoring; @@ -12,11 +13,11 @@ namespace ICSharpCode.SharpDevelop.Editor.Search { public class ProvidedDocumentInformation { - IDocument document; - ICSharpCode.TextEditor.Document.ITextBufferStrategy textBuffer; - string fileName; - int currentOffset; ITextEditor textEditor; + IDocument document; + string textBuffer; + string fileName; + int currentOffset; public string FileName { get { @@ -27,8 +28,11 @@ namespace ICSharpCode.SharpDevelop.Editor.Search public IDocument Document { get { if (document == null) { - var factory = new ICSharpCode.TextEditor.Document.DocumentFactory(); - document = new TextEditorDocument(factory.CreateFromTextBuffer(textBuffer)); + TextDocument textDocument = new TextDocument(); + textDocument.Text = textBuffer; + textDocument.UndoStack.ClearAll(); + document = new AvalonEditDocumentAdapter(textDocument, null); + this.textBuffer = null; } return document; } @@ -66,11 +70,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search public void Replace(int offset, int length, string pattern) { - if (document != null) { - document.Replace(offset, length, pattern); - } else { - textBuffer.Replace(offset, length, pattern); - } + this.Document.Replace(offset, length, pattern); if (offset <= CurrentOffset) { CurrentOffset = CurrentOffset - length + pattern.Length; @@ -107,7 +107,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search this.endOffset = this.CurrentOffset; } - public ProvidedDocumentInformation(ICSharpCode.TextEditor.Document.ITextBufferStrategy textBuffer, string fileName, int currentOffset) + public ProvidedDocumentInformation(string textBuffer, string fileName, int currentOffset) { this.textBuffer = textBuffer; this.fileName = fileName; diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs b/src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs index 3670a9a407..8387564822 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs @@ -252,8 +252,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring } } } - var strategy = ICSharpCode.TextEditor.Document.StringTextBufferStrategy.CreateTextBufferFromFile(fileName); - return new ProvidedDocumentInformation(strategy, fileName, 0); + string fileContent = ParserService.GetParseableFileContent(fileName); + return new ProvidedDocumentInformation(fileContent, fileName, 0); } public static bool IsReadOnly(IClass c)