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

Commit 07bbffc

Browse files
Loading more of the Publish functionality
co-authored-by: Jamie Cansdale <[email protected]>
1 parent 1507ada commit 07bbffc

File tree

1 file changed

+85
-3
lines changed

1 file changed

+85
-3
lines changed

src/GitHub.VisualStudio.16/Sync/PublishSection.cs

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
*/
55
using System;
66
using System.ComponentModel;
7+
using System.Globalization;
8+
using System.Reactive.Linq;
79
using System.Windows.Input;
810
using GitHub.Factories;
11+
using GitHub.Models;
912
using GitHub.Primitives;
1013
using GitHub.ViewModels.TeamExplorer;
1114
using Microsoft.TeamFoundation.Controls;
1215
using Microsoft.VisualStudio.ComponentModelHost;
1316
using GitHub.VisualStudio;
17+
using GitHub.VisualStudio.UI;
1418
using Microsoft.VisualStudio.Threading;
19+
using ReactiveUI;
1520
using Task = System.Threading.Tasks.Task;
1621

1722
namespace Microsoft.TeamExplorerSample.Sync
@@ -86,16 +91,93 @@ async Task DoPublishToGitHub()
8691

8792
void ShowPublishDialog(IComponentModel componentModel)
8893
{
94+
/*
95+
var factory = ServiceProvider.GetService<IViewViewModelFactory>();
96+
var viewModel = ServiceProvider.GetService<IRepositoryPublishViewModel>();
97+
*/
98+
8999
var compositionServices = new CompositionServices();
90100
var compositionContainer = compositionServices.CreateVisualStudioCompositionContainer(componentModel.DefaultExportProvider);
91101

92102
var factory = compositionContainer.GetExportedValue<IViewViewModelFactory>();
93103
var viewModel = compositionContainer.GetExportedValue<IRepositoryPublishViewModel>();
94104

95-
var frameworkElement = factory.CreateView<IRepositoryPublishViewModel>();
96-
frameworkElement.DataContext = viewModel;
105+
var busy = viewModel.WhenAnyValue(x => x.IsBusy).Subscribe(x => IsBusy = x);
106+
107+
var completed = viewModel.PublishRepository
108+
.Where(x => x == ProgressState.Success)
109+
.Subscribe(_ =>
110+
{
111+
var teamExplorer =
112+
VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(ITeamExplorer)) as ITeamExplorer;
113+
teamExplorer?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
114+
115+
// HandleCreatedRepo(ActiveRepo);
116+
});
117+
118+
var view = factory.CreateView<IRepositoryPublishViewModel>();
119+
view.DataContext = viewModel;
120+
121+
SectionContent = view;
122+
123+
/*
124+
125+
var view = factory.CreateView<IRepositoryPublishViewModel>();
126+
view.DataContext = viewModel;
127+
SectionContent = view;
97128
98-
this.SectionContent = frameworkElement;
129+
Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(
130+
x => view.Unloaded += x,
131+
x => view.Unloaded -= x)
132+
.Take(1)
133+
.Subscribe(_ =>
134+
{
135+
busy.Dispose();
136+
completed.Dispose();
137+
});
138+
139+
*/
140+
}
141+
142+
void HandleCreatedRepo(LocalRepositoryModel newrepo)
143+
{
144+
var msg = String.Format(CultureInfo.CurrentCulture, Constants.Notification_RepoCreated, newrepo.Name, newrepo.CloneUrl);
145+
msg += " " + String.Format(CultureInfo.CurrentCulture, Constants.Notification_CreateNewProject, newrepo.LocalPath);
146+
ShowNotification(newrepo, msg);
147+
}
148+
149+
private void ShowNotification(LocalRepositoryModel newrepo, string msg)
150+
{
151+
// var teServices = ServiceProvider.TryGetService<ITeamExplorerServices>();
152+
//
153+
// teServices.ClearNotifications();
154+
// teServices.ShowMessage(
155+
// msg,
156+
// new RelayCommand(o =>
157+
// {
158+
// var str = o.ToString();
159+
// /* the prefix is the action to perform:
160+
// * u: launch browser with url
161+
// * c: launch create new project dialog
162+
// * o: launch open existing project dialog
163+
// */
164+
// var prefix = str.Substring(0, 2);
165+
// if (prefix == "u:")
166+
// OpenInBrowser(ServiceProvider.TryGetService<IVisualStudioBrowser>(), new Uri(str.Substring(2)));
167+
// else if (prefix == "o:")
168+
// {
169+
// if (ErrorHandler.Succeeded(ServiceProvider.GetSolution().OpenSolutionViaDlg(str.Substring(2), 1)))
170+
// ServiceProvider.TryGetService<ITeamExplorer>()?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
171+
// }
172+
// else if (prefix == "c:")
173+
// {
174+
// var vsGitServices = ServiceProvider.TryGetService<IVSGitServices>();
175+
// vsGitServices.SetDefaultProjectPath(newrepo.LocalPath);
176+
// if (ErrorHandler.Succeeded(ServiceProvider.GetSolution().CreateNewProjectViaDlg(null, null, 0)))
177+
// ServiceProvider.TryGetService<ITeamExplorer>()?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
178+
// }
179+
// })
180+
// );
99181
}
100182

101183

0 commit comments

Comments
 (0)