Esempio n. 1
0
        private void ProcessLine(SnapshotSpan span)
        {
            var textMarkerGeometry = _textView.TextViewLines.GetTextMarkerGeometry(span);

            if (textMarkerGeometry == null)
            {
                return;
            }

            var bounds = textMarkerGeometry.Bounds;

            VisualToolset visualTools = _isTextViewActive ? _activeVisualToolset : _inactiveVisualToolset;
            var           geometry    = new RectangleGeometry(new Rect(0, bounds.Top, _lastWidth, (int)(bounds.Height + 0.5)));

            DrawHighlight(geometry, visualTools, span);
        }
Esempio n. 2
0
        private void DrawHighlight(Geometry g, VisualToolset visualTools, SnapshotSpan span)
        {
            if (g.CanFreeze)
            {
                g.Freeze();
            }

            var            dv       = new DrawingVisual();
            DrawingContext dContext = dv.RenderOpen();

            dContext.DrawGeometry(visualTools.Brush, visualTools.Pen, g);
            dContext.Close();

            var uiElement = new DrawingVisualHost(dv);

            _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, new object(), uiElement, null);
        }
        private void OnFormatMappingChanged(object sender, FormatItemsEventArgs e) {
            if (e.ChangedItems.Contains(ActiveSelectionPropertiesName)) {
                _activeVisualToolset = CreateVisualToolset(ActiveSelectionPropertiesName, SystemColors.HighlightColor);

                if (_isTextViewActive) {
                    Redraw();
                }
            }

            if (e.ChangedItems.Contains(InactiveSelectionPropertiesName)) {
                _inactiveVisualToolset = CreateVisualToolset(InactiveSelectionPropertiesName, SystemColors.GrayTextColor);

                if (!_isTextViewActive) {
                    Redraw();
                }
            }
        }
Esempio n. 4
0
        private VisualToolset CreateVisualToolset(string category, Color defaultColor)
        {
            var dictionary = _editorFormatMap.GetProperties(category);
            var toolset    = new VisualToolset();

            if (dictionary.Contains(EditorFormatDefinition.BackgroundBrushId))
            {
                toolset.Brush = ((Brush)(dictionary[EditorFormatDefinition.BackgroundBrushId])).Clone();
            }
            else if (dictionary.Contains(EditorFormatDefinition.BackgroundColorId))
            {
                toolset.Brush = new SolidColorBrush((Color)dictionary[EditorFormatDefinition.BackgroundColorId]);
            }
            else
            {
                toolset.Brush = new SolidColorBrush(defaultColor);
            }

            if (toolset.Brush.CanFreeze)
            {
                toolset.Brush.Freeze();
            }

            const string penResourceName = "BackgroundPen";

            if (_textView.Options.IsSimpleGraphicsEnabled() || !dictionary.Contains(penResourceName))
            {
                var useReducedOpacityForHighContrast = _textView.Options.GetOptionValue(DefaultWpfViewOptions.UseReducedOpacityForHighContrastOptionId);

                // Layer opacity should match selection painters
                _layer.Opacity = (useReducedOpacityForHighContrast || !SystemParameters.HighContrast) && (toolset.Brush is SolidColorBrush) ? 0.4 : 1;
                return(toolset);
            }

            toolset.Pen = ((Pen)dictionary[penResourceName]).Clone();

            if (toolset.Pen.CanFreeze)
            {
                toolset.Pen.Freeze();
            }

            _layer.Opacity = 1;
            return(toolset);
        }
        public HistorySelectionTextAdornment(IWpfTextView textView, IEditorFormatMapService editorFormatMapService, IRHistoryProvider historyProvider) {
            _textView = textView;
            _layer = textView.GetAdornmentLayer("HistorySelectionTextAdornment");

            _editorFormatMap = editorFormatMapService.GetEditorFormatMap(_textView);
            _history = historyProvider.GetAssociatedRHistory(_textView);

            // Advise to events
            _editorFormatMap.FormatMappingChanged += OnFormatMappingChanged;
            _textView.VisualElement.GotKeyboardFocus += OnGotKeyboardFocus;
            _textView.VisualElement.LostKeyboardFocus += OnLostKeyboardFocus;
            _textView.LayoutChanged += OnLayoutChanged;
            _textView.Closed += OnClosed;
            _history.SelectionChanged += OnSelectionChanged;

            _activeVisualToolset = CreateVisualToolset(ActiveSelectionPropertiesName, SystemColors.HighlightColor);
            _inactiveVisualToolset = CreateVisualToolset(InactiveSelectionPropertiesName, SystemColors.GrayTextColor);
            Redraw();
        }
Esempio n. 6
0
        public HistorySelectionTextAdornment(IWpfTextView textView, IEditorFormatMapService editorFormatMapService, IRHistoryProvider historyProvider)
        {
            _textView = textView;
            _layer    = textView.GetAdornmentLayer("HistorySelectionTextAdornment");

            _editorFormatMap = editorFormatMapService.GetEditorFormatMap(_textView);
            _history         = historyProvider.GetAssociatedRHistory(_textView);

            // Advise to events
            _editorFormatMap.FormatMappingChanged     += OnFormatMappingChanged;
            _textView.VisualElement.GotKeyboardFocus  += OnGotKeyboardFocus;
            _textView.VisualElement.LostKeyboardFocus += OnLostKeyboardFocus;
            _textView.LayoutChanged   += OnLayoutChanged;
            _textView.Closed          += OnClosed;
            _history.SelectionChanged += OnSelectionChanged;

            _activeVisualToolset   = CreateVisualToolset(ActiveSelectionPropertiesName, SystemColors.HighlightColor);
            _inactiveVisualToolset = CreateVisualToolset(InactiveSelectionPropertiesName, SystemColors.GrayTextColor);
            Redraw();
        }
Esempio n. 7
0
        private void OnFormatMappingChanged(object sender, FormatItemsEventArgs e)
        {
            if (e.ChangedItems.Contains(ActiveSelectionPropertiesName))
            {
                _activeVisualToolset = CreateVisualToolset(ActiveSelectionPropertiesName, SystemColors.HighlightColor);

                if (_isTextViewActive)
                {
                    Redraw();
                }
            }

            if (e.ChangedItems.Contains(InactiveSelectionPropertiesName))
            {
                _inactiveVisualToolset = CreateVisualToolset(InactiveSelectionPropertiesName, SystemColors.GrayTextColor);

                if (!_isTextViewActive)
                {
                    Redraw();
                }
            }
        }
        private VisualToolset CreateVisualToolset(string category, Color defaultColor) {
            var dictionary = _editorFormatMap.GetProperties(category);
            var toolset = new VisualToolset();

            if (dictionary.Contains(EditorFormatDefinition.BackgroundBrushId)) {
                toolset.Brush = ((Brush) (dictionary[EditorFormatDefinition.BackgroundBrushId])).Clone();
            } else if (dictionary.Contains(EditorFormatDefinition.BackgroundColorId)) { 
                toolset.Brush = new SolidColorBrush((Color) dictionary[EditorFormatDefinition.BackgroundColorId]);
            } else {
               toolset.Brush = new SolidColorBrush(defaultColor);
            }

            if (toolset.Brush.CanFreeze) {
                toolset.Brush.Freeze();
            }

            const string penResourceName = "BackgroundPen";
            if (_textView.Options.IsSimpleGraphicsEnabled() || !dictionary.Contains(penResourceName)) {
                var useReducedOpacityForHighContrast = _textView.Options.GetOptionValue(DefaultWpfViewOptions.UseReducedOpacityForHighContrastOptionId);
                
                // Layer opacity should match selection painters
                _layer.Opacity = (useReducedOpacityForHighContrast || !SystemParameters.HighContrast) && (toolset.Brush is SolidColorBrush) ? 0.4 : 1;
                return toolset;
            }

            toolset.Pen = ((Pen)dictionary[penResourceName]).Clone();

            if (toolset.Pen.CanFreeze) {
                toolset.Pen.Freeze();
            }

            _layer.Opacity = 1;
            return toolset;
        }
        private void DrawHighlight(Geometry g, VisualToolset visualTools, SnapshotSpan span) {
            if (g.CanFreeze) {
                g.Freeze();
            }

            var dv = new DrawingVisual();
            DrawingContext dContext = dv.RenderOpen();
            dContext.DrawGeometry(visualTools.Brush, visualTools.Pen, g);
            dContext.Close();

            var uiElement = new DrawingVisualHost(dv);

            _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, new object(), uiElement, null);
        }