mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-23 18:30:34 +08:00
fix: rewrite the ConfirmEmptyCommit dialog to avoid pressing the same button more than one time (#1777)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -170,6 +170,19 @@ namespace SourceGit
|
||||
return false;
|
||||
}
|
||||
|
||||
public static async Task<Models.ConfirmEmptyCommitResult> AskConfirmEmptyCommitAsync(bool hasLocalChanges)
|
||||
{
|
||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||
{
|
||||
var confirm = new Views.ConfirmEmptyCommit();
|
||||
confirm.TxtMessage.Text = Text(hasLocalChanges ? "ConfirmEmptyCommit.WithLocalChanges" : "ConfirmEmptyCommit.NoLocalChanges");
|
||||
confirm.BtnStageAllAndCommit.IsVisible = hasLocalChanges;
|
||||
return await confirm.ShowDialog<Models.ConfirmEmptyCommitResult>(owner);
|
||||
}
|
||||
|
||||
return Models.ConfirmEmptyCommitResult.Cancel;
|
||||
}
|
||||
|
||||
public static void RaiseException(string context, string message)
|
||||
{
|
||||
if (Current is App { _launcher: not null } app)
|
||||
|
||||
9
src/Models/ConfirmEmptyCommitResult.cs
Normal file
9
src/Models/ConfirmEmptyCommitResult.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public enum ConfirmEmptyCommitResult
|
||||
{
|
||||
Cancel = 0,
|
||||
StageAllAndCommit,
|
||||
CreateEmptyCommit,
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class ConfirmEmptyCommit
|
||||
{
|
||||
public bool HasLocalChanges
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Message
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public ConfirmEmptyCommit(WorkingCopy wc, bool autoPush, int unstagedCount)
|
||||
{
|
||||
_wc = wc;
|
||||
_autoPush = autoPush;
|
||||
HasLocalChanges = unstagedCount > 0;
|
||||
Message = App.Text(HasLocalChanges ? "ConfirmEmptyCommit.WithLocalChanges" : "ConfirmEmptyCommit.NoLocalChanges");
|
||||
}
|
||||
|
||||
public async Task StageAllThenCommitAsync()
|
||||
{
|
||||
await _wc.CommitAsync(true, _autoPush, Models.CommitCheckPassed.FileCount);
|
||||
}
|
||||
|
||||
public async Task ContinueAsync()
|
||||
{
|
||||
await _wc.CommitAsync(false, _autoPush, Models.CommitCheckPassed.FileCount);
|
||||
}
|
||||
|
||||
private readonly WorkingCopy _wc;
|
||||
private readonly bool _autoPush;
|
||||
}
|
||||
}
|
||||
@@ -664,8 +664,12 @@ namespace SourceGit.ViewModels
|
||||
{
|
||||
if ((!autoStage && _staged.Count == 0) || (autoStage && _cached.Count == 0))
|
||||
{
|
||||
await App.ShowDialog(new ConfirmEmptyCommit(this, autoPush, _cached.Count));
|
||||
return;
|
||||
var rs = await App.AskConfirmEmptyCommitAsync(_cached.Count > 0);
|
||||
if (rs == Models.ConfirmEmptyCommitResult.Cancel)
|
||||
return;
|
||||
|
||||
if (rs == Models.ConfirmEmptyCommitResult.StageAllAndCommit)
|
||||
autoStage = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.ConfirmEmptyCommit"
|
||||
x:DataType="vm:ConfirmEmptyCommit"
|
||||
x:Name="ThisControl"
|
||||
Icon="/App.ico"
|
||||
Title="{DynamicResource Text.Warn}"
|
||||
@@ -39,15 +37,15 @@
|
||||
|
||||
<!-- Body -->
|
||||
<Border Grid.Row="1" Margin="16">
|
||||
<TextBlock Text="{Binding Message}" MaxWidth="520" TextWrapping="Wrap"/>
|
||||
<TextBlock x:Name="TxtMessage" MaxWidth="520" TextWrapping="Wrap"/>
|
||||
</Border>
|
||||
|
||||
<!-- Buttons -->
|
||||
<StackPanel Grid.Row="2" Margin="0,0,0,16" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<Button Classes="flat"
|
||||
x:Name="BtnStageAllAndCommit"
|
||||
Height="30"
|
||||
Margin="4,0"
|
||||
IsVisible="{Binding HasLocalChanges}"
|
||||
Click="StageAllThenCommit"
|
||||
Content="{DynamicResource Text.ConfirmEmptyCommit.StageAllThenCommit}"
|
||||
HorizontalContentAlignment="Center"
|
||||
|
||||
@@ -9,25 +9,19 @@ namespace SourceGit.Views
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void StageAllThenCommit(object _1, RoutedEventArgs _2)
|
||||
private void StageAllThenCommit(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
if (DataContext is ViewModels.ConfirmEmptyCommit vm)
|
||||
await vm.StageAllThenCommitAsync();
|
||||
|
||||
Close();
|
||||
Close(Models.ConfirmEmptyCommitResult.StageAllAndCommit);
|
||||
}
|
||||
|
||||
private async void Continue(object _1, RoutedEventArgs _2)
|
||||
private void Continue(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
if (DataContext is ViewModels.ConfirmEmptyCommit vm)
|
||||
await vm.ContinueAsync();
|
||||
|
||||
Close();
|
||||
Close(Models.ConfirmEmptyCommitResult.CreateEmptyCommit);
|
||||
}
|
||||
|
||||
private void CloseWindow(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
Close();
|
||||
Close(Models.ConfirmEmptyCommitResult.Cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user