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

Commit 126a894

Browse files
authored
Merge pull request #2360 from github/essentials-publish
Adding Publish to Essentials extension
2 parents f1dc7d3 + aacbaa7 commit 126a894

23 files changed

+1056
-152
lines changed

src/GitHub.App/SampleData/SampleViewModels.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ public ReactiveCommand<Unit, ProgressState> PublishRepository
214214
private set;
215215
}
216216

217+
public ReactiveCommand<Unit, Unit> LoginAsDifferentUser
218+
{
219+
get;
220+
private set;
221+
}
222+
217223
public IReadOnlyObservableCollection<IConnection> Connections
218224
{
219225
get;

src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Linq;
77
using System.Reactive;
88
using System.Reactive.Linq;
9-
using GitHub.App;
9+
using System.Threading.Tasks;
1010
using GitHub.Extensions;
1111
using GitHub.Extensions.Reactive;
1212
using GitHub.Factories;
@@ -29,6 +29,7 @@ public class RepositoryPublishViewModel : RepositoryFormViewModel, IRepositoryPu
2929
readonly IRepositoryPublishService repositoryPublishService;
3030
readonly INotificationService notificationService;
3131
readonly IModelServiceFactory modelServiceFactory;
32+
readonly IDialogService dialogService;
3233
readonly ObservableAsPropertyHelper<IReadOnlyList<IAccount>> accounts;
3334
readonly ObservableAsPropertyHelper<bool> isHostComboBoxVisible;
3435
readonly IUsageTracker usageTracker;
@@ -39,17 +40,20 @@ public RepositoryPublishViewModel(
3940
INotificationService notificationService,
4041
IConnectionManager connectionManager,
4142
IModelServiceFactory modelServiceFactory,
43+
IDialogService dialogService,
4244
IUsageTracker usageTracker)
4345
{
4446
Guard.ArgumentNotNull(repositoryPublishService, nameof(repositoryPublishService));
4547
Guard.ArgumentNotNull(notificationService, nameof(notificationService));
4648
Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
4749
Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));
4850
Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
51+
Guard.ArgumentNotNull(dialogService, nameof(dialogService));
4952

5053
this.notificationService = notificationService;
5154
this.usageTracker = usageTracker;
5255
this.modelServiceFactory = modelServiceFactory;
56+
this.dialogService = dialogService;
5357

5458
Connections = connectionManager.Connections;
5559
this.repositoryPublishService = repositoryPublishService;
@@ -83,6 +87,8 @@ public RepositoryPublishViewModel(
8387
PublishRepository = InitializePublishRepositoryCommand();
8488
PublishRepository.IsExecuting.Subscribe(x => IsBusy = x);
8589

90+
LoginAsDifferentUser = ReactiveCommand.CreateFromTask(LoginAsDifferentUserAsync);
91+
8692
var defaultRepositoryName = repositoryPublishService.LocalRepositoryName;
8793
if (!string.IsNullOrEmpty(defaultRepositoryName))
8894
RepositoryName = defaultRepositoryName;
@@ -101,6 +107,9 @@ public RepositoryPublishViewModel(
101107
}
102108

103109
public ReactiveCommand<Unit, ProgressState> PublishRepository { get; private set; }
110+
111+
public ReactiveCommand<Unit, Unit> LoginAsDifferentUser { get; private set; }
112+
104113
public IReadOnlyObservableCollection<IConnection> Connections { get; private set; }
105114

106115
bool isBusy;
@@ -127,6 +136,14 @@ public bool IsHostComboBoxVisible
127136
get { return isHostComboBoxVisible.Value; }
128137
}
129138

139+
async Task LoginAsDifferentUserAsync()
140+
{
141+
if (await dialogService.ShowLoginDialog() is IConnection connection)
142+
{
143+
SelectedConnection = connection;
144+
}
145+
}
146+
130147
ReactiveCommand<Unit, ProgressState> InitializePublishRepositoryCommand()
131148
{
132149
var canCreate = this.WhenAny(x => x.RepositoryNameValidator.ValidationResult.IsValid, x => x.Value);

src/GitHub.Exports.Reactive/ViewModels/TeamExplorer/IRepositoryPublishViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public interface IRepositoryPublishViewModel : IViewModel, IRepositoryForm
1919
/// </summary>
2020
ReactiveCommand<Unit, ProgressState> PublishRepository { get; }
2121

22+
/// <summary>
23+
/// Command that shows login dialog.
24+
/// </summary>
25+
ReactiveCommand<Unit, Unit> LoginAsDifferentUser { get; }
26+
2227
/// <summary>
2328
/// Determines whether the host combo box is visible. Only true if the user is logged into more than one host.
2429
/// </summary>
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved. This code released
3+
* under the terms of the Microsoft Limited Public License (MS-LPL).
4+
*/
5+
using System;
6+
using System.ComponentModel;
7+
using System.Diagnostics;
8+
using Microsoft.TeamFoundation.Client;
9+
using Microsoft.TeamFoundation.Controls;
10+
11+
namespace GitHub.VisualStudio
12+
{
13+
/// <summary>
14+
/// Team Explorer plugin common base class.
15+
/// </summary>
16+
public class TeamExplorerBase : IDisposable, INotifyPropertyChanged
17+
{
18+
#region Members
19+
20+
private bool m_contextSubscribed = false;
21+
22+
#endregion
23+
24+
/// <summary>
25+
/// Get/set the service provider.
26+
/// </summary>
27+
public IServiceProvider ServiceProvider
28+
{
29+
get { return m_serviceProvider; }
30+
set
31+
{
32+
// Unsubscribe from Team Foundation context changes
33+
if (m_serviceProvider != null)
34+
{
35+
UnsubscribeContextChanges();
36+
}
37+
38+
m_serviceProvider = value;
39+
40+
// Subscribe to Team Foundation context changes
41+
if (m_serviceProvider != null)
42+
{
43+
SubscribeContextChanges();
44+
}
45+
}
46+
}
47+
private IServiceProvider m_serviceProvider = null;
48+
49+
/// <summary>
50+
/// Get the requested service from the service provider.
51+
/// </summary>
52+
public T GetService<T>()
53+
{
54+
Debug.Assert(this.ServiceProvider != null, "GetService<T> called before service provider is set");
55+
if (this.ServiceProvider != null)
56+
{
57+
return (T)this.ServiceProvider.GetService(typeof(T));
58+
}
59+
60+
return default(T);
61+
}
62+
63+
/// <summary>
64+
/// Show a notification in the Team Explorer window.
65+
/// </summary>
66+
protected Guid ShowNotification(string message, NotificationType type)
67+
{
68+
ITeamExplorer teamExplorer = GetService<ITeamExplorer>();
69+
if (teamExplorer != null)
70+
{
71+
Guid guid = Guid.NewGuid();
72+
teamExplorer.ShowNotification(message, type, NotificationFlags.None, null, guid);
73+
return guid;
74+
}
75+
76+
return Guid.Empty;
77+
}
78+
79+
#region IDisposable
80+
81+
/// <summary>
82+
/// Dispose.
83+
/// </summary>
84+
public virtual void Dispose()
85+
{
86+
UnsubscribeContextChanges();
87+
}
88+
89+
#endregion
90+
91+
#region INotifyPropertyChanged
92+
93+
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
94+
95+
/// <summary>
96+
/// Raise the PropertyChanged event for the specified property.
97+
/// </summary>
98+
/// <param name="propertyName">Property name</param>
99+
protected void RaisePropertyChanged(string propertyName)
100+
{
101+
if (this.PropertyChanged != null)
102+
{
103+
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
104+
}
105+
}
106+
107+
#endregion
108+
109+
#region Team Foundation Context
110+
111+
/// <summary>
112+
/// Subscribe to context changes.
113+
/// </summary>
114+
protected void SubscribeContextChanges()
115+
{
116+
Debug.Assert(this.ServiceProvider != null, "ServiceProvider must be set before subscribing to context changes");
117+
if (this.ServiceProvider == null || m_contextSubscribed)
118+
{
119+
return;
120+
}
121+
122+
ITeamFoundationContextManager tfContextManager = GetService<ITeamFoundationContextManager>();
123+
if (tfContextManager != null)
124+
{
125+
tfContextManager.ContextChanged += ContextChanged;
126+
m_contextSubscribed = true;
127+
}
128+
}
129+
130+
/// <summary>
131+
/// Unsubscribe from context changes.
132+
/// </summary>
133+
protected void UnsubscribeContextChanges()
134+
{
135+
if (this.ServiceProvider == null || !m_contextSubscribed)
136+
{
137+
return;
138+
}
139+
140+
ITeamFoundationContextManager tfContextManager = GetService<ITeamFoundationContextManager>();
141+
if (tfContextManager != null)
142+
{
143+
tfContextManager.ContextChanged -= ContextChanged;
144+
}
145+
}
146+
147+
/// <summary>
148+
/// ContextChanged event handler.
149+
/// </summary>
150+
protected virtual void ContextChanged(object sender, ContextChangedEventArgs e)
151+
{
152+
}
153+
154+
/// <summary>
155+
/// Get the current Team Foundation context.
156+
/// </summary>
157+
protected ITeamFoundationContext CurrentContext
158+
{
159+
get
160+
{
161+
ITeamFoundationContextManager tfContextManager = GetService<ITeamFoundationContextManager>();
162+
if (tfContextManager != null)
163+
{
164+
return tfContextManager.CurrentContext;
165+
}
166+
167+
return null;
168+
}
169+
}
170+
171+
#endregion
172+
}
173+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved. This code released
3+
* under the terms of the Microsoft Limited Public License (MS-LPL).
4+
*/
5+
using System;
6+
using System.ComponentModel.Composition;
7+
using Microsoft.TeamFoundation.Controls;
8+
using Microsoft.VisualStudio.Shell;
9+
10+
namespace GitHub.VisualStudio
11+
{
12+
/// <summary>
13+
/// Team Explorer base navigation item class.
14+
/// </summary>
15+
public class TeamExplorerBaseNavigationItem : TeamExplorerBase, ITeamExplorerNavigationItem
16+
{
17+
/// <summary>
18+
/// Constructor.
19+
/// </summary>
20+
public TeamExplorerBaseNavigationItem(IServiceProvider serviceProvider)
21+
{
22+
this.ServiceProvider = serviceProvider;
23+
}
24+
25+
#region ITeamExplorerNavigationItem
26+
27+
/// <summary>
28+
/// Get/set the item text.
29+
/// </summary>
30+
public string Text
31+
{
32+
get { return m_text; }
33+
set { m_text = value; RaisePropertyChanged("Text"); }
34+
}
35+
private string m_text;
36+
37+
/// <summary>
38+
/// Get/set the item image.
39+
/// </summary>
40+
public System.Drawing.Image Image
41+
{
42+
get { return m_image; }
43+
set { m_image = value; RaisePropertyChanged("Image"); }
44+
}
45+
private System.Drawing.Image m_image;
46+
47+
/// <summary>
48+
/// Get/set the IsVisible flag.
49+
/// </summary>
50+
public bool IsVisible
51+
{
52+
get { return m_isVisible; }
53+
set { m_isVisible = value; RaisePropertyChanged("IsVisible"); }
54+
}
55+
private bool m_isVisible = true;
56+
57+
/// <summary>
58+
/// Invalidate the item state.
59+
/// </summary>
60+
public virtual void Invalidate()
61+
{
62+
}
63+
64+
/// <summary>
65+
/// Execute the item action.
66+
/// </summary>
67+
public virtual void Execute()
68+
{
69+
}
70+
71+
#endregion
72+
}
73+
}

0 commit comments

Comments
 (0)