Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/ViewModels/Histories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,47 @@ public void Select(IList commits)
}
}

public void DoubleTapped(Models.Commit commit)
public void DoubleTapped(Models.Commit commit, Models.Decorator decorator = null)
{
if (decorator != null)
{
if (decorator.Type == Models.DecoratorType.LocalBranchHead)
{
var b = _repo.Branches.Find(x => x.FriendlyName == decorator.Name);
if (b != null)
{
_repo.CheckoutBranch(b);
return;
}
}
else if (decorator.Type == Models.DecoratorType.RemoteBranchHead)
{
var remoteBranch = _repo.Branches.Find(x => x.FriendlyName == decorator.Name);
if (remoteBranch != null)
{
var localBranch = _repo.Branches.Find(x => x.IsLocal && x.Upstream == remoteBranch.FullName);
if (localBranch != null)
{
if (localBranch.IsCurrent)
return;
if (localBranch.TrackStatus.Ahead.Count > 0)
{
if (_repo.CanCreatePopup())
_repo.ShowPopup(new CreateBranch(_repo, remoteBranch));
}
else if (localBranch.TrackStatus.Behind.Count > 0)
{
if (_repo.CanCreatePopup())
_repo.ShowPopup(new CheckoutAndFastForward(_repo, localBranch, remoteBranch));
}
else
_repo.CheckoutBranch(localBranch);
return;
}
}
}
}

if (commit == null || commit.IsCurrentHead)
return;

Expand Down
16 changes: 16 additions & 0 deletions src/Views/CommitRefsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ protected override void OnDataContextChanged(EventArgs e)
InvalidateMeasure();
}

public Models.Decorator DecoratorAt(Point point)
{
if (DataContext is not Models.Commit commit)
return null;

var x = 0.0;
for (var i = 0; i < _items.Count; i++)
{
x += _items[i].Width + 4;
if (point.X < x)
return commit.Decorators[i];
}

return null;
}

protected override Size MeasureOverride(Size availableSize)
{
_items.Clear();
Expand Down
6 changes: 5 additions & 1 deletion src/Views/Histories.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,14 @@ private void OnCommitListDoubleTapped(object sender, TappedEventArgs e)
{
if (DataContext is ViewModels.Histories histories && sender is ListBox { SelectedItems.Count: 1 })
{
Models.Decorator decorator = null;
if (e.Source is CommitRefsPresenter crp)
decorator = crp.DecoratorAt(e.GetPosition(crp));

var source = e.Source as Control;
var item = source.FindAncestorOfType<ListBoxItem>();
if (item is { DataContext: Models.Commit commit })
histories.DoubleTapped(commit);
histories.DoubleTapped(commit, decorator);
}
e.Handled = true;
}
Expand Down
Loading