Ejemplo n.º 1
0
        public static DrawingBrush GetDrawingForIcon(Octicon icon, Brush colorBrush, string theme = null)
        {
            string name = icon.ToString();

            if (theme != null)
            {
                name += "_" + theme;
            }
            if (drawingBrushes.ContainsKey(name))
            {
                return(drawingBrushes[name]);
            }

            var brush = new DrawingBrush()
            {
                Drawing = new GeometryDrawing()
                {
                    Brush    = colorBrush,
                    Geometry = OcticonPath.GetGeometryForIcon(icon).FreezeThis()
                }
                .FreezeThis(),
                Stretch = Stretch.Uniform
            }
            .FreezeThis();

            drawingBrushes.Add(name, brush);
            return(brush);
        }
        void InitializeChangesSectionCommands()
        {
            // As far as I can tell, SectionControl.SectionCommands is only available in Team
            // Foundation 15 and greater - except that it's also available in VS2015 somehow!
            // For the moment use reflection to try to get hold of the property.
            var sectionCommandsProperty = changesSection.GetType().GetProperty("SectionCommands");
            var commandType             = sectionCommandsProperty?
                                          .DeclaringType
                                          .Assembly
                                          .GetType("Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.TeamExplorerSectionCommand");
            var commandCtor = commandType?.GetConstructor(new[]
            {
                typeof(ICommand), typeof(string), typeof(object)
            });

            if (sectionCommandsProperty != null && commandCtor != null)
            {
                var list = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(commandType));

                var iconDrawing = new GeometryDrawing
                {
                    Geometry = OcticonPath.GetGeometryForIcon(Octicon.three_bars),
                };

                // I can't find a way to bind a DynamicResource to GeometryDrawing.Path, so bind the brush we
                // want to this.Foreground and bind GeometryDrawing.Path to that.
                var brushBinding = new Binding(nameof(Foreground));
                brushBinding.Source = this;
                BindingOperations.SetBinding(iconDrawing, GeometryDrawing.BrushProperty, brushBinding);

                var command = commandCtor.Invoke(new object[]
                {
                    OpenChangesOptionsMenu,
                    "Options",
                    new DrawingBrush
                    {
                        Drawing  = iconDrawing,
                        Viewport = new Rect(0.1, 0.1, 0.8, 0.8),
                    },
                });

                list.Add(command);
                sectionCommandsProperty.SetValue(changesSection, list);
            }
        }
        void InitializeChangesSectionCommands()
        {
            // As far as I can tell, SectionControl.SectionCommands is only available in Team
            // Foundation 15 and greater - except that it's also available in VS2015 somehow!
            // For the moment use reflection to try to get hold of the property.
            var sectionCommandsProperty = changesSection.GetType().GetProperty("SectionCommands");
            var commandType             = sectionCommandsProperty?
                                          .DeclaringType
                                          .Assembly
                                          .GetType("Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.TeamExplorerSectionCommand");
            var commandCtor = commandType?.GetConstructor(new[]
            {
                typeof(ICommand), typeof(string), typeof(object)
            });

            if (sectionCommandsProperty != null && commandCtor != null)
            {
                var list = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(commandType));

                var command = commandCtor.Invoke(new object[]
                {
                    OpenChangesOptionsMenu,
                    "Options",
                    new DrawingBrush
                    {
                        Drawing = new GeometryDrawing
                        {
                            Brush    = (Brush)FindResource("GitHubVsWindowText"),
                            Geometry = OcticonPath.GetGeometryForIcon(Octicon.three_bars),
                        },
                        Viewport = new Rect(0.1, 0.1, 0.8, 0.8),
                    },
                });

                list.Add(command);
                sectionCommandsProperty.SetValue(changesSection, list);
            }
        }
 private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     d.SetValue(Path.DataProperty, OcticonPath.GetGeometryForIcon((Octicon)e.NewValue));
 }