feature: add a checkbox to also delete the tracking remote branch (#99)

This commit is contained in:
leo 2024-05-05 19:45:28 +08:00
parent eced2e09bd
commit d46979a0c5
7 changed files with 42 additions and 5 deletions

View file

@ -121,6 +121,7 @@
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">Delete Branch</x:String> <x:String x:Key="Text.DeleteBranch" xml:space="preserve">Delete Branch</x:String>
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">Branch :</x:String> <x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">Branch :</x:String>
<x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">You are about to delete a remote branch!!!</x:String> <x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">You are about to delete a remote branch!!!</x:String>
<x:String x:Key="Text.DeleteBranch.WithTrackingRemote" xml:space="preserve">Also delete remote branch${0}$</x:String>
<x:String x:Key="Text.DeleteRemote" xml:space="preserve">Delete Remote</x:String> <x:String x:Key="Text.DeleteRemote" xml:space="preserve">Delete Remote</x:String>
<x:String x:Key="Text.DeleteRemote.Remote" xml:space="preserve">Remote :</x:String> <x:String x:Key="Text.DeleteRemote.Remote" xml:space="preserve">Remote :</x:String>
<x:String x:Key="Text.DeleteRepositoryNode.Target" xml:space="preserve">Target :</x:String> <x:String x:Key="Text.DeleteRepositoryNode.Target" xml:space="preserve">Target :</x:String>

View file

@ -121,6 +121,7 @@
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">删除分支确认</x:String> <x:String x:Key="Text.DeleteBranch" xml:space="preserve">删除分支确认</x:String>
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">分支名 </x:String> <x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">分支名 </x:String>
<x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">您正在删除远程上的分支,请务必小心!!!</x:String> <x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">您正在删除远程上的分支,请务必小心!!!</x:String>
<x:String x:Key="Text.DeleteBranch.WithTrackingRemote" xml:space="preserve">同时删除远程分支${0}$</x:String>
<x:String x:Key="Text.DeleteRemote" xml:space="preserve">删除远程确认</x:String> <x:String x:Key="Text.DeleteRemote" xml:space="preserve">删除远程确认</x:String>
<x:String x:Key="Text.DeleteRemote.Remote" xml:space="preserve">远程名 </x:String> <x:String x:Key="Text.DeleteRemote.Remote" xml:space="preserve">远程名 </x:String>
<x:String x:Key="Text.DeleteRepositoryNode.Target" xml:space="preserve">目标 </x:String> <x:String x:Key="Text.DeleteRepositoryNode.Target" xml:space="preserve">目标 </x:String>

View file

@ -10,10 +10,36 @@ namespace SourceGit.ViewModels
private set; private set;
} }
public Models.Branch TrackingRemoteBranch
{
get;
private set;
}
public object DeleteTrackingRemoteTip
{
get;
private set;
}
public bool AlsoDeleteTrackingRemote
{
get => _alsoDeleteTrackingRemote;
set => SetProperty(ref _alsoDeleteTrackingRemote, value);
}
public DeleteBranch(Repository repo, Models.Branch branch) public DeleteBranch(Repository repo, Models.Branch branch)
{ {
_repo = repo; _repo = repo;
Target = branch; Target = branch;
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);
}
View = new Views.DeleteBranch() { DataContext = this }; View = new Views.DeleteBranch() { DataContext = this };
} }
@ -27,6 +53,9 @@ namespace SourceGit.ViewModels
if (Target.IsLocal) if (Target.IsLocal)
{ {
Commands.Branch.Delete(_repo.FullPath, Target.Name); Commands.Branch.Delete(_repo.FullPath, Target.Name);
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
new Commands.Push(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name).Exec();
} }
else else
{ {
@ -39,5 +68,6 @@ namespace SourceGit.ViewModels
} }
private readonly Repository _repo = null; private readonly Repository _repo = null;
private bool _alsoDeleteTrackingRemote = false;
} }
} }

View file

@ -383,7 +383,6 @@ namespace SourceGit.ViewModels
fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream); fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream);
fastForward.Icon = App.CreateMenuIcon("Icons.FastForward"); fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
fastForward.IsEnabled = !string.IsNullOrEmpty(current.UpstreamTrackStatus) && current.UpstreamTrackStatus.IndexOf('↑') < 0; fastForward.IsEnabled = !string.IsNullOrEmpty(current.UpstreamTrackStatus) && current.UpstreamTrackStatus.IndexOf('↑') < 0;
;
fastForward.Click += (o, e) => fastForward.Click += (o, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (PopupHost.CanCreatePopup())

View file

@ -2,7 +2,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels" xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters" xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.DeleteBranch" x:Class="SourceGit.Views.DeleteBranch"
@ -12,7 +14,7 @@
Classes="bold" Classes="bold"
Text="{DynamicResource Text.DeleteBranch}"/> Text="{DynamicResource Text.DeleteBranch}"/>
<Grid Margin="0,16,8,0" RowDefinitions="32,Auto" ColumnDefinitions="150,*"> <Grid Margin="0,16,8,0" RowDefinitions="32,Auto" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Text="{DynamicResource Text.DeleteBranch.Branch}"/> <TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Text="{DynamicResource Text.DeleteBranch.Branch}"/>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal"> <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<Path Width="14" Height="14" Margin="8,0" Data="{StaticResource Icons.Branch}"/> <Path Width="14" Height="14" Margin="8,0" Data="{StaticResource Icons.Branch}"/>
@ -20,12 +22,16 @@
</StackPanel> </StackPanel>
<Border Grid.Row="1" Grid.Column="1" Height="32" IsVisible="{Binding !Target.IsLocal}"> <Border Grid.Row="1" Grid.Column="1" Height="32" IsVisible="{Binding !Target.IsLocal}">
<TextBlock Margin="8,0" <TextBlock Margin="6,0,0,0"
Text="{DynamicResource Text.DeleteBranch.IsRemoteTip}" Text="{DynamicResource Text.DeleteBranch.IsRemoteTip}"
Foreground="{DynamicResource Brush.FG2}" Foreground="{DynamicResource Brush.FG2}"
FontStyle="Italic" FontStyle="Italic"
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
</Border> </Border>
<Border Grid.Row="1" Grid.Column="1" Height="32" IsVisible="{Binding TrackingRemoteBranch, Converter={x:Static ObjectConverters.IsNotNull}}">
<CheckBox Margin="6,0,0,0" Content="{Binding DeleteTrackingRemoteTip}" IsChecked="{Binding AlsoDeleteTrackingRemote, Mode=TwoWay}"/>
</Border>
</Grid> </Grid>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View file

@ -113,7 +113,7 @@ namespace SourceGit.Views
e.Handled = true; e.Handled = true;
return; return;
} }
else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) || else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) ||
(!OperatingSystem.IsMacOS() && e.Key == Key.Tab)) (!OperatingSystem.IsMacOS() && e.Key == Key.Tab))
{ {
vm.GotoNextTab(); vm.GotoNextTab();

View file

@ -71,7 +71,7 @@ namespace SourceGit.Views
FontSize, FontSize,
Foreground); Foreground);
return new Size(formatted.Width - 16, formatted.Height); return new Size(formatted.Width, formatted.Height);
} }
public override void Render(DrawingContext context) public override void Render(DrawingContext context)