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

Commit fb1c337

Browse files
committed
Add button to Edit Remotes
Allow easy navigation to Repository Settings > Remotes section.
1 parent ccebc24 commit fb1c337

File tree

5 files changed

+79
-2
lines changed

5 files changed

+79
-2
lines changed

src/GitHub.App/ViewModels/GitHubPane/NoRemoteOriginViewModel.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
using System;
2+
using System.Reactive;
3+
using System.Threading.Tasks;
14
using System.ComponentModel.Composition;
5+
using GitHub.Services;
6+
using ReactiveUI;
27

38
namespace GitHub.ViewModels.GitHubPane
49
{
@@ -9,5 +14,17 @@ namespace GitHub.ViewModels.GitHubPane
914
[PartCreationPolicy(CreationPolicy.NonShared)]
1015
public class NoRemoteOriginViewModel : PanePageViewModelBase, INoRemoteOriginViewModel
1116
{
17+
ITeamExplorerServices teamExplorerServices;
18+
19+
[ImportingConstructor]
20+
public NoRemoteOriginViewModel(ITeamExplorerServices teamExplorerServices)
21+
{
22+
this.teamExplorerServices = teamExplorerServices;
23+
EditRemotes = ReactiveCommand.CreateFromTask(OnEditRemotesAsync);
24+
}
25+
26+
Task OnEditRemotesAsync() => teamExplorerServices.ShowRepositorySettingsRemotesAsync();
27+
28+
public ReactiveCommand<Unit, Unit> EditRemotes { get; }
1229
}
1330
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
namespace GitHub.ViewModels.GitHubPane
1+
using System.Reactive;
2+
using ReactiveUI;
3+
4+
namespace GitHub.ViewModels.GitHubPane
25
{
36
/// <summary>
47
/// Defines the view model for the "No Origin Remote" view in the GitHub pane.
58
/// </summary>
69
public interface INoRemoteOriginViewModel : IPanePageViewModel
710
{
11+
/// <summary>
12+
/// Gets a command that will allow the user to rename remotes.
13+
/// </summary>
14+
ReactiveCommand<Unit, Unit> EditRemotes { get; }
815
}
916
}

src/GitHub.Exports/Services/ITeamExplorerServices.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Windows.Input;
1+
using System.Threading.Tasks;
22

33
namespace GitHub.Services
44
{
@@ -7,6 +7,7 @@ public interface ITeamExplorerServices : INotificationService
77
void ShowConnectPage();
88
void ShowHomePage();
99
void ShowPublishSection();
10+
Task ShowRepositorySettingsRemotesAsync();
1011
void ClearNotifications();
1112
void OpenRepository(string repositoryPath);
1213
}

src/GitHub.TeamFoundation.14/Services/TeamExplorerServices.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using System;
2+
using System.Reactive.Linq;
3+
using System.Threading.Tasks;
24
using System.ComponentModel.Composition;
35
using System.Diagnostics.CodeAnalysis;
6+
using System.Windows;
7+
using System.Windows.Controls;
48
using System.Windows.Input;
59
using EnvDTE;
610
using GitHub.VisualStudio.TeamExplorer.Sync;
711
using Microsoft.TeamFoundation.Controls;
12+
using ReactiveUI;
813

914
namespace GitHub.Services
1015
{
@@ -58,6 +63,14 @@ public void ShowPublishSection()
5863
publish?.Connect();
5964
}
6065

66+
public async Task ShowRepositorySettingsRemotesAsync()
67+
{
68+
var te = serviceProvider.TryGetService<ITeamExplorer>();
69+
var page = await NavigateToPageAsync(te, new Guid("96903923-97e0-474a-9346-31a3ba28e6ff"));
70+
var remotes = page?.GetSection(new Guid("2e31f317-7144-4316-8aae-a796e4be1fd4"));
71+
BringIntoView(remotes);
72+
}
73+
6174
public void ShowMessage(string message)
6275
{
6376
manager = serviceProvider.GetService<ITeamExplorer, ITeamExplorerNotificationManager>();
@@ -110,5 +123,37 @@ void OpenFolder(string repositoryPath)
110123
var dte = serviceProvider.TryGetService<DTE>();
111124
dte?.ExecuteCommand("File.OpenFolder", repositoryPath);
112125
}
126+
127+
static void BringIntoView(ITeamExplorerSection section)
128+
{
129+
var control = section?.SectionContent as UserControl;
130+
if (control != null)
131+
{
132+
if (control.IsLoaded)
133+
{
134+
BringIntoView();
135+
}
136+
else
137+
{
138+
control.Loaded += (s, e) => BringIntoView();
139+
}
140+
}
141+
142+
void BringIntoView()
143+
{
144+
var targetRectangle = new Rect(0, 0, 0, 1000);
145+
control.BringIntoView(targetRectangle);
146+
}
147+
}
148+
149+
static async Task<ITeamExplorerPage> NavigateToPageAsync(ITeamExplorer teamExplorer, Guid pageId)
150+
{
151+
teamExplorer.NavigateToPage(pageId, null);
152+
var page = await teamExplorer
153+
.WhenAnyValue(x => x.CurrentPage)
154+
.Where(x => x?.GetId() == pageId)
155+
.Take(1);
156+
return page;
157+
}
113158
}
114159
}

src/GitHub.VisualStudio.UI/Views/GitHubPane/NoRemoteOriginView.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
TextWrapping="Wrap"
3838
TextAlignment="Center"
3939
HorizontalAlignment="Center" />
40+
41+
<Button HorizontalAlignment="Center"
42+
Margin="0,15"
43+
Style="{DynamicResource GitHubVsPrimaryActionButton}"
44+
Command="{Binding EditRemotes}" >
45+
<TextBlock Text="Edit Remotes" />
46+
</Button>
4047
</StackPanel>
4148
</DockPanel>
4249
</local:GenericNoRemoteOriginView>

0 commit comments

Comments
 (0)