Exemple #1
0
 private void SetActiveTabStyle()
 {
     // Finally get the current theme default backcolor if possible
     // and set the active document tab color to match and set fore
     // to inverse.
     try
     {
         PresetStyle preStyle = Themes.CurrentPreset.DefaultPreset; // Themes.CurrentPreset.Presets.Where(m => m.Key.Equals("default", StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault().Value;
         if (preStyle != null)
         {
             if (!String.IsNullOrEmpty(preStyle.Back))
             {
                 Color clr = preStyle.Back.ToColor();
                 if (clr != null)
                 {
                     DockingPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.StartColor = clr;
                     DockingPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.EndColor   = clr;
                     DockingPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.TextColor  = clr.Invert();
                     DockingPanel.Refresh();
                 }
             }
         }
     }
     catch { }
 }
        /// <summary>
        /// Load initializes the language settings, colors, etc.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ThemeSettings_Load(object sender, EventArgs e)
        {
            LanguageManager.InitializeControl(this);

            try
            {
                PresetStyle presetStyle = _Theme.DefaultPreset; //.Presets.Where(m => m.Key.Equals("default", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value;
                if (presetStyle != null)
                {
                    _DefaultBack = presetStyle.Back;
                    _DefaultFore = presetStyle.Fore;
                }
            }
            catch { }

            foreach (string key in Themes._DisplayNames.Values)
            {
                ListStyles.Items.Add(key);
            }

            //foreach (string key in _Theme.Presets.Keys)
            //{

            //        ListStyles.Items.Add(_Theme.Presets[key]);

            //}
        }
        private void ListStyles_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                PresetStyle preStyle = _Theme.GetPresetStyle(ListStyles.SelectedItem.ToString());
                ColorFore.SelectedColor = preStyle.Fore.ToColor(_DefaultFore);
                ColorBack.SelectedColor = preStyle.Back.ToColor(_DefaultBack);
                CheckBold.Checked       = preStyle.Bold;
                CheckItalic.Checked     = preStyle.Italic;
                CheckUnderline.Checked  = preStyle.Underline;
                CheckEOLFilled.Checked  = preStyle.EOLFilled;
                _ActiveStyle            = preStyle;

                UpdateSample();
            } catch { }
        }
        public void SetStyle(Scheme syntax = null)
        {
            if (syntax == null)
            {
                syntax = _CurScheme;
            }

            string defFore = "#000000";
            string defBack = "#ffffff";

            Theme theme = Themes.CurrentPreset;

            if (syntax != null)
            {
                int lex = 0;
                if (Int32.TryParse(syntax.Lexer, out lex))
                {
                    Editor.NativeInterface.SetLexer(lex);
                }
                else
                {
                    Editor.Lexing.LexerName = syntax.Lexer;
                }
            }

            #region Setup Keywords
            if (syntax != null)
            {
                foreach (Keyword keyword in syntax.Keywords)
                {
                    Editor.NativeInterface.SetKeywords(keyword.Key, keyword.Keywords);
                }
            }

            #endregion

            #region Setup Styles

            #region Setup the defaults
            try
            {
                PresetStyle preStyle = theme.DefaultPreset; // theme.Presets.Where(m => m.Key.Equals("default", StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault().Value;
                if (preStyle != null)
                {
                    try
                    {
                        BackColor = preStyle.Back.ToColor();
                    }
                    catch { }
                    for (int i = 0; i < 128; i++)
                    {
                        Editor.Styles[i].ForeColor            = preStyle.Fore.ToColor();
                        Editor.Styles[i].BackColor            = preStyle.Back.ToColor();
                        Editor.Styles[i].Bold                 = preStyle.Bold;
                        Editor.Styles[i].Italic               = preStyle.Italic;
                        Editor.Styles[i].Underline            = preStyle.Underline;
                        Editor.Styles[i].FontName             = FontName(preStyle.Font);
                        Editor.Styles[i].Size                 = (float)preStyle.FontSize;
                        Editor.Styles[i].IsSelectionEolFilled = preStyle.EOLFilled;

                        Editor.Styles.ClearAll();
                    }
                    defFore            = preStyle.Fore;
                    defBack            = preStyle.Back;
                    Editor.Caret.Color = defBack.ToColor().Invert();
                }
            }
            catch { } // Fail quietly
            #endregion

            #region Setup brace styles specifically.

            Editor.Styles[34].ForeColor = "#8080ff".ToColor();
            Editor.Styles[35].ForeColor = "#ff0000".ToColor();

            Editor.Styles[34].BackColor = "#ffff80".ToColor();
            Editor.Styles[35].BackColor = "#ffff80".ToColor();

            Editor.Styles[34].Bold = true;
            Editor.Styles[35].Bold = true;

            Editor.Styles[34].FontName = "Consolas";
            Editor.Styles[35].FontName = "Consolas";

            Editor.Styles[34].Size = 10;
            Editor.Styles[35].Size = 10;

            #endregion

            if (syntax != null)
            {
                foreach (Style style in syntax.Styles)
                {
                    if (!style.UseTemplate || String.IsNullOrEmpty(style.Template))
                    {
                        Editor.Styles[style.Key].ForeColor = style.Fore.ToColor(defFore);
                        Editor.Styles[style.Key].BackColor = style.Back.ToColor(defBack);
                        Editor.Styles[style.Key].FontName  = FontName(style.Font);
                        Editor.Styles[style.Key].Size      = (float)style.FontSize;
                        Editor.Styles[style.Key].Bold      = style.Bold;
                        Editor.Styles[style.Key].Italic    = style.Italic;
                        Editor.Styles[style.Key].Underline = style.Underline;
                    }
                    else
                    {
                        Style tempStyle = theme.GetStyle(style.Template);
                        if (tempStyle != null && !String.IsNullOrEmpty(tempStyle.Fore.FormatColor()))
                        {
                            Editor.Styles[style.Key].ForeColor = tempStyle.Fore.ToColor(defFore);
                            Editor.Styles[style.Key].BackColor = tempStyle.Back.ToColor(defBack);
                            Editor.Styles[style.Key].FontName  = FontName(tempStyle.Font);
                            Editor.Styles[style.Key].Size      = (float)tempStyle.FontSize;
                            Editor.Styles[style.Key].Bold      = tempStyle.Bold;
                            Editor.Styles[style.Key].Italic    = tempStyle.Italic;
                            Editor.Styles[style.Key].Underline = tempStyle.Underline;
                        }
                    }
                }
            }
            Editor.Folding.Flags = ScintillaNET.FoldFlag.LineAfterContracted;

            #endregion

            #region Setup folding
            if (syntax != null)
            {
                if (syntax.Folding)
                {
                    Editor.Lexing.SetProperty("fold", "1");
                    Editor.Lexing.SetProperty("fold.preprocessor", "1");
                }
                else
                {
                    Editor.Lexing.SetProperty("fold", "0");
                }
            }

            #endregion

            #region Margin Colors

            if (!String.IsNullOrEmpty(theme.FoldBackground))
            {
                Editor.NativeInterface.SetFoldMarginColour(true, System.Drawing.ColorTranslator.ToWin32(ColorTranslator.FromHtml(theme.FoldBackground)));
                Editor.Margins.FoldMarginHighlightColor = ColorTranslator.FromHtml(theme.FoldBackground);

                // Set the fold boxes to invert the background color to get a consistent look.
                Editor.Folding.MarkerScheme                = ScintillaNET.FoldMarkerScheme.BoxPlusMinus;
                Editor.Markers.Folder.ForeColor            = theme.FoldBackground.ToColor();
                Editor.Markers.FolderEnd.ForeColor         = theme.FoldBackground.ToColor();
                Editor.Markers.FolderOpen.ForeColor        = theme.FoldBackground.ToColor();
                Editor.Markers.FolderOpenMid.ForeColor     = theme.FoldBackground.ToColor();
                Editor.Markers.FolderOpenMidTail.ForeColor = theme.FoldBackground.ToColor();
                Editor.Markers.FolderSub.ForeColor         = theme.FoldBackground.ToColor();
                Editor.Markers.FolderTail.ForeColor        = theme.FoldBackground.ToColor();


                Editor.Markers.Folder.BackColor            = Editor.Markers.Folder.ForeColor.Invert();
                Editor.Markers.FolderEnd.BackColor         = Editor.Markers.FolderEnd.ForeColor.Invert();
                Editor.Markers.FolderOpen.BackColor        = Editor.Markers.FolderOpen.ForeColor.Invert();
                Editor.Markers.FolderOpenMid.BackColor     = Editor.Markers.FolderOpenMid.ForeColor.Invert();
                Editor.Markers.FolderOpenMidTail.BackColor = Editor.Markers.FolderOpenMidTail.ForeColor.Invert();
                Editor.Markers.FolderSub.BackColor         = Editor.Markers.FolderSub.ForeColor.Invert();
                Editor.Markers.FolderTail.BackColor        = Editor.Markers.FolderTail.ForeColor.Invert();

                Editor.NativeInterface.SetHighlightFold(true);
            }

            #endregion

            #region Setup Indent type

            if (syntax != null)
            {
                switch (syntax.IndentType.ToLower())
                {
                case "cpp":
                    Editor.Indentation.SmartIndentType = ScintillaNET.SmartIndent.CPP;
                    break;

                case "xml":
                    Editor.Indentation.SmartIndentType = ScintillaNET.SmartIndent.XML;
                    break;

                default:
                    Editor.Indentation.SmartIndentType = ScintillaNET.SmartIndent.Simple;
                    break;
                }
            }

            #endregion

            Editor.Indentation.ShowGuides = true;


            Editor.NativeInterface.Colourise(0, -1);

            Editor.NativeInterface.SetProperty("fold.compact", "0");

            _CurScheme = syntax;


            SetHighlightColor();

            #region Configure indicator styles

            Editor.Indicators[4].Style = ScintillaNET.IndicatorStyle.RoundBox;
            Editor.Indicators[4].Color = Themes.CurrentPreset.DefaultPreset.Back.ToColor().Invert().Lerp(Color.White, .7f);
            Editor.Indicators[4].Alpha = 40;

            #endregion
        }