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

Commit 57a9cad

Browse files
committed
Show a more useful create message
Instead of just showing the remote url of the new repo, show a link to create a new project or solution locally as well, so the user doesn't get stuck.
1 parent 8c727c4 commit 57a9cad

File tree

3 files changed

+71
-13
lines changed

3 files changed

+71
-13
lines changed

src/GitHub.Exports/Services/VSServices.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.VisualStudio.Shell.Interop;
1313
using System.Collections.Generic;
1414
using GitHub.Models;
15+
using System.Windows.Input;
1516

1617
namespace GitHub.Services
1718
{
@@ -25,6 +26,7 @@ public interface IVSServices
2526
string SetDefaultProjectPath(string path);
2627

2728
void ShowMessage(string message);
29+
void ShowMessage(string message, ICommand command);
2830
void ShowWarning(string message);
2931
void ShowError(string message);
3032
void ClearNotifications();
@@ -139,14 +141,39 @@ static string PokeTheRegistryForLocalClonePath()
139141
}
140142
}
141143

142-
const string PathsKey = @"Software\Microsoft\VisualStudio\14.0\NewProjectDialog\MRUSettingsLocalProjectLocationEntries";
144+
const string NewProjectDialogKeyPath = @"Software\Microsoft\VisualStudio\14.0\NewProjectDialog";
145+
const string MRUKeyPath = "MRUSettingsLocalProjectLocationEntries";
143146
public string SetDefaultProjectPath(string path)
144147
{
145148
string old;
146-
using (var key = Registry.CurrentUser.OpenSubKey(PathsKey, true))
149+
using (var newProjectKey = Registry.CurrentUser.OpenSubKey(NewProjectDialogKeyPath, true))
147150
{
148-
old = (string)key?.GetValue("Value0", string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);
149-
key?.SetValue("Value0", path, RegistryValueKind.String);
151+
using (var mruKey = newProjectKey?.OpenSubKey(MRUKeyPath, true))
152+
{
153+
if (mruKey == null)
154+
return String.Empty;
155+
156+
// is this already the default path? bail
157+
old = (string)mruKey.GetValue("Value0", string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);
158+
if (String.Equals(path.TrimEnd('\\'), old.TrimEnd('\\'), StringComparison.CurrentCultureIgnoreCase))
159+
return old;
160+
161+
// grab the existing list of recent paths, throwing away the last one
162+
var numEntries = (int)mruKey.GetValue("MaximumEntries", 5);
163+
var entries = new List<string>(numEntries);
164+
for (int i = 0; i < numEntries - 1; i++)
165+
{
166+
var val = (string)mruKey.GetValue("Value" + i, String.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);
167+
if (!String.IsNullOrEmpty(val))
168+
entries.Add(val);
169+
}
170+
171+
newProjectKey.SetValue("LastUsedNewProjectPath", path);
172+
mruKey.SetValue("Value0", path);
173+
// bump list of recent paths one entry down
174+
for (int i = 0; i < entries.Count; i++)
175+
mruKey.SetValue("Value" + (i+1), entries[i]);
176+
}
150177
}
151178
return old;
152179
}
@@ -158,6 +185,13 @@ public void ShowMessage(string message)
158185
manager.ShowNotification(message, NotificationType.Information, NotificationFlags.None, null, default(Guid));
159186
}
160187

188+
public void ShowMessage(string message, ICommand command)
189+
{
190+
var manager = serviceProvider.TryGetService<ITeamExplorer>() as ITeamExplorerNotificationManager;
191+
if (manager != null)
192+
manager.ShowNotification(message, NotificationType.Information, NotificationFlags.None, command, default(Guid));
193+
}
194+
161195
public void ShowWarning(string message)
162196
{
163197
var manager = serviceProvider.TryGetService<ITeamExplorer>() as ITeamExplorerNotificationManager;

src/GitHub.VisualStudio/Base/TeamExplorerBase.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ public Ret GetService<T, Ret>() where Ret : class
4444
return GetService<T>() as Ret;
4545
}
4646

47-
protected virtual void OpenInBrowser(Lazy<IVisualStudioBrowser> browser, Uri uri)
47+
protected void OpenInBrowser(Lazy<IVisualStudioBrowser> browser, Uri uri)
4848
{
49-
var b = browser.Value;
50-
Debug.Assert(b != null, "Could not create a browser helper instance.");
51-
b?.OpenUrl(uri);
49+
OpenInBrowser(browser.Value, uri);
50+
}
51+
52+
protected void OpenInBrowser(IVisualStudioBrowser browser, Uri uri)
53+
{
54+
Debug.Assert(browser != null, "Could not create a browser helper instance.");
55+
browser?.OpenUrl(uri);
5256
}
5357
}
5458
}

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using ReactiveUI;
1919
using GitHub.Exports;
2020
using System.Globalization;
21+
using Microsoft.TeamFoundation.MVVM;
22+
using GitHub.Primitives;
2123

2224
namespace GitHub.VisualStudio.TeamExplorer.Connect
2325
{
@@ -197,11 +199,8 @@ async void UpdateRepositoryList(object sender, NotifyCollectionChangedEventArgs
197199
var newrepo = e.NewItems.Cast<ISimpleRepositoryModel>().First();
198200
SelectedRepository = newrepo;
199201
if (isCreating)
200-
{
201-
var vsservices = ServiceProvider.GetExportedValue<IVSServices>();
202-
vsservices.ClearNotifications();
203-
vsservices.ShowMessage(string.Format(CultureInfo.CurrentUICulture, "[{0}]({1}) has been successfully created.", newrepo.Name, newrepo.CloneUrl));
204-
}
202+
HandleCreatedRepo(newrepo);
203+
205204
// if we've cloned a repo but the user didn't open a project in it,
206205
// then update the newly-cloned repo icon because we're not going to
207206
// switch to the TE home page
@@ -227,6 +226,27 @@ async void UpdateRepositoryList(object sender, NotifyCollectionChangedEventArgs
227226
}
228227
}
229228

229+
void HandleCreatedRepo(ISimpleRepositoryModel newrepo)
230+
{
231+
var vsservices = ServiceProvider.GetExportedValue<IVSServices>();
232+
vsservices.ClearNotifications();
233+
vsservices.ShowMessage(
234+
string.Format(CultureInfo.CurrentUICulture, "[{0}](u:{1}) has been successfully created. [Create a new project or solution](p:{2})", newrepo.Name, newrepo.CloneUrl, newrepo.LocalPath),
235+
new RelayCommand((o) =>
236+
{
237+
var str = o.ToString();
238+
var prefix = str.Substring(0, 2);
239+
if (prefix == "u:")
240+
OpenInBrowser(ServiceProvider.TryGetService<IVisualStudioBrowser>(), new Uri(str.Substring(2)));
241+
else if (prefix == "p:")
242+
{
243+
if (ErrorHandler.Succeeded(ServiceProvider.GetSolution().OpenSolutionViaDlg(str.Substring(2), 1)))
244+
ServiceProvider.TryGetService<ITeamExplorer>()?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
245+
}
246+
})
247+
);
248+
}
249+
230250
void RefreshRepositories()
231251
{
232252
connectionManager.RefreshRepositories();

0 commit comments

Comments
 (0)