feat: support compare both revision in FileHistories (#786) (#946)

This commit is contained in:
GadflyFang 2025-02-06 11:33:55 +08:00 committed by GitHub
parent 65a9406c9a
commit 9aba737d9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 206 additions and 20 deletions

View file

@ -1,6 +1,9 @@
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using SourceGit.Models;
namespace SourceGit.Views
{
@ -38,5 +41,46 @@ namespace SourceGit.Views
NotifyDonePanel.IsVisible = false;
e.Handled = true;
}
private void OnRowSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (DataContext is ViewModels.FileHistories vm && sender is ListBox { SelectedItems: IList<object> commits })
{
var selectedCommits = new List<Models.Commit>();
foreach (var commit in commits)
{
if (commit is Models.Commit modelCommit)
{
selectedCommits.Add(modelCommit);
}
}
vm.SelectedCommits = selectedCommits;
}
e.Handled = true;
}
private async void OnSaveAsPatch(object sender, RoutedEventArgs e)
{
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel == null)
return;
var vm = DataContext as ViewModels.FileHistories;
if (vm == null)
return;
var options = new FilePickerSaveOptions();
options.Title = App.Text("FileCM.SaveAsPatch");
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];
var storageFile = await topLevel.StorageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveAsPatch(storageFile.Path.LocalPath);
NotifyDonePanel.IsVisible = true;
e.Handled = true;
}
}
}