示例#1
0
        static AppContext()
        {
            ThemeProviders = new Dictionary <string, IColorTheme>();

            string themesPath = Path.Combine("Themes", "System");

            var staticData = StaticData.Instance;

            // Load available themes from StaticData
            if (staticData.DirectoryExists(themesPath))
            {
                var themeFiles = staticData.GetDirectories(themesPath).SelectMany(d => staticData.GetFiles(d).Where(p => Path.GetExtension(p) == ".json"));
                foreach (var themeFile in themeFiles)
                {
                    themes[Path.GetFileNameWithoutExtension(themeFile)] = themeFile;
                }

                foreach (var directoryTheme in StaticData.Instance.GetDirectories(themesPath).Where(d => Path.GetFileName(d) != "Menus").Select(d => new DirectoryTheme(d)))
                {
                    ThemeProviders.Add(directoryTheme.Name, directoryTheme);
                }
            }

            // Load theme
            try
            {
                if (File.Exists(ProfileManager.Instance.ProfileThemeSetPath))
                {
                    themeset = JsonConvert.DeserializeObject <ThemeSet>(File.ReadAllText(ProfileManager.Instance.ProfileThemeSetPath));
                    themeset.Theme.EnsureDefaults();

                    // If the serialized format is older than the current format, null and fall back to latest default below
                    if (themeset.SchemeVersion != ThemeSet.LatestSchemeVersion)
                    {
                        themeset = null;
                    }
                }
            }
            catch { }

            if (themeset == null)
            {
                var themeProvider = ThemeProviders["Modern"];
                themeset = themeProvider.GetTheme("Modern-Dark");
            }

            ScrollBar.DefaultThumbView.ThumbColor = new Color(themeset.Theme.TextColor, 30);

            ToolTipManager.CreateToolTip = MatterControlToolTipWidget;
        }
示例#2
0
        public static void SetTheme(ThemeSet themeSet)
        {
            themeset = themeSet;

            File.WriteAllText(
                ProfileManager.Instance.ProfileThemeSetPath,
                JsonConvert.SerializeObject(
                    themeset,
                    Formatting.Indented,
                    new JsonSerializerSettings
            {
                ContractResolver = new ThemeContractResolver()
            }));

            UiThread.RunOnIdle(() =>
            {
                UserSettings.Instance.set(UserSettingsKey.ActiveThemeName, themeset.Name);

                // Explicitly fire ReloadAll in response to user interaction
                ApplicationController.Instance.ReloadAll().ConfigureAwait(false);
            });
        }