Пример #1
0
 public App()
 {
     HighlightingExtension.RegisterCustomHighlightingPatterns();
 }
Пример #2
0
        /// <summary>
        /// Change WPF theme.
        ///
        /// This method can be called when the theme is to be reseted by all means
        /// (eg.: when powering application up).
        ///
        /// !!! Use the CurrentTheme property to change !!!
        /// !!! the theme when App is running           !!!
        /// </summary>
        public void ResetTheme()
        {
            // Reset customized resources (if there are any from last change) and
            // enforce reload of original values from resource dictionary
            if (HighlightingManager.Instance.BackupDynResources != null)
            {
                try
                {
                    foreach (string t in HighlightingManager.Instance.BackupDynResources)
                    {
                        Application.Current.Resources[t] = null;
                    }
                }
                catch
                {
                }
                finally
                {
                    HighlightingManager.Instance.BackupDynResources = null;
                }
            }

            // Get WPF Theme definition from Themes Assembly
            ThemeBase nextThemeToSwitchTo = this.mThemesManager.SelectedTheme;

            this.SwitchToSelectedTheme(nextThemeToSwitchTo);

            // Backup highlighting names (if any) and restore highlighting associations after reloading highlighting definitions
            var HlNames = new List <string>();

            foreach (EdiViewModel f in this.Documents)
            {
                if (f != null)
                {
                    if (f.HighlightingDefinition != null)
                    {
                        HlNames.Add(f.HighlightingDefinition.Name);
                    }
                    else
                    {
                        HlNames.Add(null);
                    }
                }
            }

            // Is the current theme configured with a highlighting theme???
            ////this.Config.FindHighlightingTheme(
            HighlightingThemes hlThemes = nextThemeToSwitchTo.HighlightingStyles;

            // Re-load all highlighting patterns and re-apply highlightings
            HighlightingExtension.RegisterCustomHighlightingPatterns(hlThemes);

            //Re-apply highlightings after resetting highlighting manager
            List <EdiViewModel> l = this.Documents;

            for (int i = 0; i < l.Count; i++)
            {
                if (l[i] != null)
                {
                    if (HlNames[i] == null) // The highlighting is null if highlighting is switched off for this file(!)
                    {
                        continue;
                    }

                    IHighlightingDefinition hdef = HighlightingManager.Instance.GetDefinition(HlNames[i]);

                    if (hdef != null)
                    {
                        l[i].HighlightingDefinition = hdef;
                    }
                }
            }

            var backupDynResources = new List <string>();

            // Apply global styles to theming elements (dynamic resources in resource dictionary) of editor control
            if (HighlightingManager.Instance.HlThemes != null)
            {
                foreach (WidgetStyle w in HighlightingManager.Instance.HlThemes.GlobalStyles)
                {
                    ApplyWidgetStyle(w, backupDynResources);
                }
            }

            if (backupDynResources.Count > 0)
            {
                HighlightingManager.Instance.BackupDynResources = backupDynResources;
            }
        }
Пример #3
0
 internal static void InitSession()
 {
     HighlightingExtension.RegisterCustomHighlightingPatterns();
 }