ux: disable commit button when commit message is empty

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-08 18:03:40 +08:00
parent 7cda7211f1
commit da38b72ee5
No known key found for this signature in database
3 changed files with 31 additions and 11 deletions

View file

@ -81,5 +81,8 @@ namespace SourceGit.Converters
public static readonly FuncValueConverter<string, bool> ContainsSpaces =
new FuncValueConverter<string, bool>(v => v != null && v.Contains(' '));
public static readonly FuncValueConverter<string, bool> IsNotNullOrWhitespace =
new FuncValueConverter<string, bool>(v => v != null && v.Trim().Length > 0);
}
}

View file

@ -1652,6 +1652,9 @@ namespace SourceGit.ViewModels
private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty = false, bool confirmWithFilter = false)
{
if (string.IsNullOrWhiteSpace(_commitMessage))
return;
if (!_repo.CanCreatePopup())
{
App.RaiseException(_repo.FullPath, "Repository has unfinished job! Please wait!");
@ -1672,12 +1675,6 @@ namespace SourceGit.ViewModels
return;
}
if (string.IsNullOrWhiteSpace(_commitMessage))
{
App.RaiseException(_repo.FullPath, "Commit without message is NOT allowed!");
return;
}
if (!_useAmend && !allowEmpty)
{
if ((autoStage && _count == 0) || (!autoStage && _staged.Count == 0))

View file

@ -295,7 +295,9 @@
</SplitButton.IsEnabled>
<SplitButton.Flyout>
<MenuFlyout>
<MenuItem Header="{DynamicResource Text.WorkingCopy.CommitToEdit}" Command="{Binding Commit}"/>
<MenuItem Header="{DynamicResource Text.WorkingCopy.CommitToEdit}"
Command="{Binding Commit}"
IsEnabled="{Binding CommitMessage, Converter={x:Static c:StringConverters.IsNotNullOrWhitespace}}"/>
</MenuFlyout>
</SplitButton.Flyout>
</SplitButton>
@ -309,7 +311,6 @@
Command="{Binding Commit}"
HotKey="{OnPlatform Ctrl+Enter, macOS=⌘+Enter}"
IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNull}}"
IsEnabled="{Binding !IsCommitting}"
ToolTip.Placement="Top"
ToolTip.VerticalOffset="0">
<ToolTip.Tip>
@ -324,6 +325,13 @@
</TextBlock>
</StackPanel>
</ToolTip.Tip>
<Button.IsEnabled>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="IsCommitting" Converter="{x:Static BoolConverters.Not}"/>
<Binding Path="CommitMessage" Converter="{x:Static c:StringConverters.IsNotNullOrWhitespace}"/>
</MultiBinding>
</Button.IsEnabled>
</Button>
<!-- Invisible button just to add another hotkey `Ctrl+Shift+Enter` to commit with auto-stage -->
@ -331,8 +339,14 @@
Width="0" Height="0"
Background="Transparent"
Command="{Binding CommitWithAutoStage}"
HotKey="{OnPlatform Ctrl+Shift+Enter, macOS=⌘+Shift+Enter}"
IsEnabled="{Binding !IsCommitting}"/>
HotKey="{OnPlatform Ctrl+Shift+Enter, macOS=⌘+Shift+Enter}">
<Button.IsEnabled>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="IsCommitting" Converter="{x:Static BoolConverters.Not}"/>
<Binding Path="CommitMessage" Converter="{x:Static c:StringConverters.IsNotNullOrWhitespace}"/>
</MultiBinding>
</Button.IsEnabled>
</Button>
<Button Grid.Column="8"
Classes="flat"
@ -342,10 +356,16 @@
Padding="8,0"
Command="{Binding CommitWithPush}"
HotKey="Alt+Enter"
IsEnabled="{Binding !IsCommitting}"
ToolTip.Tip="{OnPlatform Alt+Enter, macOS=⌥+Enter}"
ToolTip.Placement="Top"
ToolTip.VerticalOffset="0">
<Button.IsEnabled>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="IsCommitting" Converter="{x:Static BoolConverters.Not}"/>
<Binding Path="CommitMessage" Converter="{x:Static c:StringConverters.IsNotNullOrWhitespace}"/>
</MultiBinding>
</Button.IsEnabled>
<Button.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="HasRemotes"/>