Author: mkrueger
Date: 2008-02-15 15:34:45 -0500 (Fri, 15 Feb 2008)
New Revision: 95825

Modified:
   trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
   trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/FoldMarkerMargin.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
   trunk/monodevelop/main/src/addins/Mono.Texteditor/gtk-gui/objects.xml
Log:
* Mono.TextEditor/TextViewMargin.cs, Mono.TextEditor/Document.cs,
  Mono.TextEditor/FoldMarkerMargin.cs, Mono.TextEditor/TextEditor.cs,
  Mono.TextEditor/GutterMargin.cs: Refactored text editor.

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-15 
20:30:35 UTC (rev 95824)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-15 
20:34:45 UTC (rev 95825)
@@ -1,5 +1,11 @@
 2008-02-15  Mike Krüger <[EMAIL PROTECTED]> 
 
+       * Mono.TextEditor/TextViewMargin.cs, Mono.TextEditor/Document.cs,
+         Mono.TextEditor/FoldMarkerMargin.cs, Mono.TextEditor/TextEditor.cs,
+         Mono.TextEditor/GutterMargin.cs: Refactored text editor.
+
+2008-02-15  Mike Krüger <[EMAIL PROTECTED]> 
+
        * Mono.TextEditor/TextEditor.cs: Keypad control keys now work.
 
 2008-02-15  Mike Krüger <[EMAIL PROTECTED]> 

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs   
    2008-02-15 20:30:35 UTC (rev 95824)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs   
    2008-02-15 20:34:45 UTC (rev 95825)
@@ -154,6 +154,11 @@
                                
Mono.TextEditor.Highlighting.SyntaxModeService.StartUpdate (this, 
this.syntaxMode, offset, offset + count);
                }
                
+               public string GetTextBetween (int startOffset, int endOffset)
+               {
+                       return buffer.GetTextAt (startOffset, endOffset - 
startOffset);
+               }
+               
                public override string GetTextAt (int offset, int count)
                {
                        return buffer.GetTextAt (offset, count);

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/FoldMarkerMargin.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/FoldMarkerMargin.cs
       2008-02-15 20:30:35 UTC (rev 95824)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/FoldMarkerMargin.cs
       2008-02-15 20:34:45 UTC (rev 95825)
@@ -63,7 +63,7 @@
                
                public override void MouseHover (int x, int y, bool 
buttonPressed)
                {
-                       int lineNumber = editor.Document.VisualToLogicalLine 
((int)(y + editor.TextEditorData.VAdjustment.Value) / editor.LineHeight);
+                       int lineNumber = editor.Document.VisualToLogicalLine 
((int)(y + editor.VAdjustment.Value) / editor.LineHeight);
                        LineSegment lineSegment = null;
                        if (lineNumber < editor.Document.LineCount) {
                                lineSegment = editor.Document.GetLine 
(lineNumber);

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
   2008-02-15 20:30:35 UTC (rev 95824)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
   2008-02-15 20:34:45 UTC (rev 95825)
@@ -53,11 +53,11 @@
                
                void UpdateWidth ()
                {
-                       int currentLineCountLog10 = (int)System.Math.Log10 
(editor.TextEditorData.Document.LineCount);
+                       int currentLineCountLog10 = (int)System.Math.Log10 
(editor.Document.LineCount);
                        if (oldLineCountLog10 < currentLineCountLog10) {
                                CalculateWidth ();
                                oldLineCountLog10 = currentLineCountLog10;
-                               editor.TextEditorData.Document.CommitUpdateAll 
();
+                               editor.Document.CommitUpdateAll ();
                        }
                }
                
@@ -69,17 +69,17 @@
                
                public override void MousePressed (int button, int x, int y, 
bool doubleClick, Gdk.ModifierType modifierState)
                {
-                       int lineNumber = editor.Document.VisualToLogicalLine 
((int)(y + editor.TextEditorData.VAdjustment.Value) / editor.LineHeight);
+                       int lineNumber = editor.Document.VisualToLogicalLine 
((int)(y + editor.VAdjustment.Value) / editor.LineHeight);
                        if (lineNumber < editor.Document.LineCount) {
                                DocumentLocation loc = new DocumentLocation 
(lineNumber, 0);
                                if (loc != editor.Caret.Location) {
                                        editor.Caret.Location = loc;
-                               } else if 
(editor.TextEditorData.IsSomethingSelected) {
-                                       editor.TextEditorData.ClearSelection ();
+                               } else if (editor.IsSomethingSelected) {
+                                       editor.ClearSelection ();
                                        editor.QueueDraw ();
                                } else {
                                        LineSegment line = 
editor.Document.GetLine (lineNumber);
-                                       editor.TextEditorData.SelectionRange = 
new Segment (line.Offset, line.EditableLength); 
+                                       editor.SelectionRange = new Segment 
(line.Offset, line.EditableLength); 
                                        editor.QueueDraw ();
                                }
                        }

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs 
    2008-02-15 20:30:35 UTC (rev 95824)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs 
    2008-02-15 20:34:45 UTC (rev 95825)
@@ -265,12 +265,12 @@
                        margins.Add (foldMarkerMargin);
                        margins.Add (textViewMargin);
                        ISegment oldSelection = null;
-                       this.TextEditorData.SelectionChanged += delegate {
-                               if (this.TextEditorData.IsSomethingSelected && 
this.TextEditorData.SelectionRange.Offset > 0)
-                                       new CopyAction ().CopyToPrimary 
(this.TextEditorData);
+                       this.textEditorData.SelectionChanged += delegate {
+                               if (IsSomethingSelected && 
SelectionRange.Offset > 0)
+                                       new CopyAction ().CopyToPrimary 
(this.textEditorData);
                                
                                // Handle redraw
-                               ISegment selection = 
this.TextEditorData.SelectionRange;
+                               ISegment selection = SelectionRange;
                                int startLine    = selection != null ? 
Document.OffsetToLineNumber (selection.Offset) : -1;
                                int endLine      = selection != null ? 
Document.OffsetToLineNumber (selection.EndOffset) : -1;
                                int oldStartLine = oldSelection != null ? 
Document.OffsetToLineNumber (oldSelection.Offset) : -1;
@@ -302,6 +302,7 @@
                                }
                                oldSelection = selection;
                                this.RedrawLines (System.Math.Min (from, to), 
System.Math.Max (from, to));
+                               OnSelectionChanged (EventArgs.Empty);
                        };
                        
                        Document.DocumentUpdated += DocumentUpdatedHandler;
@@ -325,7 +326,7 @@
                
                protected virtual void OptionsChanged (object sender, EventArgs 
args)
                {
-                       this.TextEditorData.ColorStyle = 
TextEditorOptions.Options.GetColorStyle (this);
+                       this.textEditorData.ColorStyle = 
TextEditorOptions.Options.GetColorStyle (this);
                        
                        bookmarkMargin.IsVisible   = 
TextEditorOptions.Options.ShowIconMargin;
                        gutterMargin.IsVisible     = 
TextEditorOptions.Options.ShowLineNumberMargin;
@@ -547,7 +548,7 @@
                                        selection.Offset += 
selection_data.Text.Length;
                                Document.Insert (offset, selection_data.Text);
                                Caret.Offset = offset + 
selection_data.Text.Length;
-                               this.TextEditorData.SelectionRange = new 
Segment (offset, selection_data.Text.Length);
+                               SelectionRange = new Segment (offset, 
selection_data.Text.Length);
                                dragOver  = false;
                                context   = null;
                        }
@@ -590,9 +591,9 @@
                        
                        if (textViewMargin.inDrag && margin == 
this.textViewMargin) {
                                dragContents = new CopyAction ();
-                               dragContents.CopyData (this.TextEditorData);
+                               dragContents.CopyData (textEditorData);
                                Gtk.Drag.Begin (this, CopyAction.TargetList, 
DragAction.Move | DragAction.Copy, 1, e);
-                               selection = this.TextEditorData.SelectionRange;
+                               selection = SelectionRange;
                                textViewMargin.inDrag = false;
                        } else if (margin != null) {
                                margin.MouseHover ((int)(e.X - startPos), 
(int)e.Y, mousePressed);
@@ -610,21 +611,6 @@
                        return base.OnLeaveNotifyEvent (e); 
                }
 
-               public Mono.TextEditor.Highlighting.Style ColorStyle {
-                       get {
-                               return this.textEditorData.ColorStyle;
-                       }
-               }
-
-               public TextEditorData TextEditorData {
-                       get {
-                               return textEditorData;
-                       }
-                       set {
-                               textEditorData = value;
-                       }
-               }
-               
                public int LineHeight {
                        get {
                                return this.textViewMargin.LineHeight;
@@ -749,5 +735,86 @@
 //                                          e.Area.Width, e.Area.Height);
                        return true;
                }
+               
+               #region TextEditorData functions
+               public Mono.TextEditor.Highlighting.Style ColorStyle {
+                       get {
+                               return this.textEditorData.ColorStyle;
+                       }
+               }
+               
+               public bool IsSomethingSelected {
+                       get {
+                               return this.textEditorData.IsSomethingSelected;
+                       }
+               }
+               
+               public ISegment SelectionRange {
+                       get {
+                               return this.textEditorData.SelectionRange;
+                       }
+                       set {
+                               this.textEditorData.SelectionRange = value;
+                       }
+               }
+               
+               public string SelectedText {
+                       get {
+                               return this.textEditorData.SelectedText;
+                       }
+               }
+               
+               public IEnumerable<LineSegment> SelectedLines {
+                       get {
+                               return this.textEditorData.SelectedLines;
+                       }
+               }
+               
+               public Adjustment HAdjustment {
+                       get {
+                               return this.textEditorData.HAdjustment;
+                       }
+               }
+               
+               public Adjustment VAdjustment {
+                       get {
+                               return this.textEditorData.VAdjustment;
+                       }
+               }
+               
+               public void ClearSelection ()
+               {
+                       this.textEditorData.ClearSelection ();
+               }
+               
+               public void DeleteSelectedText ()
+               {
+                       this.textEditorData.DeleteSelectedText ();
+               }
+               
+               public void RunEditAction (EditAction action)
+               {
+                       action.Run (this.textEditorData);
+               }
+               
+               /// <summary>
+               /// Use with care.
+               /// </summary>
+               /// <returns>
+               /// A <see cref="TextEditorData"/>
+               /// </returns>
+               public TextEditorData GetTextEditorData ()
+               {
+                       return this.textEditorData;
+               }
+               
+               public event EventHandler SelectionChanged;
+               protected virtual void OnSelectionChanged (EventArgs args)
+               {
+                       if (SelectionChanged != null) 
+                               SelectionChanged (this, args);
+               }
+               
+               #endregion
        }
 }

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
 2008-02-15 20:30:35 UTC (rev 95824)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
 2008-02-15 20:34:45 UTC (rev 95825)
@@ -85,12 +85,6 @@
                        }
                }
                
-               public TextEditorData TextEditorData {
-                       get {
-                               return textEditor.TextEditorData;
-                       }
-               }
-
                public int CharWidth {
                        get {
                                return charWidth;
@@ -244,15 +238,15 @@
                void DrawLineText (Gdk.Drawable win, LineSegment line, int 
offset, int length, ref int xPos, int y)
                {
                        SyntaxMode mode = Document.SyntaxMode != null && 
TextEditorOptions.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : 
SyntaxMode.Default;
-                       Chunk[] chunks = mode.GetChunks (Document, 
TextEditorData.ColorStyle, line, offset, length);
-                       int selectionStart = TextEditorData.SelectionStart != 
null ? TextEditorData.SelectionStart.Segment.Offset + 
TextEditorData.SelectionStart.Column : -1;
-                       int selectionEnd   = TextEditorData.SelectionEnd != 
null ? TextEditorData.SelectionEnd.Segment.Offset + 
TextEditorData.SelectionEnd.Column : -1;
-                       int visibleColumn = 0;
-                       if (selectionStart > selectionEnd) {
-                               int tmp = selectionEnd;
-                               selectionEnd = selectionStart;
-                               selectionStart = tmp;
+                       Chunk[] chunks = mode.GetChunks (Document, 
textEditor.ColorStyle, line, offset, length);
+                       int selectionStart = -1;
+                       int selectionEnd   = -1;
+                       if (textEditor.IsSomethingSelected) {
+                               ISegment segment = textEditor.SelectionRange;
+                               selectionStart = segment.Offset;
+                               selectionEnd   = segment.EndOffset;
                        }
+                       int visibleColumn = 0;
                        
 //                             Console.WriteLine ("#" + chunks.Length);
                        foreach (Chunk chunk in chunks) {
@@ -434,33 +428,33 @@
                                clickLocation = VisualToDocumentLocation (x, y);
                                int offset = Document.LocationToOffset 
(clickLocation);
                                if (offset < 0) {
-                                       new CaretMoveToDocumentEnd ().Run 
(TextEditorData);
+                                       textEditor.RunAction (new 
CaretMoveToDocumentEnd ());
                                        return;
                                }
                                if (doubleClick) {
                                        int start = ScanWord (offset, false);
                                        int end   = ScanWord (offset, true);
-                                       if (TextEditorData.IsSomethingSelected) 
{
-                                               if 
(TextEditorData.SelectionRange.Offset == start && 
TextEditorData.SelectionRange.EndOffset == end) {
-                                                       
TextEditorData.SelectionRange = Document.GetLineByOffset (offset);
+                                       if (textEditor.IsSomethingSelected) {
+                                               if 
(textEditor.SelectionRange.Offset == start && 
textEditor.SelectionRange.EndOffset == end) {
+                                                       
textEditor.SelectionRange = Document.GetLineByOffset (offset);
                                                        return;
                                                }
                                        }
-                                       TextEditorData.SelectionRange = new 
Segment (start, end - start);
+                                       textEditor.SelectionRange = new Segment 
(start, end - start);
                                        return;
                                }
  
-                               if (TextEditorData.IsSomethingSelected && 
TextEditorData.SelectionRange.Offset <= offset && offset < 
TextEditorData.SelectionRange.EndOffset) {
+                               if (textEditor.IsSomethingSelected && 
textEditor.SelectionRange.Offset <= offset && offset < 
textEditor.SelectionRange.EndOffset) {
                                        inDrag = true;
                                } else {
                                        inSelectionDrag = true;
                                        if ((modifierState & 
Gdk.ModifierType.ShiftMask) == ModifierType.ShiftMask) {
-                                               if 
(!TextEditorData.IsSomethingSelected) 
-                                                       
SelectionMoveLeft.StartSelection (TextEditorData);
+                                               if 
(!textEditor.IsSomethingSelected) 
+                                                       
SelectionMoveLeft.StartSelection (textEditor.GetTextEditorData ());
                                                Caret.PreserveSelection = true;
                                                Caret.Location = clickLocation;
                                                Caret.PreserveSelection = false;
-                                               SelectionMoveLeft.EndSelection 
(TextEditorData);
+                                               SelectionMoveLeft.EndSelection 
(textEditor.GetTextEditorData ());
                                        } else {
                                                Caret.Location = clickLocation; 
                                        }
@@ -468,7 +462,7 @@
                                }
                        }
                        if (button == 2) {
-                               PasteAction.PasteFromPrimary (TextEditorData);
+                               PasteAction.PasteFromPrimary 
(textEditor.GetTextEditorData ());
                        }
                }
                
@@ -490,8 +484,8 @@
                        if (!buttonPressed)
                                return;
                        if (inSelectionDrag) {
-                               if (!TextEditorData.IsSomethingSelected) {
-                                       SelectionMoveLeft.StartSelection 
(TextEditorData);
+                               if (!textEditor.IsSomethingSelected) {
+                                       SelectionMoveLeft.StartSelection 
(textEditor.GetTextEditorData ());
                                }
                                Caret.PreserveSelection = true;
                                Caret.AutoScrollToCaret = false;
@@ -499,7 +493,7 @@
                                Caret.Location = VisualToDocumentLocation (x, 
y);
                                Caret.PreserveSelection = false;
                                Caret.AutoScrollToCaret = true;
-                               SelectionMoveLeft.EndSelection (TextEditorData);
+                               SelectionMoveLeft.EndSelection 
(textEditor.GetTextEditorData ());
                                this.textEditor.ScrollToCaret ();
                                this.caretBlink = false;
 //                             textEditor.RedrawLines (System.Math.Min 
(oldLine, Caret.Line), System.Math.Max (oldLine, Caret.Line));
@@ -590,7 +584,7 @@
                        
                        List<FoldSegment> foldings = Document.GetStartFoldings 
(line);
                        int offset = line.Offset;
-                       int xPos   = (int)(x - 
TextEditorData.HAdjustment.Value);
+                       int xPos   = (int)(x - textEditor.HAdjustment.Value);
                        int caretOffset = Caret.Offset;
                        for (int i = 0; i < foldings.Count; ++i) {
                                FoldSegment folding = foldings[i];
@@ -610,7 +604,7 @@
                                        
                                        layout.SetText (folding.Description);
                                        layout.GetPixelSize (out width, out 
height);
-                                       bool isFoldingSelected = 
TextEditorData.IsSomethingSelected && TextEditorData.SelectionRange.Contains 
(folding);
+                                       bool isFoldingSelected = 
textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (folding);
                                        gc.RgbFgColor = isFoldingSelected ? 
ColorStyle.SelectedBg : ColorStyle.Background;
                                        win.DrawRectangle (gc, true, new 
Rectangle (xPos, y, width - 1, this.LineHeight - 1));
                                        gc.RgbFgColor = isFoldingSelected ? 
ColorStyle.SelectedFg : ColorStyle.FoldLine;
@@ -641,7 +635,7 @@
                        if (line.EndOffset - offset > 0)
                                DrawLineText (win, line, offset, line.Offset + 
line.EditableLength - offset, ref xPos, y);
                        
-                       bool isEolSelected = TextEditorData.IsSomethingSelected 
&& TextEditorData.SelectionRange.Contains (line.Offset + line.EditableLength);
+                       bool isEolSelected = textEditor.IsSomethingSelected && 
textEditor.SelectionRange.Contains (line.Offset + line.EditableLength);
                        
                        lineArea.X     = xPos;
                        lineArea.Width = textEditor.Allocation.Width - xPos;
@@ -666,12 +660,12 @@
                
                public DocumentLocation VisualToDocumentLocation (int x, int y)
                {
-                       int lineNumber = Document.VisualToLogicalLine 
(System.Math.Min ((int)(y + TextEditorData.VAdjustment.Value) / LineHeight, 
Document.LineCount - 1));
+                       int lineNumber = Document.VisualToLogicalLine 
(System.Math.Min ((int)(y + textEditor.VAdjustment.Value) / LineHeight, 
Document.LineCount - 1));
                        LineSegment line = Document.GetLine (lineNumber);
                        int lineXPos  = 0;
                        int column;
                        int  visibleColumn = 0;
-                       int visualXPos = x + 
(int)TextEditorData.HAdjustment.Value;
+                       int visualXPos = x + (int)textEditor.HAdjustment.Value;
                        for (column = 0; column < line.EditableLength; 
column++) {
                                int delta;
                                if (this.Document.GetCharAt (line.Offset + 
column) == '\t') {

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/gtk-gui/objects.xml
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/gtk-gui/objects.xml       
2008-02-15 20:30:35 UTC (rev 95824)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/gtk-gui/objects.xml       
2008-02-15 20:34:45 UTC (rev 95825)
@@ -2,6 +2,10 @@
   <object type="Mono.TextEditor.TextEditor" palette-category="Mono.TextEditor" 
allow-children="false" base-type="Gtk.DrawingArea">
     <itemgroups>
     </itemgroups>
-    <signals />
+    <signals>
+      <itemgroup label="TextEditor Signals">
+        <signal name="SelectionChanged" />
+      </itemgroup>
+    </signals>
   </object>
 </objects>
\ No newline at end of file

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

Reply via email to