|
2 | 2 | using Microsoft.TeamFoundation.Controls.WPF; |
3 | 3 | using Microsoft.TeamFoundation.Controls.WPF.TeamExplorer; |
4 | 4 | using Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.Framework; |
| 5 | +using Microsoft.VisualStudio.ProjectSystem.VS.Interop; |
5 | 6 | using System; |
6 | 7 | using System.Collections.Generic; |
7 | 8 | using System.ComponentModel; |
8 | 9 | using System.Linq; |
| 10 | +using System.Windows; |
9 | 11 | using System.Windows.Automation.Peers; |
10 | 12 | using System.Windows.Automation.Provider; |
11 | 13 | using System.Windows.Controls; |
@@ -51,15 +53,37 @@ public override void Loaded(object sender, SectionLoadedEventArgs e) |
51 | 53 | commitButton = view.FindName("commitButton") as Button; |
52 | 54 | var commitGrid = commitButton.Parent as Grid; |
53 | 55 |
|
| 56 | + var commitCzButton = createCommitCzButton(teamExplorer); |
| 57 | + AppendButtonToPage(commitGrid, commitCzButton); |
| 58 | + } |
| 59 | + |
| 60 | + private void AppendButtonToPage(Grid commitGrid, Button commitCzButton) |
| 61 | + { |
| 62 | + if (isVs2019()) |
| 63 | + commitGrid.Children.OfType<WrapPanel>().First().Children.Insert(0, commitCzButton); |
| 64 | + else |
| 65 | + { |
| 66 | + commitCzButton.Margin = new Thickness(12, 0, 0, 0); |
| 67 | + commitGrid.Children.Insert(1, commitCzButton); |
| 68 | + Grid.SetColumn(commitCzButton, 1); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + private static Button createCommitCzButton(ITeamExplorer teamExplorer) |
| 73 | + { |
54 | 74 | var commitCzButton = new Button(); |
55 | 75 | commitCzButton.Content = "CommitCz"; |
56 | | - commitCzButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; |
57 | | - commitCzButton.Margin = new System.Windows.Thickness(12, 0, 0, 0); |
| 76 | + commitCzButton.HorizontalAlignment = HorizontalAlignment.Center; |
58 | 77 | commitCzButton.Click += (s, re) => teamExplorer.NavigateToPage(Guid.Parse(VsCommitizenPage.PageId), null); |
59 | | - commitGrid.Children.Add(commitCzButton); |
| 78 | + return commitCzButton; |
| 79 | + } |
| 80 | + |
| 81 | + private bool isVs2019() |
| 82 | + { |
| 83 | + var vsAppId = GetService<IVsAppId>(); |
| 84 | + vsAppId.GetProperty((int)VSAPropID.VSAPROPID_ProductSemanticVersion, out var semanticVersionObj); |
60 | 85 |
|
61 | | - // Place the button on the right of the Commit button |
62 | | - Grid.SetColumn(commitCzButton, 1); |
| 86 | + return (semanticVersionObj?.ToString().StartsWith("16.")).GetValueOrDefault(false); |
63 | 87 | } |
64 | 88 |
|
65 | 89 | private void TeamExplorerPageBasePropertyChanged(object sender, PropertyChangedEventArgs e) |
|
0 commit comments