mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
optimize<InteractiveRebase>: remove commit message editor from InteractiveRebase panel (as a result of my bad implementation)
This commit is contained in:
parent
c816dcf039
commit
567fad495b
3 changed files with 94 additions and 196 deletions
|
@ -35,6 +35,30 @@ namespace SourceGit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Open repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repo"></param>
|
||||||
|
public static void Open(Git.Repository repo) {
|
||||||
|
(Current.MainWindow as UI.Launcher).Open(repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save settings.
|
||||||
|
/// </summary>
|
||||||
|
public static void SaveSetting() {
|
||||||
|
var settingFile = Path.Combine(
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"SourceGit",
|
||||||
|
"preference.json");
|
||||||
|
|
||||||
|
var dir = Path.GetDirectoryName(settingFile);
|
||||||
|
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
|
||||||
|
|
||||||
|
var data = JsonSerializer.Serialize(Setting, new JsonSerializerOptions() { WriteIndented = true });
|
||||||
|
File.WriteAllText(settingFile, data);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Startup event.
|
/// Startup event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -42,20 +66,7 @@ namespace SourceGit {
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void OnAppStartup(object sender, StartupEventArgs e) {
|
private void OnAppStartup(object sender, StartupEventArgs e) {
|
||||||
// Use this app as a sequence editor?
|
// Use this app as a sequence editor?
|
||||||
var args = e.Args;
|
if (OpenAsEditor(e)) return;
|
||||||
if (args.Length > 1) {
|
|
||||||
if (args[0] == "--interactive-rebase") {
|
|
||||||
if (args.Length < 3) {
|
|
||||||
Environment.Exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
File.WriteAllText(args[2], File.ReadAllText(args[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
Environment.Exit(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load settings.
|
// Load settings.
|
||||||
var settingFile = Path.Combine(
|
var settingFile = Path.Combine(
|
||||||
|
@ -98,30 +109,6 @@ namespace SourceGit {
|
||||||
Current.MainWindow.Show();
|
Current.MainWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Open repository.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="repo"></param>
|
|
||||||
public static void Open(Git.Repository repo) {
|
|
||||||
(Current.MainWindow as UI.Launcher).Open(repo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Save settings.
|
|
||||||
/// </summary>
|
|
||||||
public static void SaveSetting() {
|
|
||||||
var settingFile = Path.Combine(
|
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
||||||
"SourceGit",
|
|
||||||
"preference.json");
|
|
||||||
|
|
||||||
var dir = Path.GetDirectoryName(settingFile);
|
|
||||||
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
|
|
||||||
|
|
||||||
var data = JsonSerializer.Serialize(Setting, new JsonSerializerOptions() { WriteIndented = true });
|
|
||||||
File.WriteAllText(settingFile, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deactivated event.
|
/// Deactivated event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -131,5 +118,29 @@ namespace SourceGit {
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
SaveSetting();
|
SaveSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Try to open app as git editor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool OpenAsEditor(StartupEventArgs e) {
|
||||||
|
if (e.Args.Length < 3) return false;
|
||||||
|
|
||||||
|
switch (e.Args[0]) {
|
||||||
|
case "--sequence":
|
||||||
|
var output = File.CreateText(e.Args[2]);
|
||||||
|
output.Write(File.ReadAllText(e.Args[1]));
|
||||||
|
output.Flush();
|
||||||
|
output.Close();
|
||||||
|
|
||||||
|
Environment.Exit(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,40 +139,11 @@
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
||||||
<Grid Grid.Column="1">
|
<TextBlock
|
||||||
<ContentControl x:Name="MessageEditorAnchor" MouseDoubleClick="PopupMessageEditor">
|
Grid.Column="1"
|
||||||
<TextBlock Text="{Binding Subject, Mode=TwoWay}" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG}"/>
|
Text="{Binding Commit.Subject}"
|
||||||
</ContentControl>
|
VerticalAlignment="Center"
|
||||||
|
Foreground="{StaticResource Brush.FG}"/>
|
||||||
<Popup x:Name="MessageEditor" Placement="Bottom" IsOpen="{Binding IsEditorOpened}" VerticalOffset="1" Height="150" Width="400" PlacementTarget="{Binding ElementName=MessageEditorAnchor}">
|
|
||||||
<Border BorderBrush="{StaticResource Brush.Accent1}" BorderThickness="1" Background="{StaticResource Brush.BG4}">
|
|
||||||
<Grid Margin="8">
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="*"/>
|
|
||||||
<RowDefinition Height="32"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
<Border Grid.Row="0" BorderBrush="{StaticResource Brush.Border1}" BorderThickness="1">
|
|
||||||
<Grid>
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="24"/>
|
|
||||||
<RowDefinition Height="1"/>
|
|
||||||
<RowDefinition Height="79"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<TextBox Grid.Row="0" Text="{Binding EditSubject, Mode=TwoWay}" Height="32" Padding="2,0" helpers:TextBoxHelper.Placeholder="Enter commit subject" BorderThickness="0"/>
|
|
||||||
<Rectangle Grid.Row="1" Height="1" Fill="{StaticResource Brush.FG}" Opacity="0.1"/>
|
|
||||||
<TextBox Grid.Row="2" Text="{Binding EditMessage, Mode=TwoWay}" TextChanged="CommitMessageChanged" Height="79" ScrollViewer.VerticalScrollBarVisibility="Auto" Padding="2" helpers:TextBoxHelper.Placeholder="Enter commit description. Optional" helpers:TextBoxHelper.PlaceholderBaseline="Top" BorderThickness="0" AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap"/>
|
|
||||||
</Grid>
|
|
||||||
</Border>
|
|
||||||
|
|
||||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,8,0,0">
|
|
||||||
<Button Click="ApplyMessageEdit" Height="24" Style="{StaticResource Style.Button.AccentBordered}" BorderThickness="1" Content="APPLY" Margin="8,0"/>
|
|
||||||
<Button Click="HideMessageEditor" Height="24" Style="{StaticResource Style.Button.Bordered}" BorderThickness="1" Content="CANCEL"/>
|
|
||||||
</StackPanel>
|
|
||||||
</Grid>
|
|
||||||
</Border>
|
|
||||||
</Popup>
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
|
|
|
@ -51,64 +51,17 @@ namespace SourceGit.UI {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rebase item.
|
/// Rebase item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class InteractiveRebaseItem : INotifyPropertyChanged {
|
public class InteractiveRebaseItem {
|
||||||
private InteractiveRebaseMode mode = InteractiveRebaseMode.Pick;
|
private InteractiveRebaseMode mode = InteractiveRebaseMode.Pick;
|
||||||
private bool isEditorOpened = false;
|
|
||||||
private string editSubject = null;
|
|
||||||
private string editMsg = null;
|
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public Git.Commit Commit {
|
||||||
|
get;
|
||||||
public Git.Commit Commit { get; set; }
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
public int Mode {
|
public int Mode {
|
||||||
get { return (int)mode; }
|
get { return (int)mode; }
|
||||||
set {
|
set { mode = (InteractiveRebaseMode)value; }
|
||||||
if (value != (int)mode) {
|
|
||||||
mode = (InteractiveRebaseMode)value;
|
|
||||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Mode"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEditorOpened {
|
|
||||||
get { return isEditorOpened; }
|
|
||||||
set {
|
|
||||||
if (value != isEditorOpened) {
|
|
||||||
isEditorOpened = value;
|
|
||||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsEditorOpened"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Subject {
|
|
||||||
get { return Commit.Subject; }
|
|
||||||
set {
|
|
||||||
if (value != Commit.Subject) {
|
|
||||||
Commit.Subject = value;
|
|
||||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Subject"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string EditSubject {
|
|
||||||
get { return editSubject; }
|
|
||||||
set {
|
|
||||||
if (value != editMsg) {
|
|
||||||
editSubject = value;
|
|
||||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("EditSubject"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string EditMessage {
|
|
||||||
get { return editMsg; }
|
|
||||||
set {
|
|
||||||
if (value != editMsg) {
|
|
||||||
editMsg = value;
|
|
||||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("EditMessage"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,46 +134,12 @@ namespace SourceGit.UI {
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private void CommitSelectionChanged(object sender, SelectionChangedEventArgs e) {
|
private void CommitSelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||||
foreach (var obj in e.RemovedItems) {
|
|
||||||
var item = obj as InteractiveRebaseItem;
|
|
||||||
if (item != null) item.IsEditorOpened = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.AddedItems.Count == 1) {
|
if (e.AddedItems.Count == 1) {
|
||||||
var item = e.AddedItems[0] as InteractiveRebaseItem;
|
var item = e.AddedItems[0] as InteractiveRebaseItem;
|
||||||
if (item != null) commitViewer.SetData(repo, item.Commit);
|
if (item != null) commitViewer.SetData(repo, item.Commit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopupMessageEditor(object sender, MouseButtonEventArgs e) {
|
|
||||||
var item = (sender as Control).DataContext as InteractiveRebaseItem;
|
|
||||||
if (item == null) return;
|
|
||||||
|
|
||||||
item.EditSubject = item.Commit.Subject;
|
|
||||||
item.EditMessage = item.Commit.Message;
|
|
||||||
item.IsEditorOpened = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HideMessageEditor(object sender, RoutedEventArgs e) {
|
|
||||||
var item = (sender as Button).DataContext as InteractiveRebaseItem;
|
|
||||||
if (item == null) return;
|
|
||||||
item.IsEditorOpened = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ApplyMessageEdit(object sender, RoutedEventArgs e) {
|
|
||||||
var item = (sender as Button).DataContext as InteractiveRebaseItem;
|
|
||||||
if (item == null) return;
|
|
||||||
|
|
||||||
item.Subject = item.EditSubject;
|
|
||||||
item.Commit.Message = item.EditMessage;
|
|
||||||
item.Mode = (int)InteractiveRebaseMode.Reword;
|
|
||||||
item.IsEditorOpened = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CommitMessageChanged(object sender, TextChangedEventArgs e) {
|
|
||||||
(sender as TextBox).ScrollToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MoveUp(object sender, RoutedEventArgs e) {
|
private void MoveUp(object sender, RoutedEventArgs e) {
|
||||||
var item = (sender as Button).DataContext as InteractiveRebaseItem;
|
var item = (sender as Button).DataContext as InteractiveRebaseItem;
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
|
@ -259,39 +178,36 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
private void Start(object sender, RoutedEventArgs e) {
|
private void Start(object sender, RoutedEventArgs e) {
|
||||||
var temp = Path.GetTempFileName();
|
var temp = Path.GetTempFileName();
|
||||||
var stream = new FileStream(temp, FileMode.Create);
|
var writer = File.CreateText(temp);
|
||||||
var writer = new StreamWriter(stream);
|
|
||||||
|
|
||||||
for (int i = Items.Count - 1; i >= 0; i--) {
|
for (int i = Items.Count - 1; i >= 0; i--) {
|
||||||
var item = Items[i];
|
var item = Items[i];
|
||||||
|
|
||||||
switch ((InteractiveRebaseMode)item.Mode) {
|
switch ((InteractiveRebaseMode)item.Mode) {
|
||||||
case InteractiveRebaseMode.Pick:
|
case InteractiveRebaseMode.Pick:
|
||||||
writer.WriteLine($"p {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"p {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||||
break;
|
break;
|
||||||
case InteractiveRebaseMode.Reword:
|
case InteractiveRebaseMode.Reword:
|
||||||
writer.WriteLine($"r {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"r {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||||
break;
|
break;
|
||||||
case InteractiveRebaseMode.Squash:
|
case InteractiveRebaseMode.Squash:
|
||||||
writer.WriteLine($"s {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"s {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||||
break;
|
break;
|
||||||
case InteractiveRebaseMode.Fixup:
|
case InteractiveRebaseMode.Fixup:
|
||||||
writer.WriteLine($"f {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"f {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||||
break;
|
break;
|
||||||
case InteractiveRebaseMode.Drop:
|
case InteractiveRebaseMode.Drop:
|
||||||
writer.WriteLine($"d {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"d {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Flush();
|
writer.Flush();
|
||||||
stream.Flush();
|
|
||||||
writer.Close();
|
writer.Close();
|
||||||
stream.Close();
|
|
||||||
|
|
||||||
repo.SetWatcherEnabled(false);
|
repo.SetWatcherEnabled(false);
|
||||||
var editor = Process.GetCurrentProcess().MainModule.FileName;
|
var editor = Process.GetCurrentProcess().MainModule.FileName;
|
||||||
var errs = repo.RunCommand($"-c sequence.editor=\"\\\"{editor}\\\" --interactive-rebase \\\"{temp}\\\"\" rebase -i {from}", null);
|
var errs = repo.RunCommand($"-c sequence.editor=\"\\\"{editor}\\\" --sequence \\\"{temp}\\\"\" rebase -i {from}", null);
|
||||||
repo.AssertCommand(errs);
|
repo.AssertCommand(errs);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
|
Loading…
Reference in a new issue