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>
This commit is contained in:
leo
2026-03-04 14:40:49 +08:00
parent 19fa154b3c
commit 7218f60dfb
2 changed files with 22 additions and 9 deletions

View File

@@ -37,12 +37,20 @@
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="8">
<v:CommitMessageToolBox x:Name="Editor" Height="400"/>
<Button Classes="flat primary"
Width="80"
Margin="0,8,0,4"
Content="{DynamicResource Text.Sure}"
Click="SaveAndClose"
HorizontalAlignment="Center"/>
<StackPanel Margin="0,8,0,4" Orientation="Horizontal" HorizontalAlignment="Center" Spacing="8">
<Button Classes="flat primary"
Width="80"
Content="{DynamicResource Text.Sure}"
Click="SaveAndClose"
HorizontalAlignment="Center"/>
<Button Classes="flat"
Width="80"
Content="{DynamicResource Text.Cancel}"
Click="CancelAndClose"
HotKey="Escape"
HorizontalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Grid>
</v:ChromelessWindow>

View File

@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text.Json;
using Avalonia.Interactivity;
namespace SourceGit.Views
@@ -15,7 +16,6 @@ namespace SourceGit.Views
public CommitMessageEditor()
{
CloseOnESC = true;
InitializeComponent();
}
@@ -67,12 +67,17 @@ namespace SourceGit.Views
private void SaveAndClose(object _1, RoutedEventArgs _2)
{
_onSave?.Invoke(Editor.CommitMessage);
_exitCode = 0;
Close();
}
private void CancelAndClose(object _1, RoutedEventArgs _2)
{
_exitCode = -1;
Close();
}
private Action<string> _onSave = null;
private bool _shouldExitApp = true;
private int _exitCode = -1;
private int _exitCode = 0;
}
}