Ejemplo n.º 1
0
        private void ApplyLeXStyle(LexStyleItem item)
        {
            River.Orqa.Editor.Syntax.ILexStyle[] styles = editor.Lexer.Scheme.LexStyles;
            bool found = false;
            int  i     = 0;

            while ((i < styles.Length) && !found)
            {
                if (!(found = styles[i].Name.Equals(item.Name)))
                {
                    i++;
                }
            }

            if (found)
            {
                styles[i].BackColor = item.BackColor;
                styles[i].ForeColor = item.ForeColor;
                styles[i].FontStyle = item.FontStyle;
            }
        }
Ejemplo n.º 2
0
        //========================================================================================
        // SetOptions()
        //========================================================================================

        public void SetOptions()
        {
            string fontName = UserOptions.GetString("editor/editorFonts/font/family");
            int    fontSize = UserOptions.GetInt("editor/editorFonts/font/size");

            editor.Font = new Font(fontName, fontSize);

            bool            beyondEof       = UserOptions.GetBoolean("editor/general/beyondEof");
            bool            beyondEoln      = UserOptions.GetBoolean("editor/general/beyondEoln");
            NavigateOptions navigateOptions = NavigateOptions.DownAtLineEnd | NavigateOptions.UpAtLineBegin;

            if (beyondEof)
            {
                navigateOptions |= NavigateOptions.BeyondEof;
            }
            if (beyondEoln)
            {
                navigateOptions |= NavigateOptions.BeyondEol;
            }
            editor.NavigateOptions = navigateOptions;

            editor.IndentOptions = IndentOptions.AutoIndent;

            bool verticalScroll   = UserOptions.GetBoolean("editor/general/verticalScroll");
            bool horizontalScroll = UserOptions.GetBoolean("editor/general/horizontalScroll");

            if (verticalScroll && horizontalScroll)
            {
                editor.Scrolling.ScrollBars = RichTextBoxScrollBars.ForcedBoth;
            }
            else if (verticalScroll)
            {
                editor.Scrolling.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
            }
            else if (horizontalScroll)
            {
                editor.Scrolling.ScrollBars = RichTextBoxScrollBars.ForcedHorizontal;
            }
            else
            {
                editor.Scrolling.ScrollBars = RichTextBoxScrollBars.None;
            }

            bool showGutter  = UserOptions.GetBoolean("editor/general/showGutter");
            int  gutterWidth = UserOptions.GetInt("editor/general/gutterWidth");
            bool lineNumbers = UserOptions.GetBoolean("editor/general/lineNumbers");

            editor.Gutter.Visible = showGutter;
            editor.Gutter.Width   = gutterWidth;
            editor.Gutter.Options = (lineNumbers ? GutterOptions.PaintLineNumbers | GutterOptions.PaintLinesOnGutter : GutterOptions.None);

            bool showMargin     = UserOptions.GetBoolean("editor/general/showMargin");
            int  marginPosition = UserOptions.GetInt("editor/general/marginPosition");
            bool wordWrap       = UserOptions.GetBoolean("editor/general/wordWrap");
            bool wrapAtMargin   = UserOptions.GetBoolean("editor/general/wrapAtMargin");

            editor.Margin.Visible  = showMargin;
            editor.Margin.Position = marginPosition;
            editor.WordWrap        = wordWrap;
            editor.WrapAtMargin    = wrapAtMargin;

            SyntaxSettings settings = new SyntaxSettings();

            bool keepTabs = UserOptions.GetBoolean("editor/editorTabs/keepTabs");
            int  tabSize  = UserOptions.GetInt("editor/editorTabs/size");

            editor.Source.Lines.TabStops = new int[1] {
                tabSize
            };
            editor.Source.Lines.UseSpaces = !keepTabs;

            // set lex styles

            XPathNavigator nav = UserOptions.OptionsDoc.CreateNavigator();

            nav.MoveToFirstChild();
            nav = nav.SelectSingleNode("editor/editorFonts/lexStyles");

            nav.MoveToFirstChild();
            LexStyleItem item;
            string       colorName;

            var foreground = FontsAndColors.PlainTextForeground;
            var background = FontsAndColors.PlainTextBackground;

            do
            {
                if (nav.NodeType == XPathNodeType.Element)
                {
                    item              = new LexStyleItem();
                    item.Name         = nav.LocalName;
                    item.InternalName = nav.LocalName;

                    colorName      = nav.GetAttribute("foreColor", nav.NamespaceURI);
                    item.ForeColor = Color.FromName(colorName);
                    if (!item.ForeColor.IsKnownColor)
                    {
                        item.ForeColor = Color.FromArgb(unchecked ((int)uint.Parse(
                                                                       colorName, System.Globalization.NumberStyles.HexNumber)));
                    }

                    if (item.Name.Equals("whitespace"))
                    {
                        foreground = item.ForeColor;
                    }

                    colorName      = nav.GetAttribute("backColor", nav.NamespaceURI);
                    item.BackColor = Color.FromName(colorName);
                    if (!item.BackColor.IsKnownColor)
                    {
                        item.BackColor = Color.FromArgb(unchecked ((int)uint.Parse(
                                                                       colorName, System.Globalization.NumberStyles.HexNumber)));
                    }

                    if (item.Name.Equals("whitespace"))
                    {
                        background = item.BackColor;
                    }

                    item.FontStyle
                        = (FontStyle)Enum.Parse(
                              typeof(FontStyle), nav.GetAttribute("style", nav.NamespaceURI));

                    ApplyLeXStyle(item);
                }
            }while (nav.MoveToNext(XPathNodeType.Element));

            editor.ForeColor = foreground;
            editor.BackColor = background;
            editor.Refresh();
        }