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

Commit

Permalink
Merge pull request #775 from github/fixes/checkout-button-tooltips
Browse files Browse the repository at this point in the history
Display checkout button tooltip even when enabled.
  • Loading branch information
StanleyGoldman authored Jan 17, 2017
2 parents 8a8766e + 5f77c4a commit 9c47021
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace GitHub.SampleData
public class PullRequestCheckoutStateDesigner : IPullRequestCheckoutState
{
public string Caption { get; set; }
public string DisabledMessage { get; set; }
public bool IsEnabled { get; set; }
public string ToolTip { get; set; }
}

public class PullRequestUpdateStateDesigner : IPullRequestUpdateState
Expand Down
8 changes: 5 additions & 3 deletions src/GitHub.App/ViewModels/PullRequestDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public PullRequestDetailViewModel(
Checkout = ReactiveCommand.CreateAsyncObservable(
this.WhenAnyValue(x => x.CheckoutState)
.Cast<CheckoutCommandState>()
.Select(x => x != null && x.DisabledMessage == null),
.Select(x => x != null && x.IsEnabled),
DoCheckout);
Checkout.ThrownExceptions.Subscribe(x => OperationError = x.Message);
Checkout.IsExecuting.Subscribe(x => isInCheckout = x);
Expand Down Expand Up @@ -533,11 +533,13 @@ class CheckoutCommandState : IPullRequestCheckoutState
public CheckoutCommandState(string caption, string disabledMessage)
{
Caption = caption;
DisabledMessage = disabledMessage;
IsEnabled = disabledMessage == null;
ToolTip = disabledMessage ?? caption;
}

public string Caption { get; }
public string DisabledMessage { get; }
public bool IsEnabled { get; }
public string ToolTip { get; }
}

class UpdateCommandState : IPullRequestUpdateState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ public interface IPullRequestCheckoutState
string Caption { get; }

/// <summary>
/// Gets the message to display when a checkout cannot be carried out.
/// Gets a value indicating whether checkout is available.
/// </summary>
string DisabledMessage { get; }
bool IsEnabled { get; }

/// <summary>
/// Gets the message to display as the checkout button's tooltip.
/// </summary>
string ToolTip { get; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis"
Visibility="{Binding CheckoutState, Converter={ui:NullToVisibilityConverter}}"
ToolTip="{Binding CheckoutState.DisabledMessage}"
ToolTip="{Binding CheckoutState.ToolTip}"
ToolTipService.ShowOnDisabled="True"/>

<!-- Pull/push buttons -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public async Task NotCheckedOut()
await target.Load(CreatePullRequest());

Assert.True(target.Checkout.CanExecute(null));
Assert.Null(target.CheckoutState.DisabledMessage);
Assert.True(target.CheckoutState.IsEnabled);
Assert.Equal("Checkout pr/123", target.CheckoutState.ToolTip);
}

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

Assert.False(target.Checkout.CanExecute(null));
Assert.Equal("Cannot checkout as your working directory has uncommitted changes.", target.CheckoutState.DisabledMessage);
Assert.Equal("Cannot checkout as your working directory has uncommitted changes.", target.CheckoutState.ToolTip);
}

[Fact]
Expand Down Expand Up @@ -268,7 +269,7 @@ public async Task UpdatesOperationErrorWithExceptionMessage()
await target.Load(pr);

Assert.False(target.Checkout.CanExecute(null));
Assert.Equal("The source repository is no longer available.", target.CheckoutState.DisabledMessage);
Assert.Equal("The source repository is no longer available.", target.CheckoutState.ToolTip);
}

[Fact]
Expand Down

0 comments on commit 9c47021

Please sign in to comment.