Browse Source

Support replacing text in EnvDTE.EditPoint

pull/375/head
Matt Ward 12 years ago
parent
commit
db9951afbf
  1. 38
      src/AddIns/Misc/PackageManagement/Project/Src/DocumentLoader.cs
  2. 15
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeModelContext.cs
  3. 84
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/EditPoint.cs
  4. 4
      src/AddIns/Misc/PackageManagement/Project/Src/IDocumentLoader.cs
  5. 24
      src/AddIns/Misc/PackageManagement/Project/Src/IRefactoringDocumentView.cs
  6. 99
      src/AddIns/Misc/PackageManagement/Project/Src/RefactoringDocumentView.cs

38
src/AddIns/Misc/PackageManagement/Project/Src/DocumentLoader.cs

@ -16,26 +16,18 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
//using System; using System;
//using ICSharpCode.SharpDevelop.Dom.Refactoring; using ICSharpCode.SharpDevelop;
//using ICSharpCode.SharpDevelop.Gui;
// namespace ICSharpCode.PackageManagement
//namespace ICSharpCode.PackageManagement {
//{ public class DocumentLoader : IDocumentLoader
// public class DocumentLoader : IDocumentLoader {
// { public IRefactoringDocumentView LoadRefactoringDocumentView(string fileName)
// public IRefactoringDocument LoadRefactoringDocument(string fileName) {
// { return SD.MainThread.InvokeIfRequired(() => {
// return LoadRefactoringDocumentView(fileName).RefactoringDocument; return new RefactoringDocumentView(fileName);
// } });
// }
// public IRefactoringDocumentView LoadRefactoringDocumentView(string fileName) }
// { }
// if (WorkbenchSingleton.InvokeRequired) {
// return WorkbenchSingleton.SafeThreadFunction(() => LoadRefactoringDocumentView(fileName));
// } else {
// return new RefactoringDocumentView(fileName);
// }
// }
// }
//}

15
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeModelContext.cs

@ -25,10 +25,21 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public class CodeModelContext public class CodeModelContext
{ {
ICodeGenerator codeGenerator; ICodeGenerator codeGenerator;
IDocumentLoader documentLoader;
public Project DteProject { get; set; } public Project DteProject { get; set; }
public IProject CurrentProject { get; set; } public IProject CurrentProject { get; set; }
public IDocumentLoader DocumentLoader { get; set; }
public IDocumentLoader DocumentLoader {
get {
if (documentLoader == null) {
documentLoader = new DocumentLoader();
}
return documentLoader;
}
set { documentLoader = value; }
}
public ICodeGenerator CodeGenerator { public ICodeGenerator CodeGenerator {
get { get {
@ -46,7 +57,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public CodeModelContext WithFilteredFileName(string fileName) public CodeModelContext WithFilteredFileName(string fileName)
{ {
CodeModelContext newContext = (CodeModelContext)MemberwiseClone(); var newContext = (CodeModelContext)MemberwiseClone();
newContext.FilteredFileName = fileName; newContext.FilteredFileName = fileName;
return newContext; return newContext;
} }

84
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/EditPoint.cs

@ -18,14 +18,15 @@
using System; using System;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
namespace ICSharpCode.PackageManagement.EnvDTE namespace ICSharpCode.PackageManagement.EnvDTE
{ {
public class EditPoint : TextPoint, global::EnvDTE.EditPoint public class EditPoint : TextPoint, global::EnvDTE.EditPoint
{ {
// IRefactoringDocument document; IDocument document;
// IRefactoringDocumentView documentView; IRefactoringDocumentView documentView;
internal EditPoint(string fileName, TextLocation location, IDocumentLoader documentLoader) internal EditPoint(string fileName, TextLocation location, IDocumentLoader documentLoader)
: base(fileName, location, documentLoader) : base(fileName, location, documentLoader)
@ -39,47 +40,46 @@ namespace ICSharpCode.PackageManagement.EnvDTE
void ReplaceText(TextPoint endPoint, string text, global::EnvDTE.vsEPReplaceTextOptions textFormatOptions) void ReplaceText(TextPoint endPoint, string text, global::EnvDTE.vsEPReplaceTextOptions textFormatOptions)
{ {
throw new NotImplementedException(); OpenDocument();
// OpenDocument(); int offset = GetStartOffset();
// int offset = GetStartOffset(); int endOffset = GetEndOffset(endPoint);
// int endOffset = GetEndOffset(endPoint); document.Replace(offset, endOffset - offset, text);
// document.Replace(offset, endOffset - offset, text); IndentReplacedText(text);
// IndentReplacedText(text); }
void OpenDocument()
{
documentView = documentLoader.LoadRefactoringDocumentView(fileName);
document = documentView.RefactoringDocument;
}
int GetStartOffset()
{
return document.PositionToOffset(Line, LineCharOffset);
}
int GetEndOffset(TextPoint endPoint)
{
return document.PositionToOffset(endPoint.Line, endPoint.LineCharOffset);
}
/// <summary>
/// Indents all lines apart from the first one since it is assumed
/// that the first line had the correct indentation.
/// </summary>
void IndentReplacedText(string text)
{
int lineCount = GetLineCount(text);
if (lineCount > 1) {
documentView.IndentLines(Line + 1, Line + lineCount);
}
}
int GetLineCount(string text)
{
return text.Split('\n').Length;
} }
// void OpenDocument()
// {
// documentView = DocumentLoader.LoadRefactoringDocumentView(FilePosition.FileName);
// document = documentView.RefactoringDocument;
// }
//
// int GetStartOffset()
// {
// return document.PositionToOffset(Line, LineCharOffset);
// }
//
// int GetEndOffset(TextPoint endPoint)
// {
// return document.PositionToOffset(endPoint.Line, endPoint.LineCharOffset);
// }
//
// /// <summary>
// /// Indents all lines apart from the first one since it is assumed
// /// that the first line had the correct indentation.
// /// </summary>
// void IndentReplacedText(string text)
// {
// int lineCount = GetLineCount(text);
// if (lineCount > 1) {
// documentView.IndentLines(Line + 1, Line + lineCount);
// }
// }
//
// int GetLineCount(string text)
// {
// return text.Split('\n').Length;
// }
//
public void Insert(string text) public void Insert(string text)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

4
src/AddIns/Misc/PackageManagement/Project/Src/IDocumentLoader.cs

@ -17,13 +17,11 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.PackageManagement namespace ICSharpCode.PackageManagement
{ {
public interface IDocumentLoader public interface IDocumentLoader
{ {
// IRefactoringDocument LoadRefactoringDocument(string fileName); IRefactoringDocumentView LoadRefactoringDocumentView(string fileName);
// IRefactoringDocumentView LoadRefactoringDocumentView(string fileName);
} }
} }

24
src/AddIns/Misc/PackageManagement/Project/Src/IRefactoringDocumentView.cs

@ -16,16 +16,14 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
//using System; using System;
//using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.NRefactory.Editor;
//using ICSharpCode.SharpDevelop.Dom.Refactoring;
// namespace ICSharpCode.PackageManagement
//namespace ICSharpCode.PackageManagement {
//{ public interface IRefactoringDocumentView
// public interface IRefactoringDocumentView {
// { IDocument RefactoringDocument { get; }
// IRefactoringDocument RefactoringDocument { get; } void IndentLines(int beginLine, int endLine);
// ICompilationUnit Parse(); }
// void IndentLines(int beginLine, int endLine); }
// }
//}

99
src/AddIns/Misc/PackageManagement/Project/Src/RefactoringDocumentView.cs

@ -16,59 +16,46 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
//using System; using System;
//using ICSharpCode.SharpDevelop; using ICSharpCode.NRefactory.Editor;
//using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop;
//using ICSharpCode.SharpDevelop.Dom.Refactoring; using ICSharpCode.SharpDevelop.Editor;
//using ICSharpCode.SharpDevelop.Editor;
//using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.PackageManagement
// {
//namespace ICSharpCode.PackageManagement public class RefactoringDocumentView : IRefactoringDocumentView
//{ {
// public class RefactoringDocumentView : IRefactoringDocumentView public RefactoringDocumentView(string fileName)
// { {
// public RefactoringDocumentView(string fileName) View = FileService.OpenFile(fileName);
// { TextEditor = GetTextEditor();
// View = FileService.OpenFile(fileName); FormattingStrategy = TextEditor.Language.FormattingStrategy;
// TextEditor = GetTextEditor(); RefactoringDocument = LoadDocument();
// FormattingStrategy = TextEditor.Language.FormattingStrategy; }
// RefactoringDocument = LoadDocument();
// } IViewContent View { get; set; }
// ITextEditor TextEditor { get; set; }
// IViewContent View { get; set; } IFormattingStrategy FormattingStrategy { get; set; }
// ITextEditor TextEditor { get; set; }
// IFormattingStrategy FormattingStrategy { get; set; } ITextEditor GetTextEditor()
// {
// ITextEditor GetTextEditor() return View.GetService<ITextEditor>();
// { }
// var textEditorProvider = View as ITextEditorProvider;
// return textEditorProvider.TextEditor; public IDocument RefactoringDocument { get; private set; }
// }
// IDocument LoadDocument()
// public IRefactoringDocument RefactoringDocument { get; private set; } {
// return new ThreadSafeDocument(TextEditor.Document);
// IRefactoringDocument LoadDocument() }
// {
// return new RefactoringDocumentAdapter(new ThreadSafeDocument(TextEditor.Document)); public void IndentLines(int beginLine, int endLine)
// } {
// SD.MainThread.InvokeIfRequired(() => {
// public ICompilationUnit Parse() using (IDisposable undoGroup = TextEditor.Document.OpenUndoGroup()) {
// { FormattingStrategy.IndentLines(TextEditor, beginLine, endLine);
// if (WorkbenchSingleton.InvokeRequired) { }
// return WorkbenchSingleton.SafeThreadFunction(() => Parse()); });
// } }
// return ParserService.ParseViewContent(View).CompilationUnit; }
// } }
//
// public void IndentLines(int beginLine, int endLine)
// {
// if (WorkbenchSingleton.InvokeRequired) {
// WorkbenchSingleton.SafeThreadCall(() => IndentLines(beginLine, endLine));
// } else {
// using (IDisposable undoGroup = TextEditor.Document.OpenUndoGroup()) {
// FormattingStrategy.IndentLines(TextEditor, beginLine, endLine);
// }
// }
// }
// }
//}

Loading…
Cancel
Save