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

Commit ccf6636

Browse files
author
Steven Kirk
committed
Display checkout button tooltip even when enabled.
Use the checkout button caption as the checkout button tooltip when the button is enabled, as the button is often truncated and so a tooltip is useful to see what the full name of the branch to check out is.
1 parent 0a1cfee commit ccf6636

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace GitHub.SampleData
1111
public class PullRequestCheckoutStateDesigner : IPullRequestCheckoutState
1212
{
1313
public string Caption { get; set; }
14-
public string DisabledMessage { get; set; }
14+
public bool IsEnabled { get; set; }
15+
public string ToolTip { get; set; }
1516
}
1617

1718
public class PullRequestUpdateStateDesigner : IPullRequestUpdateState

src/GitHub.App/ViewModels/PullRequestDetailViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public PullRequestDetailViewModel(
8888
Checkout = ReactiveCommand.CreateAsyncObservable(
8989
this.WhenAnyValue(x => x.CheckoutState)
9090
.Cast<CheckoutCommandState>()
91-
.Select(x => x != null && x.DisabledMessage == null),
91+
.Select(x => x != null && x.IsEnabled),
9292
DoCheckout);
9393
Checkout.ThrownExceptions.Subscribe(x => OperationError = x.Message);
9494
Checkout.IsExecuting.Subscribe(x => isInCheckout = x);
@@ -533,11 +533,13 @@ class CheckoutCommandState : IPullRequestCheckoutState
533533
public CheckoutCommandState(string caption, string disabledMessage)
534534
{
535535
Caption = caption;
536-
DisabledMessage = disabledMessage;
536+
IsEnabled = disabledMessage == null;
537+
ToolTip = disabledMessage ?? caption;
537538
}
538539

539540
public string Caption { get; }
540-
public string DisabledMessage { get; }
541+
public bool IsEnabled { get; }
542+
public string ToolTip { get; }
541543
}
542544

543545
class UpdateCommandState : IPullRequestUpdateState

src/GitHub.Exports.Reactive/ViewModels/IPullRequestDetailViewModel.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ public interface IPullRequestCheckoutState
4949
string Caption { get; }
5050

5151
/// <summary>
52-
/// Gets the message to display when a checkout cannot be carried out.
52+
/// Gets a value indicating whether checkout is available.
5353
/// </summary>
54-
string DisabledMessage { get; }
54+
bool IsEnabled { get; }
55+
56+
/// <summary>
57+
/// Gets the message to display as the checkout button's tooltip.
58+
/// </summary>
59+
string ToolTip { get; }
5560
}
5661

5762
/// <summary>

src/GitHub.VisualStudio/UI/Views/PullRequestDetailView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
VerticalAlignment="Center"
175175
TextTrimming="CharacterEllipsis"
176176
Visibility="{Binding CheckoutState, Converter={ui:NullToVisibilityConverter}}"
177-
ToolTip="{Binding CheckoutState.DisabledMessage}"
177+
ToolTip="{Binding CheckoutState.ToolTip}"
178178
ToolTipService.ShowOnDisabled="True"/>
179179

180180
<!-- Pull/push buttons -->

src/UnitTests/GitHub.App/ViewModels/PullRequestDetailViewModelTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ public async Task NotCheckedOut()
216216
await target.Load(CreatePullRequest());
217217

218218
Assert.True(target.Checkout.CanExecute(null));
219-
Assert.Null(target.CheckoutState.DisabledMessage);
219+
Assert.True(target.CheckoutState.IsEnabled);
220+
Assert.Equal("Checkout pr/123", target.CheckoutState.ToolTip);
220221
}
221222

222223
[Fact]
@@ -229,7 +230,7 @@ public async Task NotCheckedOutWithWorkingDirectoryDirty()
229230
await target.Load(CreatePullRequest());
230231

231232
Assert.False(target.Checkout.CanExecute(null));
232-
Assert.Equal("Cannot checkout as your working directory has uncommitted changes.", target.CheckoutState.DisabledMessage);
233+
Assert.Equal("Cannot checkout as your working directory has uncommitted changes.", target.CheckoutState.ToolTip);
233234
}
234235

235236
[Fact]
@@ -268,7 +269,7 @@ public async Task UpdatesOperationErrorWithExceptionMessage()
268269
await target.Load(pr);
269270

270271
Assert.False(target.Checkout.CanExecute(null));
271-
Assert.Equal("The source repository is no longer available.", target.CheckoutState.DisabledMessage);
272+
Assert.Equal("The source repository is no longer available.", target.CheckoutState.ToolTip);
272273
}
273274

274275
[Fact]

0 commit comments

Comments
 (0)