/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); VisualStudioModule.Initialize((DTE)GetService(typeof(DTE))); }
/// <summary> /// Creates a touch control /// </summary> /// <param name="entryCommand"></param> /// <param name="parentWindow"></param> public TouchControl(TouchBranchCommand entryCommand, Window parentWindow) { InitializeComponent(); initializeBrushes(); var segmentAmount = entryCommand.Commands.Count(); int index = 0; foreach (var command in entryCommand.Commands) { // Slice shape: var segment = TouchControlShapeFactory.GetSegment(segmentAmount, index); var path = new Path() { Data = segment, }; touchCanvas.Children.Add(path); // Invisible border that holds and centers the text label: var border = new Border() { Width = TEXT_AVAILABLE_WIDTH, Height = TEXT_AVAILABLE_HEIGHT, IsHitTestVisible = false, }; var textCenter = TouchControlShapeFactory.GetTextPosition(segmentAmount, index); Canvas.SetLeft(border, textCenter.X - TEXT_AVAILABLE_WIDTH / 2); Canvas.SetRight(border, textCenter.X + TEXT_AVAILABLE_WIDTH / 2); Canvas.SetTop(border, textCenter.Y - TEXT_AVAILABLE_HEIGHT / 2); Canvas.SetBottom(border, textCenter.Y + TEXT_AVAILABLE_HEIGHT / 2); // The text label, centered inside the invisible border var text = new TextBlock() { Text = command.DisplayName, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; border.Child = text; touchCanvas.Children.Add(border); // Give action to the slice. Looking forward to using extended `is` expression in pattern matching (https://github.com/dotnet/roslyn/issues/206) var vsCommand = command as TouchVSCommand; var branchCommand = command as TouchBranchCommand; if (vsCommand != null) { path.TouchUp += (s, e) => { e.Handled = true; VisualStudioModule.ExecuteCommand(vsCommand.VsCommandName, vsCommand.VsCommandParams); parentWindow.Hide(); }; } else if (branchCommand != null) { path.TouchUp += (s, e) => { e.Handled = true; parentWindow.Hide(); Show(branchCommand, e); }; } index++; } }