mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07: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>
|
||||
/// Startup event.
|
||||
/// </summary>
|
||||
|
@ -42,20 +66,7 @@ namespace SourceGit {
|
|||
/// <param name="e"></param>
|
||||
private void OnAppStartup(object sender, StartupEventArgs e) {
|
||||
// Use this app as a sequence editor?
|
||||
var args = e.Args;
|
||||
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;
|
||||
}
|
||||
if (OpenAsEditor(e)) return;
|
||||
|
||||
// Load settings.
|
||||
var settingFile = Path.Combine(
|
||||
|
@ -98,30 +109,6 @@ namespace SourceGit {
|
|||
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>
|
||||
/// Deactivated event.
|
||||
/// </summary>
|
||||
|
@ -131,5 +118,29 @@ namespace SourceGit {
|
|||
GC.Collect();
|
||||
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>
|
||||
|
||||
<Grid Grid.Column="1">
|
||||
<ContentControl x:Name="MessageEditorAnchor" MouseDoubleClick="PopupMessageEditor">
|
||||
<TextBlock Text="{Binding Subject, Mode=TwoWay}" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG}"/>
|
||||
</ContentControl>
|
||||
|
||||
<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
|
||||
Grid.Column="1"
|
||||
Text="{Binding Commit.Subject}"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource Brush.FG}"/>
|
||||
|
||||
<TextBlock
|
||||
Grid.Column="2"
|
||||
|
|
|
@ -51,64 +51,17 @@ namespace SourceGit.UI {
|
|||
/// <summary>
|
||||
/// Rebase item.
|
||||
/// </summary>
|
||||
public class InteractiveRebaseItem : INotifyPropertyChanged {
|
||||
public class InteractiveRebaseItem {
|
||||
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; set; }
|
||||
public Git.Commit Commit {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public int Mode {
|
||||
get { return (int)mode; }
|
||||
set {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
set { mode = (InteractiveRebaseMode)value; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,46 +134,12 @@ namespace SourceGit.UI {
|
|||
#endregion
|
||||
|
||||
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) {
|
||||
var item = e.AddedItems[0] as InteractiveRebaseItem;
|
||||
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) {
|
||||
var item = (sender as Button).DataContext as InteractiveRebaseItem;
|
||||
if (item == null) return;
|
||||
|
@ -259,39 +178,36 @@ namespace SourceGit.UI {
|
|||
|
||||
private void Start(object sender, RoutedEventArgs e) {
|
||||
var temp = Path.GetTempFileName();
|
||||
var stream = new FileStream(temp, FileMode.Create);
|
||||
var writer = new StreamWriter(stream);
|
||||
var writer = File.CreateText(temp);
|
||||
|
||||
for (int i = Items.Count - 1; i >= 0; i--) {
|
||||
var item = Items[i];
|
||||
|
||||
switch ((InteractiveRebaseMode)item.Mode) {
|
||||
case InteractiveRebaseMode.Pick:
|
||||
writer.WriteLine($"p {item.Commit.ShortSHA} {item.Subject}");
|
||||
writer.WriteLine($"p {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||
break;
|
||||
case InteractiveRebaseMode.Reword:
|
||||
writer.WriteLine($"r {item.Commit.ShortSHA} {item.Subject}");
|
||||
writer.WriteLine($"r {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||
break;
|
||||
case InteractiveRebaseMode.Squash:
|
||||
writer.WriteLine($"s {item.Commit.ShortSHA} {item.Subject}");
|
||||
writer.WriteLine($"s {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||
break;
|
||||
case InteractiveRebaseMode.Fixup:
|
||||
writer.WriteLine($"f {item.Commit.ShortSHA} {item.Subject}");
|
||||
writer.WriteLine($"f {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||
break;
|
||||
case InteractiveRebaseMode.Drop:
|
||||
writer.WriteLine($"d {item.Commit.ShortSHA} {item.Subject}");
|
||||
writer.WriteLine($"d {item.Commit.ShortSHA} {item.Commit.Subject}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
stream.Flush();
|
||||
writer.Close();
|
||||
stream.Close();
|
||||
|
||||
repo.SetWatcherEnabled(false);
|
||||
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);
|
||||
|
||||
Close();
|
||||
|
|
Loading…
Reference in a new issue