Author: lluis
Date: 2007-02-27 08:11:02 -0500 (Tue, 27 Feb 2007)
New Revision: 73462

Added:
   trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/TextEditor.cs
Modified:
   trunk/monodevelop/Core/src/MonoDevelop.Ide/ChangeLog
   trunk/monodevelop/Core/src/MonoDevelop.Ide/Makefile.am
   
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/IExtensibleTextEditor.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs
   trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs
   trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.mdp
Log:
* MonoDevelop.Ide.Gui.Content/IExtensibleTextEditor.cs: Completion
  widget is now implemented as a view interface.
* MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs: Make the Editor
  property return a TextEditor, which is more functional than a
  IEditableTextBuffer.
* MonoDevelop.Ide.mdp, Makefile.am, MonoDevelop.Ide.Gui/TextEditor.cs:
  New TextEditor class which wraps several editor interfaces.
* MonoDevelop.Ide.Gui/Document.cs: Added a TextEditor property.

Modified: trunk/monodevelop/Core/src/MonoDevelop.Ide/ChangeLog
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Ide/ChangeLog        2007-02-27 
12:54:51 UTC (rev 73461)
+++ trunk/monodevelop/Core/src/MonoDevelop.Ide/ChangeLog        2007-02-27 
13:11:02 UTC (rev 73462)
@@ -1,3 +1,14 @@
+2007-02-27  Lluis Sanchez Gual <[EMAIL PROTECTED]> 
+
+       * MonoDevelop.Ide.Gui.Content/IExtensibleTextEditor.cs: Completion
+         widget is now implemented as a view interface.
+       * MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs: Make the Editor
+         property return a TextEditor, which is more functional than a
+         IEditableTextBuffer.
+       * MonoDevelop.Ide.mdp, Makefile.am, MonoDevelop.Ide.Gui/TextEditor.cs:
+         New TextEditor class which wraps several editor interfaces.
+       * MonoDevelop.Ide.Gui/Document.cs: Added a TextEditor property.
+
 2007-02-24  Lluis Sanchez Gual <[EMAIL PROTECTED]> 
 
        * MonoDevelop.Ide.addin.xml: Fix compatible version number.

Modified: trunk/monodevelop/Core/src/MonoDevelop.Ide/Makefile.am
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Ide/Makefile.am      2007-02-27 
12:54:51 UTC (rev 73461)
+++ trunk/monodevelop/Core/src/MonoDevelop.Ide/Makefile.am      2007-02-27 
13:11:02 UTC (rev 73462)
@@ -233,6 +233,7 @@
        MonoDevelop.Ide.Gui/SdStatusBar.cs \
        MonoDevelop.Ide.Gui/StartupInfo.cs \
        MonoDevelop.Ide.Gui/StatusProgressMonitor.cs \
+       MonoDevelop.Ide.Gui/TextEditor.cs \
        MonoDevelop.Ide.Gui/TipOfTheDayStartupHandler.cs \
        MonoDevelop.Ide.Gui/ViewCommandHandlers.cs \
        MonoDevelop.Ide.Gui/ViewContentCollection.cs \

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs  
2007-02-27 12:54:51 UTC (rev 73461)
+++ trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs  
2007-02-27 13:11:02 UTC (rev 73462)
@@ -47,6 +47,8 @@
        {
                IWorkbenchWindow window;
                TextEditorExtension editorExtension;
+               bool editorChecked;
+               TextEditor textEditor;
                
                internal IWorkbenchWindow Window {
                        get { return window; }
@@ -117,6 +119,19 @@
                        }
                }
                
+               public TextEditor TextEditor {
+                       get {
+                               if (!editorChecked) {
+                                       editorChecked = true;
+                                       if (GetContent<IEditableTextBuffer> () 
!= null)
+                                               textEditor = new TextEditor 
(Window.ViewContent);
+                                       else
+                                               textEditor = null;
+                               }
+                               return textEditor;
+                       }
+               }
+               
                public bool IsViewOnly {
                        get { return Window.ViewContent.IsViewOnly; }
                }

Added: 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/TextEditor.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/TextEditor.cs    
    2007-02-27 12:54:51 UTC (rev 73461)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/TextEditor.cs    
    2007-02-27 13:11:02 UTC (rev 73462)
@@ -0,0 +1,245 @@
+
+using System;
+using MonoDevelop.Ide.Gui.Content;
+using MonoDevelop.Projects.Gui.Completion;
+
+namespace MonoDevelop.Ide.Gui
+{
+       public class TextEditor
+       {
+               IBookmarkBuffer bookmarkBuffer;
+               ICodeStyleOperations codeStyleOperations;
+               IEditableTextBuffer textBuffer;
+               IEncodedTextContent encodedTextContent;
+               IPositionable positionable;
+               ICompletionWidget completionWidget;
+               
+               // All line and column numbers are 1-based
+               
+               public TextEditor (IBaseViewContent content)
+               {
+                       bookmarkBuffer = (IBookmarkBuffer) content.GetContent 
(typeof(IBookmarkBuffer));
+                       codeStyleOperations = (ICodeStyleOperations) 
content.GetContent (typeof(ICodeStyleOperations));
+                       textBuffer = (IEditableTextBuffer) content.GetContent 
(typeof(IEditableTextBuffer));
+                       encodedTextContent = (IEncodedTextContent) 
content.GetContent (typeof(IEncodedTextContent));
+                       positionable = (IPositionable) content.GetContent 
(typeof(IPositionable));
+                       completionWidget = (ICompletionWidget) 
content.GetContent (typeof(ICompletionWidget));
+                       if (textBuffer == null)
+                               throw new InvalidOperationException ("Content 
does not provide an IEditableTextBuffer implementation.");
+               }
+               
+               public bool SupportsBookmarks {
+                       get { return bookmarkBuffer != null; }
+               }
+               
+               public bool SupportsCodeStyleOperations {
+                       get { return codeStyleOperations != null; }
+               }
+               
+               public void SetBookmarked (int position, bool mark)
+               {
+                       if (bookmarkBuffer != null)
+                               bookmarkBuffer.SetBookmarked (position, mark);
+               }
+               
+               public bool IsBookmarked (int position)
+               {
+                       if (bookmarkBuffer != null)
+                               return bookmarkBuffer.IsBookmarked (position);
+                       else
+                               return false;
+               }
+               
+               public void PrevBookmark ()
+               {
+                       if (bookmarkBuffer != null)
+                               bookmarkBuffer.PrevBookmark ();
+               }
+               
+               public void NextBookmark ()
+               {
+                       if (bookmarkBuffer != null)
+                               bookmarkBuffer.NextBookmark ();
+               }
+               
+               public void ClearBookmarks ()
+               {
+                       if (bookmarkBuffer != null)
+                               bookmarkBuffer.ClearBookmarks ();
+               }
+               
+               public IClipboardHandler ClipboardHandler {
+                       get { return textBuffer.ClipboardHandler; }
+               }
+               
+               public void Undo()
+               {
+                       textBuffer.Undo ();
+               }
+               
+               public void Redo()
+               {
+                       textBuffer.Redo ();
+               }
+               
+               public string SelectedText {
+                       get { return textBuffer.SelectedText; } 
+                       set { textBuffer.SelectedText = value; }
+               }
+               
+               public event EventHandler TextChanged {
+                       add { textBuffer.TextChanged += value; }
+                       remove { textBuffer.TextChanged -= value; }
+               }
+               
+               public int CursorPosition { 
+                       get { return textBuffer.CursorPosition; }
+                       set { textBuffer.CursorPosition = value; }
+               }
+
+               public int SelectionStartPosition {
+                       get { return textBuffer.SelectionStartPosition; }
+               }
+               
+               public int SelectionEndPosition {
+                       get { return textBuffer.SelectionEndPosition; }
+               }
+               
+               public void Select (int startPosition, int endPosition)
+               {
+                       textBuffer.Select (startPosition, endPosition);
+               }
+               
+               public void ShowPosition (int position)
+               {
+                       textBuffer.ShowPosition (position);
+               }
+               
+               public string Text {
+                       get { return textBuffer.Text; }
+               }
+               
+               public int TextLength {
+                       get { return textBuffer.Length; }
+               }
+               
+               public string GetText (int startPosition, int endPosition)
+               {
+                       return textBuffer.GetText (startPosition, endPosition);
+               }
+               
+               public char GetCharAt (int position)
+               {
+                       // TODO: Implement in ITextFile
+                       string s = GetText (position, position + 1);
+                       if (s.Length > 0)
+                               return s[0];
+                       else
+                               return (char) 0;
+               }
+               
+               public int GetPositionFromLineColumn (int line, int column)
+               {
+                       return textBuffer.GetPositionFromLineColumn (line, 
column);
+               }
+               
+               public void GetLineColumnFromPosition (int position, out int 
line, out int column)
+               {
+                       textBuffer.GetLineColumnFromPosition (position, out 
line, out column);
+               }
+               
+               public void InsertText (int position, string text)
+               {
+                       textBuffer.InsertText (position, text);
+               }
+               
+               public void DeleteText (int position, int length)
+               {
+                       textBuffer.DeleteText (position, length);
+               }
+               
+               public void JumpTo (int line, int col)
+               {
+                       if (positionable != null)
+                               positionable.JumpTo (line, col);
+                       else {
+                               int pos = GetPositionFromLineColumn (line, col);
+                               CursorPosition = pos;
+                       }
+               }
+               
+               public string SourceEncoding {
+                       get {
+                               if (encodedTextContent != null)
+                                       return 
encodedTextContent.SourceEncoding;
+                               else
+                                       return null;
+                       }
+               }
+
+               public void CommentCode ()
+               {
+                       if (codeStyleOperations != null)
+                               codeStyleOperations.CommentCode ();
+               }
+               
+               public void UncommentCode ()
+               {
+                       if (codeStyleOperations != null)
+                               codeStyleOperations.UncommentCode ();
+               }
+               
+               public void IndentSelection ()
+               {
+                       if (codeStyleOperations != null)
+                               codeStyleOperations.IndentSelection ();
+               }
+               
+               public void UnIndentSelection ()
+               {
+                       if (codeStyleOperations != null)
+                               codeStyleOperations.UnIndentSelection ();
+               }
+               
+               public int GetLineLength (int line)
+               {
+                       int pos1 = GetPositionFromLineColumn (line, 1);
+                       int pos2 = GetPositionFromLineColumn (line + 1, 1);
+                       if (pos2 == -1)
+                               return TextLength - pos1;
+                       pos2--;
+                       while (pos2 >= pos1 && (GetCharAt (pos2) == '\n' || 
GetCharAt (pos2) == '\r'))
+                               pos2--;
+                       return pos2 - pos1 + 1;
+               }
+               
+               public string GetLineText (int line)
+               {
+                       int len = GetLineLength (line);
+                       int pos = GetPositionFromLineColumn (line, 1);
+                       return GetText (pos, pos + len);
+               }
+               
+               public void ReplaceLine (int line, string txt)
+               {
+                       int len = GetLineLength (line);
+                       int pos = GetPositionFromLineColumn (line, 1);
+                       textBuffer.DeleteText (pos, len);
+                       textBuffer.InsertText (pos, txt);
+               }
+               
+               public int GetClosingBraceForLine (int line, out int 
openingLine)
+               {
+                       int offset = textBuffer.GetPositionFromLineColumn 
(line, 1);
+                       offset = 
MonoDevelop.Projects.Gui.Completion.TextUtilities.SearchBracketBackward 
(completionWidget, offset, '{', '}');
+                       if (offset == -1) {
+                               openingLine = -1;
+                               return -1;
+                       }
+                               
+                       int col;
+                       textBuffer.GetLineColumnFromPosition (offset, out 
openingLine, out col);
+                       return offset;
+               }
+       }
+}

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/IExtensibleTextEditor.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/IExtensibleTextEditor.cs
     2007-02-27 12:54:51 UTC (rev 73461)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/IExtensibleTextEditor.cs
     2007-02-27 13:11:02 UTC (rev 73462)
@@ -8,6 +8,5 @@
                // This method should return the terminator 
ITextEditorExtension that
                // will execute the default behavior (if any)
                ITextEditorExtension AttachExtension (ITextEditorExtension 
extension);
-               ICompletionWidget GetCompletionWidget ();
        }
 }

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs
       2007-02-27 12:54:51 UTC (rev 73461)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs
       2007-02-27 13:11:02 UTC (rev 73462)
@@ -18,8 +18,7 @@
                internal void Initialize (Document document)
                {
                        this.document = document;
-                       IExtensibleTextEditor editor = document.GetContent 
<IExtensibleTextEditor> ();
-                       completionWidget = editor.GetCompletionWidget ();
+                       completionWidget = document.GetContent 
<ICompletionWidget> ();
                        if (completionWidget != null)
                                completionWidget.CompletionContextChanged += 
OnCompletionContextChanged;
                        Initialize ();
@@ -29,8 +28,8 @@
                        get { return document; }
                }
                
-               protected IEditableTextBuffer Editor {
-                       get { return document.GetContent<IEditableTextBuffer> 
(); }
+               protected TextEditor Editor {
+                       get { return document.TextEditor; }
                }
                
                protected string FileName {

Modified: trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.mdp
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.mdp      
2007-02-27 12:54:51 UTC (rev 73461)
+++ trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.mdp      
2007-02-27 13:11:02 UTC (rev 73462)
@@ -262,14 +262,15 @@
     <File name="./icons/parsing.png" subtype="Code" 
buildaction="EmbedAsResource" />
     <File name="./MonoDevelop.Ide.Gui/LayoutComboBox.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./MonoDevelop.Ide.Gui/AddEntryEventHandler.cs" subtype="Code" 
buildaction="Compile" />
-    <File name="./MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs" 
subtype="Code" buildaction="Compile" />
     <File name="./MonoDevelop.Ide.Gui.Content/IExtensibleTextEditor.cs" 
subtype="Code" buildaction="Compile" />
     <File name="./templates/GenericProject.xpt.xml" subtype="Code" 
buildaction="EmbedAsResource" />
     <File name="./gtk-gui/gui.stetic" subtype="Code" 
buildaction="EmbedAsResource" />
-    <File name="./gtk-gui/MonoDevelop.Ide.Gui.Dialogs.GotoTypeDialog.cs" 
subtype="Code" buildaction="Compile" />
     <File 
name="./MonoDevelop.Ide.Gui.Pads.ProjectPad/UnknownEntryNodeBuilder.cs" 
subtype="Code" buildaction="Compile" />
     <File name="./MonoDevelop.Ide.Gui.Pads/TreeViewItem.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./AssemblyInfo.cs" subtype="Code" buildaction="Compile" />
+    <File name="./MonoDevelop.Ide.Gui.Content/TextEditorExtension.cs" 
subtype="Code" buildaction="Compile" />
+    <File name="./MonoDevelop.Ide.Gui/TextEditor.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./gtk-gui/MonoDevelop.Ide.Gui.Dialogs.GotoTypeDialog.cs" 
subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="gecko-sharp, 
Version=2.0.0.0, Culture=neutral, PublicKeyToken=ccf7d78a55e9f021" />

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to