]> O.S.I.I.S - jp/crowedit.git/commitdiff
debug tab, bold and italic formatting
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 31 Aug 2017 13:20:31 +0000 (15:20 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 31 Aug 2017 13:20:31 +0000 (15:20 +0200)
src/Parser.cs
src/SourceEditor.cs
src/TextFormatting.cs
src/XMLParser.cs

index f5d91c6741be40874338c16372b3a5b0ed30ea5d..a72746dedf9b3c40a7906114b16517201d4522d5 100644 (file)
@@ -49,6 +49,7 @@ namespace Crow.Coding
                protected bool eof = true;
 
                public List<TokenList> Tokens;
+               protected TokenList TokensLine;
 
                public Point CurrentPosition { get { return new Point (currentLine, currentColumn); } }
 
@@ -64,6 +65,10 @@ namespace Crow.Coding
                                currentTok.Start = CurrentPosition;
                        currentTok += Read();
                }
+               protected void readToCurrTok(int length) {
+                       for (int i = 0; i < length; i++)
+                               currentTok += Read ();
+               }
                protected void readAndResetCurrentTok(System.Enum type, bool startToc = false) {
                        readToCurrTok ();
                        saveAndResetCurrentTok (type);
@@ -72,7 +77,7 @@ namespace Crow.Coding
                protected void saveAndResetCurrentTok(System.Enum type) {
                        currentTok.Type = (TokenType)type;
                        currentTok.End = CurrentPosition;
-                       Tokens[currentLine].Add (currentTok);
+                       TokensLine.Add (currentTok);
                        currentTok = default(Token);
                }
                protected virtual char Peek() {
@@ -100,17 +105,12 @@ namespace Crow.Coding
                                currentColumn++;
                        return c;
                }
-               protected virtual string ReadUntil (string endExp){
+               protected virtual string ReadLineUntil (string endExp){
                        string tmp = "";
 
                        while (!eof) {
-                               if (buffer [currentLine].Length - currentColumn - endExp.Length < 0) {
-                                       currentLine++;
-                                       if (currentLine >= buffer.Length)
-                                               eof = true;
-                                       currentColumn = 0;
-                                       continue;
-                               }
+                               if (buffer [currentLine].Length - currentColumn - endExp.Length < 0)
+                                       break;
                                if (string.Equals (Peek (endExp.Length), endExp))
                                        return tmp;
                                tmp += Read();
index 237a5d87730bbd3b95af7695acf12a3dd5f7dacd..ea5b32ac8046a646e1c415690692e93e87cd25f9 100644 (file)
@@ -46,15 +46,17 @@ namespace Crow.Coding
                #region CTOR
                public SourceEditor ():base()
                {
-                       formatting.Add ((int)XMLParser.TokenType.AttributeName, new TextFormatting (Color.DarkBlue, Color.Transparent));
-                       formatting.Add ((int)XMLParser.TokenType.ElementName, new TextFormatting (Color.DarkRed, Color.Transparent));
-                       formatting.Add ((int)XMLParser.TokenType.ElementStart, new TextFormatting (Color.Red, Color.Transparent));
-                       formatting.Add ((int)XMLParser.TokenType.ElementEnd, new TextFormatting (Color.Red, Color.Transparent));
-                       formatting.Add ((int)XMLParser.TokenType.ElementClosing, new TextFormatting (Color.Red, Color.Transparent));
-
-                       formatting.Add ((int)XMLParser.TokenType.AttributeValueOpening, new TextFormatting (Color.DarkPink, Color.Transparent));
-                       formatting.Add ((int)XMLParser.TokenType.AttributeValueClosing, new TextFormatting (Color.DarkPink, Color.Transparent));
-                       formatting.Add ((int)XMLParser.TokenType.AttributeValue, new TextFormatting (Color.DarkPink, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.AttributeName, new TextFormatting (Color.UnitedNationsBlue, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.ElementName, new TextFormatting (Color.DarkBlue, Color.Transparent, true));
+                       formatting.Add ((int)XMLParser.TokenType.ElementStart, new TextFormatting (Color.Red, Color.Transparent,true));
+                       formatting.Add ((int)XMLParser.TokenType.ElementEnd, new TextFormatting (Color.Red, Color.Transparent,true));
+                       formatting.Add ((int)XMLParser.TokenType.ElementClosing, new TextFormatting (Color.Red, Color.Transparent, true));
+                       formatting.Add ((int)XMLParser.TokenType.Affectation, new TextFormatting (Color.Red, Color.Transparent, true));
+
+                       formatting.Add ((int)XMLParser.TokenType.AttributeValueOpening, new TextFormatting (Color.DarkPink, Color.Transparent,true));
+                       formatting.Add ((int)XMLParser.TokenType.AttributeValueClosing, new TextFormatting (Color.DarkPink, Color.Transparent,true));
+                       formatting.Add ((int)XMLParser.TokenType.AttributeValue, new TextFormatting (Color.DarkPink, Color.Transparent, false, true));
+                       formatting.Add ((int)XMLParser.TokenType.XMLDecl, new TextFormatting (Color.SeaGreen, Color.Transparent, true));
 
                        buffer = new CodeBuffer ();
                        buffer.LineUpadateEvent += Buffer_LineUpadateEvent;
@@ -86,7 +88,7 @@ namespace Crow.Coding
                Point _selBegin = -1;   //selection start (row,column)
                Point _selRelease = -1; //selection end (row,column)
 
-               Dictionary<int,TextFormatting> formatting = new Dictionary<int, TextFormatting>();
+               Dictionary<int, TextFormatting> formatting = new Dictionary<int, TextFormatting>();
 
                protected Rectangle rText;
                protected FontExtents fe;
@@ -505,13 +507,20 @@ namespace Crow.Coding
                                Color fg = this.Foreground;
                                Color selbg = this.SelectionBackground;
                                Color selfg = this.SelectionForeground;
+                               FontSlant fts = FontSlant.Normal;
+                               FontWeight ftw = FontWeight.Normal;
 
                                if (formatting.ContainsKey ((int)tokens [t].Type)) {
                                        TextFormatting tf = formatting [(int)tokens [t].Type];
                                        bg = tf.Background;
                                        fg = tf.Foreground;
+                                       if (tf.Bold)
+                                               ftw = FontWeight.Bold;
+                                       if (tf.Italic)
+                                               fts = FontSlant.Italic;
                                }
 
+                               gr.SelectFontFace (Font.Name, fts, ftw);
                                gr.SetSourceColor (fg);
 
                                int x = cb.X + (int)((lPtr - ScrollX) * fe.MaxXAdvance);
@@ -614,6 +623,8 @@ namespace Crow.Coding
                                CurrentLine--;
                        else
                                CurrentLine = ScrollY + (int)Math.Floor (mouseLocalPos.Y / fe.Height);
+
+                       CurrentPosition = buffer.VisualPosition; //for rounding if in middle of tabs
                }
                public override void onMouseEnter (object sender, MouseMoveEventArgs e)
                {
index 64e7aea2c40dee2c095404aaf88f14d0a02d6e97..f7b2e518ce653f542ece0fc5e4123ffc95a4f394 100644 (file)
@@ -5,10 +5,14 @@ namespace Crow.Coding
        public struct TextFormatting {
                public Color Foreground;
                public Color Background;
+               public bool Bold;
+               public bool Italic;
 
-               public TextFormatting(Color fg, Color bg){
+               public TextFormatting(Color fg, Color bg, bool bold = false, bool italic = false){
                        Foreground = fg;
                        Background = bg;
+                       Bold = bold;
+                       Italic = italic;
                }
        }
 }
index 011857119d6ebc8a68cafde6e282907d2c0df082..29f57b31b6dc02fbfbbd6e4fa1cc7d4389b4eb63 100644 (file)
@@ -111,6 +111,7 @@ namespace Crow.Coding
                        currentColumn = 0;
                        eof = false;
                        bool eol = false;
+                       TokensLine = Tokens [line];
 
                        //retrieve current parser state from previous line
                        if (line > 0)
@@ -118,10 +119,8 @@ namespace Crow.Coding
                        else
                                curState = States.init;
 
-                       States previousEndingState = (States)Tokens[line].EndingState;
-                       Tokens[line].Clear ();
-
-
+                       States previousEndingState = (States)TokensLine.EndingState;
+                       TokensLine.Clear ();
 
                        while (! (eof||eol)) {
                                SkipWhiteSpaces ();
@@ -143,7 +142,8 @@ namespace Crow.Coding
                                                if (curState != States.init)
                                                        throw new ParsingException (this, "prolog may appear only on first line");
                                                readToCurrTok ();
-                                               currentTok += ReadUntil ("?>");
+                                               currentTok += ReadLineUntil ("?>");
+                                               readToCurrTok (2);
                                                saveAndResetCurrentTok (TokenType.XMLDecl);
                                                curState = States.prolog;
                                                break;
@@ -154,7 +154,7 @@ namespace Crow.Coding
                                                        readToCurrTok ();
                                                        if (Peek () != '-')
                                                                throw new ParsingException (this, "Expecting comment start tag");
-                                                       currentTok += ReadUntil ("--");
+                                                       currentTok += ReadLineUntil ("--");
                                                        if (Peek () != '>')
                                                                throw new ParsingException (this, "Expecting comment closing tag");
                                                        readAndResetCurrentTok (TokenType.BlockComment);
@@ -164,7 +164,7 @@ namespace Crow.Coding
                                                }
                                                break;
                                        default:
-                                               if (!(curState == States.Content || curState == States.XML || curState == States.init))
+                                               if (!(curState == States.Content || curState == States.XML || curState == States.init || curState == States.prolog))
                                                        throw new ParsingException (this, "Unexpected char: '<'");
                                                if (Peek () == '/') {
                                                        curState = States.EndTag;
@@ -228,7 +228,7 @@ namespace Crow.Coding
                                                readAndResetCurrentTok (TokenType.AttributeValueOpening, true);
 
                                                currentTok.Start = CurrentPosition;
-                                               currentTok.Content = ReadUntil (new string (new char[]{ openAttVal }));
+                                               currentTok.Content = ReadLineUntil (new string (new char[]{ openAttVal }));
                                                saveAndResetCurrentTok (TokenType.AttributeValue);
 
                                                if (Peek () != openAttVal)
@@ -242,8 +242,8 @@ namespace Crow.Coding
                                }
                        }
 
-                       Tokens[line].EndingState = (int)curState;
-                       Tokens [line].Dirty = false;
+                       TokensLine.EndingState = (int)curState;
+                       TokensLine.Dirty = false;
 
                        if (previousEndingState != curState && line < Tokens.Count - 1)
                                Tokens [line + 1].Dirty = true;