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

Commit d06ba40

Browse files
committed
First try opening in active repository
This enables round tripping between `Copy link to clipboard` and `Open from GitHub`.
1 parent 39f3a54 commit d06ba40

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public GitHubContext FindContextFromWindowTitle(string windowTitle)
219219
return null;
220220
}
221221

222-
public bool TryOpenFile(GitHubContext context, string repositoryDir)
222+
public bool TryOpenFile(string repositoryDir, GitHubContext context)
223223
{
224224
var fileName = context.BlobName;
225225
if (fileName == null)

src/GitHub.VisualStudio/Commands/OpenFromUrlCommand.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class OpenFromUrlCommand : VsCommand<string>, IOpenFromUrlCommand
2323
readonly Lazy<GitHubContextService> gitHubContextService;
2424
readonly Lazy<IRepositoryCloneService> repositoryCloneService;
2525
readonly Lazy<IPullRequestEditorService> pullRequestEditorService;
26+
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
2627
readonly Lazy<IGitHubToolWindowManager> gitHubToolWindowManager;
2728
readonly Lazy<DTE> dte;
2829
readonly IServiceProvider serviceProvider;
@@ -42,12 +43,14 @@ public OpenFromUrlCommand(
4243
Lazy<GitHubContextService> gitHubContextService,
4344
Lazy<IRepositoryCloneService> repositoryCloneService,
4445
Lazy<IPullRequestEditorService> pullRequestEditorService,
46+
Lazy<ITeamExplorerContext> teamExplorerContext,
4547
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider) :
4648
base(CommandSet, CommandId)
4749
{
4850
this.gitHubContextService = gitHubContextService;
4951
this.repositoryCloneService = repositoryCloneService;
5052
this.pullRequestEditorService = pullRequestEditorService;
53+
this.teamExplorerContext = teamExplorerContext;
5154
this.serviceProvider = serviceProvider;
5255
dte = new Lazy<DTE>(() => (DTE)serviceProvider.GetService(typeof(DTE)));
5356
gitHubToolWindowManager = new Lazy<IGitHubToolWindowManager>(
@@ -72,6 +75,16 @@ public override async Task Execute(string url)
7275
return;
7376
}
7477

78+
var activeDir = teamExplorerContext.Value.ActiveRepository?.LocalPath;
79+
if (activeDir != null)
80+
{
81+
// Try opening file in current context
82+
if (gitHubContextService.Value.TryOpenFile(activeDir, context))
83+
{
84+
return;
85+
}
86+
}
87+
7588
// Keep repos in unique dir while testing
7689
var defaultSubPath = "GitHubCache";
7790

@@ -125,7 +138,7 @@ public override async Task Execute(string url)
125138
}
126139

127140
await TryOpenPullRequest(context);
128-
gitHubContextService.Value.TryOpenFile(context, repositoryDir);
141+
gitHubContextService.Value.TryOpenFile(repositoryDir, context);
129142
}
130143

131144
VSConstants.MessageBoxResult ShowInfoMessage(string message)

0 commit comments

Comments
 (0)