Author: mkrueger
Date: 2008-02-11 09:20:08 -0500 (Mon, 11 Feb 2008)
New Revision: 95436
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/BookmarkMargin.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/IMargin.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
Log:
* Mono.TextEditor/FoldMarkerMargin.cs, Mono.TextEditor/IMargin.cs,
Mono.TextEditor/TextEditor.cs, Mono.TextEditor/BookmarkMargin.cs,
Mono.TextEditor/GutterMargin.cs,
Mono.TextEditor.Highlighting/SyntaxMode.cs,
Mono.TextEditor.Highlighting/SyntaxModeService.cs,
Mono.TextEditor.Highlighting/Rule.cs: Optimized performance a bit.
(To get real performance gain, scrolling must be solved
differently)
Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-11
13:45:49 UTC (rev 95435)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-11
14:20:08 UTC (rev 95436)
@@ -1,3 +1,13 @@
+2008-02-11 Mike Krüger <[EMAIL PROTECTED]>
+
+ * Mono.TextEditor/FoldMarkerMargin.cs, Mono.TextEditor/IMargin.cs,
+ Mono.TextEditor/TextEditor.cs, Mono.TextEditor/BookmarkMargin.cs,
+ Mono.TextEditor/GutterMargin.cs,
+ Mono.TextEditor.Highlighting/SyntaxMode.cs,
+ Mono.TextEditor.Highlighting/SyntaxModeService.cs,
+ Mono.TextEditor.Highlighting/Rule.cs: Optimized performance a bit. (To
+ get real performance gain, scrolling must be solved differently)
+
2008-02-10 Mike Krüger <[EMAIL PROTECTED]>
* Mono.TextEditor/LineSplitter.cs, Mono.TextEditor/TextEditor.cs,
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/BookmarkMargin.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/BookmarkMargin.cs
2008-02-11 13:45:49 UTC (rev 95435)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/BookmarkMargin.cs
2008-02-11 14:20:08 UTC (rev 95436)
@@ -33,6 +33,7 @@
public class BookmarkMargin : AbstractMargin
{
TextEditor editor;
+ Gdk.GC backgroundGC, seperatorGC;
static Gdk.Pixbuf bookmarkPixbuf;
@@ -52,6 +53,15 @@
}
}
+ public override void OptionsChanged ()
+ {
+ backgroundGC = new Gdk.GC (editor.GdkWindow);
+ backgroundGC.RgbFgColor = editor.ColorStyle.IconBarBg;
+
+ seperatorGC = new Gdk.GC (editor.GdkWindow);
+ seperatorGC.RgbFgColor =
editor.ColorStyle.IconBarSeperator;
+ }
+
public override void MousePressed (int button, int x, int y,
bool doubleClick)
{
if (button != 1 || doubleClick)
@@ -68,16 +78,13 @@
public override void Draw (Gdk.Window win, Gdk.Rectangle area,
int line, int x, int y)
{
Gdk.Rectangle drawArea = new Gdk.Rectangle (x, y,
Width, editor.LineHeight);
- Gdk.GC gc = new Gdk.GC (win);
- gc.RgbFgColor = editor.ColorStyle.IconBarBg;
- win.DrawRectangle (gc, true, drawArea);
- gc.RgbFgColor = editor.ColorStyle.IconBarSeperator;
- win.DrawLine (gc, x + Width - 1, drawArea.Top, x +
Width - 1, drawArea.Bottom);
+
+ win.DrawRectangle (backgroundGC, true, drawArea);
+ win.DrawLine (seperatorGC, x + Width - 1, drawArea.Top,
x + Width - 1, drawArea.Bottom);
if (line < editor.Splitter.LineCount) {
LineSegment lineSegment =
editor.Document.GetLine (line);
- if (lineSegment.IsBookmarked) {
- win.DrawPixbuf
(editor.Style.BackgroundGC (StateType.Normal), bookmarkPixbuf, 0, 0, x + 1, y,
bookmarkPixbuf.Width, bookmarkPixbuf.Height, Gdk.RgbDither.None, 0, 0);
- }
+ if (lineSegment.IsBookmarked)
+ win.DrawPixbuf (backgroundGC,
bookmarkPixbuf, 0, 0, x + 1, y, bookmarkPixbuf.Width, bookmarkPixbuf.Height,
Gdk.RgbDither.None, 0, 0);
}
}
}
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-11 13:45:49 UTC (rev 95435)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/FoldMarkerMargin.cs
2008-02-11 14:20:08 UTC (rev 95436)
@@ -82,28 +82,37 @@
}
}
+ public override void OptionsChanged ()
+ {
+ foldBgGC = new Gdk.GC (editor.GdkWindow);
+ foldBgGC.RgbFgColor = editor.ColorStyle.FoldBg;
+
+ foldLineGC = new Gdk.GC (editor.GdkWindow);
+ foldLineGC.RgbFgColor = editor.ColorStyle.FoldLine;
+
+ foldLineHighlightedGC = new Gdk.GC (editor.GdkWindow);
+ foldLineHighlightedGC.RgbFgColor =
editor.ColorStyle.FoldLineHighlighted;
+
+ foldToggleMarkerGC = new Gdk.GC (editor.GdkWindow);
+ foldToggleMarkerGC.RgbFgColor =
editor.ColorStyle.FoldToggleMarker;
+ }
+ Gdk.GC foldBgGC, foldLineGC, foldLineHighlightedGC,
foldToggleMarkerGC;
+
void DrawFoldSegment (Gdk.Window win, int x, int y, bool
isOpen, bool isSelected)
{
-
- Gdk.GC gc = new Gdk.GC (win);
-
Gdk.Rectangle drawArea = new Gdk.Rectangle (x + 3, y +
3, foldSegmentSize, foldSegmentSize);
- gc.RgbFgColor = editor.ColorStyle.FoldBg;
- win.DrawRectangle (gc, true, drawArea);
-
- gc.RgbFgColor = isSelected ?
editor.ColorStyle.FoldLineHighlighted : editor.ColorStyle.FoldLine;
- win.DrawRectangle (gc, false, drawArea);
+ win.DrawRectangle (foldBgGC, true, drawArea);
+ win.DrawRectangle (isSelected ? foldLineHighlightedGC
: foldLineGC, false, drawArea);
- gc.RgbFgColor = editor.ColorStyle.FoldToggleMarker;
- win.DrawLine (gc,
+ win.DrawLine (foldToggleMarkerGC,
drawArea.Left + 2,
drawArea.Top + 4,
drawArea.Right - 2,
drawArea.Top + 4);
if (!isOpen)
- win.DrawLine (gc,
+ win.DrawLine (foldToggleMarkerGC,
drawArea.Left + 4,
drawArea.Top + 2,
drawArea.Left + 4,
@@ -112,11 +121,9 @@
void DrawDashedVLine (Gdk.Window win, int x, int top, int
bottom)
{
- Gdk.GC gc = new Gdk.GC (win);
- gc.RgbFgColor = editor.ColorStyle.FoldLine;
for (int i = top; i <= bottom; i++) {
if (i % 2 == 0)
- win.DrawPoint (gc, x, i);
+ win.DrawPoint (foldLineGC, x, i);
}
}
@@ -132,14 +139,7 @@
public override void Draw (Gdk.Window win, Gdk.Rectangle area,
int line, int x, int y)
{
Gdk.Rectangle drawArea = new Gdk.Rectangle (x, y,
Width, editor.LineHeight);
- Gdk.GC gc = new Gdk.GC (win);
- Gdk.GC selectedGc = new Gdk.GC (win);
- selectedGc.RgbFgColor =
editor.ColorStyle.FoldLineHighlighted;
-
- gc.RgbFgColor = editor.ColorStyle.FoldBg;
- win.DrawRectangle (gc, true, drawArea);
-
- gc.RgbFgColor = editor.ColorStyle.FoldLine;
+ win.DrawRectangle (foldBgGC, true, drawArea);
DrawDashedVLine (win, x, drawArea.Top, drawArea.Bottom);
if (line < editor.Splitter.LineCount) {
@@ -176,18 +176,18 @@
}
DrawFoldSegment (win, x, y, isVisible,
isStartSelected);
if (isContaining ||
isFoldEndFromUpperFold)
- win.DrawLine
(isContainingSelected ? selectedGc : gc, xPos, drawArea.Top, xPos,
foldSegmentYPos - 1);
+ win.DrawLine
(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Top,
xPos, foldSegmentYPos - 1);
if (isContaining || moreLinedOpenFold)
- win.DrawLine (isEndSelected ||
(isStartSelected && isVisible) || isContainingSelected ? selectedGc : gc, xPos,
foldSegmentYPos + foldSegmentSize + 1, xPos, drawArea.Bottom);
+ win.DrawLine (isEndSelected ||
(isStartSelected && isVisible) || isContainingSelected ? foldLineHighlightedGC
: foldLineGC, xPos, foldSegmentYPos + foldSegmentSize + 1, xPos,
drawArea.Bottom);
} else {
if (isFoldEnd) {
int yMid = drawArea.Top +
drawArea.Height / 2;
- win.DrawLine (isEndSelected ?
selectedGc : gc, xPos, yMid, xPos + foldSegmentSize / 2, yMid);
- win.DrawLine
(isContainingSelected || isEndSelected ? selectedGc : gc, xPos, drawArea.Top,
xPos, yMid);
+ win.DrawLine (isEndSelected ?
foldLineHighlightedGC : foldLineGC, xPos, yMid, xPos + foldSegmentSize / 2,
yMid);
+ win.DrawLine
(isContainingSelected || isEndSelected ? foldLineHighlightedGC : foldLineGC,
xPos, drawArea.Top, xPos, yMid);
if (isContaining)
- win.DrawLine
(isContainingSelected ? selectedGc : gc, xPos, yMid + 1, xPos,
drawArea.Bottom);
+ win.DrawLine
(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid + 1,
xPos, drawArea.Bottom);
} else if (isContaining) {
- win.DrawLine
(isContainingSelected ? selectedGc : gc, xPos, drawArea.Top, xPos,
drawArea.Bottom);
+ win.DrawLine
(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Top,
xPos, drawArea.Bottom);
}
}
}
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-11 13:45:49 UTC (rev 95435)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
2008-02-11 14:20:08 UTC (rev 95436)
@@ -90,17 +90,26 @@
}
}
+ Gdk.GC lineNumberBgGC, lineNumberGC, lineNumberHighlightGC;
+ public override void OptionsChanged ()
+ {
+ lineNumberBgGC = new Gdk.GC (editor.GdkWindow);
+ lineNumberBgGC.RgbFgColor =
editor.ColorStyle.LineNumberBg;
+
+ lineNumberGC = new Gdk.GC (editor.GdkWindow);
+ lineNumberGC.RgbFgColor =
editor.ColorStyle.LineNumberFg;
+
+ lineNumberHighlightGC = new Gdk.GC (editor.GdkWindow);
+ lineNumberHighlightGC.RgbFgColor =
editor.ColorStyle.LineNumberFgHighlighted;
+ }
+
public override void Draw (Gdk.Window win, Gdk.Rectangle area,
int line, int x, int y)
{
Gdk.Rectangle drawArea = new Rectangle (x, y, Width,
editor.LineHeight);
-
- Gdk.GC gc = new Gdk.GC (win);
- gc.RgbFgColor = editor.ColorStyle.LineNumberBg;
- win.DrawRectangle (gc, true, drawArea);
+ win.DrawRectangle (lineNumberBgGC, true, drawArea);
if (line < editor.Splitter.LineCount) {
layout.SetText ((line + 1).ToString ());
- gc.RgbFgColor = editor.Caret.Line == line ?
editor.ColorStyle.LineNumberFgHighlighted : editor.ColorStyle.LineNumberFg;
- win.DrawLayout (gc, x + 1, y, layout);
+ win.DrawLayout (editor.Caret.Line == line ?
lineNumberHighlightGC : lineNumberGC, x + 1, y, layout);
}
}
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IMargin.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IMargin.cs
2008-02-11 13:45:49 UTC (rev 95435)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IMargin.cs
2008-02-11 14:20:08 UTC (rev 95436)
@@ -43,6 +43,9 @@
get;
set;
}
+
+ void OptionsChanged ();
+
void Draw (Gdk.Window win, Gdk.Rectangle area, int line, int x,
int y);
void MousePressed (int button, int x, int y, bool doubleClick);
@@ -77,6 +80,9 @@
}
public abstract void Draw (Gdk.Window win, Gdk.Rectangle area,
int line, int x, int y);
+ public virtual void OptionsChanged ()
+ {
+ }
public virtual void MousePressed (int button, int x, int y,
bool doubleClick)
{
}
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-11 13:45:49 UTC (rev 95435)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
2008-02-11 14:20:08 UTC (rev 95436)
@@ -46,7 +46,13 @@
BookmarkMargin bookmarkMargin;
GutterMargin gutterMargin;
FoldMarkerMargin foldMarkerMargin;
+ LineSegment longestLine;
+ List<IMargin> margins = new List<IMargin> ();
+ Pango.Layout layout;
+ int oldRequest = -1;
+ int charWidth;
+ Pango.Layout tabMarker, spaceMarker, eolMarker,
invalidLineMarker;
Gdk.Cursor defaultCursor;
Gdk.Cursor textCursor;
int caretBlinkStatus;
@@ -103,43 +109,73 @@
{
}
- public TextEditor(Document doc)
+ protected override void OnSetScrollAdjustments (Adjustment
hAdjustement, Adjustment vAdjustement)
{
+ this.textEditorData.HAdjustment = hAdjustement;
+ this.textEditorData.VAdjustment = vAdjustement;
+ if (hAdjustement == null || vAdjustement == null)
+ return;
+// double oldValue = this.textEditorData.VAdjustment.Value;
+ this.textEditorData.HAdjustment.ValueChanged +=
delegate {
+ this.QueueDraw ();
+ };
+ this.textEditorData.VAdjustment.ValueChanged +=
delegate {
+ this.QueueDraw ();
+// int delta = (int)(oldValue -
this.textEditorData.VAdjustment.Value);
+// System.Console.WriteLine(delta);
+// Gdk.Image image = this.GdkWindow.GetImage (0,
0, this.Allocation.Width, this.Allocation.Height);
+// GdkWindow.DrawImage (Style.BaseGC
(StateType.Normal), image, 0, 0, 0, delta, this.Allocation.Width,
this.Allocation.Height );
+// oldValue =
this.textEditorData.VAdjustment.Value;
+ };
+ }
+
+// protected override bool OnScrollEvent (Gdk.EventScroll evnt)
+// {
+// if (evnt.Direction == ScrollDirection.Down ||
evnt.Direction == ScrollDirection.Up) {
+// //this.GdkWindow.MoveRegion
(this.GdkWindow.VisibleRegion, 0, (int)evnt.Y);
+// }
+// return true;
+// }
+
+ public TextEditor (Document doc)
+ {
this.textEditorData.Document = doc;
this.Events = EventMask.AllEventsMask;
base.CanFocus = true;
- this.ParentSet += delegate {
-// if (Parent is Viewport) {
-// Viewport vp = (Viewport)Parent;
-// this.textEditorData.HAdjustment =
vp.Hadjustment;
+
+// this.ParentSet += delegate {
+//// if (Parent is Viewport) {
+//// Viewport vp = (Viewport)Parent;
+////
+//// }
+// if (Parent is ScrolledWindow) {
+// ScrolledWindow sw =
(ScrolledWindow)Parent;
+// this.textEditorData.HAdjustment =
sw.Hadjustment;
//
this.textEditorData.HAdjustment.ValueChanged += delegate {
-// this.QueueDraw ();
+//
// };
//
-// this.textEditorData.VAdjustment =
vp.Vadjustment;
+// this.textEditorData.VAdjustment =
sw.Vadjustment;
//
this.textEditorData.VAdjustment.ValueChanged += delegate {
// this.QueueDraw ();
// };
// }
- if (Parent is ScrolledWindow) {
- ScrolledWindow sw =
(ScrolledWindow)Parent;
- this.textEditorData.HAdjustment =
sw.Hadjustment;
-
this.textEditorData.HAdjustment.ValueChanged += delegate {
- this.QueueDraw ();
- };
-
- this.textEditorData.VAdjustment =
sw.Vadjustment;
-
this.textEditorData.VAdjustment.ValueChanged += delegate {
- this.QueueDraw ();
- };
- }
- };
+// };
this.SizeAllocated += delegate {
SetAdjustments ();
};
ResetCaretBlink ();
+ tabMarker = new Pango.Layout (this.PangoContext);
+ tabMarker.SetText ("\u00BB");
+ spaceMarker = new Pango.Layout (this.PangoContext);
+ spaceMarker.SetText ("\u00B7");
+ eolMarker = new Pango.Layout (this.PangoContext);
+ eolMarker.SetText ("\u00B6");
+ invalidLineMarker = new Pango.Layout
(this.PangoContext);
+ invalidLineMarker.SetText ("~");
+
layout = new Pango.Layout (this.PangoContext);
layout.Alignment = Pango.Alignment.Left;
@@ -242,7 +278,7 @@
from = endLine;
to = oldEndLine;
}
- } else {
+ } else {
if (selection == null) {
from = oldStartLine;
to = oldEndLine;
@@ -336,13 +372,21 @@
layout.FontDescription = TextEditorOptions.Options.Font;
layout.SetText ("H");
layout.GetPixelSize (out this.charWidth, out
this.lineHeight);
+
this.ColorStyle =
TextEditorOptions.Options.GetColorStyle (this);
bookmarkMargin.IsVisible =
TextEditorOptions.Options.ShowIconMargin;
gutterMargin.IsVisible =
TextEditorOptions.Options.ShowLineNumberMargin;
foldMarkerMargin.IsVisible =
TextEditorOptions.Options.ShowFoldMargin;
+ foreach (IMargin margin in this.margins) {
+ margin.OptionsChanged ();
+ }
this.QueueDraw ();
}
+ void IMargin.OptionsChanged ()
+ {
+ }
+
protected override void OnRealized ()
{
base.OnRealized ();
@@ -640,7 +684,6 @@
{
if (line.EditableLength == 0)
return 0;
- System.Console.WriteLine(line);
string text = this.Document.Buffer.GetTextAt
(line.Offset, System.Math.Min (column, line.EditableLength));
text = text.Replace ("\t", new string (' ',
TextEditorOptions.Options.TabSize));
layout.SetText (text);
@@ -665,8 +708,8 @@
(byte)(((byte)color.Green * 19) / 20),
(byte)(((byte)color.Blue * 19) / 20));
}
-
- void DrawRectangleWithRuler (Gdk.Window win, Gdk.GC gc, int x,
Gdk.Rectangle area, Gdk.Color color)
+ Gdk.GC gc;
+ void DrawRectangleWithRuler (Gdk.Window win, int x,
Gdk.Rectangle area, Gdk.Color color)
{
gc.RgbFgColor = color;
if (TextEditorOptions.Options.ShowRuler) {
@@ -681,10 +724,9 @@
public void Draw (Gdk.Window win, Gdk.Rectangle area, int
lineNr, int x, int y)
{
- layout.Alignment = Pango.Alignment.Left;
+ layout.Alignment = Pango.Alignment.Left;
LineSegment line = lineNr < Splitter.LineCount ?
Splitter.Get (lineNr) : null;
- Gdk.GC gc = new Gdk.GC (win);
gc.ClipRectangle = new Gdk.Rectangle (x, y,
this.Allocation.Width - x, LineHeight);
Gdk.Rectangle lineArea = new Gdk.Rectangle (x, y,
area.Width - x, LineHeight);
@@ -723,7 +765,7 @@
// draw space before selection
int visualXStart = ColumnToVisualX
(line, selectionColumnStart) - (int)this.textEditorData.HAdjustment.Value;
lineArea = new Gdk.Rectangle (x, y,
visualXStart, LineHeight);
- DrawRectangleWithRuler (win, gc, x,
lineArea, defaultStateType);
+ DrawRectangleWithRuler (win, x,
lineArea, defaultStateType);
// draw selection (if selection is in
the middle)
if (selectionColumnEnd >= 0) {
@@ -731,32 +773,20 @@
int reminder = System.Math.Max
(0, -visualXStart);
if (visualXEnd - visualXStart >
reminder) {
lineArea = new
Gdk.Rectangle (x + visualXStart + reminder, y, visualXEnd - visualXStart -
reminder, LineHeight);
- DrawRectangleWithRuler
(win, gc, x, lineArea, ColorStyle.SelectedBg);
+ DrawRectangleWithRuler
(win, x, lineArea, ColorStyle.SelectedBg);
}
}
// draw remaining line (unselected, if
in middle, otherwise rest of line is selected)
lineArea = new Gdk.Rectangle
(System.Math.Max (x, lineArea.Right), y, area.Width - System.Math.Max (x,
lineArea.Right), LineHeight);
- DrawRectangleWithRuler (win, gc, x,
lineArea, selectionColumnEnd >= 0 ? defaultStateType :
this.ColorStyle.SelectedBg);
+ DrawRectangleWithRuler (win, x,
lineArea, selectionColumnEnd >= 0 ? defaultStateType :
this.ColorStyle.SelectedBg);
drawDefaultBg = false;
}
}
int width, height;
if (drawDefaultBg) {
- DrawRectangleWithRuler (win, gc, x, lineArea,
isSelected ? this.ColorStyle.SelectedBg : defaultStateType);
-
-// Color color = isSelected ?
this.ColorStyle.SelectedBg : defaultStateType;
-// gc.RgbFgColor = color;
-// if (TextEditorOptions.Options.ShowRuler) {
-// win.DrawRectangle (gc, true, new
Rectangle (lineArea.X, lineArea.Y,
-//
rulerX, lineArea.Height));
-// gc.RgbFgColor = DimColor (color);
-// win.DrawRectangle (gc, true, new
Rectangle (lineArea.X + rulerX, lineArea.Y,
-//
lineArea.Width - rulerX, lineArea.Height));
-// } else {
-// win.DrawRectangle (gc, true, lineArea);
-// }
+ DrawRectangleWithRuler (win, x, lineArea,
isSelected ? this.ColorStyle.SelectedBg : defaultStateType);
}
@@ -767,7 +797,7 @@
if (line == null) {
if (TextEditorOptions.Options.ShowInvalidLines)
- DrawInvalidLineMarker (win, gc, x, y);
+ DrawInvalidLineMarker (win, x, y);
return;
}
@@ -787,7 +817,7 @@
// win.DrawLayout (gc, xPos, y, layout);
layout.GetPixelSize (out width, out
height);
- DrawLineText (win, gc, line, offset,
foldOffset - offset, ref xPos, y);
+ DrawLineText (win, line, offset,
foldOffset - offset, ref xPos, y);
// xPos += width;
offset = folding.EndLine.Offset +
folding.EndColumn;
@@ -800,8 +830,8 @@
gc.RgbFgColor = ColorStyle.FoldLine;
win.DrawLayout (gc, xPos, y, layout);
if (caretOffset == foldOffset)
- DrawCaret (win, gc, xPos, y);
-
+ DrawCaret (win, xPos, y);
+
xPos += width;
if (folding.EndLine != line) {
@@ -820,14 +850,14 @@
// Draw remaining line
if (line.EndOffset - offset > 0)
- DrawLineText (win, gc, line, offset,
line.Offset + line.EditableLength - offset, ref xPos, y);
+ DrawLineText (win, line, offset, line.Offset +
line.EditableLength - offset, ref xPos, y);
if (caretOffset == line.Offset + line.EditableLength)
- DrawCaret (win, gc, xPos, y);
+ DrawCaret (win, xPos, y);
if (TextEditorOptions.Options.ShowEolMarkers)
- DrawEolMarker (win, gc, ref xPos, y);
+ DrawEolMarker (win, ref xPos, y);
}
- void DrawCaret (Gdk.Window win, Gdk.GC gc, int x, int y)
+ void DrawCaret (Gdk.Window win, int x, int y)
{
if (!caretBlink || !this.IsFocus)
return;
@@ -839,7 +869,7 @@
}
}
- void DrawLineText (Gdk.Window win, Gdk.GC gc, LineSegment line,
int offset, int length, ref int xPos, int y)
+ void DrawLineText (Gdk.Window 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);
@@ -871,23 +901,20 @@
// Console.WriteLine ("#" + chunks.Length);
foreach (Chunk chunk in chunks) {
-// Console.WriteLine (chunk + " style:" +
chunk.Style);
- layout.FontDescription.Weight =
chunk.Style.Bold ? Pango.Weight.Bold : Pango.Weight.Normal;
- layout.FontDescription.Style =
chunk.Style.Italic ? Pango.Style.Italic : Pango.Style.Normal;
if (chunk.Offset >= selectionStart &&
chunk.EndOffset <= selectionEnd) {
- DrawTextWithHighlightedWs (win, gc,
selectedTextColor, ref xPos, y, Document.Buffer.GetTextAt (chunk));
+ DrawTextWithHighlightedWs (win,
selectedTextColor, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (chunk));
} else if (chunk.Offset >= selectionStart &&
chunk.Offset < selectionEnd && chunk.EndOffset > selectionEnd) {
- DrawTextWithHighlightedWs (win, gc,
selectedTextColor, ref xPos, y, Document.Buffer.GetTextAt (chunk.Offset,
selectionEnd - chunk.Offset));
- DrawTextWithHighlightedWs (win, gc,
chunk.Style.Color, ref xPos, y, Document.Buffer.GetTextAt (selectionEnd,
chunk.EndOffset - selectionEnd));
+ DrawTextWithHighlightedWs (win,
selectedTextColor, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (chunk.Offset, selectionEnd - chunk.Offset));
+ DrawTextWithHighlightedWs (win,
chunk.Style.Color, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (selectionEnd, chunk.EndOffset - selectionEnd));
} else if (chunk.Offset < selectionStart &&
chunk.EndOffset > selectionStart && chunk.EndOffset <= selectionEnd) {
- DrawTextWithHighlightedWs (win, gc,
chunk.Style.Color, ref xPos, y, Document.Buffer.GetTextAt (chunk.Offset,
selectionStart - chunk.Offset));
- DrawTextWithHighlightedWs (win, gc,
selectedTextColor, ref xPos, y, Document.Buffer.GetTextAt (selectionStart,
chunk.EndOffset - selectionStart));
+ DrawTextWithHighlightedWs (win,
chunk.Style.Color, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (chunk.Offset, selectionStart - chunk.Offset));
+ DrawTextWithHighlightedWs (win,
selectedTextColor, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (selectionStart, chunk.EndOffset - selectionStart));
} else if (chunk.Offset < selectionStart &&
chunk.EndOffset > selectionEnd) {
- DrawTextWithHighlightedWs (win, gc,
chunk.Style.Color, ref xPos, y, Document.Buffer.GetTextAt (chunk.Offset,
selectionStart - chunk.Offset));
- DrawTextWithHighlightedWs (win, gc,
selectedTextColor, ref xPos, y, Document.Buffer.GetTextAt (selectionStart,
selectionEnd - selectionStart));
- DrawTextWithHighlightedWs (win, gc,
chunk.Style.Color, ref xPos, y, Document.Buffer.GetTextAt (selectionEnd,
chunk.EndOffset - selectionEnd));
+ DrawTextWithHighlightedWs (win,
chunk.Style.Color, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (chunk.Offset, selectionStart - chunk.Offset));
+ DrawTextWithHighlightedWs (win,
selectedTextColor, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (selectionStart, selectionEnd - selectionStart));
+ DrawTextWithHighlightedWs (win,
chunk.Style.Color, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (selectionEnd, chunk.EndOffset - selectionEnd));
} else
- DrawTextWithHighlightedWs (win, gc,
chunk.Style.Color, ref xPos, y, Document.Buffer.GetTextAt (chunk));
+ DrawTextWithHighlightedWs (win,
chunk.Style.Color, chunk.Style.Bold, chunk.Style.Italic, ref xPos, y,
Document.Buffer.GetTextAt (chunk));
}
if (line.Markers != null) {
foreach (TextMarker marker in line.Markers) {
@@ -898,45 +925,47 @@
int caretOffset = Caret.Offset;
if (offset <= caretOffset && caretOffset < offset +
length) {
int caretX = GetWidth (Buffer.GetTextAt
(offset, caretOffset - offset));
- DrawCaret (win, gc, xStart + caretX, y);
+ DrawCaret (win, xStart + caretX, y);
}
}
- void DrawTextWithHighlightedWs (Gdk.Window win, Gdk.GC gc,
Gdk.Color defaultColor, ref int xPos, int y, string text)
+ void DrawTextWithHighlightedWs (Gdk.Window win, Gdk.Color
defaultColor, bool bold, bool italic, ref int xPos, int y, string text)
{
string[] spaces = text.Split (' ');
- Pango.Weight weight = layout.FontDescription.Weight;
- Pango.Style style = layout.FontDescription.Style;
-
for (int i = 0; i < spaces.Length; i++) {
string[] tabs = spaces[i].Split ('\t');
for (int j = 0; j < tabs.Length; j++) {
- gc.RgbFgColor = defaultColor;
-
- layout.FontDescription.Weight = weight;
- layout.FontDescription.Style = style;
- DrawText (win, gc, ref xPos, y,
tabs[j]);
+ gc.RgbFgColor = defaultColor;
+ if (bold)
+ layout.FontDescription.Weight =
Pango.Weight.Bold;
+ if (italic)
+ layout.FontDescription.Style =
Pango.Style.Italic;
+ DrawText (win, ref xPos, y, tabs[j]);
+ if (bold)
+ layout.FontDescription.Weight =
Pango.Weight.Normal;
+ if (italic)
+ layout.FontDescription.Style =
Pango.Style.Normal;
if (j + 1 < tabs.Length) {
if
(TextEditorOptions.Options.ShowTabs) {
- DrawTabMarker (win, gc,
ref xPos, y);
+ DrawTabMarker (win, ref
xPos, y);
} else {
- DrawText (win, gc, ref
xPos, y, new string (' ', TextEditorOptions.Options.TabSize));
+ DrawText (win, ref
xPos, y, new string (' ', TextEditorOptions.Options.TabSize));
}
}
}
if (i + 1 < spaces.Length) {
if
(TextEditorOptions.Options.ShowSpaces) {
- DrawSpaceMarker (win, gc, ref
xPos, y);
+ DrawSpaceMarker (win, ref xPos,
y);
} else {
- DrawText (win, gc, ref xPos, y,
" ");
+ DrawText (win, ref xPos, y, "
");
}
}
}
}
- void DrawText (Gdk.Window win, Gdk.GC gc, ref int xPos, int y,
string text)
+ void DrawText (Gdk.Window win, ref int xPos, int y, string text)
{
layout.SetText (text);
win.DrawLayout (gc, xPos, y, layout);
@@ -945,36 +974,30 @@
xPos += width;
}
- void DrawEolMarker (Gdk.Window win, Gdk.GC gc, ref int xPos,
int y)
+ void DrawEolMarker (Gdk.Window win, ref int xPos, int y)
{
gc.RgbFgColor = ColorStyle.WhitespaceMarker;
- layout.FontDescription.Weight = Pango.Weight.Normal;
- layout.FontDescription.Style = Pango.Style.Normal;
- DrawText (win, gc, ref xPos, y, "\u00B6");
+ win.DrawLayout (gc, xPos, y, eolMarker);
}
- void DrawSpaceMarker (Gdk.Window win, Gdk.GC gc, ref int xPos,
int y)
+ void DrawSpaceMarker (Gdk.Window win, ref int xPos, int y)
{
gc.RgbFgColor = ColorStyle.WhitespaceMarker;
- layout.FontDescription.Weight = Pango.Weight.Normal;
- layout.FontDescription.Style = Pango.Style.Normal;
- DrawText (win, gc, ref xPos, y, "\u00B7");
+ win.DrawLayout (gc, xPos, y, spaceMarker);
+ xPos += charWidth;
}
- void DrawTabMarker (Gdk.Window win, Gdk.GC gc, ref int xPos,
int y)
+ void DrawTabMarker (Gdk.Window win, ref int xPos, int y)
{
gc.RgbFgColor = ColorStyle.WhitespaceMarker;
- layout.FontDescription.Weight = Pango.Weight.Normal;
- layout.FontDescription.Style = Pango.Style.Normal;
- DrawText (win, gc, ref xPos, y, "\u00BB" + new string
(' ', TextEditorOptions.Options.TabSize - 1));
+ win.DrawLayout (gc, xPos, y, tabMarker);
+ xPos += charWidth * TextEditorOptions.Options.TabSize;
}
- void DrawInvalidLineMarker (Gdk.Window win, Gdk.GC gc, int x,
int y)
+ void DrawInvalidLineMarker (Gdk.Window win, int x, int y)
{
gc.RgbFgColor = ColorStyle.InvalidLineMarker;
- layout.FontDescription.Weight = Pango.Weight.Normal;
- layout.FontDescription.Style = Pango.Style.Normal;
- DrawText (win, gc, ref x, y, "~");
+ win.DrawLayout (gc, x, y, invalidLineMarker);
}
public Gdk.Point DocumentToVisualLocation (DocumentLocation loc)
@@ -1095,7 +1118,6 @@
}
- LineSegment longestLine;
void SetAdjustments ()
{
this.textEditorData.VAdjustment.SetBounds (0,
@@ -1105,21 +1127,19 @@
this.Allocation.Height);
if (longestLine != null)
this.textEditorData.HAdjustment.SetBounds (0,
- longestLine.Length * 8 +
100,
- 8,
+ (longestLine.Length +
100) * this.charWidth,
+ this.charWidth,
this.Allocation.Width,
this.Allocation.Width);
}
- List<IMargin> margins = new List<IMargin> ();
- Pango.Layout layout;
- int oldRequest = -1;
- int charWidth;
protected override bool OnExposeEvent (Gdk.EventExpose e)
{
- Gdk.Window win = e.Window;
+ Gdk.Window win = e.Window;
Gdk.Rectangle area = e.Area;
+ if (gc == null)
+ gc = new Gdk.GC (win);
int width;
if (TextEditorOptions.Options.ShowRuler) {
layout.SetText (new string (' ',
TextEditorOptions.Options.RulerColumn));
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
2008-02-11 13:45:49 UTC (rev 95435)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
2008-02-11 14:20:08 UTC (rev 95436)
@@ -33,6 +33,13 @@
namespace Mono.TextEditor.Highlighting
{
+ public class SemanticRule
+ {
+ public virtual void Analyze (Document doc, List<Chunk> chunks,
int startOffset, int endOffset)
+ {
+// System.Console.WriteLine(doc.Buffer.GetTextAt
(startOffset, endOffset - startOffset));
+ }
+ }
public class Rule
{
protected string name;
@@ -44,6 +51,8 @@
protected List<Match> matches = new List<Match> ();
protected List<Marker> prevMarker = new List<Marker> ();
+ public List<SemanticRule> SemanticRules = new
List<SemanticRule> ();
+
public string Name {
get {
return name;
@@ -118,9 +127,6 @@
return false;
}
-
-
-
public class Pair<S, T>
{
public S o1;
@@ -195,7 +201,7 @@
}
}
}
-
+
public const string Node = "Rule";
public static Rule Read (XmlReader reader)
{
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
2008-02-11 13:45:49 UTC (rev 95435)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
2008-02-11 14:20:08 UTC (rev 95436)
@@ -77,6 +77,7 @@
Rule.Pair<Span, object> spanPair = null;
Span curSpan;
+ int ruleStart;
public ChunkParser (Document doc, Style style,
SyntaxMode mode, LineSegment line)
{
@@ -85,6 +86,7 @@
this.mode = mode;
this.line = line;
}
+
void AddChunk (ref Chunk curChunk, int length,
ChunkStyle style)
{
if (curChunk.Length > 0) {
@@ -134,7 +136,7 @@
wordOffset = 0;
}
- void SetSpan ()
+ void SetSpan (int offset)
{
curSpan = spanStack.Count > 0 ? spanStack.Peek
() : null;
if (curSpan != null) {
@@ -149,6 +151,12 @@
curRule = mode;
spanTree = curRule.spanTree;
}
+ if (curRule != null) {
+ foreach (SemanticRule semanticRule in
curRule.SemanticRules) {
+ semanticRule.Analyze (this.doc,
result, ruleStart, offset);
+ }
+ }
+ ruleStart = offset;
}
int wordOffset = 0;
@@ -159,6 +167,7 @@
public Chunk[] GetChunks (int offset, int length)
{
curRule = mode;
+ this.ruleStart = offset;
spanStack = line.StartSpan != null ? new
Stack<Span> (line.StartSpan) : new Stack<Span> ();
SyntaxModeService.ScanSpans (doc, curRule,
spanStack, line.Offset, offset);
pair = null;
@@ -166,10 +175,10 @@
maxEnd = System.Math.Min (offset + length,
line.Offset + line.EditableLength);
int endOffset = 0;
- SetSpan ();
+ SetSpan (offset);
SetTree ();
bool isNoKeyword = false;
-// bool isAfterSpan = false;
+// bool isAfterSpan = false;
for (int i = offset; i < maxEnd; i++) {
char ch = doc.Buffer.GetCharAt (i);
if (curSpan != null &&
!String.IsNullOrEmpty (curSpan.End)) {
@@ -179,7 +188,7 @@
curChunk.Length
-= curSpan.End.Length - 1;
AddChunk (ref
curChunk, curSpan.End.Length, !String.IsNullOrEmpty (curSpan.TagColor) ?
style.GetChunkStyle (curSpan.TagColor) : GetSpanStyle (spanStack));
spanStack.Pop
();
- SetSpan ();
+ SetSpan (i);
SetTree ();
curChunk.Style
= GetSpanStyle (spanStack);
endOffset = 0;
@@ -208,14 +217,12 @@
curChunk.Length -=
span.Begin.Length - 1;
AddChunk (ref curChunk,
span.Begin.Length, !String.IsNullOrEmpty (span.TagColor) ? style.GetChunkStyle
(span.TagColor) : GetSpanStyle (spanStack));
- SetSpan ();
+ SetSpan (i);
SetTree ();
if
(!String.IsNullOrEmpty (span.NextColor))
curChunk.Style
= style.GetChunkStyle (span.NextColor);
continue;
}
- } else {
- SetSpan ();
}
skip:
;
@@ -251,10 +258,11 @@
AddChunk (ref curChunk, wordOffset,
GetChunkStyleColor (spanStack, pair.o1));
curChunk.Style = GetChunkStyleColor
(spanStack, pair.o1);
}
- if (curChunk.Length > 0) {
+
+ if (curChunk.Length > 0)
result.Add (curChunk);
- }
+ SetSpan (maxEnd);
return result.ToArray ();
}
}
@@ -268,6 +276,13 @@
return null;
}
+ public void AddSemanticRule (string name, SemanticRule
semanticRule)
+ {
+ Rule rule = GetRule (name);
+ if (rule != null)
+ rule.SemanticRules.Add (semanticRule);
+ }
+
public override string ToString ()
{
return String.Format ("[SyntaxMode: Name={0},
MimeType={1}]", Name, MimeType);
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
2008-02-11 13:45:49 UTC (rev 95435)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
2008-02-11 14:20:08 UTC (rev 95436)
@@ -240,6 +240,7 @@
}
reader.Close ();
}
+ SyntaxModeService.GetSyntaxMode
("text/x-csharp").AddSemanticRule ("Comment", new SemanticRule ());
}
}
}
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches