2021-04-29 05:05:55 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Controls;
|
2021-05-12 19:55:25 -07:00
|
|
|
using System.Windows.Input;
|
2021-04-29 05:05:55 -07:00
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
|
|
|
namespace SourceGit.Views.Widgets {
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 提交详情
|
|
|
|
/// </summary>
|
|
|
|
public partial class CommitDetail : UserControl {
|
|
|
|
private string repo = null;
|
|
|
|
private Models.Commit commit = null;
|
2021-04-30 00:33:26 -07:00
|
|
|
private Commands.Context cancelToken = new Commands.Context();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
public CommitDetail() {
|
|
|
|
InitializeComponent();
|
2021-06-07 05:09:59 -07:00
|
|
|
|
|
|
|
Unloaded += (o, e) => {
|
|
|
|
changeList.ItemsSource = new List<Models.Change>();
|
|
|
|
changeContainer.CleanUp();
|
|
|
|
revisionFiles.Cleanup();
|
|
|
|
};
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetData(string repo, Models.Commit commit) {
|
|
|
|
cancelToken.IsCancelRequested = true;
|
2021-04-30 00:33:26 -07:00
|
|
|
cancelToken = new Commands.Context();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
this.repo = repo;
|
|
|
|
this.commit = commit;
|
|
|
|
|
2021-04-30 00:33:26 -07:00
|
|
|
revisionFiles.SetData(repo, commit.SHA, cancelToken);
|
2021-04-29 05:05:55 -07:00
|
|
|
UpdateInformation(commit);
|
|
|
|
UpdateChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
#region DATA
|
|
|
|
private void UpdateInformation(Models.Commit commit) {
|
|
|
|
txtSHA.Text = commit.SHA;
|
|
|
|
txtMessage.Text = (commit.Subject + "\n\n" + commit.Message.Trim()).Trim();
|
|
|
|
|
|
|
|
avatarAuthor.Email = commit.Author.Email;
|
|
|
|
avatarAuthor.FallbackLabel = commit.Author.Name;
|
|
|
|
txtAuthorName.Text = commit.Author.Name;
|
|
|
|
txtAuthorEmail.Text = commit.Author.Email;
|
|
|
|
txtAuthorTime.Text = commit.Author.Time;
|
|
|
|
|
|
|
|
avatarCommitter.Email = commit.Committer.Email;
|
|
|
|
avatarCommitter.FallbackLabel = commit.Committer.Name;
|
|
|
|
txtCommitterName.Text = commit.Committer.Name;
|
|
|
|
txtCommitterEmail.Text = commit.Committer.Email;
|
|
|
|
txtCommitterTime.Text = commit.Committer.Time;
|
|
|
|
|
|
|
|
if (commit.Committer.Email == commit.Author.Email && commit.Committer.Time == commit.Author.Time) {
|
|
|
|
avatarCommitter.Visibility = Visibility.Hidden;
|
|
|
|
committerInfoPanel.Visibility = Visibility.Hidden;
|
|
|
|
} else {
|
|
|
|
avatarCommitter.Visibility = Visibility.Visible;
|
|
|
|
committerInfoPanel.Visibility = Visibility.Visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commit.Parents.Count == 0) {
|
|
|
|
rowParents.Height = new GridLength(0);
|
|
|
|
} else {
|
|
|
|
rowParents.Height = GridLength.Auto;
|
|
|
|
var shortPIDs = new List<string>();
|
|
|
|
foreach (var p in commit.Parents) shortPIDs.Add(p.Substring(0, 10));
|
|
|
|
listParents.ItemsSource = shortPIDs;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!commit.HasDecorators) {
|
|
|
|
rowRefs.Height = new GridLength(0);
|
|
|
|
} else {
|
|
|
|
rowRefs.Height = GridLength.Auto;
|
|
|
|
listRefs.ItemsSource = commit.Decorators;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateChanges() {
|
2021-04-30 00:33:26 -07:00
|
|
|
var cmd = new Commands.CommitChanges(repo, commit.SHA) { Ctx = cancelToken };
|
2021-04-29 05:05:55 -07:00
|
|
|
Task.Run(() => {
|
|
|
|
var changes = cmd.Result();
|
2021-04-30 00:33:26 -07:00
|
|
|
if (cmd.Ctx.IsCancelRequested) return;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
Dispatcher.Invoke(() => {
|
|
|
|
changeList.ItemsSource = changes;
|
|
|
|
changeContainer.SetData(repo, new List<Models.Commit>() { commit }, changes);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2021-05-12 19:55:25 -07:00
|
|
|
#region EVENTS
|
2021-04-29 05:05:55 -07:00
|
|
|
private void OnNavigateParent(object sender, RequestNavigateEventArgs e) {
|
|
|
|
Models.Watcher.Get(repo)?.NavigateTo(e.Uri.OriginalString);
|
|
|
|
}
|
|
|
|
|
2021-05-12 19:55:25 -07:00
|
|
|
private void OnChangeListMouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
|
|
|
var row = sender as DataGridRow;
|
|
|
|
if (row == null) return;
|
|
|
|
|
|
|
|
var change = row.DataContext as Models.Change;
|
|
|
|
if (change == null) return;
|
|
|
|
|
|
|
|
body.SelectedIndex = 1;
|
|
|
|
changeContainer.Select(change);
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
private void OnChangeListContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
|
|
|
var row = sender as DataGridRow;
|
|
|
|
if (row == null) return;
|
|
|
|
|
|
|
|
var change = row.DataContext as Models.Change;
|
|
|
|
if (change == null) return;
|
|
|
|
|
|
|
|
var menu = new ContextMenu();
|
2021-04-30 00:33:26 -07:00
|
|
|
if (change.Index != Models.Change.Status.Deleted) {
|
2021-04-29 05:05:55 -07:00
|
|
|
var history = new MenuItem();
|
|
|
|
history.Header = App.Text("FileHistory");
|
2021-04-30 00:33:26 -07:00
|
|
|
history.IsEnabled = change.Index != Models.Change.Status.Deleted;
|
2021-04-29 05:05:55 -07:00
|
|
|
history.Click += (o, ev) => {
|
2021-04-30 00:33:26 -07:00
|
|
|
var viewer = new Views.Histories(repo, change.Path);
|
2021-04-29 05:05:55 -07:00
|
|
|
viewer.Show();
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var blame = new MenuItem();
|
|
|
|
blame.Header = App.Text("Blame");
|
2021-04-30 00:33:26 -07:00
|
|
|
blame.IsEnabled = change.Index != Models.Change.Status.Deleted;
|
2021-04-29 05:05:55 -07:00
|
|
|
blame.Click += (obj, ev) => {
|
2021-04-30 00:33:26 -07:00
|
|
|
var viewer = new Blame(repo, change.Path, commit.SHA);
|
2021-04-29 05:05:55 -07:00
|
|
|
viewer.Show();
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var explore = new MenuItem();
|
|
|
|
explore.Header = App.Text("RevealFile");
|
2021-04-30 00:33:26 -07:00
|
|
|
explore.IsEnabled = change.Index != Models.Change.Status.Deleted;
|
2021-04-29 05:05:55 -07:00
|
|
|
explore.Click += (o, ev) => {
|
2021-04-30 00:33:26 -07:00
|
|
|
var full = Path.GetFullPath(repo + "\\" + change.Path);
|
2021-04-29 05:05:55 -07:00
|
|
|
Process.Start("explorer", $"/select,{full}");
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
menu.Items.Add(history);
|
|
|
|
menu.Items.Add(blame);
|
|
|
|
menu.Items.Add(explore);
|
|
|
|
}
|
|
|
|
|
|
|
|
var copyPath = new MenuItem();
|
|
|
|
copyPath.Header = App.Text("CopyPath");
|
|
|
|
copyPath.Click += (obj, ev) => {
|
2021-04-30 00:33:26 -07:00
|
|
|
Clipboard.SetText(change.Path);
|
|
|
|
ev.Handled = true;
|
2021-04-29 05:05:55 -07:00
|
|
|
};
|
|
|
|
menu.Items.Add(copyPath);
|
|
|
|
|
2021-04-30 00:33:26 -07:00
|
|
|
menu.IsOpen = true;
|
2021-04-29 05:05:55 -07:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|