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

Commit a3feb6f

Browse files
authored
Merge branch 'master' into fixes/1360-dispose-pane-pages
2 parents 2beed5e + 816c4eb commit a3feb6f

File tree

14 files changed

+117
-69
lines changed

14 files changed

+117
-69
lines changed

src/GitHub.App/Factories/ViewViewModelFactory.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ public class ViewViewModelFactory : IViewViewModelFactory
2020

2121
[ImportingConstructor]
2222
public ViewViewModelFactory(
23-
IGitHubServiceProvider serviceProvider,
24-
ICompositionService cc)
23+
IGitHubServiceProvider serviceProvider)
2524
{
2625
this.serviceProvider = serviceProvider;
27-
cc.SatisfyImportsOnce(this);
2826
}
2927

30-
[ImportMany(AllowRecomposition = true)]
28+
[ImportMany]
3129
IEnumerable<ExportFactory<FrameworkElement, IViewModelMetadata>> Views { get; set; }
3230

3331
/// <inheritdoc/>
@@ -45,7 +43,7 @@ public FrameworkElement CreateView<TViewModel>() where TViewModel : IViewModel
4543
/// <inheritdoc/>
4644
public FrameworkElement CreateView(Type viewModel)
4745
{
48-
var f = Views.FirstOrDefault(x => x.Metadata.ViewModelType.Contains(viewModel));
46+
var f = Views.FirstOrDefault(x => x.Metadata.ViewModelType.Contains(viewModel.FullName));
4947
return f?.CreateExport().Value;
5048
}
5149
}

src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public PullRequestDetailViewModelDesigner()
6161
var repositoriesDir = new PullRequestDirectoryNode("Repositories");
6262
var itrackingBranch = new PullRequestFileNode(repoPath, @"GitHub\Models\ITrackingBranch.cs", "abc", PullRequestFileStatus.Modified, null);
6363
var oldBranchModel = new PullRequestFileNode(repoPath, @"GitHub\Models\OldBranchModel.cs", "abc", PullRequestFileStatus.Removed, null);
64-
var concurrentRepositoryConnection = new PullRequestFileNode(repoPath, @"GitHub\Repositories\ConcurrentRepositoryConnection.cs", "abc", PullRequestFileStatus.Added, "add");
64+
var concurrentRepositoryConnection = new PullRequestFileNode(repoPath, @"GitHub\Repositories\ConcurrentRepositoryConnection.cs", "abc", PullRequestFileStatus.Added, null);
6565

6666
repositoriesDir.Files.Add(concurrentRepositoryConnection);
6767
modelsDir.Directories.Add(repositoriesDir);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ async Task UpdateContent(ILocalRepositoryModel repository)
372372

373373
Connection = await connectionManager.GetConnection(hostAddress);
374374

375-
if (Connection != null)
375+
if (Connection?.IsLoggedIn == true)
376376
{
377377
Content = navigator;
378378
await ShowDefaultPage();
@@ -411,8 +411,8 @@ static async Task<bool> IsValidRepository(ISimpleApiClient client)
411411

412412
static Regex CreateRoute(string route)
413413
{
414-
// Build RegEx from route (:foo to named group (?<foo>[a-z0-9]+)).
415-
var routeFormat = new Regex("(:([a-z]+))\\b").Replace(route, "(?<$2>[a-z0-9]+)");
414+
// Build RegEx from route (:foo to named group (?<foo>[\w_.-]+)).
415+
var routeFormat = new Regex("(:([a-z]+))\\b").Replace(route, @"(?<$2>[\w_.-]+)");
416416
return new Regex(routeFormat, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
417417
}
418418
}

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ public Task<string> ExtractFile(IPullRequestFileNode file, bool head)
473473
{
474474
var relativePath = Path.Combine(file.DirectoryPath, file.FileName);
475475
var encoding = pullRequestsService.GetEncoding(LocalRepository, relativePath);
476+
477+
if (!head && file.OldPath != null)
478+
{
479+
relativePath = file.OldPath;
480+
}
481+
476482
return pullRequestsService.ExtractFile(LocalRepository, model, relativePath, head, encoding).ToTask();
477483
}
478484

@@ -552,7 +558,7 @@ async Task<IPullRequestDirectoryNode> CreateChangedFilesTree(IPullRequestModel p
552558
changedFile.FileName,
553559
changedFile.Sha,
554560
changedFile.Status,
555-
GetStatusDisplay(changedFile, changes));
561+
GetOldFileName(changedFile, changes));
556562

557563
var file = await Session.GetFile(changedFile.FileName);
558564
var fileCommentCount = file?.WhenAnyValue(x => x.InlineCommentThreads)
@@ -598,28 +604,15 @@ static string GetBranchDisplayName(bool isFromFork, string targetBranchLabel)
598604
}
599605
}
600606

601-
string GetStatusDisplay(IPullRequestFileModel file, TreeChanges changes)
607+
string GetOldFileName(IPullRequestFileModel file, TreeChanges changes)
602608
{
603-
switch (file.Status)
609+
if (file.Status == PullRequestFileStatus.Renamed)
604610
{
605-
case PullRequestFileStatus.Added:
606-
return Resources.AddedFileStatus;
607-
case PullRequestFileStatus.Renamed:
608-
var fileName = file.FileName.Replace("/", "\\");
609-
var change = changes?.Renamed.FirstOrDefault(x => x.Path == fileName);
610-
611-
if (change != null)
612-
{
613-
return Path.GetDirectoryName(change.OldPath) == Path.GetDirectoryName(change.Path) ?
614-
Path.GetFileName(change.OldPath) : change.OldPath;
615-
}
616-
else
617-
{
618-
return Resources.RenamedFileStatus;
619-
}
620-
default:
621-
return null;
611+
var fileName = file.FileName.Replace("/", "\\");
612+
return changes?.Renamed.FirstOrDefault(x => x.Path == fileName)?.OldPath;
622613
}
614+
615+
return null;
623616
}
624617

625618
IObservable<Unit> DoCheckout(object unused)

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using GitHub.App;
34
using GitHub.Extensions;
45
using GitHub.Models;
56
using ReactiveUI;
@@ -21,23 +22,43 @@ public class PullRequestFileNode : ReactiveObject, IPullRequestFileNode
2122
/// <param name="sha">The SHA of the file.</param>
2223
/// <param name="status">The way the file was changed.</param>
2324
/// <param name="statusDisplay">The string to display in the [message] box next to the filename.</param>
25+
/// <param name="oldPath">
26+
/// The old path of a moved/renamed file, relative to the repository. Should be null if the
27+
/// file was not moved/renamed.
28+
/// </param>
2429
public PullRequestFileNode(
2530
string repositoryPath,
2631
string path,
2732
string sha,
2833
PullRequestFileStatus status,
29-
string statusDisplay)
34+
string oldPath)
3035
{
3136
Guard.ArgumentNotEmptyString(repositoryPath, nameof(repositoryPath));
3237
Guard.ArgumentNotEmptyString(path, nameof(path));
3338
Guard.ArgumentNotEmptyString(sha, nameof(sha));
3439

3540
FileName = Path.GetFileName(path);
3641
DirectoryPath = Path.GetDirectoryName(path);
37-
DisplayPath = Path.Combine(Path.GetFileName(repositoryPath), DirectoryPath);
3842
Sha = sha;
3943
Status = status;
40-
StatusDisplay = statusDisplay;
44+
OldPath = oldPath;
45+
46+
if (status == PullRequestFileStatus.Added)
47+
{
48+
StatusDisplay = Resources.AddedFileStatus;
49+
}
50+
else if (status == PullRequestFileStatus.Renamed)
51+
{
52+
if (oldPath != null)
53+
{
54+
StatusDisplay = Path.GetDirectoryName(oldPath) == Path.GetDirectoryName(path) ?
55+
Path.GetFileName(oldPath) : oldPath;
56+
}
57+
else
58+
{
59+
StatusDisplay = Resources.RenamedFileStatus;
60+
}
61+
}
4162
}
4263

4364
/// <summary>
@@ -51,9 +72,9 @@ public PullRequestFileNode(
5172
public string DirectoryPath { get; }
5273

5374
/// <summary>
54-
/// Gets the path to display in the "Path" column of the changed files list.
75+
/// Gets the old path of a moved/renamed file, relative to the root of the repository.
5576
/// </summary>
56-
public string DisplayPath { get; }
77+
public string OldPath { get; }
5778

5879
/// <summary>
5980
/// Gets the SHA of the file.

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public PullRequestListViewModel(
8888
.Where(x => PullRequests != null)
8989
.Subscribe(f => UpdateFilter(SelectedState, SelectedAssignee, SelectedAuthor, f));
9090

91+
this.WhenAnyValue(x => x.SelectedRepository)
92+
.Skip(1)
93+
.Subscribe(_ => ResetAndLoad());
94+
9195
OpenPullRequest = ReactiveCommand.Create();
9296
OpenPullRequest.Subscribe(DoOpenPullRequest);
9397
CreatePullRequest = ReactiveCommand.Create();
@@ -117,9 +121,9 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
117121
new[] { remoteRepository.Parent, remoteRepository } :
118122
new[] { remoteRepository };
119123
SelectedState = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0];
124+
125+
// Setting SelectedRepository will cause a Load().
120126
SelectedRepository = Repositories[0];
121-
WebUrl = repository.CloneUrl?.ToRepositoryUrl().Append("pulls");
122-
await Load();
123127
}
124128
finally
125129
{
@@ -324,6 +328,7 @@ void CreatePullRequests()
324328

325329
void ResetAndLoad()
326330
{
331+
WebUrl = SelectedRepository.CloneUrl?.ToRepositoryUrl().Append("pulls");
327332
CreatePullRequests();
328333
UpdateFilter(SelectedState, SelectedAssignee, SelectedAuthor, SearchQuery);
329334
Load().Forget();

src/GitHub.Exports.Reactive/ViewModels/GitHubPane/IPullRequestFileNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public interface IPullRequestFileNode : IPullRequestChangeNode
1010
string FileName { get; }
1111

1212
/// <summary>
13-
/// Gets the path to display in the "Path" column of the changed files list.
13+
/// Gets the old path of a moved/renamed file, relative to the root of the repository.
1414
/// </summary>
15-
string DisplayPath { get; }
15+
string OldPath { get; }
1616

1717
/// <summary>
1818
/// Gets the SHA of the file.

src/GitHub.Exports/Exports/ExportMetadata.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ public enum LinkType
3232
/// </summary>
3333
[MetadataAttribute]
3434
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
35+
[SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments",
36+
Justification = "Store string rather than Type as metadata")]
3537
public sealed class ExportViewForAttribute : ExportAttribute
3638
{
3739
public ExportViewForAttribute(Type viewModelType)
3840
: base(typeof(FrameworkElement))
3941
{
40-
ViewModelType = viewModelType;
42+
ViewModelType = viewModelType.FullName;
4143
}
4244

43-
public Type ViewModelType { get; }
45+
public string ViewModelType { get; }
4446
}
4547

4648
/// <summary>
@@ -69,7 +71,7 @@ public ExportMenuAttribute() : base(typeof(IMenuHandler))
6971
public interface IViewModelMetadata
7072
{
7173
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
72-
Type[] ViewModelType { get; }
74+
string[] ViewModelType { get; }
7375
}
7476

7577
/// <summary>

src/GitHub.TeamFoundation.14/RegistryHelper.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,42 @@ static RegistryKey OpenGitKey(string path)
2121

2222
internal static IEnumerable<ILocalRepositoryModel> PokeTheRegistryForRepositoryList()
2323
{
24-
using (var key = OpenGitKey("Repositories"))
24+
var key = OpenGitKey("Repositories");
25+
26+
if (key != null)
2527
{
26-
return key.GetSubKeyNames().Select(x =>
28+
using (key)
2729
{
28-
using (var subkey = key.OpenSubKey(x))
30+
return key.GetSubKeyNames().Select(x =>
2931
{
30-
try
31-
{
32-
var path = subkey?.GetValue("Path") as string;
33-
if (path != null && Directory.Exists(path))
34-
return new LocalRepositoryModel(path);
35-
}
36-
catch (Exception)
32+
var subkey = key.OpenSubKey(x);
33+
34+
if (subkey != null)
3735
{
38-
// no sense spamming the log, the registry might have ton of stale things we don't care about
36+
using (subkey)
37+
{
38+
try
39+
{
40+
var path = subkey?.GetValue("Path") as string;
41+
if (path != null && Directory.Exists(path))
42+
return new LocalRepositoryModel(path);
43+
}
44+
catch (Exception)
45+
{
46+
// no sense spamming the log, the registry might have ton of stale things we don't care about
47+
}
48+
49+
}
3950
}
51+
4052
return null;
41-
}
42-
})
43-
.Where(x => x != null)
44-
.ToList();
53+
})
54+
.Where(x => x != null)
55+
.ToList();
56+
}
4557
}
58+
59+
return new ILocalRepositoryModel[0];
4660
}
4761

4862
internal static string PokeTheRegistryForLocalClonePath()

src/GitHub.VisualStudio/Views/GitHubPane/GitHubPaneView.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
xmlns:uc="clr-namespace:GitHub.UI.Controls;assembly=GitHub.UI"
1111
xmlns:vuc="clr-namespace:GitHub.VisualStudio.UI.Controls;assembly=GitHub.VisualStudio.UI"
1212
xmlns:views="clr-namespace:GitHub.VisualStudio.Views"
13+
Foreground="{DynamicResource GitHubVsWindowText}"
1314
d:DesignHeight="300"
1415
d:DesignWidth="300"
1516
mc:Ignorable="d">
@@ -82,8 +83,7 @@
8283
HorizontalAlignment="Center"
8384
VerticalAlignment="Center"
8485
Visibility="{Binding ContentOverride, Converter={u:EqualsToVisibilityConverter Spinner}, FallbackValue=Collapsed}"/>
85-
<Border Background="White"
86-
HorizontalAlignment="Stretch"
86+
<Border HorizontalAlignment="Stretch"
8787
VerticalAlignment="Stretch"
8888
Visibility="{Binding ContentOverride, Converter={u:EqualsToVisibilityConverter Error}, FallbackValue=Collapsed}">
8989
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">

0 commit comments

Comments
 (0)