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 = public static readonly FuncValueConverter<string, bool> ContainsSpaces =
new FuncValueConverter<string, bool>(v => v != null && v.Contains(' ')); 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) private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty = false, bool confirmWithFilter = false)
{ {
if (string.IsNullOrWhiteSpace(_commitMessage))
return;
if (!_repo.CanCreatePopup()) if (!_repo.CanCreatePopup())
{ {
App.RaiseException(_repo.FullPath, "Repository has unfinished job! Please wait!"); App.RaiseException(_repo.FullPath, "Repository has unfinished job! Please wait!");
@ -1672,12 +1675,6 @@ namespace SourceGit.ViewModels
return; return;
} }
if (string.IsNullOrWhiteSpace(_commitMessage))
{
App.RaiseException(_repo.FullPath, "Commit without message is NOT allowed!");
return;
}
if (!_useAmend && !allowEmpty) if (!_useAmend && !allowEmpty)
{ {
if ((autoStage && _count == 0) || (!autoStage && _staged.Count == 0)) if ((autoStage && _count == 0) || (!autoStage && _staged.Count == 0))

View file

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