diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index abceea9a..4d6656e3 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -55,7 +55,7 @@ namespace SourceGit.Models _watchers.Add(wc); _watchers.Add(git); - } + } _timer = new Timer(Tick, null, 100, 100); } diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index ebc23c7f..a004ed79 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -209,48 +209,56 @@ namespace SourceGit.ViewModels } } - public void DoubleTapped(Models.Commit commit, Models.Decorator decorator = null) + public bool CheckoutBranchByDecorator(Models.Decorator decorator) { - if (decorator != null) + if (decorator == null) + return false; + + if (decorator.Type == Models.DecoratorType.CurrentBranchHead || + decorator.Type == Models.DecoratorType.CurrentCommitHead) + return true; + + if (decorator.Type == Models.DecoratorType.LocalBranchHead) { - 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; - } - } - } + var b = _repo.Branches.Find(x => x.Name == decorator.Name); + if (b == null) + return false; + + _repo.CheckoutBranch(b); + return true; } - if (commit == null || commit.IsCurrentHead) + if (decorator.Type == Models.DecoratorType.RemoteBranchHead) + { + var rb = _repo.Branches.Find(x => x.FriendlyName == decorator.Name); + if (rb == null) + return false; + + var lb = _repo.Branches.Find(x => x.IsLocal && x.Upstream == rb.FullName); + if (lb == null || lb.TrackStatus.Ahead.Count > 0) + { + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CreateBranch(_repo, rb)); + } + else if (lb.TrackStatus.Behind.Count > 0) + { + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CheckoutAndFastForward(_repo, lb, rb)); + } + else if (!lb.IsCurrent) + { + _repo.CheckoutBranch(lb); + } + + return true; + } + + return false; + } + + public void CheckoutBranchByCommit(Models.Commit commit) + { + if (commit.IsCurrentHead) return; var firstRemoteBranch = null as Models.Branch; @@ -258,28 +266,28 @@ namespace SourceGit.ViewModels { if (d.Type == Models.DecoratorType.LocalBranchHead) { - var b = _repo.Branches.Find(x => x.FriendlyName == d.Name); - if (b != null) - { - _repo.CheckoutBranch(b); - return; - } + var b = _repo.Branches.Find(x => x.Name == d.Name); + if (b == null) + continue; + + _repo.CheckoutBranch(b); + return; } else if (d.Type == Models.DecoratorType.RemoteBranchHead) { - var remoteBranch = _repo.Branches.Find(x => x.FriendlyName == d.Name); - if (remoteBranch != null) + var rb = _repo.Branches.Find(x => x.FriendlyName == d.Name); + if (rb == null) + continue; + + var lb = _repo.Branches.Find(x => x.IsLocal && x.Upstream == rb.FullName); + if (lb is { TrackStatus.Ahead.Count: 0 }) { - var localBranch = _repo.Branches.Find(x => x.IsLocal && x.Upstream == remoteBranch.FullName); - if (localBranch is { TrackStatus.Ahead.Count: 0 }) - { - if (_repo.CanCreatePopup()) - _repo.ShowPopup(new CheckoutAndFastForward(_repo, localBranch, remoteBranch)); - return; - } + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CheckoutAndFastForward(_repo, lb, rb)); + return; } - firstRemoteBranch ??= remoteBranch; + firstRemoteBranch ??= rb; } } diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 47b3fae6..f41bc162 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -810,7 +810,7 @@ namespace SourceGit.ViewModels }; addToIgnore.Items.Add(byExtensionInSameFolder); } - } + } menu.Items.Add(addToIgnore); hasExtra = true; @@ -1414,7 +1414,7 @@ namespace SourceGit.ViewModels menu.Items.Add(explore); menu.Items.Add(new MenuItem() { Header = "-" }); - } + } var unstage = new MenuItem(); unstage.Header = App.Text("FileCM.UnstageMulti", _selectedStaged.Count); diff --git a/src/Views/CommitRefsPresenter.cs b/src/Views/CommitRefsPresenter.cs index e8fa4517..a5717c6c 100644 --- a/src/Views/CommitRefsPresenter.cs +++ b/src/Views/CommitRefsPresenter.cs @@ -17,6 +17,7 @@ namespace SourceGit.Views public IBrush Brush { get; set; } = null; public bool IsHead { get; set; } = false; public double Width { get; set; } = 0.0; + public Models.Decorator Decorator { get; set; } = null; } public static readonly StyledProperty FontFamilyProperty = @@ -93,6 +94,19 @@ namespace SourceGit.Views ShowTagsProperty); } + public Models.Decorator DecoratorAt(Point point) + { + var x = 0.0; + foreach (var item in _items) + { + x += item.Width; + if (point.X < x) + return item.Decorator; + } + + return null; + } + public override void Render(DrawingContext context) { if (_items.Count == 0) @@ -156,22 +170,6 @@ namespace SourceGit.Views 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(); @@ -214,7 +212,8 @@ namespace SourceGit.Views { Label = label, Brush = normalBG, - IsHead = isHead + IsHead = isHead, + Decorator = decorator, }; StreamGeometry geo; diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml index d19edd0e..35951cb1 100644 --- a/src/Views/Histories.axaml +++ b/src/Views/Histories.axaml @@ -70,7 +70,6 @@ LayoutUpdated="OnCommitListLayoutUpdated" SelectionChanged="OnCommitListSelectionChanged" ContextRequested="OnCommitListContextRequested" - DoubleTapped="OnCommitListDoubleTapped" KeyDown="OnCommitListKeyDown">