示例#1
0
 internal SyntaxHighlightPage(ConfigPage page) : this()
 {
     _servicePage                   = page;
     _ColorBox.Checked              = _FontFamilyBox.Checked = _FontSizeBox.Checked = _FontStyleBox.Checked = true;
     _ColorBox.CheckedChanged      += (s, args) => _StyleFilters = _StyleFilters.SetFlags(StyleFilters.Color, _ColorBox.Checked);
     _FontFamilyBox.CheckedChanged += (s, args) => _StyleFilters = _StyleFilters.SetFlags(StyleFilters.FontFamily, _FontFamilyBox.Checked);
     _FontSizeBox.CheckedChanged   += (s, args) => _StyleFilters = _StyleFilters.SetFlags(StyleFilters.FontSize, _FontSizeBox.Checked);
     _FontStyleBox.CheckedChanged  += (s, args) => _StyleFilters = _StyleFilters.SetFlags(StyleFilters.FontStyle, _FontStyleBox.Checked);
     _UI.CommonEventAction         += () => Config.Instance.FireConfigChangedEvent(Features.SyntaxHighlight);
 }
示例#2
0
文件: Config.cs 项目: AmadeusW/Codist
 public static void LoadConfig(string configPath, StyleFilters styleFilter = StyleFilters.None)
 {
     if (Interlocked.Exchange(ref _LoadingConfig, 1) != 0)
     {
         return;
     }
     Debug.WriteLine("Load config: " + configPath);
     try {
         Instance = InternalLoadConfig(configPath, styleFilter);
         Loaded?.Invoke(Instance, EventArgs.Empty);
         Updated?.Invoke(Instance, new ConfigUpdatedEventArgs(styleFilter != StyleFilters.None ? Features.SyntaxHighlight : Features.All));
     }
     catch (Exception ex) {
         Debug.WriteLine(ex.ToString());
         Instance = GetDefaultConfig();
     }
     finally {
         _LoadingConfig = 0;
     }
 }
示例#3
0
 static void MergeCodeStyle <TStyle>(List <TStyle> source, IEnumerable <TStyle> target, StyleFilters styleFilters) where TStyle : StyleBase
 {
     foreach (var item in target)
     {
         if (item.IsSet == false)
         {
             continue;
         }
         var s = source.Find(i => i.Id == item.Id);
         if (s != null)
         {
             item.CopyTo(s, styleFilters);
         }
     }
 }
示例#4
0
        static Config InternalLoadConfig(string configPath, StyleFilters styleFilter)
        {
            var configContent = configPath == LightTheme ? Properties.Resources.Light
                                : configPath == DarkTheme ? Properties.Resources.Dark
                                : configPath == SimpleTheme ? Properties.Resources.Simple
                                : File.ReadAllText(configPath);
            var config = JsonConvert.DeserializeObject <Config>(configContent, new JsonSerializerSettings {
                DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
                NullValueHandling    = NullValueHandling.Ignore,
                Error = (sender, args) => {
                    args.ErrorContext.Handled = true;                     // ignore json error
                }
            });

            if (styleFilter == StyleFilters.None)
            {
                var l = config.Labels;
                for (var i = l.Count - 1; i >= 0; i--)
                {
                    if (String.IsNullOrWhiteSpace(l[i].Label))
                    {
                        l.RemoveAt(i);
                    }
                }
                if (l.Count == 0)
                {
                    InitDefaultLabels(l);
                }
            }
            var removeFontNames = System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Control;

            LoadStyleEntries <CodeStyle, CodeStyleTypes>(config.GeneralStyles, removeFontNames);
            LoadStyleEntries <CommentStyle, CommentStyleTypes>(config.CommentStyles, removeFontNames);
            LoadStyleEntries <CppStyle, CppStyleTypes>(config.CppStyles, removeFontNames);
            LoadStyleEntries <CSharpStyle, CSharpStyleTypes>(config.CodeStyles, removeFontNames);
            LoadStyleEntries <XmlCodeStyle, XmlStyleTypes>(config.XmlCodeStyles, removeFontNames);
            LoadStyleEntries <SymbolMarkerStyle, SymbolMarkerStyleTypes>(config.SymbolMarkerStyles, removeFontNames);
            if (styleFilter == StyleFilters.All)
            {
                // don't override other settings if loaded from predefined themes or syntax config file
                ResetCodeStyle(Instance.GeneralStyles, config.GeneralStyles);
                ResetCodeStyle(Instance.CommentStyles, config.CommentStyles);
                ResetCodeStyle(Instance.CodeStyles, config.CodeStyles);
                ResetCodeStyle(Instance.CppStyles, config.CppStyles);
                ResetCodeStyle(Instance.XmlCodeStyles, config.XmlCodeStyles);
                ResetCodeStyle(Instance.SymbolMarkerStyles, config.SymbolMarkerStyles);
                ResetCodeStyle(Instance.MarkerSettings, config.MarkerSettings);
                _LastLoaded = DateTime.Now;
                return(Instance);
            }
            else if (styleFilter != StyleFilters.None)
            {
                MergeCodeStyle(Instance.GeneralStyles, config.GeneralStyles, styleFilter);
                MergeCodeStyle(Instance.CommentStyles, config.CommentStyles, styleFilter);
                MergeCodeStyle(Instance.CodeStyles, config.CodeStyles, styleFilter);
                MergeCodeStyle(Instance.CppStyles, config.CppStyles, styleFilter);
                MergeCodeStyle(Instance.XmlCodeStyles, config.XmlCodeStyles, styleFilter);
                MergeCodeStyle(Instance.SymbolMarkerStyles, config.SymbolMarkerStyles, styleFilter);
                //MergeCodeStyle(Instance.MarkerSettings, config.MarkerSettings, styleFilter);
                ResetCodeStyle(Instance.MarkerSettings, config.MarkerSettings);
                _LastLoaded = DateTime.Now;
                return(Instance);
            }
            _LastLoaded = DateTime.Now;
            Debug.WriteLine("Config loaded");
            return(config);
        }