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

Commit 1e8e35d

Browse files
committed
Use ITeamExplorerServices.OpenRepository
Stop the `How would you like to get started?` dialog from appearing when a repository is double clicked on. Convert GitHubConnectSection to use ITeamExplorerServices.OpenRepository instead of IVSServices.TryOpenRepository to change repository context. This method knows how to change context for Visual Studio 2015, 2017 and 2019.
1 parent 394bcc0 commit 1e8e35d

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
using System.Collections.Specialized;
33
using System.ComponentModel;
44
using System.Globalization;
5+
using System.IO;
56
using System.Linq;
6-
using System.Reactive;
77
using System.Reactive.Linq;
8-
using System.Reactive.Subjects;
98
using System.Threading.Tasks;
109
using System.Windows.Input;
1110
using GitHub.Api;
@@ -15,7 +14,6 @@
1514
using GitHub.Primitives;
1615
using GitHub.Services;
1716
using GitHub.Settings;
18-
using GitHub.UI;
1917
using GitHub.VisualStudio.Base;
2018
using GitHub.VisualStudio.Helpers;
2119
using GitHub.VisualStudio.UI;
@@ -31,7 +29,7 @@ public class GitHubConnectSection : TeamExplorerSectionBase, IGitHubConnectSecti
3129
{
3230
static readonly ILogger log = LogManager.ForContext<GitHubConnectSection>();
3331
readonly IPackageSettings packageSettings;
34-
readonly IVSServices vsServices;
32+
readonly ITeamExplorerServices teamExplorerServices;
3533
readonly int sectionIndex;
3634
readonly ILocalRepositories localRepositories;
3735
readonly IUsageTracker usageTracker;
@@ -110,7 +108,7 @@ public GitHubConnectSection(IGitHubServiceProvider serviceProvider,
110108
ITeamExplorerServiceHolder holder,
111109
IConnectionManager manager,
112110
IPackageSettings packageSettings,
113-
IVSServices vsServices,
111+
ITeamExplorerServices teamExplorerServices,
114112
ILocalRepositories localRepositories,
115113
IUsageTracker usageTracker,
116114
int index)
@@ -120,7 +118,7 @@ public GitHubConnectSection(IGitHubServiceProvider serviceProvider,
120118
Guard.ArgumentNotNull(holder, nameof(holder));
121119
Guard.ArgumentNotNull(manager, nameof(manager));
122120
Guard.ArgumentNotNull(packageSettings, nameof(packageSettings));
123-
Guard.ArgumentNotNull(vsServices, nameof(vsServices));
121+
Guard.ArgumentNotNull(teamExplorerServices, nameof(teamExplorerServices));
124122
Guard.ArgumentNotNull(localRepositories, nameof(localRepositories));
125123
Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));
126124

@@ -130,7 +128,7 @@ public GitHubConnectSection(IGitHubServiceProvider serviceProvider,
130128
sectionIndex = index;
131129

132130
this.packageSettings = packageSettings;
133-
this.vsServices = vsServices;
131+
this.teamExplorerServices = teamExplorerServices;
134132
this.localRepositories = localRepositories;
135133
this.usageTracker = usageTracker;
136134

@@ -462,15 +460,27 @@ public bool OpenRepository()
462460
var old = Repositories.FirstOrDefault(x => x.Equals(Holder.ActiveRepo));
463461
if (!Equals(SelectedRepository, old))
464462
{
465-
var opened = vsServices.TryOpenRepository(SelectedRepository.LocalPath);
466-
if (!opened)
463+
try
467464
{
468-
// TryOpenRepository might fail because dir no longer exists. Let user find solution themselves.
469-
opened = ErrorHandler.Succeeded(ServiceProvider.GetSolution().OpenSolutionViaDlg(SelectedRepository.LocalPath, 1));
470-
if (!opened)
465+
var repositoryPath = SelectedRepository.LocalPath;
466+
if (Directory.Exists(repositoryPath))
471467
{
472-
return false;
468+
teamExplorerServices.OpenRepository(SelectedRepository.LocalPath);
473469
}
470+
else
471+
{
472+
// If directory no longer exists, let user find solution themselves
473+
var opened = ErrorHandler.Succeeded(ServiceProvider.GetSolution().OpenSolutionViaDlg(SelectedRepository.LocalPath, 1));
474+
if (!opened)
475+
{
476+
return false;
477+
}
478+
}
479+
}
480+
catch (Exception e)
481+
{
482+
log.Error(e, nameof(OpenRepository));
483+
return false;
474484
}
475485
}
476486

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public GitHubConnectSection0(IGitHubServiceProvider serviceProvider,
1818
ITeamExplorerServiceHolder holder,
1919
IConnectionManager manager,
2020
IPackageSettings settings,
21-
IVSServices vsServices,
21+
ITeamExplorerServices teamExplorerServices,
2222
ILocalRepositories localRepositories,
2323
IUsageTracker usageTracker)
24-
: base(serviceProvider, apiFactory, holder, manager, settings, vsServices, localRepositories, usageTracker, 0)
24+
: base(serviceProvider, apiFactory, holder, manager, settings, teamExplorerServices, localRepositories, usageTracker, 0)
2525
{
2626
}
2727
}

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public GitHubConnectSection1(IGitHubServiceProvider serviceProvider,
1818
ITeamExplorerServiceHolder holder,
1919
IConnectionManager manager,
2020
IPackageSettings settings,
21-
IVSServices vsServices,
21+
ITeamExplorerServices teamExplorerServices,
2222
ILocalRepositories localRepositories,
2323
IUsageTracker usageTracker)
24-
: base(serviceProvider, apiFactory, holder, manager, settings, vsServices, localRepositories, usageTracker, 1)
24+
: base(serviceProvider, apiFactory, holder, manager, settings, teamExplorerServices, localRepositories, usageTracker, 1)
2525
{
2626
}
2727
}

0 commit comments

Comments
 (0)