Skip to content

Commit 6f24d66

Browse files
committed
fix: rewrite the ConfirmEmptyCommit dialog to avoid pressing the same button more than one time (#1777)
Signed-off-by: leo <[email protected]>
1 parent c1e28a1 commit 6f24d66

File tree

6 files changed

+35
-57
lines changed

6 files changed

+35
-57
lines changed

src/App.axaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ public static async Task<bool> AskConfirmAsync(string message)
170170
return false;
171171
}
172172

173+
public static async Task<Models.ConfirmEmptyCommitResult> AskConfirmEmptyCommitAsync(bool hasLocalChanges)
174+
{
175+
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
176+
{
177+
var confirm = new Views.ConfirmEmptyCommit();
178+
confirm.TxtMessage.Text = Text(hasLocalChanges ? "ConfirmEmptyCommit.WithLocalChanges" : "ConfirmEmptyCommit.NoLocalChanges");
179+
confirm.BtnStageAllAndCommit.IsVisible = hasLocalChanges;
180+
return await confirm.ShowDialog<Models.ConfirmEmptyCommitResult>(owner);
181+
}
182+
183+
return Models.ConfirmEmptyCommitResult.Cancel;
184+
}
185+
173186
public static void RaiseException(string context, string message)
174187
{
175188
if (Current is App { _launcher: not null } app)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace SourceGit.Models
2+
{
3+
public enum ConfirmEmptyCommitResult
4+
{
5+
Cancel = 0,
6+
StageAllAndCommit,
7+
CreateEmptyCommit,
8+
}
9+
}

src/ViewModels/ConfirmEmptyCommit.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/ViewModels/WorkingCopy.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,12 @@ public async Task CommitAsync(bool autoStage, bool autoPush, Models.CommitCheckP
664664
{
665665
if ((!autoStage && _staged.Count == 0) || (autoStage && _cached.Count == 0))
666666
{
667-
await App.ShowDialog(new ConfirmEmptyCommit(this, autoPush, _cached.Count));
668-
return;
667+
var rs = await App.AskConfirmEmptyCommitAsync(_cached.Count > 0);
668+
if (rs == Models.ConfirmEmptyCommitResult.Cancel)
669+
return;
670+
671+
if (rs == Models.ConfirmEmptyCommitResult.StageAllAndCommit)
672+
autoStage = true;
669673
}
670674
}
671675

src/Views/ConfirmEmptyCommit.axaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:v="using:SourceGit.Views"
6-
xmlns:vm="using:SourceGit.ViewModels"
76
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
87
x:Class="SourceGit.Views.ConfirmEmptyCommit"
9-
x:DataType="vm:ConfirmEmptyCommit"
108
x:Name="ThisControl"
119
Icon="/App.ico"
1210
Title="{DynamicResource Text.Warn}"
@@ -39,15 +37,15 @@
3937

4038
<!-- Body -->
4139
<Border Grid.Row="1" Margin="16">
42-
<TextBlock Text="{Binding Message}" MaxWidth="520" TextWrapping="Wrap"/>
40+
<TextBlock x:Name="TxtMessage" MaxWidth="520" TextWrapping="Wrap"/>
4341
</Border>
4442

4543
<!-- Buttons -->
4644
<StackPanel Grid.Row="2" Margin="0,0,0,16" Orientation="Horizontal" HorizontalAlignment="Center">
4745
<Button Classes="flat"
46+
x:Name="BtnStageAllAndCommit"
4847
Height="30"
4948
Margin="4,0"
50-
IsVisible="{Binding HasLocalChanges}"
5149
Click="StageAllThenCommit"
5250
Content="{DynamicResource Text.ConfirmEmptyCommit.StageAllThenCommit}"
5351
HorizontalContentAlignment="Center"

src/Views/ConfirmEmptyCommit.axaml.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,19 @@ public ConfirmEmptyCommit()
99
InitializeComponent();
1010
}
1111

12-
private async void StageAllThenCommit(object _1, RoutedEventArgs _2)
12+
private void StageAllThenCommit(object _1, RoutedEventArgs _2)
1313
{
14-
if (DataContext is ViewModels.ConfirmEmptyCommit vm)
15-
await vm.StageAllThenCommitAsync();
16-
17-
Close();
14+
Close(Models.ConfirmEmptyCommitResult.StageAllAndCommit);
1815
}
1916

20-
private async void Continue(object _1, RoutedEventArgs _2)
17+
private void Continue(object _1, RoutedEventArgs _2)
2118
{
22-
if (DataContext is ViewModels.ConfirmEmptyCommit vm)
23-
await vm.ContinueAsync();
24-
25-
Close();
19+
Close(Models.ConfirmEmptyCommitResult.CreateEmptyCommit);
2620
}
2721

2822
private void CloseWindow(object _1, RoutedEventArgs _2)
2923
{
30-
Close();
24+
Close(Models.ConfirmEmptyCommitResult.Cancel);
3125
}
3226
}
3327
}

0 commit comments

Comments
 (0)