refactor: rewrite the way to deal with uncommitted local changes when checkout/pull/create branch (#1085)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-13 10:21:54 +08:00
parent e430e847ff
commit 0e261cffd2
No known key found for this signature in database
21 changed files with 63 additions and 260 deletions

View file

@ -18,7 +18,7 @@
<RowDefinition Height="32"/>
<RowDefinition Height="Auto" MinHeight="32"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
@ -32,21 +32,13 @@
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
<WrapPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.DoNothing}"
x:Name="RadioDoNothing"
GroupName="LocalChanges"
<WrapPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton GroupName="LocalChanges"
Margin="0,0,8,0"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
x:Name="RadioStashAndReply"
GroupName="LocalChanges"
Margin="0,0,8,0"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
x:Name="RadioDiscard"
GroupName="LocalChanges"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton GroupName="LocalChanges"
Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"/>
</WrapPanel>
</Grid>
</StackPanel>

View file

@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
@ -9,51 +8,5 @@ namespace SourceGit.Views
{
InitializeComponent();
}
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
var vm = DataContext as ViewModels.Checkout;
if (vm == null)
return;
switch (vm.PreAction)
{
case Models.DealWithLocalChanges.DoNothing:
RadioDoNothing.IsChecked = true;
break;
case Models.DealWithLocalChanges.StashAndReaply:
RadioStashAndReply.IsChecked = true;
break;
default:
RadioDiscard.IsChecked = true;
break;
}
}
private void OnLocalChangeActionIsCheckedChanged(object sender, RoutedEventArgs e)
{
var vm = DataContext as ViewModels.Checkout;
if (vm == null)
return;
if (RadioDoNothing.IsChecked == true)
{
if (vm.PreAction != Models.DealWithLocalChanges.DoNothing)
vm.PreAction = Models.DealWithLocalChanges.DoNothing;
return;
}
if (RadioStashAndReply.IsChecked == true)
{
if (vm.PreAction != Models.DealWithLocalChanges.StashAndReaply)
vm.PreAction = Models.DealWithLocalChanges.StashAndReaply;
return;
}
if (vm.PreAction != Models.DealWithLocalChanges.Discard)
vm.PreAction = Models.DealWithLocalChanges.Discard;
}
}
}

View file

@ -30,16 +30,16 @@
<StackPanel Grid.Row="1" Grid.Column="1" Height="32" Orientation="Horizontal">
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReply}"
GroupName="LocalChanges"
IsChecked="{Binding AutoStash, Mode=TwoWay}" />
Margin="0,0,8,0"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"
GroupName="LocalChanges"
Margin="8,0,0,0" />
GroupName="LocalChanges"/>
</StackPanel>
<Grid Grid.Row="2" Grid.Column="1" ColumnDefinitions="Auto,*" Margin="0,6,0,0">
<Path Grid.Column="0"
Width="14" Height="14"
Data="{StaticResource Icons.Error}"
<Path Grid.Column="0"
Width="14" Height="14"
Data="{StaticResource Icons.Error}"
Fill="DarkOrange"/>
<TextBlock Grid.Column="1" Margin="8,0,0,0"
Text="{DynamicResource Text.Checkout.Commit.Warning}"

View file

@ -70,20 +70,12 @@
IsVisible="{Binding !IsBareRepository}"/>
<Border Grid.Row="3" Grid.Column="1" MinHeight="32" IsVisible="{Binding !IsBareRepository}">
<WrapPanel Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.DoNothing}"
x:Name="RadioDoNothing"
GroupName="LocalChanges"
<RadioButton GroupName="LocalChanges"
Margin="0,0,8,0"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
x:Name="RadioStashAndReply"
GroupName="LocalChanges"
Margin="0,0,8,0"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
x:Name="RadioDiscard"
GroupName="LocalChanges"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton GroupName="LocalChanges"
Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"/>
</WrapPanel>
</Border>

View file

@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
@ -9,51 +8,5 @@ namespace SourceGit.Views
{
InitializeComponent();
}
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
var vm = DataContext as ViewModels.CreateBranch;
if (vm == null)
return;
switch (vm.PreAction)
{
case Models.DealWithLocalChanges.DoNothing:
RadioDoNothing.IsChecked = true;
break;
case Models.DealWithLocalChanges.StashAndReaply:
RadioStashAndReply.IsChecked = true;
break;
default:
RadioDiscard.IsChecked = true;
break;
}
}
private void OnLocalChangeActionIsCheckedChanged(object sender, RoutedEventArgs e)
{
var vm = DataContext as ViewModels.CreateBranch;
if (vm == null)
return;
if (RadioDoNothing.IsChecked == true)
{
if (vm.PreAction != Models.DealWithLocalChanges.DoNothing)
vm.PreAction = Models.DealWithLocalChanges.DoNothing;
return;
}
if (RadioStashAndReply.IsChecked == true)
{
if (vm.PreAction != Models.DealWithLocalChanges.StashAndReaply)
vm.PreAction = Models.DealWithLocalChanges.StashAndReaply;
return;
}
if (vm.PreAction != Models.DealWithLocalChanges.Discard)
vm.PreAction = Models.DealWithLocalChanges.Discard;
}
}
}

View file

@ -22,7 +22,7 @@
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
@ -84,22 +84,14 @@
Margin="0,0,8,0"
Text="{DynamicResource Text.Pull.LocalChanges}"/>
<WrapPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.DoNothing}"
x:Name="RadioDoNothing"
<RadioButton GroupName="LocalChanges"
Margin="0,0,8,0"
GroupName="LocalChanges"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.StashAndReply}"
x:Name="RadioStashAndReply"
Margin="0,0,8,0"
GroupName="LocalChanges"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.Discard}"
x:Name="RadioDiscard"
GroupName="LocalChanges"
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
Content="{DynamicResource Text.Pull.LocalChanges.StashAndReply}"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton GroupName="LocalChanges"
Content="{DynamicResource Text.Pull.LocalChanges.Discard}"/>
</WrapPanel>
<CheckBox Grid.Row="4" Grid.Column="1"
Content="{DynamicResource Text.Pull.FetchAllBranches}"
IsChecked="{Binding FetchAllBranches, Mode=TwoWay}"/>

View file

@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
@ -9,51 +8,5 @@ namespace SourceGit.Views
{
InitializeComponent();
}
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
var vm = DataContext as ViewModels.Pull;
if (vm == null)
return;
switch (vm.PreAction)
{
case Models.DealWithLocalChanges.DoNothing:
RadioDoNothing.IsChecked = true;
break;
case Models.DealWithLocalChanges.StashAndReaply:
RadioStashAndReply.IsChecked = true;
break;
default:
RadioDiscard.IsChecked = true;
break;
}
}
private void OnLocalChangeActionIsCheckedChanged(object sender, RoutedEventArgs e)
{
var vm = DataContext as ViewModels.Pull;
if (vm == null)
return;
if (RadioDoNothing.IsChecked == true)
{
if (vm.PreAction != Models.DealWithLocalChanges.DoNothing)
vm.PreAction = Models.DealWithLocalChanges.DoNothing;
return;
}
if (RadioStashAndReply.IsChecked == true)
{
if (vm.PreAction != Models.DealWithLocalChanges.StashAndReaply)
vm.PreAction = Models.DealWithLocalChanges.StashAndReaply;
return;
}
if (vm.PreAction != Models.DealWithLocalChanges.Discard)
vm.PreAction = Models.DealWithLocalChanges.Discard;
}
}
}