|
4 | 4 | */ |
5 | 5 | using System; |
6 | 6 | using System.ComponentModel; |
| 7 | +using System.Globalization; |
| 8 | +using System.Reactive.Linq; |
7 | 9 | using System.Windows.Input; |
8 | 10 | using GitHub.Factories; |
| 11 | +using GitHub.Models; |
9 | 12 | using GitHub.Primitives; |
10 | 13 | using GitHub.ViewModels.TeamExplorer; |
11 | 14 | using Microsoft.TeamFoundation.Controls; |
12 | 15 | using Microsoft.VisualStudio.ComponentModelHost; |
13 | 16 | using GitHub.VisualStudio; |
| 17 | +using GitHub.VisualStudio.UI; |
14 | 18 | using Microsoft.VisualStudio.Threading; |
| 19 | +using ReactiveUI; |
15 | 20 | using Task = System.Threading.Tasks.Task; |
16 | 21 |
|
17 | 22 | namespace Microsoft.TeamExplorerSample.Sync |
@@ -86,16 +91,93 @@ async Task DoPublishToGitHub() |
86 | 91 |
|
87 | 92 | void ShowPublishDialog(IComponentModel componentModel) |
88 | 93 | { |
| 94 | + /* |
| 95 | + var factory = ServiceProvider.GetService<IViewViewModelFactory>(); |
| 96 | + var viewModel = ServiceProvider.GetService<IRepositoryPublishViewModel>(); |
| 97 | + */ |
| 98 | + |
89 | 99 | var compositionServices = new CompositionServices(); |
90 | 100 | var compositionContainer = compositionServices.CreateVisualStudioCompositionContainer(componentModel.DefaultExportProvider); |
91 | 101 |
|
92 | 102 | var factory = compositionContainer.GetExportedValue<IViewViewModelFactory>(); |
93 | 103 | var viewModel = compositionContainer.GetExportedValue<IRepositoryPublishViewModel>(); |
94 | 104 |
|
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; |
97 | 128 |
|
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 | +// ); |
99 | 181 | } |
100 | 182 |
|
101 | 183 |
|
|
0 commit comments