mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 13:20:30 +08:00
feature: auto-open commit message editor
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -17,23 +17,14 @@ namespace SourceGit.Views
|
||||
{
|
||||
_onSave = msg => File.WriteAllText(file, msg);
|
||||
_shouldExitApp = true;
|
||||
|
||||
var content = File.ReadAllText(file).ReplaceLineEndings("\n").Trim();
|
||||
var parts = content.Split('\n', 2);
|
||||
Editor.SubjectEditor.Text = parts[0];
|
||||
if (parts.Length > 1)
|
||||
Editor.DescriptionEditor.Text = parts[1];
|
||||
Editor.Text = File.ReadAllText(file).ReplaceLineEndings("\n").Trim();
|
||||
}
|
||||
|
||||
public void AsBuiltin(string msg, Action<string> onSave)
|
||||
{
|
||||
_onSave = onSave;
|
||||
_shouldExitApp = false;
|
||||
|
||||
var parts = msg.Split('\n', 2);
|
||||
Editor.SubjectEditor.Text = parts[0];
|
||||
if (parts.Length > 1)
|
||||
Editor.DescriptionEditor.Text = parts[1];
|
||||
Editor.Text = msg.Trim();
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
ItemsSource="{Binding Items}"
|
||||
SelectionMode="Single"
|
||||
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
|
||||
SelectionChanged="OnRowsSelectionChanged"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
Grid.IsSharedSizeScope="True">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
@@ -99,6 +100,23 @@ namespace SourceGit.Views
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnRowsSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (!_firstSelectionChangedHandled &&
|
||||
sender is InteractiveRebaseListBox list &&
|
||||
list.SelectedItem is ViewModels.InteractiveRebaseItem item)
|
||||
{
|
||||
_firstSelectionChangedHandled = true;
|
||||
|
||||
if (item.Action == Models.InteractiveRebaseAction.Reword)
|
||||
{
|
||||
var dialog = new CommitMessageEditor();
|
||||
dialog.AsBuiltin(item.FullMessage, msg => item.FullMessage = msg);
|
||||
dialog.ShowDialog(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSetupRowHeaderDragDrop(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Border border)
|
||||
@@ -242,5 +260,7 @@ namespace SourceGit.Views
|
||||
|
||||
flyout.Items.Add(menuItem);
|
||||
}
|
||||
|
||||
private bool _firstSelectionChangedHandled = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user