Ejemplo n.º 1
0
        /// <summary>
        /// Invoke this method to apply a change of theme to the content of the document
        /// (eg: Adjust the highlighting colors when changing from "Dark" to "Light"
        ///      WITH current text document loaded.)
        /// </summary>
        internal void OnAppThemeChanged(IThemedHighlightingManager hlManager)
        {
            if (hlManager == null)
            {
                return;
            }

            // Does this highlighting definition have an associated highlighting theme?
            if (hlManager.CurrentTheme.HlTheme != null)
            {
                // A highlighting theme with GlobalStyles?
                // Apply these styles to the resource keys of the editor
                foreach (var item in hlManager.CurrentTheme.HlTheme.GlobalStyles)
                {
                    switch (item.TypeName)
                    {
                    case "DefaultStyle":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorBackground, item.backgroundcolor);
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorForeground, item.foregroundcolor);
                        break;

                    case "CurrentLineBackground":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorCurrentLineBackgroundBrushKey, item.backgroundcolor);
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorCurrentLineBorderBrushKey, item.bordercolor);
                        break;

                    case "LineNumbersForeground":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorLineNumbersForeground, item.foregroundcolor);
                        break;

                    case "Selection":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorSelectionBrush, item.backgroundcolor);
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorSelectionBorder, item.bordercolor);
                        break;

                    case "Hyperlink":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorLinkTextBackgroundBrush, item.backgroundcolor);
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorLinkTextForegroundBrush, item.foregroundcolor);
                        break;

                    case "NonPrintableCharacter":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorNonPrintableCharacterBrush, item.foregroundcolor);
                        break;

                    default:
                        throw new System.ArgumentOutOfRangeException("GlobalStyle named '{0}' is not supported.", item.TypeName);
                    }
                }
            }

            if (IsHighlightingDefinitionOff == true)
            {
                return;
            }

            // 1st try: Find highlighting based on currently selected highlighting
            // The highlighting name may be the same as before, but the highlighting theme has just changed
            if (HighlightingDefinition != null)
            {
                // Reset property for currently select highlighting definition
                HighlightingDefinition = hlManager.GetDefinition(HighlightingDefinition.Name);

                if (HighlightingDefinition != null)
                {
                    return;
                }
            }

            // 2nd try: Find highlighting based on extension of file currenlty being viewed
            if (string.IsNullOrEmpty(this.FileName))
            {
                return;
            }

            string extension = System.IO.Path.GetExtension(this.FileName);

            if (string.IsNullOrEmpty(extension))
            {
                return;
            }

            // Reset property for currently select highlighting definition
            HighlightingDefinition = hlManager.GetDefinitionByExtension(extension);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets a highlighting definition by name. Returns null if the definition is not found.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public IHighlightingDefinition GetDefinition(string name)
 {
     return(_hlManager.GetDefinition(name));
 }
        /// <summary>
        /// Invoke this method to apply a change of theme to the content of the document
        /// (eg: Adjust the highlighting colors when changing from "Dark" to "Light"
        ///      WITH current text document loaded.)
        /// </summary>
        internal void OnAppThemeChanged(IThemedHighlightingManager hlManager)
        {
            if (hlManager == null)
            {
                return;
            }

            // Does this highlighting definition have an associated highlighting theme?
            if (hlManager.CurrentTheme.HlTheme != null)
            {
                // A highlighting theme with GlobalStyles?
                // Apply these styles to the resource keys of the editor
                foreach (var item in hlManager.CurrentTheme.HlTheme.GlobalStyles)
                {
                    switch (item.TypeName)
                    {
                    case "DefaultStyle":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorBackground, item.backgroundcolor);
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorForeground, item.foregroundcolor);
                        break;

                    case "CurrentLineBackground":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorCurrentLineBackgroundBrushKey, item.backgroundcolor);
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorCurrentLineBorderBrushKey, item.bordercolor);
                        break;

                    case "LineNumbersForeground":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorLineNumbersForeground, item.foregroundcolor);
                        break;

//// Not changing selection color here since this should be controlled by current AccentColor via BindToMLib
                    case "Selection":
////							ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorSelectionBrush, item.backgroundcolor);
////							ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorSelectionBorder, item.bordercolor);
                        break;

                    case "Hyperlink":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorLinkTextBackgroundBrush, item.backgroundcolor);
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorLinkTextForegroundBrush, item.foregroundcolor);
                        break;

                    case "NonPrintableCharacter":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorNonPrintableCharacterBrush, item.foregroundcolor);
                        break;

                    default:
                        throw new System.ArgumentOutOfRangeException("GlobalStyle named '{0}' is not supported.", item.TypeName);
                    }
                }
            }

            // 1st try: Find highlighting based on currently selected highlighting
            // The highlighting name may be the same as before, but the highlighting theme has just changed
            if (HighlightingDefinition != null)
            {
                // Reset property for currently select highlighting definition
                HighlightingDefinition = hlManager.GetDefinition(HighlightingDefinition.Name);
                NotifyPropertyChanged(() => this.HighlightingDefinitions);

                if (HighlightingDefinition != null)
                {
                    return;
                }
            }

            // 2nd try: Find highlighting based on extension of file currenlty being viewed
            if (string.IsNullOrEmpty(FilePath))
            {
                // No file path is available -> no default highlighting
                HighlightingDefinition = null;
                NotifyPropertyChanged(() => this.HighlightingDefinitions);
                return;
            }

            string extension = System.IO.Path.GetExtension(FilePath);

            if (string.IsNullOrEmpty(extension))
            {
                // File path is available but no extension to speak of -> no default highlighting
                HighlightingDefinition = null;
                NotifyPropertyChanged(() => this.HighlightingDefinitions);
                return;
            }

            // Reset property for currently select highlighting definition
            HighlightingDefinition = hlManager.GetDefinitionByExtension(extension);
            NotifyPropertyChanged(() => this.HighlightingDefinitions);
        }