mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-30 08:34:59 +00:00
feature<Histories>: add reword/squash context menu for HEAD commit
This commit is contained in:
parent
76f192785c
commit
59fa5304d8
9 changed files with 279 additions and 6 deletions
59
src/Views/Popups/Reword.xaml
Normal file
59
src/Views/Popups/Reword.xaml
Normal file
|
@ -0,0 +1,59 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.Reword"
|
||||
x:Name="me"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
|
||||
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="500">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="32"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="0" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Reword.On}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="0" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.Commit}"/>
|
||||
<TextBlock x:Name="txtCurrent" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="1" Grid.Column="0"
|
||||
Margin="0,8,8,0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Top"
|
||||
Text="{DynamicResource Text.Reword.Message}"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="1" Grid.Column="1"
|
||||
x:Name="txtMsg"
|
||||
Height="100" Margin="0,8,0,0" Padding="1"
|
||||
AcceptsReturn="True"
|
||||
AcceptsTab="True"
|
||||
TextWrapping="Wrap"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Msg" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validations:CommitMessage/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</controls:TextEdit.Text>
|
||||
</controls:TextEdit>
|
||||
</Grid>
|
||||
</controls:PopupWidget>
|
40
src/Views/Popups/Reword.xaml.cs
Normal file
40
src/Views/Popups/Reword.xaml.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
/// <summary>
|
||||
/// 编辑HEAD的提交描述
|
||||
/// </summary>
|
||||
public partial class Reword : Controls.PopupWidget {
|
||||
private string repo = null;
|
||||
private string old = null;
|
||||
|
||||
public string Msg { get; set; }
|
||||
|
||||
public Reword(string repo, Models.Commit commit) {
|
||||
this.repo = repo;
|
||||
this.old = $"{commit.Subject}\n{commit.Message}".Trim();
|
||||
this.Msg = old;
|
||||
InitializeComponent();
|
||||
txtCurrent.Text = $"{commit.ShortSHA} {commit.Subject}";
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("Reword");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
txtMsg.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
if (Validation.GetHasError(txtMsg)) return null;
|
||||
|
||||
return Task.Run(() => {
|
||||
if (old == Msg) return true;
|
||||
|
||||
Models.Watcher.SetEnabled(repo, false);
|
||||
new Commands.Reword(repo, Msg).Exec();
|
||||
Models.Watcher.SetEnabled(repo, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
73
src/Views/Popups/Squash.xaml
Normal file
73
src/Views/Popups/Squash.xaml
Normal file
|
@ -0,0 +1,73 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.Squash"
|
||||
x:Name="me"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
|
||||
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="32"/>
|
||||
<RowDefinition Height="32"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="0" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Squash.Head}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="0" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.Commit}"/>
|
||||
<TextBlock x:Name="txtHead" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="1" Grid.Column="0"
|
||||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Squash.To}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<StackPanel
|
||||
Grid.Row="1" Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icon.Commit}"/>
|
||||
<TextBlock x:Name="txtParent" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="2" Grid.Column="0"
|
||||
Margin="0,8,8,0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Top"
|
||||
Text="{DynamicResource Text.Squash.Message}"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="2" Grid.Column="1"
|
||||
x:Name="txtMsg"
|
||||
Height="100" Margin="0,8,0,0" Padding="1"
|
||||
AcceptsReturn="True"
|
||||
AcceptsTab="True"
|
||||
TextWrapping="Wrap"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||
<controls:TextEdit.Text>
|
||||
<Binding ElementName="me" Path="Msg" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validations:CommitMessage/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</controls:TextEdit.Text>
|
||||
</controls:TextEdit>
|
||||
</Grid>
|
||||
</controls:PopupWidget>
|
40
src/Views/Popups/Squash.xaml.cs
Normal file
40
src/Views/Popups/Squash.xaml.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
/// <summary>
|
||||
/// 合并当前HEAD提交到上一个
|
||||
/// </summary>
|
||||
public partial class Squash : Controls.PopupWidget {
|
||||
private string repo = null;
|
||||
private string to = null;
|
||||
|
||||
public string Msg { get; set; }
|
||||
|
||||
public Squash(string repo, Models.Commit head, Models.Commit parent) {
|
||||
this.repo = repo;
|
||||
this.to = parent.SHA;
|
||||
this.Msg = $"{parent.Subject}\n{parent.Message}".Trim();
|
||||
InitializeComponent();
|
||||
txtHead.Text = $"{head.ShortSHA} {head.Subject}";
|
||||
txtParent.Text = $"{parent.ShortSHA} {parent.Subject}";
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("Squash");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
txtMsg.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
if (Validation.GetHasError(txtMsg)) return null;
|
||||
|
||||
return Task.Run(() => {
|
||||
Models.Watcher.SetEnabled(repo, false);
|
||||
var succ = new Commands.Reset(repo, to, "--soft").Exec();
|
||||
if (succ) new Commands.Commit(repo, Msg, true).Exec();
|
||||
Models.Watcher.SetEnabled(repo, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -294,6 +294,31 @@ namespace SourceGit.Views.Widgets {
|
|||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(reset);
|
||||
} else {
|
||||
var reword = new MenuItem();
|
||||
reword.Header = App.Text("CommitCM.Reword");
|
||||
reword.Click += (o, e) => {
|
||||
new Popups.Reword(repo.Path, commit).Show();
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(reword);
|
||||
|
||||
var squash = new MenuItem();
|
||||
squash.Header = App.Text("CommitCM.Squash");
|
||||
squash.IsEnabled = commit.Parents.Count == 1;
|
||||
squash.Click += (o, e) => {
|
||||
foreach (var c in cachedCommits) {
|
||||
if (c.SHA == commit.Parents[0]) {
|
||||
new Popups.Squash(repo.Path, commit, c).Show();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Models.Exception.Raise("Can NOT found parent of HEAD!");
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(squash);
|
||||
}
|
||||
|
||||
if (!merged) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue