示例#1
0
        public GlyphMarginVisualManager(IWpfTextView textView, IGlyphFactory <TGlyphTag> glyphFactory, Grid glyphMarginGrid,
                                        IEditorFormatMap editorFormatMap, string marginPropertiesName)
        {
            this.textView             = textView;
            this.marginPropertiesName = marginPropertiesName;
            this.editorFormatMap      = editorFormatMap;
            this.editorFormatMap.FormatMappingChanged += OnFormatMappingChanged;
            this.textView.Closed += new EventHandler(OnTextViewClosed);
            this.glyphFactory     = glyphFactory;
            this.glyphMarginGrid  = glyphMarginGrid;
            UpdateBackgroundColor();

            glyphs  = new Dictionary <UIElement, GlyphData <TGlyphTag> >();
            visuals = new Dictionary <Type, Canvas>();

            foreach (Type type in glyphFactory.GetTagTypes())
            {
                if (!visuals.ContainsKey(type))
                {
                    var element = new Canvas();
                    element.ClipToBounds = true;
                    glyphMarginGrid.Children.Add(element);
                    visuals[type] = element;
                }
            }
        }
示例#2
0
        public GlyphMargin(
            IWpfTextViewHost wpfTextViewHost,
            IGlyphFactory <TGlyphTag> glyphFactory,
            Func <Grid> gridFactory,
            ITagAggregator <TGlyphTag> tagAggregator,
            IEditorFormatMap editorFormatMap,
            Func <ITextBuffer, bool> isMarginVisible,
            string marginPropertiesName, string marginName, bool handleZoom = true, double marginWidth = 17.0)
        {
            textView             = wpfTextViewHost.TextView;
            this.tagAggregator   = tagAggregator;
            this.isMarginVisible = isMarginVisible;
            this.marginName      = marginName;
            this.handleZoom      = handleZoom;
            this.marginWidth     = marginWidth;

            marginVisual       = gridFactory();
            marginVisual.Width = marginWidth;

            visualManager = new GlyphMarginVisualManager <TGlyphTag>(textView, glyphFactory, marginVisual,
                                                                     this, editorFormatMap, marginPropertiesName);

            // Do on Loaded to give diff view a chance to initialize.
            marginVisual.Loaded += OnLoaded;
        }
        IWpfTextViewMargin CreateMargin <TGlyphTag>(IGlyphFactory <TGlyphTag> glyphFactory, Func <Grid> gridFactory,
                                                    IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin parent, IEditorFormatMap editorFormatMap) where TGlyphTag : ITag
        {
            var tagAggregator = tagAggregatorFactory.CreateTagAggregator <TGlyphTag>(wpfTextViewHost.TextView);

            return(new GlyphMargin <TGlyphTag>(wpfTextViewHost, glyphFactory, gridFactory, tagAggregator, editorFormatMap,
                                               IsMarginVisible, MarginPropertiesName, MarginName, true, 17.0));
        }
示例#4
0
 public GlyphFactoryInfo(int order, IGlyphFactory factory, IGlyphFactoryProvider glyphFactoryProvider)
 {
     Order           = order;
     Factory         = factory ?? throw new ArgumentNullException(nameof(factory));
     FactoryProvider = glyphFactoryProvider ?? throw new ArgumentNullException(nameof(glyphFactoryProvider));
     Canvas          = new Canvas {
         Background = Brushes.Transparent
     };
 }
示例#5
0
        IWpfTextViewMargin CreateMargin <TGlyphTag>(IGlyphFactory <TGlyphTag> glyphFactory, Func <Grid> gridFactory,
                                                    IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin parent, IEditorFormatMap editorFormatMap) where TGlyphTag : ITag
        {
            var tagAggregator = tagAggregatorFactory.CreateTagAggregator <TGlyphTag>(wpfTextViewHost.TextView);
            var margin        = new GlyphMargin <TGlyphTag>(wpfTextViewHost, glyphFactory, gridFactory, tagAggregator, editorFormatMap,
                                                            IsMarginVisible, MarginPropertiesName, MarginName, true, 17.0);

            TrackCommentGlyphOnDiffView(wpfTextViewHost, margin.VisualElement);
            return(margin);
        }
示例#6
0
 public GlyphFactoryInfo(int order, IGlyphFactory factory)
 {
     if (factory == null)
     {
         throw new ArgumentNullException(nameof(factory));
     }
     Order   = order;
     Factory = factory;
     Canvas  = new Canvas {
         Background = Brushes.Transparent
     };
 }
示例#7
0
        public GlyphMargin(
            IWpfTextView textView,
            IGlyphFactory <TGlyphTag> glyphFactory,
            Grid marginGrid,
            IViewTagAggregatorFactoryService tagAggregatorFactory,
            IEditorFormatMap editorFormatMap,
            string marginPropertiesName)
        {
            this.textView             = textView;
            this.marginGrid           = marginGrid;
            this.tagAggregatorFactory = tagAggregatorFactory;
            visualManager             = new GlyphMarginVisualManager <TGlyphTag>(textView, glyphFactory, marginGrid, editorFormatMap, marginPropertiesName);

            // Initialize when first visible
            visibleSubscription = marginGrid.WhenAnyValue(x => x.IsVisible).Distinct().Where(x => x).Subscribe(_ => Initialize());
        }
示例#8
0
        Dictionary <Type, GlyphFactoryInfo> CreateGlyphFactories()
        {
            var dict        = new Dictionary <Type, GlyphFactoryInfo>();
            var contentType = wpfTextViewHost.TextView.TextDataModel.ContentType;
            int order       = 0;

            foreach (var lazy in lazyGlyphFactoryProviders)
            {
                if (!contentType.IsOfAnyType(lazy.Metadata.ContentTypes))
                {
                    continue;
                }
                IGlyphFactory glyphFactory = null;
                foreach (var type in lazy.Metadata.TagTypes)
                {
                    Debug.Assert(type != null);
                    if (type == null)
                    {
                        break;
                    }
                    Debug.Assert(!dict.ContainsKey(type));
                    if (dict.ContainsKey(type))
                    {
                        continue;
                    }
                    Debug.Assert(typeof(IGlyphTag).IsAssignableFrom(type));
                    if (!typeof(IGlyphTag).IsAssignableFrom(type))
                    {
                        continue;
                    }

                    if (glyphFactory == null)
                    {
                        glyphFactory = lazy.Value.GetGlyphFactory(wpfTextViewHost.TextView, this);
                        if (glyphFactory == null)
                        {
                            break;
                        }
                    }

                    dict.Add(type, new GlyphFactoryInfo(order++, glyphFactory));
                }
            }
            return(dict);
        }
示例#9
0
        void InitializeGlyphFactories(IContentType beforeContentType, IContentType afterContentType)
        {
            var oldFactories = new Dictionary <IGlyphFactoryProvider, IGlyphFactory>();

            foreach (var info in glyphFactories.Values)
            {
                oldFactories[info.FactoryProvider] = info.Factory;
            }
            glyphFactories.Clear();

            bool newFactory = false;
            int  order      = 0;

            foreach (var lazy in lazyGlyphFactoryProviders)
            {
                if (!afterContentType.IsOfAnyType(lazy.Metadata.ContentTypes))
                {
                    continue;
                }
                IGlyphFactory glyphFactory = null;
                foreach (var type in lazy.Metadata.TagTypes)
                {
                    Debug.Assert(type != null);
                    if (type == null)
                    {
                        break;
                    }
                    Debug.Assert(!glyphFactories.ContainsKey(type));
                    if (glyphFactories.ContainsKey(type))
                    {
                        continue;
                    }
                    Debug.Assert(typeof(IGlyphTag).IsAssignableFrom(type));
                    if (!typeof(IGlyphTag).IsAssignableFrom(type))
                    {
                        continue;
                    }

                    if (glyphFactory == null)
                    {
                        if (oldFactories.TryGetValue(lazy.Value, out glyphFactory))
                        {
                            oldFactories.Remove(lazy.Value);
                        }
                        else
                        {
                            glyphFactory = lazy.Value.GetGlyphFactory(wpfTextViewHost.TextView, this);
                            if (glyphFactory == null)
                            {
                                break;
                            }
                            newFactory = true;
                        }
                    }

                    glyphFactories.Add(type, new GlyphFactoryInfo(order++, glyphFactory, lazy.Value));
                }
            }

            foreach (var factory in oldFactories.Values)
            {
                (factory as IDisposable)?.Dispose();
            }
            if (newFactory || oldFactories.Count != 0)
            {
                childCanvases = glyphFactories.Values.OrderBy(a => a.Order).Select(a => a.Canvas).ToArray();
                iconCanvas.Children.Clear();
                foreach (var c in childCanvases)
                {
                    iconCanvas.Children.Add(c);
                }

                if (beforeContentType != null)
                {
                    RefreshEverything();
                }
            }
        }
 public void SetUp()
 {
     glyphFactory = new PeerReviewGlyphFactory();
 }
示例#11
0
			public GlyphFactoryInfo(int order, IGlyphFactory factory, IGlyphFactoryProvider glyphFactoryProvider) {
				if (factory == null)
					throw new ArgumentNullException(nameof(factory));
				if (glyphFactoryProvider == null)
					throw new ArgumentNullException(nameof(glyphFactoryProvider));
				Order = order;
				Factory = factory;
				FactoryProvider = glyphFactoryProvider;
				Canvas = new Canvas { Background = Brushes.Transparent };
			}