Ejemplo n.º 1
0
 /// <summary>
 /// Gets symbol from current editor selection and decides if it's applicable
 /// </summary>
 void GetSymbol()
 {
     var originalSelection = new Range(E, E.Selection.Start, E.Selection.End);
     S = E.SelectWord();
     E.Selection.Normalize();
     var point = E.PlaceToPoint(E.Selection.Start);
     var target = E.PointToScreen(point);
     target.X -= E.Left;
     target.Y -= Height - ClientRectangle.Height - E.Left + 3;
     Location = target;
     Symbol.Text = S;
     var style = E.Selection.Chars.First().style;
     var notApplicableForStyles = new StyleIndex[] {
         EditorSyntax.StyleMap.Command,
         EditorSyntax.StyleMap.Comment,
         EditorSyntax.StyleMap.Keyword0,
         EditorSyntax.StyleMap.Keyword1,
         EditorSyntax.StyleMap.Keyword2,
         EditorSyntax.StyleMap.Keyword3,
         EditorSyntax.StyleMap.Keyword4,
         EditorSyntax.StyleMap.Number
     };
     var applicable = !notApplicableForStyles.Contains(style);
     if (applicable) ShowDialog();
     else { E.Selection = originalSelection; Dispose(); }
 }
 public Char(char c, System.Drawing.SizeF size)
 {
     this.c = c;
     style = StyleIndex.None;
     this.size = size;
 }
Ejemplo n.º 3
0
 internal static void FlushRendering(Graphics gr, FastColoredTextBox textbox, StyleIndex styleIndex, Point pos, Range range)
 {
     if (range.End > range.Start)
     {
         int mask = 1;
         bool hasTextStyle = false;
         for (int i = 0; i < textbox.Styles.Length; i++)
         {
             if (textbox.Styles[i] != null && ((int)styleIndex & mask) != 0)
             {
                 Style style = textbox.Styles[i];
                 bool isTextStyle = style is TextStyle;
                 if (!hasTextStyle || !isTextStyle || textbox.AllowSeveralTextStyleDrawing)
                     //cancelling secondary rendering by TextStyle
                     style.Draw(gr, pos, range); //rendering
                 hasTextStyle |= isTextStyle;
             }
             mask = mask << 1;
         }
         //draw by default renderer
         if (!hasTextStyle)
             textbox.DefaultStyle.Draw(gr, pos, range);
     }
     else
     {
         // empty range
     }
 }
Ejemplo n.º 4
0
 string GetStyleName(StyleIndex styleIndex)
 {
     return(styleIndex.ToString().Replace(" ", "").Replace(",", ""));
 }
Ejemplo n.º 5
0
        private void Flush(StringBuilder sb, StringBuilder tempSB, StyleIndex currentStyle)
        {
            //find textRenderer
            if (tempSB.Length == 0)
                return;

            var desc = GetRtfDescriptor(currentStyle);
            var cf = GetColorTableNumber(desc.ForeColor);
            var cb = GetColorTableNumber(desc.BackColor);
            var tags = new StringBuilder();
            if (cf >= 0)
                tags.AppendFormat(@"\cf{0}", cf);
            if (cb >= 0)
                tags.AppendFormat(@"\highlight{0}", cb);
            if(!string.IsNullOrEmpty(desc.AdditionalTags))
                tags.Append(desc.AdditionalTags.Trim());

            if(tags.Length > 0)
                sb.AppendFormat(@"{{{0} {1}}}", tags, tempSB.ToString());
            else
                sb.Append(tempSB.ToString());
            tempSB.Length = 0;
        }
Ejemplo n.º 6
0
        private string GetCss(StyleIndex styleIndex)
        {
            List<Style> styles = new List<Style>();
            //find text renderer
            TextStyle textStyle = null;
            int mask = 1;
            bool hasTextStyle = false;
            for (int i = 0; i < tb.Styles.Length; i++)
            {
                if (tb.Styles[i] != null && ((int)styleIndex & mask) != 0)
                if (tb.Styles[i].IsExportable)
                {
                    var style = tb.Styles[i];
                    styles.Add(style);

                    bool isTextStyle = style is TextStyle;
                    if (isTextStyle)
                        if (!hasTextStyle || tb.AllowSeveralTextStyleDrawing)
                        {
                            hasTextStyle = true;
                            textStyle = style as TextStyle;
                        }
                }
                mask = mask << 1;
            }
            //add TextStyle css
            string result = "";

            if (!hasTextStyle)
            {
                //draw by default renderer
                result = tb.DefaultStyle.GetCSS();
            }
            else
            {
                result = textStyle.GetCSS();
            }
            //add non TextStyle css
            foreach(var style in styles)
            if (style != textStyle)
                result += style.GetCSS();

            return result;
        }
Ejemplo n.º 7
0
        public TextEditElement(int row, int col, int width, int height, Func <string> readContent, Action <string> saveContent, StyleIndex styleIndex = StyleIndex.TextElement)
            : base(row, col, width, height, styleIndex, readContent)
        {
            this.saveContent = saveContent;

            Normalize();
        }
Ejemplo n.º 8
0
 public Char(char c)
 {
     C = c;
     Style = StyleIndex.None;
 }
Ejemplo n.º 9
0
        private string GetCss(StyleIndex styleIndex)
        {
            //find text renderer
            TextStyle textStyle    = null;
            int       mask         = 1;
            bool      hasTextStyle = false;

            for (int i = 0; i < tb.Styles.Length; i++)
            {
                if (tb.Styles[i] != null && ((int)styleIndex & mask) != 0)
                {
                    Style style       = tb.Styles[i];
                    bool  isTextStyle = style is TextStyle;
                    if (isTextStyle)
                    {
                        if (!hasTextStyle || tb.AllowSeveralTextStyleDrawing)
                        {
                            hasTextStyle = true;
                            textStyle    = style as TextStyle;
                        }
                    }
                }
                mask = mask << 1;
            }
            //draw by default renderer
            if (!hasTextStyle)
            {
                textStyle = tb.DefaultStyle;
            }
            //
            string result = "";
            string s      = "";

            if (textStyle.BackgroundBrush is SolidBrush)
            {
                s = GetColorAsString((textStyle.BackgroundBrush as SolidBrush).Color);
                if (s != "")
                {
                    result += "background-color:" + s + ";";
                }
            }
            if (textStyle.ForeBrush is SolidBrush)
            {
                s = GetColorAsString((textStyle.ForeBrush as SolidBrush).Color);
                if (s != "")
                {
                    result += "color:" + s + ";";
                }
            }
            if ((textStyle.FontStyle & FontStyle.Bold) != 0)
            {
                result += "font-weight:bold;";
            }
            if ((textStyle.FontStyle & FontStyle.Italic) != 0)
            {
                result += "font-style:oblique;";
            }
            if ((textStyle.FontStyle & FontStyle.Strikeout) != 0)
            {
                result += "text-decoration:line-through;";
            }
            if ((textStyle.FontStyle & FontStyle.Underline) != 0)
            {
                result += "text-decoration:underline;";
            }

            return(result);
        }
Ejemplo n.º 10
0
        public TextEditElement(int row, int col, Func <string> readContent, Action <string> saveContent, StyleIndex styleIndex = StyleIndex.TextElement)
            : base(row, col, DefaultContentLength(readContent), 1, styleIndex, readContent)
        {
            this.saveContent = saveContent;

            Normalize();
        }
Ejemplo n.º 11
0
 public string GetStyleName(StyleIndex styleIndex)
 {
     return(styleIndex.ToString().Replace(" ", string.Empty).Replace(",", string.Empty));
 }
Ejemplo n.º 12
0
 private string GetStyleName(StyleIndex styleIndex) => styleIndex.ToString().Replace(" ", "").Replace(",", "");
Ejemplo n.º 13
0
 private void Flush(StringBuilder sb, StringBuilder tempSB, StyleIndex currentStyle)
 {
     //find textRenderer
     //var textStyle = styles.Where(s => s is TextStyle).FirstOrDefault();
     //
     if (tempSB.Length == 0)
         return;
     if (UseStyleTag)
         sb.AppendFormat("<font class=fctb{0}>{1}</font>", GetStyleName(currentStyle), tempSB.ToString());
     else
     {
         string css = GetCss(currentStyle);
         if(css!=string.Empty)
             sb.AppendFormat("<font style=\"{0}\">", css);
         sb.Append(tempSB.ToString());
         if (css != string.Empty)
             sb.Append("</font>");
     }
     tempSB.Length = 0;
 }
Ejemplo n.º 14
0
        private string GetCss(StyleIndex styleIndex)
        {
            //find text renderer
            TextStyle textStyle = null;
            int mask = 1;
            bool hasTextStyle = false;
            for (int i = 0; i < tb.Styles.Length; i++)
            {
                if (tb.Styles[i] != null && ((int)styleIndex & mask) != 0)
                {
                    Style style = tb.Styles[i];
                    bool isTextStyle = style is TextStyle;
                    if (isTextStyle)
                        if (!hasTextStyle || tb.AllowSeveralTextStyleDrawing)
                        {
                            hasTextStyle = true;
                            textStyle = style as TextStyle;
                        }
                }
                mask = mask << 1;
            }
            //draw by default renderer
            if (!hasTextStyle)
                textStyle = tb.DefaultStyle;
            //
            string result = "";
            string s = "";
            if (textStyle.BackgroundBrush is SolidBrush)
            {
                s = GetColorAsString((textStyle.BackgroundBrush as SolidBrush).Color);
                if (s != "")
                    result += "background-color:" + s + ";";
            }
            if (textStyle.ForeBrush is SolidBrush)
            {
                s = GetColorAsString((textStyle.ForeBrush as SolidBrush).Color);
                if (s != "")
                    result += "color:" + s + ";";
            }
            if ((textStyle.FontStyle & FontStyle.Bold) != 0)
                result += "font-weight:bold;";
            if ((textStyle.FontStyle & FontStyle.Italic) != 0)
                result += "font-style:oblique;";
            if ((textStyle.FontStyle & FontStyle.Strikeout) != 0)
                result += "text-decoration:line-through;";
            if ((textStyle.FontStyle & FontStyle.Underline) != 0)
                result += "text-decoration:underline;";

            return result;
        }
Ejemplo n.º 15
0
        public TextEditElement(IPosition position, ISize size, Func <string> readContent, Action <string> saveContent, StyleIndex styleIndex = StyleIndex.TextElement)
            : base(position, size, styleIndex, readContent)
        {
            this.saveContent = saveContent;

            Normalize();
        }
Ejemplo n.º 16
0
 public Char(char c)
 {
     this.c = c;
     style = StyleIndex.None;
 }
Ejemplo n.º 17
0
 public Char(char c)
 {
     this.c = c;
     style  = StyleIndex.None;
 }
Ejemplo n.º 18
0
        private RTFStyleDescriptor GetRtfDescriptor(StyleIndex styleIndex)
        {
            List<Style> styles = new List<Style>();
            //find text renderer
            TextStyle textStyle = null;
            int mask = 1;
            bool hasTextStyle = false;
            for (int i = 0; i < tb.Styles.Length; i++)
            {
                if (tb.Styles[i] != null && ((int)styleIndex & mask) != 0)
                    if (tb.Styles[i].IsExportable)
                    {
                        var style = tb.Styles[i];
                        styles.Add(style);

                        bool isTextStyle = style is TextStyle;
                        if (isTextStyle)
                            if (!hasTextStyle || tb.AllowSeveralTextStyleDrawing)
                            {
                                hasTextStyle = true;
                                textStyle = style as TextStyle;
                            }
                    }
                mask = mask << 1;
            }
            //Add TextStyle css
            RTFStyleDescriptor result = null;

            if (!hasTextStyle)
            {
                //draw by default renderer
                result = tb.DefaultStyle.GetRTF();
            }
            else
            {
                result = textStyle.GetRTF();
            }

            return result;
        }
Ejemplo n.º 19
0
        public VirtualConsole(string title, int rows = 25, int cols = 80, Styles styles = null, StyleIndex styleIndex = StyleIndex.RootWindow, IConsoleMouse consoleMouse = null, bool?setWindowSize = null)
        {
            rows = Math.Min(Math.Max(rows, minRows), maxRows);
            cols = Math.Min(Math.Max(cols, minCols), maxCols);

            if (styles == null)
            { // use a default style pack
                styles = new Styles();
            }

            var style     = styles[styleIndex];
            var styleItem = GetPackedStyle(ref style);

            displayChars = Enumerable.Repeat(' ', rows * cols).ToArray();
            packedStyles = Enumerable.Repeat(styleItem, rows * cols).ToArray();

            this.title      = title;
            this.rows       = rows;
            this.cols       = cols;
            this.styleIndex = styleIndex;
            this.styles     = styles;

            this.setWindowSize = setWindowSize ?? defaultSetWindowSize;

            ConsoleInit(this.setWindowSize);

            if (consoleMouse != null)
            {
                consoleMouse.Init(this);
            }
        }
Ejemplo n.º 20
0
 private void Flush(StringBuilder sb, StringBuilder tempSB, StyleIndex currentStyle)
 {
     //find textRenderer
     if (tempSB.Length == 0)
         return;
     if (UseStyleTag)
         sb.AppendFormat("<font class=fctb{0}>{1}</font>", GetStyleName(currentStyle), tempSB.ToString());
     else
     {
         string css = GetCss(currentStyle);
         if(css!="")
             sb.AppendFormat("<font style=\"{0}\">", css);
         sb.Append(tempSB.ToString());
         if (css != "")
             sb.Append("</font>");
     }
     tempSB.Length = 0;
 }
Ejemplo n.º 21
0
        public string GetHtml(Range r)
        {
            tb = r.tb;
            Dictionary <StyleIndex, object> styles = new Dictionary <StyleIndex, object>();
            StringBuilder sb             = new StringBuilder();
            StringBuilder tempSB         = new StringBuilder();
            StyleIndex    currentStyleId = StyleIndex.None;

            r.Normalize();
            int currentLine = r.Start.iLine;

            styles[currentStyleId] = null;
            //
            if (UseOriginalFont)
            {
                sb.AppendFormat("<font style=\"font-family: {0}, monospace; font-size: {1}pt; line-height: {2}px;\">",
                                r.tb.Font.Name, r.tb.Font.SizeInPoints, r.tb.CharHeight);
            }

            //
            if (IncludeLineNumbers)
            {
                tempSB.AppendFormat("<span class=lineNumber>{0}</span>  ", currentLine + 1);
            }
            //
            bool hasNonSpace = false;

            foreach (Place p in r)
            {
                Char c = r.tb[p.iLine][p.iChar];
                if (c.style != currentStyleId)
                {
                    Flush(sb, tempSB, currentStyleId);
                    currentStyleId         = c.style;
                    styles[currentStyleId] = null;
                }

                if (p.iLine != currentLine)
                {
                    for (int i = currentLine; i < p.iLine; i++)
                    {
                        tempSB.Append(UseBr ? "<br>" : "");
                        if (IncludeLineNumbers)
                        {
                            tempSB.AppendFormat("<span class=lineNumber>{0}</span>  ", i + 2);
                        }
                    }
                    currentLine = p.iLine;
                    hasNonSpace = false;
                }
                switch (c.c)
                {
                case ' ':
                    if ((hasNonSpace || !UseForwardNbsp) && !UseNbsp)
                    {
                        goto default;
                    }

                    tempSB.Append("&nbsp;");
                    break;

                case '<':
                    tempSB.Append("&lt;");
                    break;

                case '>':
                    tempSB.Append("&gt;");
                    break;

                case '&':
                    tempSB.Append("&amp;");
                    break;

                default:
                    hasNonSpace = true;
                    tempSB.Append(c.c);
                    break;
                }
            }
            Flush(sb, tempSB, currentStyleId);

            if (UseOriginalFont)
            {
                sb.Append("</font>");
            }

            //build styles
            if (UseStyleTag)
            {
                tempSB.Length = 0;
                tempSB.Append("<style type=\"text/css\">");
                foreach (var styleId in styles.Keys)
                {
                    tempSB.AppendFormat(".fctb{0}{{ {1} }}\r\n", GetStyleName(styleId), GetCss(styleId));
                }
                tempSB.Append("</style>");

                sb.Insert(0, tempSB.ToString());
            }

            if (IncludeLineNumbers)
            {
                sb.Insert(0, LineNumbersCSS);
            }

            return(sb.ToString());
        }
Ejemplo n.º 22
0
 string GetStyleName(StyleIndex styleIndex)
 {
     return styleIndex.ToString().Replace(" ", "").Replace(",", "");
 }
Ejemplo n.º 23
0
 public Char(char c)
 {
     this.c = c;
     style  = StyleIndex.None;
     type   = HighlightType.Defaul;
 }