Author: mkrueger
Date: 2008-02-15 14:13:46 -0500 (Fri, 15 Feb 2008)
New Revision: 95792

Modified:
   trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
   trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GapBuffer.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
   trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IBuffer.cs
Log:
* Mono.TextEditor/DefaultEditActions.cs, Mono.TextEditor/Document.cs,
  Mono.TextEditor/IBuffer.cs, Mono.TextEditor/GapBuffer.cs,
  Mono.TextEditor/GutterMargin.cs: Fixed gutter bug & refactored.


Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-15 
19:13:38 UTC (rev 95791)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-15 
19:13:46 UTC (rev 95792)
@@ -1,5 +1,11 @@
 2008-02-15  Mike Krüger <[EMAIL PROTECTED]> 
 
+       * Mono.TextEditor/DefaultEditActions.cs, Mono.TextEditor/Document.cs,
+         Mono.TextEditor/IBuffer.cs, Mono.TextEditor/GapBuffer.cs,
+         Mono.TextEditor/GutterMargin.cs: Fixed gutter bug & refactored.
+
+2008-02-15  Mike Krüger <[EMAIL PROTECTED]> 
+
        * Mono.TextEditor/DefaultEditActions.cs, 
Mono.TextEditor/TextViewMargin.cs,
          Mono.TextEditor/Document.cs, Mono.TextEditor/LineSplitter.cs,
          Mono.TextEditor/TextUtil.cs, Mono.TextEditor/FoldMarkerMargin.cs,

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
     2008-02-15 19:13:38 UTC (rev 95791)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
     2008-02-15 19:13:46 UTC (rev 95792)
@@ -610,7 +610,7 @@
        {
                public override void Run (TextEditorData data)
                {
-                       StringBuilder newLine = new StringBuilder 
(data.Document.Eol);
+                       StringBuilder newLine = new StringBuilder 
(data.Document.EolMarker);
                        
                        
 /*                     if (TextEditorOptions.Options.AutoIndent) {

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 19:13:38 UTC (rev 95791)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs   
    2008-02-15 19:13:46 UTC (rev 95792)
@@ -44,7 +44,12 @@
                string mimeType;
                string fileName;
                
-               public string Eol {
+               /// <value>
+               /// The eol mark used in this document - it's taken from the 
first line in the document,
+               /// if no eol mark is found it's using the default 
(Environment.NewLine).
+               /// The value is saved, even when all lines are deleted the eol 
marker will still be the old eol marker.
+               /// </value>
+               public string EolMarker {
                        get {
                                if (eol == null && splitter.LineCount > 0) {
                                        LineSegment line = splitter.Get (0);
@@ -86,25 +91,7 @@
                public Document()
                {
                        buffer = new GapBuffer ();
-                       buffer.TextReplacing += delegate(object sender, 
ReplaceEventArgs args) {
-                               if (!isInUndo) {
-                                       UndoOperation operation = new 
UndoOperation (args, buffer.GetTextAt (args.Offset, args.Count));
-                                       if (currentAtomicOperation != null) {
-                                               currentAtomicOperation.Add 
(operation);
-                                       } else {
-                                               undoStack.Push (operation);
-                                       }
-                                       redoStack.Clear ();
-                               }
-                       };
-                       
                        splitter = new LineSplitter (buffer);
-                       
-                       buffer.TextReplaced +=  delegate(object sender, 
ReplaceEventArgs args) {
-                               splitter.TextReplaced (sender, args);
-                               if (this.syntaxMode != null)
-                                       
Mono.TextEditor.Highlighting.SyntaxModeService.StartUpdate (this, 
this.syntaxMode, args.Offset, args.Offset + args.Count);
-                       };
                }
                
                #region Buffer implementation
@@ -120,14 +107,51 @@
                        }
                        set {
                                splitter.Clear ();
+                               int oldLength = Length;
+                               ReplaceEventArgs args = new ReplaceEventArgs 
(0, oldLength, new StringBuilder (value));
+                               this.OnTextReplacing (args);
                                this.buffer.Text = value;
+                               splitter.TextReplaced (this, args);
+                               if (this.syntaxMode != null)
+                                       
Mono.TextEditor.Highlighting.SyntaxModeService.StartUpdate (this, 
this.syntaxMode, 0, value.Length);
                                
Mono.TextEditor.Highlighting.SyntaxModeService.WaitForUpdate ();
+                               this.OnTextReplaced (args);
                        }
                }
                
+               public void Insert (int offset, string value)
+               {
+                       Insert (offset, new StringBuilder (value));
+               }
+               
+               public void Replace (int offset, int count, string value)
+               {
+                       Replace (offset, count, new StringBuilder (value));
+               }
+               
                public override void Replace (int offset, int count, 
StringBuilder value)
                {
+//                     Debug.Assert (count >= 0);
+//                     Debug.Assert (0 <= offset && offset + count <= Length);
+                       
+                       ReplaceEventArgs args = new ReplaceEventArgs (offset, 
count, value);
+                       OnTextReplacing (args);
+                       
+                       if (!isInUndo) {
+                               UndoOperation operation = new UndoOperation 
(args, GetTextAt (offset, count));
+                               if (currentAtomicOperation != null) {
+                                       currentAtomicOperation.Add (operation);
+                               } else {
+                                       undoStack.Push (operation);
+                               }
+                               redoStack.Clear ();
+                       }
+                       
                        buffer.Replace (offset, count, value);
+                       OnTextReplaced (args);
+                       splitter.TextReplaced (this, args);
+                       if (this.syntaxMode != null)
+                               
Mono.TextEditor.Highlighting.SyntaxModeService.StartUpdate (this, 
this.syntaxMode, offset, offset + count);
                }
                
                public override string GetTextAt (int offset, int count)
@@ -139,6 +163,21 @@
                {
                        return buffer.GetCharAt (offset);
                }
+               
+               protected virtual void OnTextReplaced (ReplaceEventArgs args)
+               {
+                       if (TextReplaced != null)
+                               TextReplaced (this, args);
+               }
+               public event EventHandler<ReplaceEventArgs> TextReplaced;
+               
+               protected virtual void OnTextReplacing (ReplaceEventArgs args)
+               {
+                       if (TextReplacing != null)
+                               TextReplacing (this, args);
+               }
+               public event EventHandler<ReplaceEventArgs> TextReplacing;
+               
                #endregion
                
                #region Line Splitter operations

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GapBuffer.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GapBuffer.cs  
    2008-02-15 19:13:38 UTC (rev 95791)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GapBuffer.cs  
    2008-02-15 19:13:46 UTC (rev 95792)
@@ -53,10 +53,8 @@
                                return GetTextAt (0, Length);
                        }
                        set {
-                               int oldLength = buffer.Length;
                                buffer = value != null ? value.ToCharArray () : 
new char[0];
                                gapBegin = gapEnd = gapLength = 0;
-                               this.OnTextReplaced (new ReplaceEventArgs (0, 
oldLength, new StringBuilder (value)));
                        }
                }
                
@@ -90,7 +88,6 @@
 //                     Debug.Assert (count >= 0);
 //                     Debug.Assert (0 <= offset && offset + count <= Length);
                        
-                       OnTextReplacing (new ReplaceEventArgs (offset, count, 
text));
                        if (text != null) { 
                                PlaceGap (offset, text.Length - count);
                                text.CopyTo (0, buffer, offset, text.Length);
@@ -102,7 +99,6 @@
                        gapLength = gapEnd - gapBegin;
                        if (gapLength > maxGapLength) 
                                CreateBuffer (gapBegin, minGapLength);
-                       OnTextReplaced (new ReplaceEventArgs (offset, count, 
text));
                }
                
                void PlaceGap (int newOffset, int minLength)

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 19:13:38 UTC (rev 95791)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
   2008-02-15 19:13:46 UTC (rev 95792)
@@ -36,7 +36,7 @@
                TextEditor editor;
                Pango.Layout layout;
                int width;
-               int oldLineCountLog10 = 100;
+               int oldLineCountLog10 = 1;
                
                public GutterMargin (TextEditor editor)
                {
@@ -46,10 +46,9 @@
                
                void CalculateWidth ()
                {
-                       layout.SetText (editor.Document.LineCount.ToString ());
+                       layout.SetText (editor.Document.LineCount.ToString () + 
"_");
                        int height;
                        layout.GetPixelSize (out this.width, out height);
-                       this.width += 5;
                }
                
                void UpdateWidth ()
@@ -57,8 +56,8 @@
                        int currentLineCountLog10 = (int)System.Math.Log10 
(editor.TextEditorData.Document.LineCount);
                        if (oldLineCountLog10 < currentLineCountLog10) {
                                CalculateWidth ();
-                               editor.TextEditorData.Document.CommitUpdateAll 
();
                                oldLineCountLog10 = currentLineCountLog10;
+                               editor.TextEditorData.Document.CommitUpdateAll 
();
                        }
                }
                

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IBuffer.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IBuffer.cs    
    2008-02-15 19:13:38 UTC (rev 95791)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IBuffer.cs    
    2008-02-15 19:13:46 UTC (rev 95792)
@@ -48,9 +48,6 @@
                string GetTextAt (int offset, int count);
                string GetTextAt (ISegment segment);
                char GetCharAt (int offset);
-               
-               event EventHandler<ReplaceEventArgs> TextReplacing;
-               event EventHandler<ReplaceEventArgs> TextReplaced;
        }
        
        public abstract class AbstractBuffer : IBuffer
@@ -83,19 +80,5 @@
                {
                        return GetTextAt (segment.Offset, segment.Length);
                }
-               
-               protected virtual void OnTextReplaced (ReplaceEventArgs args)
-               {
-                       if (TextReplaced != null)
-                               TextReplaced (this, args);
-               }
-               public event EventHandler<ReplaceEventArgs> TextReplaced;
-               
-               protected virtual void OnTextReplacing (ReplaceEventArgs args)
-               {
-                       if (TextReplacing != null)
-                               TextReplacing (this, args);
-               }
-               public event EventHandler<ReplaceEventArgs> TextReplacing;
        }
 }

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

Reply via email to