Skip to content

Commit 4fe2cff

Browse files
authored
fix: stash button is hidden (#20)
1 parent f4e9fd1 commit 4fe2cff

File tree

5 files changed

+330
-5
lines changed

5 files changed

+330
-5
lines changed

vs-commitizen.vs2015/GitChangesSection.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
using Microsoft.TeamFoundation.Controls.WPF;
33
using Microsoft.TeamFoundation.Controls.WPF.TeamExplorer;
44
using Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.Framework;
5+
using Microsoft.VisualStudio.ProjectSystem.VS.Interop;
56
using System;
67
using System.Collections.Generic;
78
using System.ComponentModel;
89
using System.Linq;
10+
using System.Windows;
911
using System.Windows.Automation.Peers;
1012
using System.Windows.Automation.Provider;
1113
using System.Windows.Controls;
@@ -51,15 +53,37 @@ public override void Loaded(object sender, SectionLoadedEventArgs e)
5153
commitButton = view.FindName("commitButton") as Button;
5254
var commitGrid = commitButton.Parent as Grid;
5355

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+
{
5474
var commitCzButton = new Button();
5575
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;
5877
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);
6085

61-
// Place the button on the right of the Commit button
62-
Grid.SetColumn(commitCzButton, 1);
86+
return (semanticVersionObj?.ToString().StartsWith("16.")).GetValueOrDefault(false);
6387
}
6488

6589
private void TeamExplorerPageBasePropertyChanged(object sender, PropertyChangedEventArgs e)

0 commit comments

Comments
 (0)