Author: mkrueger
Date: 2008-01-27 09:30:20 -0500 (Sun, 27 Jan 2008)
New Revision: 94050

Modified:
   trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
Log:
* Mono.TextEditor/TextEditorData.cs, Mono.TextEditor/TextEditor.cs:
  Optimized re-draws a bit.

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-01-27 
14:11:23 UTC (rev 94049)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-01-27 
14:30:20 UTC (rev 94050)
@@ -1,3 +1,13 @@
+2008-01-27  Mike Krüger <[EMAIL PROTECTED]> 
+
+       * Mono.TextEditor/TextEditorData.cs, Mono.TextEditor/TextEditor.cs:
+         Optimized re-draws a bit.
+
+2008-01-27  Mike Krüger <[EMAIL PROTECTED]> 
+
+       * Mono.TextEditor/TextEditorData.cs, Mono.TextEditor/TextEditor.cs:
+         Optimized re-draws a bit.
+
 2008-01-26  Mike Krüger <[EMAIL PROTECTED]> 
 
        * Mono.TextEditor/DefaultEditActions.cs,

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs 
    2008-01-27 14:11:23 UTC (rev 94049)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs 
    2008-01-27 14:30:20 UTC (rev 94050)
@@ -224,6 +224,41 @@
                                        RedrawLine (Caret.Line);
                                }
                        };
+                       ISegment oldSelection = null;
+                       this.TextEditorData.SelectionChanged += delegate {
+                               ISegment selection = 
this.TextEditorData.SelectionRange;
+                               int startLine    = selection != null ? 
Document.Splitter.GetLineNumberForOffset (selection.Offset) : -1;
+                               int endLine      = selection != null ? 
Document.Splitter.GetLineNumberForOffset (selection.EndOffset) : -1;
+                               int oldStartLine = oldSelection != null ? 
Document.Splitter.GetLineNumberForOffset (oldSelection.Offset) : -1;
+                               int oldEndLine   = oldSelection != null ? 
Document.Splitter.GetLineNumberForOffset (oldSelection.EndOffset) : -1;
+                               if (endLine < 0 && startLine >=0)
+                                       endLine = Splitter.LineCount;
+                               if (oldEndLine < 0 && oldStartLine >=0)
+                                       oldEndLine = Splitter.LineCount;
+                               int from = oldEndLine, to = endLine;
+                               if (selection != null && oldSelection != null) {
+                                       if (startLine != oldStartLine && 
endLine != oldEndLine) {
+                                               from = System.Math.Min 
(startLine, oldStartLine);
+                                               to   = System.Math.Max 
(endLine, oldEndLine);
+                                       } else if (startLine != oldStartLine) {
+                                               from = startLine;
+                                               to   = oldStartLine;
+                                       } else if (endLine != oldEndLine) {
+                                               from = endLine;
+                                               to   = oldEndLine;
+                                       }
+                           } else {
+                                       if (selection == null) {
+                                               from = oldStartLine;
+                                               to = oldEndLine;
+                                       } else if (oldSelection == null) {
+                                               from = startLine;
+                                               to = endLine;
+                                       } 
+                               }
+                               oldSelection = selection;
+                               this.RedrawLines (System.Math.Min (from, to), 
System.Math.Max (from, to));
+                       };
                        Document.Splitter.LinesInserted  += delegate (object 
sender, LineEventArgs e) {
                                int lineNumber = 
Document.Splitter.GetLineNumberForOffset (e.Line.Offset);
                                RedrawFromLine (lineNumber);
@@ -245,12 +280,6 @@
                                        request.Update (this);
                                }
                        };
-                       this.textEditorData.SelectionStartChanged += delegate {
-                               this.QueueDraw ();
-                       };
-                       this.textEditorData.SelectionEndChanged += delegate {
-                               this.QueueDraw ();
-                       };
                        this.ColorStyle = new DefaultStyle (this);
                        
                        textCursor = new Gdk.Cursor (Gdk.CursorType.Xterm);
@@ -317,14 +346,13 @@
                
                public void RedrawLines (int start, int end)
                {
-//                     Console.WriteLine ("redraw:" + logicalLine);
-                       this.QueueDrawArea (0, 
(int)-this.textEditorData.VAdjustment.Value + Document.LogicalToVisualLine 
(start) * LineHeight, 
-                                           this.Allocation.Width, 
-                                           
(int)-this.textEditorData.VAdjustment.Value + Document.LogicalToVisualLine 
(end) * LineHeight + LineHeight);
+                       System.Console.WriteLine(start + " -- " + end);
+                       int visualStart = 
(int)-this.textEditorData.VAdjustment.Value + Document.LogicalToVisualLine 
(start) * LineHeight;
+                       int visualEnd   = 
(int)-this.textEditorData.VAdjustment.Value + Document.LogicalToVisualLine 
(end) * LineHeight + LineHeight;
+                       this.QueueDrawArea (0, visualStart, 
this.Allocation.Width, visualEnd - visualStart );
                }
                public void RedrawFromLine (int logicalLine)
                {
-//                     Console.WriteLine ("redraw from :" + logicalLine);
                        this.QueueDrawArea (0, 
(int)-this.textEditorData.VAdjustment.Value + Document.LogicalToVisualLine 
(logicalLine) * LineHeight, this.Allocation.Width, this.Allocation.Height);
                }
                
@@ -902,7 +930,6 @@
                                        inSelectionDrag = true;
                                        Caret.Location = clickLocation; 
                                        this.caretBlink = false;
-                                       this.QueueDraw ();
                                }
                        }
                }
@@ -927,11 +954,12 @@
                                        SelectionMoveLeft.StartSelection 
(this.textEditorData);
                                }
                                Caret.PreserveSelection = true;
+                               int oldLine = Caret.Line;
                                Caret.Location = VisualToDocumentLocation (x, 
y);
                                Caret.PreserveSelection = false;
                                SelectionMoveLeft.EndSelection 
(this.textEditorData);
                                this.caretBlink = false;
-                               this.QueueDraw ();
+//                             this.RedrawLines (System.Math.Min (oldLine, 
Caret.Line), System.Math.Max (oldLine, Caret.Line));
                        }
                }
                
@@ -999,7 +1027,7 @@
                                startLine = (area.Top + reminder) / 
this.LineHeight;
                                endLine   = startLine + (area.Height / 
this.LineHeight) - 1;
                        }
-//                     System.Console.WriteLine(startLine + " -- " + endLine);
+//                     System.Console.WriteLine("draw" + startLine + " -- to: 
" + endLine);
                        for (int visualLineNumber = startLine; visualLineNumber 
<= endLine; visualLineNumber++) {
                                int curX = 0;
                                int logicalLineNumber = 
Document.VisualToLogicalLine (visualLineNumber + firstLine);

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
 2008-01-27 14:11:23 UTC (rev 94049)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
 2008-01-27 14:30:20 UTC (rev 94050)
@@ -109,8 +109,9 @@
                                LineSegment startLine = 
document.Splitter.GetByOffset (start);
                                LineSegment endLine   = 
document.Splitter.GetByOffset (end);
                                this.Caret.Offset = end;
-                               SelectionStart = new SelectionMarker 
(startLine, start - startLine.Offset);
-                               SelectionEnd   = new SelectionMarker (endLine, 
end - endLine.Offset);
+                               selectionStart = new SelectionMarker 
(startLine, start - startLine.Offset);
+                               selectionEnd   = new SelectionMarker (endLine, 
end - endLine.Offset);
+                               OnSelectionChanged (EventArgs.Empty);           
                
                        }
                }
                
@@ -146,8 +147,7 @@
                        }
                        set {
                                selectionStart = value;
-                               if (SelectionStartChanged != null) 
-                                       SelectionStartChanged (this, 
EventArgs.Empty);
+                               OnSelectionChanged (EventArgs.Empty);
                        }
                }
 
@@ -157,14 +157,14 @@
                        }
                        set {
                                selectionEnd = value;
-                               if (SelectionEndChanged != null) 
-                                       SelectionEndChanged (this, 
EventArgs.Empty);
+                               OnSelectionChanged (EventArgs.Empty);
                        }
                }
                
                public void ClearSelection ()
                {
-                       SelectionStart = SelectionEnd = null;
+                       this.selectionStart = this.selectionEnd = null;
+                       OnSelectionChanged (EventArgs.Empty);
                }
                
                public void DeleteSelectedText ()
@@ -175,7 +175,11 @@
                        ClearSelection();
                }
                
-               public event EventHandler SelectionEndChanged;
-               public event EventHandler SelectionStartChanged;
+               public event EventHandler SelectionChanged;
+               protected virtual void OnSelectionChanged (EventArgs args)
+               {
+                       if (SelectionChanged != null) 
+                               SelectionChanged (this, args);
+               }
        }
 }

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

Reply via email to