Skip to content

Commit 1872148

Browse files
committed
fix: the way to deal with local changes did not update after radio toggle changed (#748)
1 parent 1c0d8a2 commit 1872148

File tree

6 files changed

+160
-22
lines changed

6 files changed

+160
-22
lines changed

src/Views/Checkout.axaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,21 @@
3232
HorizontalAlignment="Right" VerticalAlignment="Center"
3333
Margin="0,0,8,0"
3434
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
35-
<WrapPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
36-
<WrapPanel.Resources>
37-
<ac:EnumToBoolConverter x:Key="EnumToBoolConverter"/>
38-
</WrapPanel.Resources>
39-
35+
<WrapPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
4036
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.DoNothing}"
37+
x:Name="RadioDoNothing"
4138
GroupName="LocalChanges"
4239
Margin="0,0,8,0"
43-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.DoNothing}}"/>
40+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
4441
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
42+
x:Name="RadioStashAndReply"
4543
GroupName="LocalChanges"
4644
Margin="0,0,8,0"
47-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.StashAndReaply}}"/>
45+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
4846
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
47+
x:Name="RadioDiscard"
4948
GroupName="LocalChanges"
50-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.Discard}}"/>
49+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
5150
</WrapPanel>
5251
</Grid>
5352
</StackPanel>

src/Views/Checkout.axaml.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia.Controls;
2+
using Avalonia.Interactivity;
23

34
namespace SourceGit.Views
45
{
@@ -8,5 +9,51 @@ public Checkout()
89
{
910
InitializeComponent();
1011
}
12+
13+
protected override void OnLoaded(RoutedEventArgs e)
14+
{
15+
base.OnLoaded(e);
16+
17+
var vm = DataContext as ViewModels.Checkout;
18+
if (vm == null)
19+
return;
20+
21+
switch (vm.PreAction)
22+
{
23+
case Models.DealWithLocalChanges.DoNothing:
24+
RadioDoNothing.IsChecked = true;
25+
break;
26+
case Models.DealWithLocalChanges.StashAndReaply:
27+
RadioStashAndReply.IsChecked = true;
28+
break;
29+
default:
30+
RadioDiscard.IsChecked = true;
31+
break;
32+
}
33+
}
34+
35+
private void OnLocalChangeActionIsCheckedChanged(object sender, RoutedEventArgs e)
36+
{
37+
var vm = DataContext as ViewModels.Checkout;
38+
if (vm == null)
39+
return;
40+
41+
if (RadioDoNothing.IsChecked == true)
42+
{
43+
if (vm.PreAction != Models.DealWithLocalChanges.DoNothing)
44+
vm.PreAction = Models.DealWithLocalChanges.DoNothing;
45+
return;
46+
}
47+
48+
if (RadioStashAndReply.IsChecked == true)
49+
{
50+
if (vm.PreAction != Models.DealWithLocalChanges.StashAndReaply)
51+
vm.PreAction = Models.DealWithLocalChanges.StashAndReaply;
52+
return;
53+
}
54+
55+
if (vm.PreAction != Models.DealWithLocalChanges.Discard)
56+
vm.PreAction = Models.DealWithLocalChanges.Discard;
57+
}
1158
}
1259
}

src/Views/CreateBranch.axaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,20 @@
6969
Margin="0,0,8,0"
7070
Text="{DynamicResource Text.CreateBranch.LocalChanges}"/>
7171
<WrapPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
72-
<WrapPanel.Resources>
73-
<ac:EnumToBoolConverter x:Key="EnumToBoolConverter"/>
74-
</WrapPanel.Resources>
75-
7672
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.DoNothing}"
73+
x:Name="RadioDoNothing"
7774
GroupName="LocalChanges"
7875
Margin="0,0,8,0"
79-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.DoNothing}}"/>
76+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
8077
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
78+
x:Name="RadioStashAndReply"
8179
GroupName="LocalChanges"
8280
Margin="0,0,8,0"
83-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.StashAndReaply}}"/>
81+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
8482
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
83+
x:Name="RadioDiscard"
8584
GroupName="LocalChanges"
86-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.Discard}}"/>
85+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
8786
</WrapPanel>
8887

8988
<CheckBox Grid.Row="3" Grid.Column="1"

src/Views/CreateBranch.axaml.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia.Controls;
2+
using Avalonia.Interactivity;
23

34
namespace SourceGit.Views
45
{
@@ -8,5 +9,51 @@ public CreateBranch()
89
{
910
InitializeComponent();
1011
}
12+
13+
protected override void OnLoaded(RoutedEventArgs e)
14+
{
15+
base.OnLoaded(e);
16+
17+
var vm = DataContext as ViewModels.CreateBranch;
18+
if (vm == null)
19+
return;
20+
21+
switch (vm.PreAction)
22+
{
23+
case Models.DealWithLocalChanges.DoNothing:
24+
RadioDoNothing.IsChecked = true;
25+
break;
26+
case Models.DealWithLocalChanges.StashAndReaply:
27+
RadioStashAndReply.IsChecked = true;
28+
break;
29+
default:
30+
RadioDiscard.IsChecked = true;
31+
break;
32+
}
33+
}
34+
35+
private void OnLocalChangeActionIsCheckedChanged(object sender, RoutedEventArgs e)
36+
{
37+
var vm = DataContext as ViewModels.CreateBranch;
38+
if (vm == null)
39+
return;
40+
41+
if (RadioDoNothing.IsChecked == true)
42+
{
43+
if (vm.PreAction != Models.DealWithLocalChanges.DoNothing)
44+
vm.PreAction = Models.DealWithLocalChanges.DoNothing;
45+
return;
46+
}
47+
48+
if (RadioStashAndReply.IsChecked == true)
49+
{
50+
if (vm.PreAction != Models.DealWithLocalChanges.StashAndReaply)
51+
vm.PreAction = Models.DealWithLocalChanges.StashAndReaply;
52+
return;
53+
}
54+
55+
if (vm.PreAction != Models.DealWithLocalChanges.Discard)
56+
vm.PreAction = Models.DealWithLocalChanges.Discard;
57+
}
1158
}
1259
}

src/Views/Pull.axaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,20 @@
7777
Margin="0,0,8,0"
7878
Text="{DynamicResource Text.Pull.LocalChanges}"/>
7979
<WrapPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
80-
<WrapPanel.Resources>
81-
<ac:EnumToBoolConverter x:Key="EnumToBoolConverter"/>
82-
</WrapPanel.Resources>
83-
8480
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.DoNothing}"
81+
x:Name="RadioDoNothing"
8582
Margin="0,0,8,0"
8683
GroupName="LocalChanges"
87-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.DoNothing}}"/>
84+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
8885
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.StashAndReply}"
86+
x:Name="RadioStashAndReply"
8987
Margin="0,0,8,0"
9088
GroupName="LocalChanges"
91-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.StashAndReaply}}"/>
89+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
9290
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.Discard}"
91+
x:Name="RadioDiscard"
9392
GroupName="LocalChanges"
94-
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.Discard}}"/>
93+
IsCheckedChanged="OnLocalChangeActionIsCheckedChanged"/>
9594
</WrapPanel>
9695

9796
<CheckBox Grid.Row="4" Grid.Column="1"

src/Views/Pull.axaml.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia.Controls;
2+
using Avalonia.Interactivity;
23

34
namespace SourceGit.Views
45
{
@@ -8,5 +9,51 @@ public Pull()
89
{
910
InitializeComponent();
1011
}
12+
13+
protected override void OnLoaded(RoutedEventArgs e)
14+
{
15+
base.OnLoaded(e);
16+
17+
var vm = DataContext as ViewModels.Pull;
18+
if (vm == null)
19+
return;
20+
21+
switch (vm.PreAction)
22+
{
23+
case Models.DealWithLocalChanges.DoNothing:
24+
RadioDoNothing.IsChecked = true;
25+
break;
26+
case Models.DealWithLocalChanges.StashAndReaply:
27+
RadioStashAndReply.IsChecked = true;
28+
break;
29+
default:
30+
RadioDiscard.IsChecked = true;
31+
break;
32+
}
33+
}
34+
35+
private void OnLocalChangeActionIsCheckedChanged(object sender, RoutedEventArgs e)
36+
{
37+
var vm = DataContext as ViewModels.Pull;
38+
if (vm == null)
39+
return;
40+
41+
if (RadioDoNothing.IsChecked == true)
42+
{
43+
if (vm.PreAction != Models.DealWithLocalChanges.DoNothing)
44+
vm.PreAction = Models.DealWithLocalChanges.DoNothing;
45+
return;
46+
}
47+
48+
if (RadioStashAndReply.IsChecked == true)
49+
{
50+
if (vm.PreAction != Models.DealWithLocalChanges.StashAndReaply)
51+
vm.PreAction = Models.DealWithLocalChanges.StashAndReaply;
52+
return;
53+
}
54+
55+
if (vm.PreAction != Models.DealWithLocalChanges.Discard)
56+
vm.PreAction = Models.DealWithLocalChanges.Discard;
57+
}
1158
}
1259
}

0 commit comments

Comments
 (0)