refactor: commit message editor (#2096)

- When using `SourceGit` as standalone commit message editor, always quits with code `0`.
- Use hotkey `ESC` and dialog titlebar button instead of a custom `OK` button to close this window.
This commit is contained in:
leo
2026-02-04 10:43:16 +08:00
parent 5f0bd16eac
commit ceea4a18fc
2 changed files with 8 additions and 11 deletions

View File

@@ -37,12 +37,10 @@
<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"/>
<Button Width="0" Height="0"
Margin="0" Padding="0"
Click="OnCloseByHotKey"
HotKey="Escape"/>
</StackPanel>
</Grid>
</v:ChromelessWindow>

View File

@@ -60,19 +60,18 @@ namespace SourceGit.Views
{
base.OnClosed(e);
_onSave?.Invoke(Editor.CommitMessage);
if (_shouldExitApp)
App.Quit(_exitCode);
App.Quit(0);
}
private void SaveAndClose(object _1, RoutedEventArgs _2)
private void OnCloseByHotKey(object sender, RoutedEventArgs e)
{
_onSave?.Invoke(Editor.CommitMessage);
_exitCode = 0;
Close();
}
private Action<string> _onSave = null;
private bool _shouldExitApp = true;
private int _exitCode = -1;
}
}