sourcegit/src/Views/RevisionCompare.axaml.cs
leo 9cb85081ab
feature: saving as patch supports multiple commits (#658)
Signed-off-by: leo <longshuang@msn.cn>
2024-11-06 12:35:55 +08:00

56 lines
1.7 KiB
C#

using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
namespace SourceGit.Views
{
public partial class RevisionCompare : UserControl
{
public RevisionCompare()
{
InitializeComponent();
}
private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e)
{
if (DataContext is ViewModels.RevisionCompare vm && sender is ChangeCollectionView view)
{
var menu = vm.CreateChangeContextMenu();
menu?.Open(view);
}
e.Handled = true;
}
private void OnPressedSHA(object sender, PointerPressedEventArgs e)
{
if (DataContext is ViewModels.RevisionCompare vm && sender is TextBlock block)
vm.NavigateTo(block.Text);
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.RevisionCompare;
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)
vm.SaveAsPatch(storageFile.Path.LocalPath);
e.Handled = true;
}
}
}