예제 #1
0
        public void TextViewCreated(IWpfTextView textView)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IEditorFormatMap formatMap = FormatMapService.GetEditorFormatMap(textView);

            ResourceDictionary mplContent      = formatMap.GetProperties("MplContent");
            ResourceDictionary mplCodeBrackets = formatMap.GetProperties("MplCodeBrackets");

            if (MplPackage.Options.SolarizedTheme)
            {
                if (MplPackage.Options.DarkThemesList.Contains(MplPackage.GetThemeName()))
                {
                    //dark theme
                    textView.Background = Constants.backgroundDarkBrush;
                }
                else
                {
                    //light theme
                    textView.Background = Constants.backgroundLightBrush;
                }

                formatMap.BeginBatchUpdate();

                mplContent[EditorFormatDefinition.ForegroundColorId] = MplPackage.MplContentColor;
                mplContent[EditorFormatDefinition.ForegroundBrushId] = new SolidColorBrush(MplPackage.MplContentColor);
                formatMap.SetProperties("MplContent", mplContent);

                mplCodeBrackets[EditorFormatDefinition.ForegroundColorId] = MplPackage.MplEmphasizedColor;
                mplCodeBrackets[EditorFormatDefinition.ForegroundBrushId] = new SolidColorBrush(MplPackage.MplEmphasizedColor);
                formatMap.SetProperties("MplCodeBrackets", mplCodeBrackets);

                formatMap.EndBatchUpdate();
            }
        }
예제 #2
0
        private static void UpdateEditorColors(IEditorFormatMap formatMap)
        {
            try
            {
                formatMap.BeginBatchUpdate();
                foreach (var pair in ThemeColors.EditorColors)
                {
                    var type  = pair.Key;
                    var color = pair.Value;

                    var property = formatMap.GetProperties(type);
                    if (property == null)
                    {
                        Error.LogError($"Cannot find editor format related to {type}", Module);
                        continue;
                    }

                    property.Remove("ForegroundColor");
                    property.Remove("BackgroundColor");
                    property.Add("ForegroundColor", color.Foreground);
                    property.Add("BackgroundColor", color.Background);

                    formatMap.SetProperties(type, property);
                }
            }
            finally
            {
                formatMap.EndBatchUpdate();
            }
        }
예제 #3
0
        static void ChangeEditorFormat(IEditorFormatMap formatMap, string propertyId, Action <System.Windows.ResourceDictionary> changer)
        {
            var m = formatMap.GetProperties(propertyId);

            if (m != null)
            {
                changer(m);
            }
            formatMap.SetProperties(propertyId, m);
        }
예제 #4
0
    //</Snippet3>

    //<Snippet4>
    public void TextViewCreated(IWpfTextView textView)
    {
        IEditorFormatMap formatMap = FormatMapService.GetEditorFormatMap(textView);

        ResourceDictionary regularCaretProperties   = formatMap.GetProperties("Caret");
        ResourceDictionary overwriteCaretProperties = formatMap.GetProperties("Overwrite Caret");
        ResourceDictionary indicatorMargin          = formatMap.GetProperties("Indicator Margin");
        ResourceDictionary visibleWhitespace        = formatMap.GetProperties("Visible Whitespace");
        ResourceDictionary selectedText             = formatMap.GetProperties("Selected Text");
        ResourceDictionary inactiveSelectedText     = formatMap.GetProperties("Inactive Selected Text");

        formatMap.BeginBatchUpdate();

        regularCaretProperties[EditorFormatDefinition.ForegroundBrushId] = Brushes.Magenta;
        formatMap.SetProperties("Caret", regularCaretProperties);

        overwriteCaretProperties[EditorFormatDefinition.ForegroundBrushId] = Brushes.Turquoise;
        formatMap.SetProperties("Overwrite Caret", overwriteCaretProperties);

        indicatorMargin[EditorFormatDefinition.BackgroundColorId] = Colors.LightGreen;
        formatMap.SetProperties("Indicator Margin", indicatorMargin);

        visibleWhitespace[EditorFormatDefinition.ForegroundColorId] = Colors.Red;
        formatMap.SetProperties("Visible Whitespace", visibleWhitespace);

        selectedText[EditorFormatDefinition.BackgroundBrushId] = Brushes.LightPink;
        formatMap.SetProperties("Selected Text", selectedText);

        inactiveSelectedText[EditorFormatDefinition.BackgroundBrushId] = Brushes.DeepPink;
        formatMap.SetProperties("Inactive Selected Text", inactiveSelectedText);

        formatMap.EndBatchUpdate();
    }
        void SetGradientBrush()
        {
            // Change the selected text properties to use a gradient brush and an outline pen
            var properties = formatMap.GetProperties("Selected Text");

            bool modified = false;

            if (properties[EditorFormatDefinition.BackgroundBrushId] != gradientBrush)
            {
                modified = true;
                properties[EditorFormatDefinition.BackgroundBrushId] = gradientBrush;
            }
            if (properties["BackgroundPen"] != gradientBorder)
            {
                modified = true;
                properties["BackgroundPen"] = gradientBorder;
            }

            if (modified)
            {
                formatMap.SetProperties("Selected Text", properties);
            }
        }
        void InitializeAll()
        {
            bool callBeginEndUpdate = !editorFormatMap.IsInBatchUpdate;

            if (callBeginEndUpdate)
            {
                editorFormatMap.BeginBatchUpdate();
            }

            var theme     = themeService.Theme;
            var textProps = textAppearanceCategory.CreateResourceDictionary(theme);
            var winbg     = textProps[EditorFormatMapConstants.TextViewBackgroundId] as Brush ?? SystemColors.WindowBrush;
            var winbgRes  = editorFormatMap.GetProperties(EditorFormatMapConstants.TextViewBackgroundId);

            if (winbgRes[EditorFormatDefinition.BackgroundBrushId] != winbg)
            {
                winbgRes[EditorFormatDefinition.BackgroundBrushId] = winbg;
                editorFormatMap.SetProperties(EditorFormatMapConstants.TextViewBackgroundId, winbgRes);
            }

            foreach (var t in GetEditorFormatDefinitions())
            {
                var key   = t.Item1.Name;
                var props = t.Item2.CreateThemeResourceDictionary(theme);
                editorFormatMap.SetProperties(key, props);
            }

            var ptDict = CreatePlainTextDictionary(textProps);

            editorFormatMap.SetProperties(EditorFormatMapConstants.PlainText, ptDict);

            if (callBeginEndUpdate)
            {
                editorFormatMap.EndBatchUpdate();
            }
        }
예제 #7
0
 public void SetProperties(string key, ResourceDictionary properties)
 {
     viewProps.Add(key);
     categoryMap.SetProperties(key, properties);
 }