diff --git a/src/App.axaml.cs b/src/App.axaml.cs index ef91ccdb..6b42700d 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -531,8 +531,8 @@ namespace SourceGit return true; } - var editor = new Views.StandaloneCommitMessageEditor(); - editor.SetFile(file); + var editor = new Views.CommitMessageEditor(); + editor.AsStandalone(file); desktop.MainWindow = editor; return true; } diff --git a/src/Views/StandaloneCommitMessageEditor.axaml b/src/Views/CommitMessageEditor.axaml similarity index 96% rename from src/Views/StandaloneCommitMessageEditor.axaml rename to src/Views/CommitMessageEditor.axaml index 8a0dc91a..c469ae8d 100644 --- a/src/Views/StandaloneCommitMessageEditor.axaml +++ b/src/Views/CommitMessageEditor.axaml @@ -4,7 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:v="using:SourceGit.Views" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="SourceGit.Views.StandaloneCommitMessageEditor" + x:Class="SourceGit.Views.CommitMessageEditor" x:Name="ThisControl" Icon="/App.ico" Title="{DynamicResource Text.CodeEditor}" diff --git a/src/Views/CommitMessageEditor.axaml.cs b/src/Views/CommitMessageEditor.axaml.cs new file mode 100644 index 00000000..7a23f85c --- /dev/null +++ b/src/Views/CommitMessageEditor.axaml.cs @@ -0,0 +1,69 @@ +using System; +using System.IO; + +using Avalonia.Interactivity; + +namespace SourceGit.Views +{ + public partial class CommitMessageEditor : ChromelessWindow + { + public CommitMessageEditor() + { + InitializeComponent(); + } + + public void AsStandalone(string file) + { + _onSave = msg => File.WriteAllText(file, msg); + _shouldExitApp = true; + + var content = File.ReadAllText(file).ReplaceLineEndings("\n").Trim(); + var firstLineEnd = content.IndexOf('\n', StringComparison.Ordinal); + if (firstLineEnd == -1) + { + Editor.SubjectEditor.Text = content; + } + else + { + Editor.SubjectEditor.Text = content.Substring(0, firstLineEnd); + Editor.DescriptionEditor.Text = content.Substring(firstLineEnd + 1).Trim(); + } + } + + public void AsBuiltin(string msg, Action onSave) + { + _onSave = onSave; + _shouldExitApp = false; + + var firstLineEnd = msg.IndexOf('\n', StringComparison.Ordinal); + if (firstLineEnd == -1) + { + Editor.SubjectEditor.Text = msg; + } + else + { + Editor.SubjectEditor.Text = msg.Substring(0, firstLineEnd); + Editor.DescriptionEditor.Text = msg.Substring(firstLineEnd + 1).Trim(); + } + } + + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + + if (_shouldExitApp) + App.Quit(_exitCode); + } + + private void SaveAndClose(object _1, RoutedEventArgs _2) + { + _onSave?.Invoke(Editor.Text); + _exitCode = 0; + Close(); + } + + private Action _onSave = null; + private bool _shouldExitApp = true; + private int _exitCode = -1; + } +} diff --git a/src/Views/CommitMessageTextBox.axaml.cs b/src/Views/CommitMessageTextBox.axaml.cs index 8b6535e5..5330852c 100644 --- a/src/Views/CommitMessageTextBox.axaml.cs +++ b/src/Views/CommitMessageTextBox.axaml.cs @@ -201,7 +201,14 @@ namespace SourceGit.Views private void OnOpenConventionalCommitHelper(object _, RoutedEventArgs e) { - App.ShowWindow(new ViewModels.ConventionalCommitMessageBuilder(text => Text = text), true); + var toplevel = TopLevel.GetTopLevel(this); + if (toplevel is Window owner) + { + var vm = new ViewModels.ConventionalCommitMessageBuilder(text => Text = text); + var builder = new ConventionalCommitMessageBuilder() { DataContext = vm }; + builder.ShowDialog(owner); + } + e.Handled = true; } diff --git a/src/Views/InteractiveRebase.axaml b/src/Views/InteractiveRebase.axaml index f9f69e88..b505827b 100644 --- a/src/Views/InteractiveRebase.axaml +++ b/src/Views/InteractiveRebase.axaml @@ -189,14 +189,11 @@ - diff --git a/src/Views/InteractiveRebase.axaml.cs b/src/Views/InteractiveRebase.axaml.cs index 5c8caa53..3406e631 100644 --- a/src/Views/InteractiveRebase.axaml.cs +++ b/src/Views/InteractiveRebase.axaml.cs @@ -167,6 +167,18 @@ namespace SourceGit.Views e.Handled = true; } + private void OnOpenCommitMessageEditor(object sender, RoutedEventArgs e) + { + if (sender is Button { DataContext: ViewModels.InteractiveRebaseItem item }) + { + var dialog = new CommitMessageEditor(); + dialog.AsBuiltin(item.FullMessage, msg => item.FullMessage = msg); + dialog.ShowDialog(this); + } + + e.Handled = true; + } + private async void OnStartJobs(object _1, RoutedEventArgs _2) { var vm = DataContext as ViewModels.InteractiveRebase; diff --git a/src/Views/StandaloneCommitMessageEditor.axaml.cs b/src/Views/StandaloneCommitMessageEditor.axaml.cs deleted file mode 100644 index 8a49ee74..00000000 --- a/src/Views/StandaloneCommitMessageEditor.axaml.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.IO; - -using Avalonia.Interactivity; - -namespace SourceGit.Views -{ - public partial class StandaloneCommitMessageEditor : ChromelessWindow - { - public StandaloneCommitMessageEditor() - { - InitializeComponent(); - } - - public void SetFile(string file) - { - _file = file; - - var content = File.ReadAllText(file).ReplaceLineEndings("\n").Trim(); - var firstLineEnd = content.IndexOf('\n'); - if (firstLineEnd == -1) - { - Editor.SubjectEditor.Text = content; - } - else - { - Editor.SubjectEditor.Text = content.Substring(0, firstLineEnd); - Editor.DescriptionEditor.Text = content.Substring(firstLineEnd + 1).Trim(); - } - } - - protected override void OnClosed(EventArgs e) - { - base.OnClosed(e); - App.Quit(_exitCode); - } - - private void SaveAndClose(object _1, RoutedEventArgs _2) - { - if (!string.IsNullOrEmpty(_file)) - { - File.WriteAllText(_file, Editor.Text); - _exitCode = 0; - } - - Close(); - } - - private string _file = string.Empty; - private int _exitCode = -1; - } -}