sourcegit/src/Views/Histories.xaml.cs

66 lines
2.1 KiB
C#
Raw Normal View History

2021-04-29 05:05:55 -07:00
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
namespace SourceGit.Views {
/// <summary>
/// 文件历史
/// </summary>
public partial class Histories : Controls.Window {
2021-04-29 05:05:55 -07:00
private string repo = null;
private string file = null;
private bool isLFSEnabled = false;
2021-04-29 05:05:55 -07:00
public Histories(string repo, string file) {
this.repo = repo;
this.file = file;
this.isLFSEnabled = new Commands.LFS(repo).IsFiltered(file);
2021-04-29 05:05:55 -07:00
InitializeComponent();
Task.Run(() => {
var commits = new Commands.Commits(repo, $"-n 10000 -- \"{file}\"").Result();
Dispatcher.Invoke(() => {
loading.IsAnimating = false;
loading.Visibility = Visibility.Collapsed;
commitList.ItemsSource = commits;
commitList.SelectedIndex = 0;
});
});
}
#region WINDOW_COMMANDS
private void Minimize(object sender, RoutedEventArgs e) {
SystemCommands.MinimizeWindow(this);
}
private void Quit(object sender, RoutedEventArgs e) {
Close();
}
#endregion
#region EVENTS
private void OnCommitSelectedChanged(object sender, SelectedCellsChangedEventArgs e) {
var commit = (sender as DataGrid).SelectedItem as Models.Commit;
if (commit == null) return;
var start = $"{commit.SHA}^";
if (commit.Parents.Count == 0) start = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
diffViewer.Diff(repo, new Widgets.DiffViewer.Option() {
RevisionRange = new string[] { start, commit.SHA },
Path = file,
UseLFS = isLFSEnabled,
2021-04-29 05:05:55 -07:00
});
}
private void GotoCommit(object sender, RequestNavigateEventArgs e) {
Models.Watcher.Get(repo).NavigateTo(e.Uri.OriginalString);
e.Handled = true;
}
#endregion
}
}