Skip to content

Commit 7218f60

Browse files
committed
refactor: standalone commit message editor (#2096)
- Clicking `OK` button will apply the modified message and exit with code `0` - Clicking `CANCEL` or pressing `ESC` will not apply the modified message and exit with code `-1` - Clicking the window caption button `X` will not apply the modified message and exit with code `0` Signed-off-by: leo <longshuang@msn.cn>
1 parent 19fa154 commit 7218f60

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/Views/CommitMessageEditor.axaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@
3737

3838
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="8">
3939
<v:CommitMessageToolBox x:Name="Editor" Height="400"/>
40-
<Button Classes="flat primary"
41-
Width="80"
42-
Margin="0,8,0,4"
43-
Content="{DynamicResource Text.Sure}"
44-
Click="SaveAndClose"
45-
HorizontalAlignment="Center"/>
40+
41+
<StackPanel Margin="0,8,0,4" Orientation="Horizontal" HorizontalAlignment="Center" Spacing="8">
42+
<Button Classes="flat primary"
43+
Width="80"
44+
Content="{DynamicResource Text.Sure}"
45+
Click="SaveAndClose"
46+
HorizontalAlignment="Center"/>
47+
<Button Classes="flat"
48+
Width="80"
49+
Content="{DynamicResource Text.Cancel}"
50+
Click="CancelAndClose"
51+
HotKey="Escape"
52+
HorizontalAlignment="Center"/>
53+
</StackPanel>
4654
</StackPanel>
4755
</Grid>
4856
</v:ChromelessWindow>

src/Views/CommitMessageEditor.axaml.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Text.Json;
4+
45
using Avalonia.Interactivity;
56

67
namespace SourceGit.Views
@@ -15,7 +16,6 @@ public string ConventionalTypesOverride
1516

1617
public CommitMessageEditor()
1718
{
18-
CloseOnESC = true;
1919
InitializeComponent();
2020
}
2121

@@ -67,12 +67,17 @@ protected override void OnClosed(EventArgs e)
6767
private void SaveAndClose(object _1, RoutedEventArgs _2)
6868
{
6969
_onSave?.Invoke(Editor.CommitMessage);
70-
_exitCode = 0;
70+
Close();
71+
}
72+
73+
private void CancelAndClose(object _1, RoutedEventArgs _2)
74+
{
75+
_exitCode = -1;
7176
Close();
7277
}
7378

7479
private Action<string> _onSave = null;
7580
private bool _shouldExitApp = true;
76-
private int _exitCode = -1;
81+
private int _exitCode = 0;
7782
}
7883
}

0 commit comments

Comments
 (0)