diff options
author | Mike Krüger <mkrueger@novell.com> | 2010-07-21 23:04:41 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@novell.com> | 2010-07-21 23:04:41 +0400 |
commit | c7c7967acedb28572a6b14c859031a1f98694d91 (patch) | |
tree | eaa7ec52bfa70d7c77ef63acc013bfba86b57207 /main/src/core/MonoDevelop.Ide | |
parent | 165e9be7cc4236571eeb5d5d9a6770dddda38156 (diff) |
* MonoDevelop.Ide.Gui/Document.cs:
* MonoDevelop.Ide/RootWorkspace.cs:
* MonoDevelop.Ide/ProjectOperations.cs: Changed document parsing/text
file provider now returns texteditordata provider.
svn path=/trunk/monodevelop/; revision=160690
Diffstat (limited to 'main/src/core/MonoDevelop.Ide')
4 files changed, 101 insertions, 11 deletions
diff --git a/main/src/core/MonoDevelop.Ide/ChangeLog b/main/src/core/MonoDevelop.Ide/ChangeLog index 16ade92392..f3262c17b8 100644 --- a/main/src/core/MonoDevelop.Ide/ChangeLog +++ b/main/src/core/MonoDevelop.Ide/ChangeLog @@ -1,5 +1,13 @@ 2010-07-21 Mike Krüger <mkrueger@novell.com> + * MonoDevelop.Ide.Gui/Document.cs: + * MonoDevelop.Ide/RootWorkspace.cs: + * MonoDevelop.Ide/ProjectOperations.cs: Changed document + parsing/text file provider now returns texteditordata + provider. + +2010-07-21 Mike Krüger <mkrueger@novell.com> + * MonoDevelop.Ide.Gui/Document.cs: Be more carefully when updating parsed documents. diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs index fcb025eea2..a74a84fd01 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs @@ -489,12 +489,12 @@ namespace MonoDevelop.Ide.Gui if (editor == null) return; Editor.Document.TextReplaced += OnDocumentChanged; - //this.parsedDocument = MonoDevelop.Projects.Dom.Parser.ProjectDomService.Parse (Project, FileName, DesktopService.GetMimeTypeForUri (FileName), TextEditor.Text); - + this.parsedDocument = MonoDevelop.Projects.Dom.Parser.ProjectDomService.GetParsedDocument (this.dom, FileName); + OnDocumentParsed (EventArgs.Empty); + // If the new document is a text editor, attach the extensions ExtensionNodeList extensions = AddinManager.GetExtensionNodes ("/MonoDevelop/Ide/TextEditorExtensions", typeof(TextEditorExtensionNode)); - editorExtension = null; TextEditorExtension last = null; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs index 556d683071..4df010669c 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs @@ -48,6 +48,7 @@ using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Projects; using MonoDevelop.Core.Assemblies; using MonoDevelop.Core.Instrumentation; +using Mono.TextEditor; namespace MonoDevelop.Ide { @@ -262,7 +263,7 @@ namespace MonoDevelop.Ide IType declaringType = SearchContainingPart (member); fileName = declaringType.CompilationUnit.FileName; } - Document doc = IdeApp.Workbench.OpenDocument (fileName, member.Location.Line, member.Location.Column, true); + var doc = IdeApp.Workbench.OpenDocument (fileName, member.Location.Line, member.Location.Column, true); if (doc != null) { MonoDevelop.Ide.Gui.Content.IUrlHandler handler = doc.ActiveView as MonoDevelop.Ide.Gui.Content.IUrlHandler; if (handler != null) @@ -1029,7 +1030,7 @@ namespace MonoDevelop.Ide case BeforeCompileAction.Nothing: break; case BeforeCompileAction.PromptForSave: - foreach (Document doc in IdeApp.Workbench.Documents) { + foreach (var doc in IdeApp.Workbench.Documents) { if (doc.IsDirty && doc.Project != null) { if (MessageService.AskQuestion ( GettextCatalog.GetString ("Save changed documents before building?"), @@ -1044,7 +1045,7 @@ namespace MonoDevelop.Ide } break; case BeforeCompileAction.SaveAllFiles: - foreach (Document doc in new List<Document> (IdeApp.Workbench.Documents)) + foreach (var doc in new List<MonoDevelop.Ide.Gui.Document> (IdeApp.Workbench.Documents)) if (doc.IsDirty && doc.Project != null) doc.Save (); break; @@ -1572,17 +1573,98 @@ namespace MonoDevelop.Ide } } - class OpenDocumentFileProvider: ITextFileProvider - {
+ public class TextFileProvider : ITextFileProvider + { + static TextFileProvider instance = new TextFileProvider (); + public static TextFileProvider Instance { + get { + return instance; + } + } + + TextFileProvider () + { + } + + class ProviderProxy : ITextEditorDataProvider, IEditableTextFile + { + TextEditorData data; + public ProviderProxy (TextEditorData data) + { + this.data = data; + } + + public TextEditorData GetTextEditorData () + { + return data; + } + + #region IEditableTextFile implementation + public FilePath Name { get { return data.Document.FileName; } } + + public int Length { get { return data.Length; } } + + public string GetText (int startPosition, int endPosition) + { + return data.GetTextBetween (startPosition, endPosition); + } + public char GetCharAt (int position) + { + return data.GetCharAt (position); + } + + public int GetPositionFromLineColumn (int line, int column) + { + return data.Document.LocationToOffset (line - 1, column - 1); + } + + public void GetLineColumnFromPosition (int position, out int line, out int column) + { + var loc = data.Document.OffsetToLocation (position); + line = loc.Line + 1; + column = loc.Column + 1; + } + + public int InsertText (int position, string text) + { + int result = data.Insert (position, text); + File.WriteAllText (Name, Text); + return result; + } + + + public void DeleteText (int position, int length) + { + data.Remove (position, length); + File.WriteAllText (Name, Text); + } + + public string Text { + get { + return data.Text; + } + set { + data.Text = value; + } + } + + #endregion + }
+ public IEditableTextFile GetEditableTextFile (FilePath filePath) { - foreach (Document doc in IdeApp.Workbench.Documents) { + foreach (var doc in IdeApp.Workbench.Documents) { if (doc.FileName == filePath) { IEditableTextFile ef = doc.GetContent<IEditableTextFile> (); if (ef != null) return ef; } } - return null; + + TextEditorData data = new TextEditorData (); + data.Document.FileName = filePath; + data.Text = File.ReadAllText (filePath); + return new ProviderProxy (data); } + } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/RootWorkspace.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/RootWorkspace.cs index 2c97098428..90efc4a4b3 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/RootWorkspace.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/RootWorkspace.cs @@ -163,7 +163,7 @@ namespace MonoDevelop.Ide public CodeRefactorer GetCodeRefactorer (Solution solution) { CodeRefactorer refactorer = new CodeRefactorer (solution); - refactorer.TextFileProvider = new OpenDocumentFileProvider (); + refactorer.TextFileProvider = TextFileProvider.Instance; return refactorer; } |