mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-23 03:14:59 +00:00
fix: Conventional Commit Helper
not working in Interactive Rebase
(#1446)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
f59b34fe25
commit
9d2f8b1555
7 changed files with 97 additions and 64 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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}"
|
69
src/Views/CommitMessageEditor.axaml.cs
Normal file
69
src/Views/CommitMessageEditor.axaml.cs
Normal file
|
@ -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<string> 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<string> _onSave = null;
|
||||
private bool _shouldExitApp = true;
|
||||
private int _exitCode = -1;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -189,14 +189,11 @@
|
|||
|
||||
<!-- Subject -->
|
||||
<Grid Grid.Column="2" ColumnDefinitions="Auto,*" ClipToBounds="True">
|
||||
<Button Grid.Column="0" Classes="icon_button" Margin="0,0,8,0" IsVisible="{Binding Action, Converter={x:Static c:InteractiveRebaseActionConverters.CanEditMessage}}">
|
||||
<Button.Flyout>
|
||||
<Flyout Placement="BottomEdgeAlignedLeft">
|
||||
<Panel Width="600" Height="120">
|
||||
<v:CommitMessageTextBox Text="{Binding FullMessage, Mode=TwoWay}"/>
|
||||
</Panel>
|
||||
</Flyout>
|
||||
</Button.Flyout>
|
||||
<Button Grid.Column="0"
|
||||
Classes="icon_button"
|
||||
Margin="0,0,8,0"
|
||||
IsVisible="{Binding Action, Converter={x:Static c:InteractiveRebaseActionConverters.CanEditMessage}}"
|
||||
Click="OnOpenCommitMessageEditor">
|
||||
<Path Width="14" Height="14" Margin="0,4,0,0" Data="{StaticResource Icons.Edit}"/>
|
||||
</Button>
|
||||
<TextBlock Grid.Column="1" Classes="primary" Margin="0,0,4,0" Text="{Binding Subject}"/>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue