diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2014-04-02 18:25:43 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2014-04-02 18:25:43 +0400 |
commit | b1e29c52195bcc083f6a2ef3a35037479d96174d (patch) | |
tree | f19a2fab04319c3f7cce7f04e424a8fd66b51a2d /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content | |
parent | 15649ed717a18790ffdb5afd6757fac5b1b95499 (diff) |
[Ide] Added basic text editor model.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content')
4 files changed, 55 insertions, 58 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/CompletionTextEditorExtension.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/CompletionTextEditorExtension.cs index 87562cd44b..df0bd52a91 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/CompletionTextEditorExtension.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/CompletionTextEditorExtension.cs @@ -34,6 +34,7 @@ using MonoDevelop.Ide.Commands; using MonoDevelop.Core; using MonoDevelop.Ide.CodeTemplates; using ICSharpCode.NRefactory.Completion; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.Ide.Gui.Content { @@ -73,10 +74,10 @@ namespace MonoDevelop.Ide.Gui.Content public void ShowCompletion (ICompletionDataList completionList) { - currentCompletionContext = CompletionWidget.CreateCodeCompletionContext (Document.Editor.Caret.Offset); + currentCompletionContext = CompletionWidget.CreateCodeCompletionContext (Document.Editor.CaretOffset); int cpos, wlen; if (!GetCompletionCommandOffset (out cpos, out wlen)) { - cpos = Document.Editor.Caret.Offset; + cpos = Document.Editor.CaretOffset; wlen = 0; } currentCompletionContext.TriggerOffset = cpos; @@ -127,7 +128,7 @@ namespace MonoDevelop.Ide.Gui.Content return res; // don't complete on block selection - if (/*!EnableCodeCompletion ||*/ Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block) + if (/*!EnableCodeCompletion ||*/ Document.Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block) return res; // Handle code completion @@ -136,10 +137,10 @@ namespace MonoDevelop.Ide.Gui.Content int triggerWordLength = currentCompletionContext.TriggerWordLength; ICompletionDataList completionList = HandleCodeCompletion (currentCompletionContext, keyChar, ref triggerWordLength); - if (triggerWordLength > 0 && (triggerWordLength < Editor.Caret.Offset - || (triggerWordLength == 1 && Editor.Caret.Offset == 1))) { + if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset + || (triggerWordLength == 1 && Editor.CaretOffset == 1))) { currentCompletionContext - = CompletionWidget.CreateCodeCompletionContext (Editor.Caret.Offset - triggerWordLength); + = CompletionWidget.CreateCodeCompletionContext (Editor.CaretOffset - triggerWordLength); currentCompletionContext.TriggerWordLength = triggerWordLength; } if (completionList != null) { @@ -163,13 +164,13 @@ namespace MonoDevelop.Ide.Gui.Content protected void ShowCompletion (ICompletionDataList completionList, int triggerWordLength, char keyChar) { - if (Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block) + if (Document.Editor.SelectionMode == SelectionMode.Block) return; if (CompletionWidget != null && currentCompletionContext == null) { currentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; - if (triggerWordLength > 0 && triggerWordLength < Editor.Caret.Offset) { + if (triggerWordLength > 0 && triggerWordLength < Editor.CaretOffset) { currentCompletionContext = - CompletionWidget.CreateCodeCompletionContext (Editor.Caret.Offset - triggerWordLength); + CompletionWidget.CreateCodeCompletionContext (Editor.CaretOffset - triggerWordLength); currentCompletionContext.TriggerWordLength = triggerWordLength; } if (completionList != null) @@ -210,7 +211,7 @@ namespace MonoDevelop.Ide.Gui.Content [CommandHandler (TextEditorCommands.ShowCompletionWindow)] public virtual void RunCompletionCommand () { - if (Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block) + if (Document.Editor.SelectionMode == SelectionMode.Block) return; if (CompletionWindowManager.IsVisible) { @@ -220,7 +221,7 @@ namespace MonoDevelop.Ide.Gui.Content ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset (out cpos, out wlen)) { - cpos = Editor.Caret.Offset; + cpos = Editor.CaretOffset; wlen = 0; } currentCompletionContext = CompletionWidget.CreateCodeCompletionContext (cpos); @@ -238,7 +239,7 @@ namespace MonoDevelop.Ide.Gui.Content ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset (out cpos, out wlen)) { - cpos = Editor.Caret.Offset; + cpos = Editor.CaretOffset; wlen = 0; } @@ -263,7 +264,7 @@ namespace MonoDevelop.Ide.Gui.Content ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset (out cpos, out wlen)) { - cpos = Editor.Caret.Offset; + cpos = Editor.CaretOffset; wlen = 0; } try { @@ -283,12 +284,12 @@ namespace MonoDevelop.Ide.Gui.Content [CommandHandler (TextEditorCommands.ShowParameterCompletionWindow)] public virtual void RunParameterCompletionCommand () { - if (Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block || CompletionWidget == null) + if (Document.Editor.SelectionMode == SelectionMode.Block || CompletionWidget == null) return; ParameterDataProvider cp = null; int cpos; if (!GetParameterCompletionCommandOffset (out cpos)) - cpos = Editor.Caret.Offset; + cpos = Editor.CaretOffset; CodeCompletionContext ctx = CompletionWidget.CreateCodeCompletionContext (cpos); cp = ParameterCompletionCommand (ctx); if (cp != null) { @@ -323,7 +324,7 @@ namespace MonoDevelop.Ide.Gui.Content public virtual bool GetCompletionCommandOffset (out int cpos, out int wlen) { cpos = wlen = 0; - int pos = Editor.Caret.Offset - 1; + int pos = Editor.CaretOffset - 1; while (pos >= 0) { char c = Editor.GetCharAt (pos); if (!char.IsLetterOrDigit (c) && c != '_') @@ -335,7 +336,7 @@ namespace MonoDevelop.Ide.Gui.Content pos++; cpos = pos; - int len = Editor.Length; + int len = Editor.TextLength; while (pos < len) { char c = Editor.GetCharAt (pos); @@ -411,7 +412,7 @@ namespace MonoDevelop.Ide.Gui.Content int pos = completionContext.TriggerOffset; if (pos <= 0) return null; - var cp = HandleParameterCompletion (completionContext, Editor.Document.GetCharAt (pos - 1)); + var cp = HandleParameterCompletion (completionContext, Editor.GetCharAt (pos - 1)); if (cp != null) return cp; return null; @@ -445,17 +446,17 @@ namespace MonoDevelop.Ide.Gui.Content return -1; } - void HandlePaste (int insertionOffset, string text, int insertedChars) - { - ParameterInformationWindowManager.HideWindow (this, CompletionWidget); - CompletionWindowManager.HideWindow (); - } - - void HandleFocusOutEvent (object o, Gtk.FocusOutEventArgs args) - { - ParameterInformationWindowManager.HideWindow (this, CompletionWidget); - CompletionWindowManager.HideWindow (); - } +// void HandlePaste (int insertionOffset, string text, int insertedChars) +// { +// ParameterInformationWindowManager.HideWindow (this, CompletionWidget); +// CompletionWindowManager.HideWindow (); +// } +// +// void HandleFocusOutEvent (object o, Gtk.FocusOutEventArgs args) +// { +// ParameterInformationWindowManager.HideWindow (this, CompletionWidget); +// CompletionWindowManager.HideWindow (); +// } public override void Initialize () { @@ -464,13 +465,13 @@ namespace MonoDevelop.Ide.Gui.Content CompletionWidget = Document.GetContent <ICompletionWidget> (); if (CompletionWidget != null) CompletionWidget.CompletionContextChanged += OnCompletionContextChanged; - document.Editor.Caret.PositionChanged += HandlePositionChanged; - document.Editor.Paste += HandlePaste; - if (document.Editor.Parent != null) - document.Editor.Parent.TextArea.FocusOutEvent += HandleFocusOutEvent; + document.Editor.CaretPositionChanged += HandlePositionChanged; +// document.Editor.Paste += HandlePaste; +// if (document.Editor.Parent != null) +// document.Editor.Parent.TextArea.FocusOutEvent += HandleFocusOutEvent; } - void HandlePositionChanged (object sender, Mono.TextEditor.DocumentLocationEventArgs e) + void HandlePositionChanged (object sender, EventArgs e) { CompletionWindowManager.UpdateCursorPosition (); } @@ -488,10 +489,10 @@ namespace MonoDevelop.Ide.Gui.Content ParameterInformationWindowManager.HideWindow (this, CompletionWidget); disposed = true; - if (document.Editor.Parent != null) - document.Editor.Parent.TextArea.FocusOutEvent -= HandleFocusOutEvent; - document.Editor.Paste -= HandlePaste; - document.Editor.Caret.PositionChanged -= HandlePositionChanged; +// if (document.Editor.Parent != null) +// document.Editor.Parent.TextArea.FocusOutEvent -= HandleFocusOutEvent; +// document.Editor.Paste -= HandlePaste; + document.Editor.CaretPositionChanged -= HandlePositionChanged; CompletionWindowManager.WindowClosed -= HandleWindowClosed; if (CompletionWidget != null) CompletionWidget.CompletionContextChanged -= OnCompletionContextChanged; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/DocumentStateTracker.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/DocumentStateTracker.cs index 45303e9457..adee1dcd78 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/DocumentStateTracker.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/DocumentStateTracker.cs @@ -30,7 +30,8 @@ using System; using System.Collections.Generic; -using Mono.TextEditor; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Core.Text; namespace MonoDevelop.Ide.Gui.Content { @@ -40,25 +41,25 @@ namespace MonoDevelop.Ide.Gui.Content T currentEngine; Stack<T> cachedEngines = new Stack<T> (); - TextEditorData editor; + ITextEditor editor; - public DocumentStateTracker (T engine, TextEditorData editor) + public DocumentStateTracker (T engine, ITextEditor editor) { this.currentEngine = engine; this.editor = editor; - editor.Document.TextReplaced += textChanged; + editor.TextChanged += textChanged; } public void Dispose () { - editor.Document.TextReplaced -= textChanged; + editor.TextChanged -= textChanged; } public T Engine { get { return currentEngine; } } - void textChanged (object sender, DocumentChangeEventArgs args) + void textChanged (object sender, TextChangeEventArgs args) { if (args.Offset< currentEngine.Position) ResetEngineToPosition (args.Offset); @@ -85,7 +86,7 @@ namespace MonoDevelop.Ide.Gui.Content } public void UpdateEngine () { - UpdateEngine (editor.Caret.Offset); + UpdateEngine (editor.CaretOffset); } //Makes sure that the smart indent engine's cursor has caught up with the @@ -112,7 +113,7 @@ namespace MonoDevelop.Ide.Gui.Content // get the engine caught up int nextSave = (cachedEngines.Count == 0)? BUFFER_SIZE : cachedEngines.Peek ().Position + BUFFER_SIZE; if (currentEngine.Position + 1 == position) { - char ch = editor.Document.GetCharAt (currentEngine.Position); + char ch = editor.GetCharAt (currentEngine.Position); currentEngine.Push (ch); ConsoleWrite ("pushing character '{0}'", ch); if (currentEngine.Position == nextSave) @@ -124,7 +125,7 @@ namespace MonoDevelop.Ide.Gui.Content int endCut = currentEngine.Position + BUFFER_SIZE; if (endCut > position) endCut = position; - string buffer = editor.Document.GetTextBetween (currentEngine.Position, endCut); + string buffer = editor.GetTextBetween (currentEngine.Position, endCut); ConsoleWrite ("getting buffer between {0} and {1}" /* '{2}'"*/, currentEngine.Position, endCut - 1, buffer); foreach (char ch in buffer) { currentEngine.Push (ch); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/ITextEditorResolver.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/ITextEditorResolver.cs index 5c1006a192..7938ec041f 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/ITextEditorResolver.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/ITextEditorResolver.cs @@ -26,14 +26,11 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System; using System.Collections.Generic; using System.Linq; -using Mono.TextEditor; using Mono.Addins; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.Semantics; -using MonoDevelop.Ide.TypeSystem; namespace MonoDevelop.Ide.Gui.Content { @@ -86,11 +83,11 @@ namespace MonoDevelop.Ide.Gui.Content } public static ResolveResult GetLanguageItem (this MonoDevelop.Ide.Gui.Document document, int offset, out DomRegion expressionRegion) - {
- if (document == null)
+ { + if (document == null) throw new System.ArgumentNullException ("document"); - var textEditorResolver = TextEditorResolverService.GetProvider (document.Editor.Document.MimeType); + var textEditorResolver = TextEditorResolverService.GetProvider (document.Editor.MimeType); if (textEditorResolver != null) { return textEditorResolver.GetLanguageItem (document, offset, out expressionRegion); } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs index 276c61db99..da9742332a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs @@ -28,13 +28,11 @@ using System; using MonoDevelop.Projects; -using MonoDevelop.Ide.CodeCompletion; using MonoDevelop.Components.Commands; -using MonoDevelop.Ide.Commands;
using MonoDevelop.Core; -using Mono.TextEditor; using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.Ide.TypeSystem; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.Ide.Gui.Content { @@ -59,7 +57,7 @@ namespace MonoDevelop.Ide.Gui.Content get { return document; } } - protected TextEditorData Editor { + protected ITextEditor Editor { get { return document != null ? document.Editor : null; } } @@ -80,7 +78,7 @@ namespace MonoDevelop.Ide.Gui.Content if (project != null) return TypeSystemService.GetProjectContext (project); - return TypeSystemService.GetContext (file, Document.Editor.Document.MimeType, Document.Editor.Text); + return TypeSystemService.GetContext (file, Document.Editor.MimeType, Document.Editor.Text); } protected Ambience GetAmbience () |