feature: add tooltip for branches (#228)

This commit is contained in:
leo 2024-07-02 10:23:21 +08:00
parent 7965338d7c
commit 4ef0f1180f
No known key found for this signature in database
21 changed files with 54 additions and 48 deletions

View file

@ -1,10 +0,0 @@
using Avalonia.Data.Converters;
namespace SourceGit.Converters
{
public static class BranchConverters
{
public static readonly FuncValueConverter<Models.Branch, string> ToName =
new FuncValueConverter<Models.Branch, string>(v => v.IsLocal ? v.Name : $"{v.Remote}/{v.Name}");
}
}

View file

@ -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}";
}
}

View file

@ -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)

View file

@ -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;

View file

@ -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!");
}

View file

@ -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 };

View file

@ -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);
}
}

View file

@ -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!");
}
}

View file

@ -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");

View file

@ -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) =>
{

View file

@ -23,7 +23,7 @@
<DataTemplate DataType="m:Branch">
<StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch}"/>
<TextBlock VerticalAlignment="Center" Text="{Binding Converter={x:Static c:BranchConverters.ToName}}" Margin="8,0,0,0"/>
<TextBlock VerticalAlignment="Center" Text="{Binding FriendlyName}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>

View file

@ -61,7 +61,7 @@
User="{Binding BaseHead.Author}"/>
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding BaseHead.Author.Name}" Margin="8,0,0,0"/>
<Border Grid.Column="2" Background="{DynamicResource Brush.Accent}" CornerRadius="4">
<TextBlock Text="{Binding Base, Converter={x:Static c:BranchConverters.ToName}}" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
<TextBlock Text="{Binding Base.FriendlyName}" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
</Border>
<TextBlock Grid.Column="3" Classes="monospace" Text="{Binding BaseHead.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0" TextDecorations="Underline" PointerPressed="OnPressedSHA"/>
<TextBlock Grid.Column="4" Classes="monospace" Text="{Binding BaseHead.CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
@ -82,7 +82,7 @@
User="{Binding ToHead.Author}"/>
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding ToHead.Author.Name}" Margin="8,0,0,0"/>
<Border Grid.Column="2" Background="{DynamicResource Brush.Accent}" CornerRadius="4">
<TextBlock Text="{Binding To, Converter={x:Static c:BranchConverters.ToName}}" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
<TextBlock Text="{Binding To.FriendlyName}" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
</Border>
<TextBlock Grid.Column="3" Classes="monospace" Text="{Binding ToHead.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0" TextDecorations="Underline" PointerPressed="OnPressedSHA"/>
<TextBlock Grid.Column="4" Classes="monospace" Text="{Binding ToHead.CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>

View file

@ -24,7 +24,7 @@
<DataTemplate DataType="m:Branch">
<StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch}"/>
<TextBlock VerticalAlignment="Center" Text="{Binding Converter={x:Static c:BranchConverters.ToName}}" Margin="8,0,0,0"/>
<TextBlock VerticalAlignment="Center" Text="{Binding FriendlyName}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>

View file

@ -23,7 +23,7 @@
<DataTemplate DataType="m:Branch">
<StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch}"/>
<TextBlock VerticalAlignment="Center" Text="{Binding Converter={x:Static c:BranchConverters.ToName}}" Margin="8,0,0,0"/>
<TextBlock VerticalAlignment="Center" Text="{Binding FriendlyName}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>

View file

@ -18,7 +18,7 @@
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Text="{DynamicResource Text.DeleteBranch.Branch}"/>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<Path Width="14" Height="14" Margin="8,0" Data="{StaticResource Icons.Branch}"/>
<TextBlock Text="{Binding Target, Converter={x:Static c:BranchConverters.ToName}}"/>
<TextBlock Text="{Binding Target.FriendlyName}}"/>
</StackPanel>
<Border Grid.Row="1" Grid.Column="1" Height="32" IsVisible="{Binding !Target.IsLocal}">

View file

@ -64,8 +64,7 @@
<DataGridTemplateColumn Width="*" Header="NAME">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={x:Static c:BranchConverters.ToName}}" ClipToBounds="True"
Classes="monospace" />
<TextBlock Text="{Binding FriendlyName}" ClipToBounds="True" Classes="monospace" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

View file

@ -16,7 +16,7 @@
<TextBlock Text="{Binding Local.Name}" Margin="8,0,0,0"/>
<TextBlock Text="→" Margin="8,0"/>
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch}"/>
<TextBlock Text="{Binding To, Converter={x:Static c:BranchConverters.ToName}}" Margin="8,0,0,0"/>
<TextBlock Text="{Binding To.FriendlyName}" Margin="8,0,0,0"/>
</StackPanel>
</StackPanel>
</UserControl>

View file

@ -54,7 +54,7 @@
<Grid Grid.Row="1" ColumnDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,*" Margin="8">
<TextBlock Grid.Column="0" Text="{DynamicResource Text.InteractiveRebase.Target}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
<Path Grid.Column="1" Width="14" Height="14" Margin="8,0,0,0" Data="{StaticResource Icons.Branch}"/>
<TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Current, Converter={x:Static c:BranchConverters.ToName}}" Margin="8,0,0,0"/>
<TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Current.FriendlyName}" Margin="8,0,0,0"/>
<TextBlock Grid.Column="3" Margin="48,0,0,0" Text="{DynamicResource Text.InteractiveRebase.On}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
<Path Grid.Column="4" Width="14" Height="14" Margin="8,8,0,0" Data="{StaticResource Icons.Commit}"/>

View file

@ -48,7 +48,7 @@
<DataTemplate x:DataType="{x:Type m:Branch}">
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
<Path Margin="0,0,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Branch}"/>
<TextBlock Text="{Binding Converter={x:Static c:BranchConverters.ToName}}"/>
<TextBlock Text="{Binding FriendlyName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>

View file

@ -31,7 +31,7 @@
<DataTemplate DataType="m:Branch">
<StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch}"/>
<TextBlock VerticalAlignment="Center" Text="{Binding Converter={x:Static c:BranchConverters.ToName}}" Margin="8,0,0,0"/>
<TextBlock VerticalAlignment="Center" Text="{Binding FriendlyName}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>

View file

@ -269,7 +269,7 @@
</TreeView.Styles>
<TreeView.ItemTemplate>
<TreeDataTemplate ItemsSource="{Binding Children}" x:DataType="{x:Type vm:BranchTreeNode}">
<Grid Height="24" ColumnDefinitions="20,*,Auto,Auto" Background="Transparent" DoubleTapped="OnDoubleTappedBranchNode">
<Grid Height="24" ColumnDefinitions="20,*,Auto,Auto" Background="Transparent" DoubleTapped="OnDoubleTappedBranchNode" ToolTip.Tip="{Binding Tooltip}">
<Path Grid.Column="0" Classes="folder_icon" Width="12" Height="12" HorizontalAlignment="Left" Margin="0,1,0,0" IsVisible="{Binding IsFolder}"/>
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Margin="0,2,0,0" Data="{StaticResource Icons.Check}" IsVisible="{Binding IsCurrent}" VerticalAlignment="Center"/>
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Margin="2,0,0,0" Data="{StaticResource Icons.Branch}" VerticalAlignment="Center">
@ -281,7 +281,10 @@
</Path.IsVisible>
</Path>
<TextBlock Grid.Column="1" Text="{Binding Name}" Classes="monospace" FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
<TextBlock Grid.Column="1"
Text="{Binding Name}"
Classes="monospace"
FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
<Border Grid.Column="2" Margin="8,0" Height="18" CornerRadius="9" VerticalAlignment="Center" Background="{DynamicResource Brush.Badge}" IsVisible="{Binding IsUpstreamTrackStatusVisible}">
<TextBlock Classes="monospace" FontSize="10" HorizontalAlignment="Center" Margin="9,0" Text="{Binding UpstreamTrackStatus}" Foreground="{DynamicResource Brush.BadgeFG}"/>
@ -294,7 +297,8 @@
IsVisible="{Binding IsBranch}"
Checked="OnToggleFilter"
Unchecked="OnToggleFilter"
IsChecked="{Binding IsFiltered}"/>
IsChecked="{Binding IsFiltered}"
ToolTip.Tip="{DynamicResource Text.Filter}"/>
</Grid>
</TreeDataTemplate>
</TreeView.ItemTemplate>
@ -343,7 +347,7 @@
<TreeView.ItemTemplate>
<TreeDataTemplate ItemsSource="{Binding Children}" x:DataType="{x:Type vm:BranchTreeNode}">
<Grid Height="24" ColumnDefinitions="20,*,Auto" Background="Transparent" DoubleTapped="OnDoubleTappedBranchNode">
<Grid Height="24" ColumnDefinitions="20,*,Auto" Background="Transparent" DoubleTapped="OnDoubleTappedBranchNode" ToolTip.Tip="{Binding Tooltip}">
<Path Grid.Column="0" Classes="folder_icon" Width="10" Height="10" HorizontalAlignment="Left" Margin="0,2,0,0" IsVisible="{Binding IsFolder}" VerticalAlignment="Center"/>
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Margin="0,2,0,0" Data="{StaticResource Icons.Remote}" IsVisible="{Binding IsRemote}" VerticalAlignment="Center"/>
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Margin="2,0,0,0" Data="{StaticResource Icons.Branch}" IsVisible="{Binding IsBranch}" VerticalAlignment="Center"/>
@ -357,7 +361,8 @@
Checked="OnToggleFilter"
Unchecked="OnToggleFilter"
IsVisible="{Binding IsBranch}"
IsChecked="{Binding IsFiltered}"/>
IsChecked="{Binding IsFiltered}"
ToolTip.Tip="{DynamicResource Text.Filter}"/>
</Grid>
</TreeDataTemplate>
</TreeView.ItemTemplate>
@ -444,7 +449,8 @@
Background="Transparent"
Checked="OnToggleFilter"
Unchecked="OnToggleFilter"
IsChecked="{Binding IsFiltered}"/>
IsChecked="{Binding IsFiltered}"
ToolTip.Tip="{DynamicResource Text.Filter}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>