Skip to content

Commit da38b72

Browse files
committed
ux: disable commit button when commit message is empty
Signed-off-by: leo <[email protected]>
1 parent 7cda721 commit da38b72

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/Converters/StringConverters.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,8 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
8181

8282
public static readonly FuncValueConverter<string, bool> ContainsSpaces =
8383
new FuncValueConverter<string, bool>(v => v != null && v.Contains(' '));
84+
85+
public static readonly FuncValueConverter<string, bool> IsNotNullOrWhitespace =
86+
new FuncValueConverter<string, bool>(v => v != null && v.Trim().Length > 0);
8487
}
8588
}

src/ViewModels/WorkingCopy.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,9 @@ private void SetDetail(Models.Change change, bool isUnstaged)
16521652

16531653
private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty = false, bool confirmWithFilter = false)
16541654
{
1655+
if (string.IsNullOrWhiteSpace(_commitMessage))
1656+
return;
1657+
16551658
if (!_repo.CanCreatePopup())
16561659
{
16571660
App.RaiseException(_repo.FullPath, "Repository has unfinished job! Please wait!");
@@ -1672,12 +1675,6 @@ private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty = false, bo
16721675
return;
16731676
}
16741677

1675-
if (string.IsNullOrWhiteSpace(_commitMessage))
1676-
{
1677-
App.RaiseException(_repo.FullPath, "Commit without message is NOT allowed!");
1678-
return;
1679-
}
1680-
16811678
if (!_useAmend && !allowEmpty)
16821679
{
16831680
if ((autoStage && _count == 0) || (!autoStage && _staged.Count == 0))

src/Views/WorkingCopy.axaml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@
295295
</SplitButton.IsEnabled>
296296
<SplitButton.Flyout>
297297
<MenuFlyout>
298-
<MenuItem Header="{DynamicResource Text.WorkingCopy.CommitToEdit}" Command="{Binding Commit}"/>
298+
<MenuItem Header="{DynamicResource Text.WorkingCopy.CommitToEdit}"
299+
Command="{Binding Commit}"
300+
IsEnabled="{Binding CommitMessage, Converter={x:Static c:StringConverters.IsNotNullOrWhitespace}}"/>
299301
</MenuFlyout>
300302
</SplitButton.Flyout>
301303
</SplitButton>
@@ -309,7 +311,6 @@
309311
Command="{Binding Commit}"
310312
HotKey="{OnPlatform Ctrl+Enter, macOS=⌘+Enter}"
311313
IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNull}}"
312-
IsEnabled="{Binding !IsCommitting}"
313314
ToolTip.Placement="Top"
314315
ToolTip.VerticalOffset="0">
315316
<ToolTip.Tip>
@@ -324,15 +325,28 @@
324325
</TextBlock>
325326
</StackPanel>
326327
</ToolTip.Tip>
328+
329+
<Button.IsEnabled>
330+
<MultiBinding Converter="{x:Static BoolConverters.And}">
331+
<Binding Path="IsCommitting" Converter="{x:Static BoolConverters.Not}"/>
332+
<Binding Path="CommitMessage" Converter="{x:Static c:StringConverters.IsNotNullOrWhitespace}"/>
333+
</MultiBinding>
334+
</Button.IsEnabled>
327335
</Button>
328336

329337
<!-- Invisible button just to add another hotkey `Ctrl+Shift+Enter` to commit with auto-stage -->
330338
<Button Grid.Column="7"
331339
Width="0" Height="0"
332340
Background="Transparent"
333341
Command="{Binding CommitWithAutoStage}"
334-
HotKey="{OnPlatform Ctrl+Shift+Enter, macOS=⌘+Shift+Enter}"
335-
IsEnabled="{Binding !IsCommitting}"/>
342+
HotKey="{OnPlatform Ctrl+Shift+Enter, macOS=⌘+Shift+Enter}">
343+
<Button.IsEnabled>
344+
<MultiBinding Converter="{x:Static BoolConverters.And}">
345+
<Binding Path="IsCommitting" Converter="{x:Static BoolConverters.Not}"/>
346+
<Binding Path="CommitMessage" Converter="{x:Static c:StringConverters.IsNotNullOrWhitespace}"/>
347+
</MultiBinding>
348+
</Button.IsEnabled>
349+
</Button>
336350

337351
<Button Grid.Column="8"
338352
Classes="flat"
@@ -342,10 +356,16 @@
342356
Padding="8,0"
343357
Command="{Binding CommitWithPush}"
344358
HotKey="Alt+Enter"
345-
IsEnabled="{Binding !IsCommitting}"
346359
ToolTip.Tip="{OnPlatform Alt+Enter, macOS=⌥+Enter}"
347360
ToolTip.Placement="Top"
348361
ToolTip.VerticalOffset="0">
362+
<Button.IsEnabled>
363+
<MultiBinding Converter="{x:Static BoolConverters.And}">
364+
<Binding Path="IsCommitting" Converter="{x:Static BoolConverters.Not}"/>
365+
<Binding Path="CommitMessage" Converter="{x:Static c:StringConverters.IsNotNullOrWhitespace}"/>
366+
</MultiBinding>
367+
</Button.IsEnabled>
368+
349369
<Button.IsVisible>
350370
<MultiBinding Converter="{x:Static BoolConverters.And}">
351371
<Binding Path="HasRemotes"/>

0 commit comments

Comments
 (0)