Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 37b888e

Browse files
committed
Change the way the connect section is shown
So we can start fixing #371 and also show the list of github repos in the connect area.
1 parent 06562db commit 37b888e

File tree

5 files changed

+72
-11
lines changed

5 files changed

+72
-11
lines changed

src/GitHub.Exports/Services/VSExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using GitHub.Services;
2+
using Microsoft.TeamFoundation.Controls;
23
using System;
34
using System.Diagnostics;
45

@@ -34,5 +35,10 @@ public static T GetService<T>(this IServiceProvider serviceProvider)
3435
{
3536
return (T)serviceProvider.GetService(typeof(T));
3637
}
38+
39+
public static ITeamExplorerSection GetSection(this IServiceProvider serviceProvider, Guid section)
40+
{
41+
return serviceProvider?.GetService<ITeamExplorerPage>()?.GetSection(section);
42+
}
3743
}
3844
}

src/GitHub.VisualStudio/Base/TeamExplorerInvitationBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace GitHub.VisualStudio.Base
77
{
88
public class TeamExplorerInvitationBase : TeamExplorerBase, ITeamExplorerServiceInvitation, INotifyPropertySource
99
{
10+
public static readonly Guid TeamExplorerInvitationSectionGuid = new Guid("8914ac06-d960-4537-8345-cb13c00378d8");
11+
1012
public virtual void Initialize(IServiceProvider serviceProvider)
1113
{
1214
ServiceProvider = serviceProvider;

src/GitHub.VisualStudio/TeamExplorer/Connect/GitHubConnectSection.cs

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using GitHub.Api;
1+
using System;
2+
using GitHub.Api;
23
using GitHub.Models;
34
using GitHub.Services;
45
using GitHub.UI;
6+
using GitHub.Extensions;
57
using GitHub.VisualStudio.Base;
68
using GitHub.VisualStudio.UI.Views;
79
using Microsoft.TeamFoundation.Controls;
810
using System.Collections.Specialized;
11+
using GitHub.VisualStudio.Helpers;
912

1013
namespace GitHub.VisualStudio.TeamExplorer.Connect
1114
{
@@ -21,13 +24,38 @@ protected GitHubConnectContent View
2124

2225
protected IConnection SectionConnection { get; set; }
2326

27+
bool loggedIn;
28+
bool LoggedIn
29+
{
30+
get { return loggedIn; }
31+
set {
32+
loggedIn = ShowLogout = value;
33+
ShowLogin = !value;
34+
}
35+
}
36+
37+
bool showLogin;
38+
public bool ShowLogin
39+
{
40+
get { return showLogin; }
41+
set { showLogin = value; this.RaisePropertyChange(); }
42+
}
43+
44+
bool showLogout;
45+
public bool ShowLogout
46+
{
47+
get { return showLogout; }
48+
set { showLogout = value; this.RaisePropertyChange(); }
49+
}
50+
2451
public GitHubConnectSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder, IConnectionManager manager, int index)
2552
: base(apiFactory, holder, manager)
2653
{
2754
Title = "GitHub";
2855
IsEnabled = true;
2956
IsVisible = false;
3057
IsExpanded = true;
58+
LoggedIn = false;
3159

3260
sectionIndex = index;
3361

@@ -55,13 +83,26 @@ protected void Refresh(IConnection connection)
5583
{
5684
if (connection == null)
5785
{
86+
LoggedIn = false;
5887
IsVisible = false;
88+
if (sectionIndex == 0 && ServiceProvider != null)
89+
{
90+
var section = ServiceProvider?.GetSection(TeamExplorerInvitationBase.TeamExplorerInvitationSectionGuid);
91+
IsVisible = !(section?.IsVisible ?? true); // only show this when the invitation section is hidden. When in doubt, don't show it.
92+
if (section != null)
93+
section.PropertyChanged += (s, p) =>
94+
{
95+
if (p.PropertyName == "IsVisible")
96+
IsVisible = LoggedIn || !((ITeamExplorerSection)s).IsVisible;
97+
};
98+
}
5999
}
60100
else if (SectionConnection != connection)
61101
{
62102
SectionConnection = connection;
63103
Title = connection.HostAddress.Title;
64104
IsVisible = true;
105+
LoggedIn = true;
65106
}
66107
}
67108

@@ -74,27 +115,21 @@ public override void Refresh()
74115
public override void Initialize(object sender, SectionInitializeEventArgs e)
75116
{
76117
base.Initialize(sender, e);
77-
78-
// when we start up the connection list is loaded before we can get notifications so refresh manually
79-
if (SectionConnection == null && connectionManager.Connections.Count > sectionIndex)
80-
Refresh(connectionManager.Connections[sectionIndex]);
118+
UpdateConnection();
81119
}
82120

83121
void UpdateConnection()
84122
{
85123
if (connectionManager.Connections.Count > sectionIndex)
86124
Refresh(connectionManager.Connections[sectionIndex]);
87125
else
88-
Refresh(null);
126+
Refresh(SectionConnection);
89127
}
90128

91129
void OnPropertyChange(object sender, System.ComponentModel.PropertyChangedEventArgs e)
92130
{
93131
if (e.PropertyName == "IsVisible" && IsVisible && View == null)
94-
{
95-
View = new GitHubConnectContent();
96-
View.ViewModel = this;
97-
}
132+
View = new GitHubConnectContent() { DataContext = this };
98133
}
99134

100135
public void DoCreate()
@@ -116,6 +151,11 @@ public void SignOut()
116151
SectionConnection.Logout();
117152
}
118153

154+
public void Login()
155+
{
156+
StartFlow(UIControllerFlow.Authentication);
157+
}
158+
119159
void StartFlow(UIControllerFlow controllerFlow)
120160
{
121161
var uiProvider = ServiceProvider.GetExportedValue<IUIProvider>();

src/GitHub.VisualStudio/UI/Views/GitHubConnectContent.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio;component/SharedDictionary.xaml" />
1919
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
2020
</ResourceDictionary.MergedDictionaries>
21+
<ui:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
2122
<Style TargetType="Label">
2223
<Setter Property="Foreground" Value="{DynamicResource VsBrush.GrayText}" />
2324
<Setter Property="Padding" Value="0" />
@@ -30,7 +31,10 @@
3031
<Label Margin="3 0 3 0">|</Label>
3132
<Button Style="{StaticResource ActionLinkButton}" KeyboardNavigation.TabIndex="1" x:Name="createLink" Click="createLink_Click">Create</Button>
3233
<Label Margin="3 0 3 0">|</Label>
33-
<Button Style="{StaticResource ActionLinkButton}" KeyboardNavigation.TabIndex="2" x:Name="signOut" Click="signOut_Click">Sign out</Button>
34+
<Button Style="{StaticResource ActionLinkButton}" KeyboardNavigation.TabIndex="2" x:Name="signOut" Click="signOut_Click"
35+
Visibility="{Binding ShowLogout, Converter={StaticResource BooleanToVisibilityConverter}}">Sign out</Button>
36+
<Button Style="{StaticResource ActionLinkButton}" KeyboardNavigation.TabIndex="2" x:Name="login" Click="login_Click"
37+
Visibility="{Binding ShowLogin, Converter={StaticResource BooleanToVisibilityConverter}}">Login</Button>
3438
</WrapPanel>
3539
</Grid>
3640
</UserControl>

src/GitHub.VisualStudio/UI/Views/GitHubConnectContent.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public partial class GitHubConnectContent : UserControl
1414
public GitHubConnectContent()
1515
{
1616
InitializeComponent();
17+
18+
DataContextChanged += (s, e) => ViewModel = e.NewValue as GitHubConnectSection;
1719
}
1820

1921
void cloneLink_Click(object sender, RoutedEventArgs e)
@@ -37,6 +39,13 @@ void signOut_Click(object sender, RoutedEventArgs e)
3739
signOut.IsEnabled = true;
3840
}
3941

42+
private void login_Click(object sender, RoutedEventArgs e)
43+
{
44+
login.IsEnabled = false;
45+
ViewModel.Login();
46+
login.IsEnabled = true;
47+
}
48+
4049
public GitHubConnectSection ViewModel
4150
{
4251
get { return (GitHubConnectSection)GetValue(ViewModelProperty); }

0 commit comments

Comments
 (0)