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

Commit 007d8cb

Browse files
authored
Merge branch 'master' into grokys/pr-details-busy
2 parents 5ede6bc + f778c6c commit 007d8cb

File tree

15 files changed

+103
-71
lines changed

15 files changed

+103
-71
lines changed

src/GitHub.App/GitHub.App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<Reference Include="WindowsBase" />
133133
</ItemGroup>
134134
<ItemGroup>
135+
<Compile Include="ViewModels\ViewModelBase.cs" />
135136
<None Include="..\..\script\Key.snk" Condition="$(Buildtype) == 'Internal'">
136137
<Link>Key.snk</Link>
137138
</None>

src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public PullRequestDetailViewModelDesigner()
7575
public string TargetBranchDisplayName { get; set; }
7676
public bool IsLoading { get; }
7777
public bool IsBusy { get; }
78+
public bool IsCheckedOut { get; }
7879
public bool IsFromFork { get; }
7980
public string Body { get; }
8081
public IReadOnlyList<IPullRequestChangeNode> ChangedFilesTree => changedFilesTree;
@@ -89,12 +90,12 @@ public PullRequestDetailViewModelDesigner()
8990
public ReactiveCommand<object> OpenFile { get; }
9091
public ReactiveCommand<object> DiffFile { get; }
9192

92-
public Task<string> ExtractFile(IPullRequestFileNode file)
93+
public Task<Tuple<string, string>> ExtractDiffFiles(IPullRequestFileNode file)
9394
{
9495
return null;
9596
}
9697

97-
public Task<Tuple<string, string>> ExtractDiffFiles(IPullRequestFileNode file)
98+
public string GetLocalFilePath(IPullRequestFileNode file)
9899
{
99100
return null;
100101
}

src/GitHub.App/Services/DialogService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Task<CloneDialogResult> ShowCloneDialog([AllowNull] IConnection connectio
3030
{
3131
var vm = x.View.ViewModel as IBaseCloneViewModel;
3232

33-
((IHasDone)x.View.ViewModel).Done.Subscribe(_ =>
33+
vm.Done.Subscribe(_ =>
3434
{
3535
basePath = vm?.BaseRepositoryPath;
3636
repository = vm?.SelectedRepository;
@@ -58,7 +58,7 @@ public Task<string> ShowReCloneDialog(IRepositoryModel repository)
5858
vm.SelectedRepository = repository;
5959
}
6060

61-
((IHasDone)x.View.ViewModel).Done.Subscribe(_ =>
61+
vm.Done.Subscribe(_ =>
6262
{
6363
basePath = vm?.BaseRepositoryPath;
6464
});

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ public IObservable<Tuple<string, string>> ExtractDiffFiles(
287287
IModelService modelService,
288288
IPullRequestModel pullRequest,
289289
string fileName,
290-
string fileSha)
290+
string fileSha,
291+
bool isPullRequestBranchCheckedOut)
291292
{
292293
return Observable.Defer(async () =>
293294
{
@@ -300,7 +301,9 @@ public IObservable<Tuple<string, string>> ExtractDiffFiles(
300301

301302
// The right file - if it comes from a fork - may not be fetched so fall back to
302303
// getting the file contents from the model service.
303-
var right = await GetFileFromRepositoryOrApi(repository, repo, modelService, pullRequest.Head.Sha, fileName, fileSha);
304+
var right = isPullRequestBranchCheckedOut ?
305+
Path.Combine(repository.LocalPath, fileName) :
306+
await GetFileFromRepositoryOrApi(repository, repo, modelService, pullRequest.Head.Sha, fileName, fileSha);
304307

305308
if (left == null)
306309
{

src/GitHub.App/ViewModels/DialogViewModelBase.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
using System.Windows.Input;
2-
using ReactiveUI;
3-
using NullGuard;
4-
using GitHub.UI;
5-
using System;
1+
using System;
62
using System.Reactive;
73
using GitHub.Extensions.Reactive;
4+
using NullGuard;
5+
using ReactiveUI;
86

97
namespace GitHub.ViewModels
108
{
119
/// <summary>
1210
/// Base class for view models that can be dismissed, such as dialogs.
1311
/// </summary>
14-
public abstract class DialogViewModelBase : ReactiveObject, IDialogViewModel, IHasBusy
12+
public abstract class DialogViewModelBase : ViewModelBase, IDialogViewModel, IHasBusy
1513
{
1614
protected ObservableAsPropertyHelper<bool> isShowing;
1715
string title;
@@ -51,10 +49,5 @@ public bool IsBusy
5149

5250
/// <inheritdoc/>
5351
IObservable<Unit> IHasCancel.Cancel => Cancel.SelectUnit();
54-
55-
/// <inheritdoc/>
56-
public virtual void Initialize([AllowNull] ViewWithData data)
57-
{
58-
}
5952
}
6053
}

src/GitHub.App/ViewModels/PanePageViewModelBase.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace GitHub.ViewModels
77
/// <summary>
88
/// Base class for view models that appear as a page in a navigable pane, such as the GitHub pane.
99
/// </summary>
10-
public class PanePageViewModelBase : ReactiveObject, IPanePageViewModel
10+
public class PanePageViewModelBase : ViewModelBase, IPanePageViewModel
1111
{
1212
string title;
1313

@@ -25,10 +25,5 @@ public string Title
2525
get { return title; }
2626
protected set { this.RaiseAndSetIfChanged(ref title, value); }
2727
}
28-
29-
/// <inheritdoc/>
30-
public virtual void Initialize([AllowNull] ViewWithData data)
31-
{
32-
}
3328
}
3429
}

src/GitHub.App/ViewModels/PullRequestDetailViewModel.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class PullRequestDetailViewModel : PanePageViewModelBase, IPullRequestDet
4141
string operationError;
4242
bool isBusy;
4343
bool isLoading;
44+
bool isCheckedOut;
4445
bool isFromFork;
4546
bool isInCheckout;
4647

@@ -105,7 +106,7 @@ public PullRequestDetailViewModel(
105106
SubscribeOperationError(Push);
106107

107108
OpenOnGitHub = ReactiveCommand.Create();
108-
OpenFile = ReactiveCommand.Create();
109+
OpenFile = ReactiveCommand.Create(this.WhenAnyValue(x => x.IsCheckedOut));
109110
DiffFile = ReactiveCommand.Create();
110111
}
111112

@@ -156,6 +157,14 @@ public bool IsBusy
156157
private set { this.RaiseAndSetIfChanged(ref isBusy, value); }
157158
}
158159

160+
/// Gets a value indicating whether the pull request branch is checked out.
161+
/// </summary>
162+
public bool IsCheckedOut
163+
{
164+
get { return isCheckedOut; }
165+
private set { this.RaiseAndSetIfChanged(ref isCheckedOut, value); }
166+
}
167+
159168
/// <summary>
160169
/// Gets a value indicating whether the view model is loading.
161170
/// </summary>
@@ -289,9 +298,10 @@ public async Task Load(IPullRequestModel pullRequest)
289298
ChangedFilesTree = CreateChangedFilesTree(pullRequest, changes).Children.ToList();
290299

291300
var localBranches = await pullRequestsService.GetLocalBranches(repository, pullRequest).ToList();
292-
var isCheckedOut = localBranches.Contains(repository.CurrentBranch);
293301

294-
if (isCheckedOut)
302+
IsCheckedOut = localBranches.Contains(repository.CurrentBranch);
303+
304+
if (IsCheckedOut)
295305
{
296306
var divergence = await pullRequestsService.CalculateHistoryDivergence(repository, Model.Number);
297307
var pullEnabled = divergence.BehindBy > 0;
@@ -360,25 +370,24 @@ public async Task Load(IPullRequestModel pullRequest)
360370
}
361371

362372
/// <summary>
363-
/// Gets the specified file as it appears in the pull request.
373+
/// Gets the before and after files needed for viewing a diff.
364374
/// </summary>
365-
/// <param name="file">The file or directory node.</param>
366-
/// <returns>The path to the extracted file.</returns>
367-
public Task<string> ExtractFile(IPullRequestFileNode file)
375+
/// <param name="file">The changed file.</param>
376+
/// <returns>A tuple containing the full path to the before and after files.</returns>
377+
public Task<Tuple<string, string>> ExtractDiffFiles(IPullRequestFileNode file)
368378
{
369379
var path = Path.Combine(file.DirectoryPath, file.FileName);
370-
return pullRequestsService.ExtractFile(repository, modelService, model.Head.Sha, path, file.Sha).ToTask();
380+
return pullRequestsService.ExtractDiffFiles(repository, modelService, model, path, file.Sha, IsCheckedOut).ToTask();
371381
}
372382

373383
/// <summary>
374-
/// Gets the before and after files needed for viewing a diff.
384+
/// Gets the full path to a file in the working directory.
375385
/// </summary>
376-
/// <param name="file">The changed file.</param>
377-
/// <returns>A tuple containing the full path to the before and after files.</returns>
378-
public Task<Tuple<string, string>> ExtractDiffFiles(IPullRequestFileNode file)
386+
/// <param name="file">The file.</param>
387+
/// <returns>The full path to the file in the working directory.</returns>
388+
public string GetLocalFilePath(IPullRequestFileNode file)
379389
{
380-
var path = Path.Combine(file.DirectoryPath, file.FileName);
381-
return pullRequestsService.ExtractDiffFiles(repository, modelService, model, path, file.Sha).ToTask();
390+
return Path.Combine(repository.LocalPath, file.DirectoryPath, file.FileName);
382391
}
383392

384393
void SubscribeOperationError(ReactiveCommand<Unit> command)

src/GitHub.App/ViewModels/PullRequestListViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ public IAccount EmptyUser
226226
get { return emptyUser; }
227227
}
228228

229-
readonly Subject<ViewWithData> load = new Subject<ViewWithData>();
230-
public IObservable<ViewWithData> Navigate => load;
229+
readonly Subject<ViewWithData> navigate = new Subject<ViewWithData>();
230+
public IObservable<ViewWithData> Navigate => navigate;
231231

232232
public ReactiveCommand<object> OpenPullRequest { get; }
233233
public ReactiveCommand<object> CreatePullRequest { get; }
@@ -263,13 +263,13 @@ void SaveSettings()
263263
void DoOpenPullRequest(object pullRequest)
264264
{
265265
var d = new ViewWithData(UIControllerFlow.PullRequestDetail) { Data = pullRequest };
266-
load.OnNext(d);
266+
navigate.OnNext(d);
267267
}
268268

269269
void DoCreatePullRequest()
270270
{
271271
var d = new ViewWithData(UIControllerFlow.PullRequestCreation);
272-
load.OnNext(d);
272+
navigate.OnNext(d);
273273
}
274274
}
275275
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using GitHub.UI;
3+
using NullGuard;
4+
using ReactiveUI;
5+
6+
namespace GitHub.ViewModels
7+
{
8+
/// <summary>
9+
/// Base class for view models.
10+
/// </summary>
11+
public abstract class ViewModelBase : ReactiveObject, IViewModel
12+
{
13+
/// <inheritdoc/>
14+
public virtual void Initialize([AllowNull] ViewWithData data)
15+
{
16+
}
17+
}
18+
}

src/GitHub.Exports.Reactive/Services/IPullRequestService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,18 @@ IObservable<string> ExtractFile(
120120
/// <param name="pullRequest">The pull request details.</param>
121121
/// <param name="fileName">The filename relative to the repository root.</param>
122122
/// <param name="fileSha">The SHA of the file in the pull request.</param>
123-
/// <returns>The filenames of the left and right files for the diff.</returns>
123+
/// <param name="isPullRequestBranchCheckedOut">
124+
/// Whether the pull request branch is currently checked out. If so the right file returned
125+
/// will be the path to the file in the working directory.
126+
/// </param>
127+
/// <returns>The paths of the left and right files for the diff.</returns>
124128
IObservable<Tuple<string, string>> ExtractDiffFiles(
125129
ILocalRepositoryModel repository,
126130
IModelService modelService,
127131
IPullRequestModel pullRequest,
128132
string fileName,
129-
string fileSha);
133+
string fileSha,
134+
bool isPullRequestBranchCheckedOut);
130135

131136
/// <summary>
132137
/// Remotes all unused remotes that were created by GitHub for Visual Studio to track PRs

0 commit comments

Comments
 (0)