From 4ef0f1180fa62937612b1ead79773048ffb22880 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 2 Jul 2024 10:23:21 +0800 Subject: [PATCH] feature: add tooltip for branches (#228) --- src/Converters/BranchConverters.cs | 10 ---------- src/Models/Branch.cs | 2 ++ src/ViewModels/AddWorktree.cs | 2 +- src/ViewModels/BranchTreeNode.cs | 11 +++++++++++ src/ViewModels/CreateBranch.cs | 3 +-- src/ViewModels/DeleteBranch.cs | 5 ++--- src/ViewModels/DeleteMultipleBranches.cs | 2 +- src/ViewModels/GitFlowStart.cs | 3 +-- src/ViewModels/Histories.cs | 4 ++-- src/ViewModels/Repository.cs | 19 ++++++++++--------- src/Views/Archive.axaml | 2 +- src/Views/BranchCompare.axaml | 4 ++-- src/Views/CreateBranch.axaml | 2 +- src/Views/CreateTag.axaml | 2 +- src/Views/DeleteBranch.axaml | 2 +- src/Views/DeleteMultipleBranches.axaml | 3 +-- src/Views/FastForwardWithoutCheckout.axaml | 2 +- src/Views/InteractiveRebase.axaml | 2 +- src/Views/Pull.axaml | 2 +- src/Views/Rebase.axaml | 2 +- src/Views/Repository.axaml | 18 ++++++++++++------ 21 files changed, 54 insertions(+), 48 deletions(-) delete mode 100644 src/Converters/BranchConverters.cs diff --git a/src/Converters/BranchConverters.cs b/src/Converters/BranchConverters.cs deleted file mode 100644 index d20ed89f..00000000 --- a/src/Converters/BranchConverters.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Avalonia.Data.Converters; - -namespace SourceGit.Converters -{ - public static class BranchConverters - { - public static readonly FuncValueConverter ToName = - new FuncValueConverter(v => v.IsLocal ? v.Name : $"{v.Remote}/{v.Name}"); - } -} diff --git a/src/Models/Branch.cs b/src/Models/Branch.cs index a22ee553..07f5374e 100644 --- a/src/Models/Branch.cs +++ b/src/Models/Branch.cs @@ -11,5 +11,7 @@ public string UpstreamTrackStatus { get; set; } public string Remote { get; set; } public bool IsHead { get; set; } + + public string FriendlyName => IsLocal ? Name : $"{Remote}/{Name}"; } } diff --git a/src/ViewModels/AddWorktree.cs b/src/ViewModels/AddWorktree.cs index 04cda5b5..00cf604b 100644 --- a/src/ViewModels/AddWorktree.cs +++ b/src/ViewModels/AddWorktree.cs @@ -71,7 +71,7 @@ namespace SourceGit.ViewModels if (branch.IsLocal) LocalBranches.Add(branch.Name); else - RemoteBranches.Add($"{branch.Remote}/{branch.Name}"); + RemoteBranches.Add(branch.FriendlyName); } if (RemoteBranches.Count > 0) diff --git a/src/ViewModels/BranchTreeNode.cs b/src/ViewModels/BranchTreeNode.cs index ef61579d..11486c20 100644 --- a/src/ViewModels/BranchTreeNode.cs +++ b/src/ViewModels/BranchTreeNode.cs @@ -69,6 +69,17 @@ namespace SourceGit.ViewModels set => SetProperty(ref _isSelected, value); } + public string Tooltip + { + get + { + if (Backend is Models.Branch b) + return b.FriendlyName; + + return null; + } + } + public CornerRadius CornerRadius { get => _cornerRadius; diff --git a/src/ViewModels/CreateBranch.cs b/src/ViewModels/CreateBranch.cs index e80dec15..2f7ac4f8 100644 --- a/src/ViewModels/CreateBranch.cs +++ b/src/ViewModels/CreateBranch.cs @@ -72,8 +72,7 @@ namespace SourceGit.ViewModels foreach (var b in creator._repo.Branches) { - var test = b.IsLocal ? b.Name : $"{b.Remote}/{b.Name}"; - if (test == name) + if (b.FriendlyName == name) return new ValidationResult("A branch with same name already exists!"); } diff --git a/src/ViewModels/DeleteBranch.cs b/src/ViewModels/DeleteBranch.cs index 787e00fc..292cc2aa 100644 --- a/src/ViewModels/DeleteBranch.cs +++ b/src/ViewModels/DeleteBranch.cs @@ -35,9 +35,8 @@ namespace SourceGit.ViewModels if (branch.IsLocal && !string.IsNullOrEmpty(branch.Upstream)) { - var upstream = branch.Upstream.Substring(13); - TrackingRemoteBranch = repo.Branches.Find(x => !x.IsLocal && $"{x.Remote}/{x.Name}" == upstream); - DeleteTrackingRemoteTip = new Views.NameHighlightedTextBlock("DeleteBranch.WithTrackingRemote", upstream); + TrackingRemoteBranch = repo.Branches.Find(x => x.FullName == branch.Upstream); + DeleteTrackingRemoteTip = new Views.NameHighlightedTextBlock("DeleteBranch.WithTrackingRemote", TrackingRemoteBranch.FriendlyName); } View = new Views.DeleteBranch() { DataContext = this }; diff --git a/src/ViewModels/DeleteMultipleBranches.cs b/src/ViewModels/DeleteMultipleBranches.cs index 433d80c6..6048ec68 100644 --- a/src/ViewModels/DeleteMultipleBranches.cs +++ b/src/ViewModels/DeleteMultipleBranches.cs @@ -37,7 +37,7 @@ namespace SourceGit.ViewModels { foreach (var target in Targets) { - SetProgressDescription($"Deleting remote branch : {target.Remote}/{target.Name}"); + SetProgressDescription($"Deleting remote branch : {target.FriendlyName}"); Commands.Branch.DeleteRemote(_repo.FullPath, target.Remote, target.Name); } } diff --git a/src/ViewModels/GitFlowStart.cs b/src/ViewModels/GitFlowStart.cs index 0806dfb4..ca580d99 100644 --- a/src/ViewModels/GitFlowStart.cs +++ b/src/ViewModels/GitFlowStart.cs @@ -39,8 +39,7 @@ namespace SourceGit.ViewModels var check = $"{starter._prefix}{name}"; foreach (var b in starter._repo.Branches) { - var test = b.IsLocal ? b.Name : $"{b.Remote}/{b.Name}"; - if (test == check) + if (b.FriendlyName == check) return new ValidationResult("A branch with same name already exists!"); } } diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 7bdd0bf2..5d035f3b 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -175,7 +175,7 @@ namespace SourceGit.ViewModels } else if (d.Type == Models.DecoratorType.RemoteBranchHead) { - var b = _repo.Branches.Find(x => !x.IsLocal && d.Name == $"{x.Remote}/{x.Name}"); + var b = _repo.Branches.Find(x => !x.IsLocal && d.Name == x.FriendlyName); FillRemoteBranchMenu(menu, b, current, commit.IsMerged); } else if (d.Type == Models.DecoratorType.Tag) @@ -583,7 +583,7 @@ namespace SourceGit.ViewModels private void FillRemoteBranchMenu(ContextMenu menu, Models.Branch branch, Models.Branch current, bool merged) { - var name = $"{branch.Remote}/{branch.Name}"; + var name = branch.FriendlyName; var submenu = new MenuItem(); submenu.Icon = App.CreateMenuIcon("Icons.Branch"); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index dec5486d..3246b967 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1202,7 +1202,7 @@ namespace SourceGit.ViewModels if (upstream != null) { var fastForward = new MenuItem(); - fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", $"{upstream.Remote}/{upstream.Name}"); + fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream.FriendlyName); fastForward.Icon = App.CreateMenuIcon("Icons.FastForward"); fastForward.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus) && branch.UpstreamTrackStatus.IndexOf('↑') < 0; fastForward.Click += (o, e) => @@ -1491,9 +1491,10 @@ namespace SourceGit.ViewModels { var menu = new ContextMenu(); var current = Branches.Find(x => x.IsCurrent); + var name = branch.FriendlyName; var checkout = new MenuItem(); - checkout.Header = new Views.NameHighlightedTextBlock("BranchCM.Checkout", $"{branch.Remote}/{branch.Name}"); + checkout.Header = new Views.NameHighlightedTextBlock("BranchCM.Checkout", name); checkout.Icon = App.CreateMenuIcon("Icons.Check"); checkout.Click += (o, e) => { @@ -1506,7 +1507,7 @@ namespace SourceGit.ViewModels if (current != null) { var pull = new MenuItem(); - pull.Header = new Views.NameHighlightedTextBlock("BranchCM.PullInto", $"{branch.Remote}/{branch.Name}", current.Name); + pull.Header = new Views.NameHighlightedTextBlock("BranchCM.PullInto", name, current.Name); pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Click += (o, e) => { @@ -1516,17 +1517,17 @@ namespace SourceGit.ViewModels }; var merge = new MenuItem(); - merge.Header = new Views.NameHighlightedTextBlock("BranchCM.Merge", $"{branch.Remote}/{branch.Name}", current.Name); + merge.Header = new Views.NameHighlightedTextBlock("BranchCM.Merge", name, current.Name); merge.Icon = App.CreateMenuIcon("Icons.Merge"); merge.Click += (o, e) => { if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Merge(this, $"{branch.Remote}/{branch.Name}", current.Name)); + PopupHost.ShowPopup(new Merge(this, name, current.Name)); e.Handled = true; }; var rebase = new MenuItem(); - rebase.Header = new Views.NameHighlightedTextBlock("BranchCM.Rebase", current.Name, $"{branch.Remote}/{branch.Name}"); + rebase.Header = new Views.NameHighlightedTextBlock("BranchCM.Rebase", current.Name, name); rebase.Icon = App.CreateMenuIcon("Icons.Rebase"); rebase.Click += (o, e) => { @@ -1573,7 +1574,7 @@ namespace SourceGit.ViewModels menu.Items.Add(new MenuItem() { Header = "-" }); var delete = new MenuItem(); - delete.Header = new Views.NameHighlightedTextBlock("BranchCM.Delete", $"{branch.Remote}/{branch.Name}"); + delete.Header = new Views.NameHighlightedTextBlock("BranchCM.Delete", name); delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Click += (o, e) => { @@ -1617,7 +1618,7 @@ namespace SourceGit.ViewModels copy.Icon = App.CreateMenuIcon("Icons.Copy"); copy.Click += (o, e) => { - App.CopyText(branch.Remote + "/" + branch.Name); + App.CopyText(name); e.Handled = true; }; @@ -1810,7 +1811,7 @@ namespace SourceGit.ViewModels { var dup = b; var target = new MenuItem(); - target.Header = b.IsLocal ? b.Name : $"{b.Remote}/{b.Name}"; + target.Header = b.FriendlyName; target.Icon = App.CreateMenuIcon(b.IsCurrent ? "Icons.Check" : "Icons.Branch"); target.Click += (_, e) => { diff --git a/src/Views/Archive.axaml b/src/Views/Archive.axaml index 33b58fe4..6d9bc3b2 100644 --- a/src/Views/Archive.axaml +++ b/src/Views/Archive.axaml @@ -23,7 +23,7 @@ - + diff --git a/src/Views/BranchCompare.axaml b/src/Views/BranchCompare.axaml index 9ad7db03..1ba30119 100644 --- a/src/Views/BranchCompare.axaml +++ b/src/Views/BranchCompare.axaml @@ -61,7 +61,7 @@ User="{Binding BaseHead.Author}"/> - + @@ -82,7 +82,7 @@ User="{Binding ToHead.Author}"/> - + diff --git a/src/Views/CreateBranch.axaml b/src/Views/CreateBranch.axaml index a6565807..f69ea150 100644 --- a/src/Views/CreateBranch.axaml +++ b/src/Views/CreateBranch.axaml @@ -24,7 +24,7 @@ - + diff --git a/src/Views/CreateTag.axaml b/src/Views/CreateTag.axaml index f3de6717..a3f901a4 100644 --- a/src/Views/CreateTag.axaml +++ b/src/Views/CreateTag.axaml @@ -23,7 +23,7 @@ - + diff --git a/src/Views/DeleteBranch.axaml b/src/Views/DeleteBranch.axaml index 8245c091..07230de9 100644 --- a/src/Views/DeleteBranch.axaml +++ b/src/Views/DeleteBranch.axaml @@ -18,7 +18,7 @@ - + diff --git a/src/Views/DeleteMultipleBranches.axaml b/src/Views/DeleteMultipleBranches.axaml index 75f28674..9fd87b90 100644 --- a/src/Views/DeleteMultipleBranches.axaml +++ b/src/Views/DeleteMultipleBranches.axaml @@ -64,8 +64,7 @@ - + diff --git a/src/Views/FastForwardWithoutCheckout.axaml b/src/Views/FastForwardWithoutCheckout.axaml index cb33c09e..713e9c3b 100644 --- a/src/Views/FastForwardWithoutCheckout.axaml +++ b/src/Views/FastForwardWithoutCheckout.axaml @@ -16,7 +16,7 @@ - + diff --git a/src/Views/InteractiveRebase.axaml b/src/Views/InteractiveRebase.axaml index 8e966509..d4238d65 100644 --- a/src/Views/InteractiveRebase.axaml +++ b/src/Views/InteractiveRebase.axaml @@ -54,7 +54,7 @@ - + diff --git a/src/Views/Pull.axaml b/src/Views/Pull.axaml index fca58231..0d749e60 100644 --- a/src/Views/Pull.axaml +++ b/src/Views/Pull.axaml @@ -48,7 +48,7 @@ - + diff --git a/src/Views/Rebase.axaml b/src/Views/Rebase.axaml index aa52a15b..f98756af 100644 --- a/src/Views/Rebase.axaml +++ b/src/Views/Rebase.axaml @@ -31,7 +31,7 @@ - + diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index edbf9432..0a3a9478 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -269,7 +269,7 @@ - + @@ -281,7 +281,10 @@ - + @@ -294,7 +297,8 @@ IsVisible="{Binding IsBranch}" Checked="OnToggleFilter" Unchecked="OnToggleFilter" - IsChecked="{Binding IsFiltered}"/> + IsChecked="{Binding IsFiltered}" + ToolTip.Tip="{DynamicResource Text.Filter}"/> @@ -343,7 +347,7 @@ - + @@ -357,7 +361,8 @@ Checked="OnToggleFilter" Unchecked="OnToggleFilter" IsVisible="{Binding IsBranch}" - IsChecked="{Binding IsFiltered}"/> + IsChecked="{Binding IsFiltered}" + ToolTip.Tip="{DynamicResource Text.Filter}"/> @@ -444,7 +449,8 @@ Background="Transparent" Checked="OnToggleFilter" Unchecked="OnToggleFilter" - IsChecked="{Binding IsFiltered}"/> + IsChecked="{Binding IsFiltered}" + ToolTip.Tip="{DynamicResource Text.Filter}"/>