mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-30 00:24:59 +00:00
feature: add conventional commit message generator (#574)
This commit is contained in:
parent
2821bab77c
commit
9153bbe07f
10 changed files with 369 additions and 8 deletions
146
src/Views/ConventionalCommitMessageBuilder.axaml
Normal file
146
src/Views/ConventionalCommitMessageBuilder.axaml
Normal file
|
@ -0,0 +1,146 @@
|
|||
<v:ChromelessWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:m="using:SourceGit.Models"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
xmlns:c="using:SourceGit.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.ConventionalCommitMessageBuilder"
|
||||
x:DataType="vm:ConventionalCommitMessageBuilder"
|
||||
x:Name="ThisControl"
|
||||
Icon="/App.ico"
|
||||
Title="{DynamicResource Text.ConventionalCommit}"
|
||||
Width="600"
|
||||
SizeToContent="Height"
|
||||
CanResize="False"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Grid RowDefinitions="Auto,Auto,Auto" MinWidth="494">
|
||||
<!-- TitleBar -->
|
||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
|
||||
<Border Grid.Column="0" Grid.ColumnSpan="3"
|
||||
Background="{DynamicResource Brush.TitleBar}"
|
||||
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
||||
PointerPressed="BeginMoveWindow"/>
|
||||
|
||||
<Path Grid.Column="0"
|
||||
Width="14" Height="14"
|
||||
Data="{StaticResource Icons.Code}"
|
||||
Margin="10,0,0,0"
|
||||
IsVisible="{OnPlatform True, macOS=False}"/>
|
||||
|
||||
<v:CaptionButtonsMacOS Grid.Column="0"
|
||||
Margin="0,2,0,0"
|
||||
IsCloseButtonOnly="True"
|
||||
IsVisible="{OnPlatform False, macOS=True}"/>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.ConventionalCommit}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
IsHitTestVisible="False"/>
|
||||
|
||||
<v:CaptionButtons Grid.Column="2"
|
||||
IsCloseButtonOnly="True"
|
||||
IsVisible="{OnPlatform True, macOS=False}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- Body -->
|
||||
<Grid Grid.Row="1" Margin="16,8" RowDefinitions="32,32,32,100,100,32" ColumnDefinitions="Auto,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Top"
|
||||
Margin="0,6,8,0"
|
||||
Text="{DynamicResource Text.ConventionalCommit.Type}"/>
|
||||
<ComboBox Grid.Row="0" Grid.Column="1"
|
||||
Height="28" Padding="8,0"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding Source={x:Static m:ConventionalCommitType.Supported}}"
|
||||
SelectedItem="{Binding Type, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="{x:Type m:ConventionalCommitType}">
|
||||
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Type}"/>
|
||||
<TextBlock Margin="6,0,0,0" Text="{Binding Description}" Foreground="{DynamicResource Brush.FG2}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Top"
|
||||
Margin="0,6,8,0"
|
||||
Text="{DynamicResource Text.ConventionalCommit.Scope}"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1"
|
||||
Height="26"
|
||||
VerticalAlignment="Center"
|
||||
CornerRadius="2"
|
||||
Watermark="{DynamicResource Text.Optional}"
|
||||
Text="{Binding Scope, Mode=TwoWay}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Top"
|
||||
Margin="0,6,8,0"
|
||||
Text="{DynamicResource Text.ConventionalCommit.ShortDescription}"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1"
|
||||
Height="26"
|
||||
VerticalAlignment="Center"
|
||||
CornerRadius="2"
|
||||
Text="{Binding Description, Mode=TwoWay}"/>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Top"
|
||||
Margin="0,6,8,0"
|
||||
Text="{DynamicResource Text.ConventionalCommit.Detail}"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="1"
|
||||
Height="96"
|
||||
AcceptsReturn="True"
|
||||
AcceptsTab="True"
|
||||
TextWrapping="Wrap"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Top"
|
||||
CornerRadius="2"
|
||||
Watermark="{DynamicResource Text.Optional}"
|
||||
Text="{Binding Detail, Mode=TwoWay}"/>
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Top"
|
||||
Margin="0,6,8,0"
|
||||
Text="{DynamicResource Text.ConventionalCommit.BreakingChanges}"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="1"
|
||||
Height="96"
|
||||
AcceptsReturn="True"
|
||||
AcceptsTab="True"
|
||||
TextWrapping="Wrap"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Top"
|
||||
CornerRadius="2"
|
||||
Watermark="{DynamicResource Text.Optional}"
|
||||
Text="{Binding BreakingChanges, Mode=TwoWay}"/>
|
||||
|
||||
<TextBlock Grid.Row="5" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Top"
|
||||
Margin="0,6,8,0"
|
||||
Text="{DynamicResource Text.ConventionalCommit.ClosedIssue}"/>
|
||||
<TextBox Grid.Row="5" Grid.Column="1"
|
||||
Height="26"
|
||||
VerticalAlignment="Center"
|
||||
CornerRadius="2"
|
||||
Watermark="{DynamicResource Text.Optional}"
|
||||
Text="{Binding ClosedIssue, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- Apply Button -->
|
||||
<Button Grid.Row="2"
|
||||
Classes="flat primary"
|
||||
Height="32" Width="80"
|
||||
Margin="0,8,0,16"
|
||||
HorizontalAlignment="Center"
|
||||
Content="{DynamicResource Text.Sure}"
|
||||
Click="OnApplyClicked"/>
|
||||
</Grid>
|
||||
</v:ChromelessWindow>
|
29
src/Views/ConventionalCommitMessageBuilder.axaml.cs
Normal file
29
src/Views/ConventionalCommitMessageBuilder.axaml.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class ConventionalCommitMessageBuilder : ChromelessWindow
|
||||
{
|
||||
public ConventionalCommitMessageBuilder()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
|
||||
{
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
|
||||
private void OnApplyClicked(object _, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.ConventionalCommitMessageBuilder builder)
|
||||
{
|
||||
if (builder.Apply())
|
||||
Close();
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -185,7 +185,7 @@
|
|||
<v:CommitMessageTextBox Grid.Row="2" Text="{Binding CommitMessage, Mode=TwoWay}"/>
|
||||
|
||||
<!-- Commit Options -->
|
||||
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,Auto,Auto,*,Auto,Auto,Auto,Auto">
|
||||
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,Auto,Auto,Auto,*,Auto,Auto,Auto,Auto">
|
||||
<Button Grid.Column="0"
|
||||
Classes="icon_button"
|
||||
Margin="4,0,0,0" Padding="0"
|
||||
|
@ -198,7 +198,6 @@
|
|||
|
||||
<Button Grid.Column="1"
|
||||
Classes="icon_button"
|
||||
Width="32"
|
||||
Margin="4,2,0,0"
|
||||
Click="OnOpenAIAssist"
|
||||
ToolTip.Tip="{DynamicResource Text.AIAssistant.Tip}"
|
||||
|
@ -207,23 +206,33 @@
|
|||
<Path Width="15" Height="15" Data="{StaticResource Icons.AIAssist}"/>
|
||||
</Button>
|
||||
|
||||
<CheckBox Grid.Column="2"
|
||||
<Button Grid.Column="2"
|
||||
Classes="icon_button"
|
||||
Margin="0,2,0,0"
|
||||
Click="OnOpenConventionalCommitHelper"
|
||||
ToolTip.Tip="{DynamicResource Text.ConventionalCommit}"
|
||||
ToolTip.Placement="Top"
|
||||
ToolTip.VerticalOffset="0">
|
||||
<Path Width="15" Height="15" Data="{StaticResource Icons.CommitMessageGenerator}"/>
|
||||
</Button>
|
||||
|
||||
<CheckBox Grid.Column="3"
|
||||
Height="24"
|
||||
Margin="4,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
IsChecked="{Binding AutoStageBeforeCommit, Mode=TwoWay}"
|
||||
Content="{DynamicResource Text.WorkingCopy.AutoStage}"/>
|
||||
|
||||
<CheckBox Grid.Column="3"
|
||||
<CheckBox Grid.Column="4"
|
||||
Height="24"
|
||||
Margin="8,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
IsChecked="{Binding UseAmend, Mode=TwoWay}"
|
||||
Content="{DynamicResource Text.WorkingCopy.Amend}"/>
|
||||
|
||||
<v:LoadingIcon Grid.Column="5" Width="18" Height="18" IsVisible="{Binding IsCommitting}"/>
|
||||
<v:LoadingIcon Grid.Column="6" Width="18" Height="18" IsVisible="{Binding IsCommitting}"/>
|
||||
|
||||
<Button Grid.Column="6"
|
||||
<Button Grid.Column="7"
|
||||
Classes="flat primary"
|
||||
Content="{DynamicResource Text.WorkingCopy.Commit}"
|
||||
Height="28"
|
||||
|
@ -248,13 +257,13 @@
|
|||
</Button>
|
||||
|
||||
<!-- Invisible button just to add another hotkey `Ctrl+Shift+Enter` to commit with auto-stage -->
|
||||
<Button Grid.Column="7"
|
||||
<Button Grid.Column="8"
|
||||
Width="0" Height="0"
|
||||
Background="Transparent"
|
||||
Command="{Binding CommitWithAutoStage}"
|
||||
HotKey="{OnPlatform Ctrl+Shift+Enter, macOS=⌘+Shift+Enter}"/>
|
||||
|
||||
<Button Grid.Column="8"
|
||||
<Button Grid.Column="9"
|
||||
Classes="flat"
|
||||
Content="{DynamicResource Text.WorkingCopy.CommitAndPush}"
|
||||
Height="28"
|
||||
|
|
|
@ -144,5 +144,20 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnOpenConventionalCommitHelper(object _, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.WorkingCopy vm)
|
||||
{
|
||||
var dialog = new ConventionalCommitMessageBuilder()
|
||||
{
|
||||
DataContext = new ViewModels.ConventionalCommitMessageBuilder(vm)
|
||||
};
|
||||
|
||||
App.OpenDialog(dialog);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue