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

Commit 53abd60

Browse files
committed
Show custom notifications for cloned repos too
Now both creating and cloning show messages with the url of the repository, plus a link to create or open a project/solution, depending on the situation. If it's a created repo, link to the Create dialog. If it's a cloned repo that doesn't have commits, link to the Create dialog. If it's a cloned repo that has commits, link to the Open dialog.
1 parent 3cf7b2a commit 53abd60

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
namespace GitHub.VisualStudio.Helpers
22
{
3-
public static class Constants
3+
internal static class Constants
44
{
55
public const string NoAngleBracketsErrorMessage = "Failed to parse signature - Neither `name` nor `email` should contain angle brackets chars.";
66
public const int MaxRepositoryNameLength = 100;
77
public const int MaxDirectoryLength = 200; // Windows allows 248, but we need to allow room for subdirectories.
88
public const int MaxFilePathLength = 260;
9+
10+
public const string Notification_RepoCreated = "[{0}](u:{1}) has been successfully created.";
11+
public const string Notification_RepoCloned = "[{0}](u:{1}) has been successfully cloned.";
12+
public const string Notification_CreateNewProject = "[Create a new project or solution](c:{0})";
13+
public const string Notification_OpenProject = "[Open an existing project or solution](o:{0})";
914
}
1015
}

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

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,15 @@ async void UpdateRepositoryList(object sender, NotifyCollectionChangedEventArgs
197197
if (isCloning || isCreating)
198198
{
199199
var newrepo = e.NewItems.Cast<ISimpleRepositoryModel>().First();
200+
200201
SelectedRepository = newrepo;
201202
if (isCreating)
202203
HandleCreatedRepo(newrepo);
204+
else
205+
HandleClonedRepo(newrepo);
203206

204-
// if we've cloned a repo but the user didn't open a project in it,
205-
// then update the newly-cloned repo icon because we're not going to
206-
// switch to the TE home page
207-
if ((isCloning && !OpenRepository()) || isCreating)
208-
{
209-
var repo = await ApiFactory.Create(newrepo.CloneUrl).GetRepository();
210-
newrepo.SetIcon(repo.Private, repo.Fork);
211-
}
207+
var repo = await ApiFactory.Create(newrepo.CloneUrl).GetRepository();
208+
newrepo.SetIcon(repo.Private, repo.Fork);
212209
}
213210
// looks like it's just a refresh with new stuff on the list, update the icons
214211
else
@@ -227,24 +224,55 @@ async void UpdateRepositoryList(object sender, NotifyCollectionChangedEventArgs
227224
}
228225

229226
void HandleCreatedRepo(ISimpleRepositoryModel newrepo)
227+
{
228+
var msg = string.Format(CultureInfo.CurrentUICulture, Constants.Notification_RepoCreated, newrepo.Name, newrepo.CloneUrl);
229+
msg += " " + string.Format(CultureInfo.CurrentUICulture, Constants.Notification_CreateNewProject, newrepo.LocalPath);
230+
ShowNotification(newrepo, msg);
231+
}
232+
233+
void HandleClonedRepo(ISimpleRepositoryModel newrepo)
234+
{
235+
var msg = string.Format(CultureInfo.CurrentUICulture, Constants.Notification_RepoCloned, newrepo.Name, newrepo.CloneUrl);
236+
if (newrepo.HasCommits())
237+
msg += " " + string.Format(CultureInfo.CurrentUICulture, Constants.Notification_OpenProject, newrepo.LocalPath);
238+
else
239+
msg += " " + string.Format(CultureInfo.CurrentUICulture, Constants.Notification_CreateNewProject, newrepo.LocalPath);
240+
ShowNotification(newrepo, msg);
241+
}
242+
243+
void ShowNotification(ISimpleRepositoryModel newrepo, string msg)
230244
{
231245
var vsservices = ServiceProvider.GetExportedValue<IVSServices>();
232246
vsservices.ClearNotifications();
233247
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),
248+
msg,
235249
new RelayCommand((o) =>
236250
{
237251
var str = o.ToString();
252+
/* the prefix is the action to perform:
253+
* u: launch browser with url
254+
* c: launch create new project dialog
255+
* o: launch open existing project dialog
256+
*/
238257
var prefix = str.Substring(0, 2);
239258
if (prefix == "u:")
240259
OpenInBrowser(ServiceProvider.TryGetService<IVisualStudioBrowser>(), new Uri(str.Substring(2)));
241-
else if (prefix == "p:")
260+
else if (prefix == "o:")
242261
{
243262
if (ErrorHandler.Succeeded(ServiceProvider.GetSolution().OpenSolutionViaDlg(str.Substring(2), 1)))
244263
ServiceProvider.TryGetService<ITeamExplorer>()?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
245264
}
265+
else if (prefix == "c:")
266+
{
267+
vsservices.SetDefaultProjectPath(newrepo.LocalPath);
268+
if (ErrorHandler.Succeeded(ServiceProvider.GetSolution().CreateNewProjectViaDlg(null, null, 0)))
269+
ServiceProvider.TryGetService<ITeamExplorer>()?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
270+
}
246271
})
247272
);
273+
#if DEBUG
274+
VsOutputLogger.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0} Notification", DateTime.Now));
275+
#endif
248276
}
249277

250278
void RefreshRepositories()
@@ -356,11 +384,18 @@ public SectionStateTracker(ITeamExplorerSection section, Action onRefreshed)
356384

357385
section.PropertyChanged += TrackState;
358386
}
359-
387+
#if DEBUG
388+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
389+
#endif
360390
void TrackState(object sender, PropertyChangedEventArgs e)
361391
{
362392
if (machine.PermittedTriggers.Contains(e.PropertyName))
393+
{
394+
#if DEBUG
395+
VsOutputLogger.WriteLine(String.Format(CultureInfo.InvariantCulture, "{3} {0} title:{1} busy:{2}", e.PropertyName, ((ITeamExplorerSection)sender).Title, ((ITeamExplorerSection)sender).IsBusy, DateTime.Now));
396+
#endif
363397
machine.Fire(e.PropertyName);
398+
}
364399
}
365400
}
366401
}

0 commit comments

Comments
 (0)