sourcegit/src/Views/WorkingCopy.axaml.cs

82 lines
2.4 KiB
C#
Raw Normal View History

using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class WorkingCopy : UserControl
{
public WorkingCopy()
{
InitializeComponent();
}
private void OnOpenCommitMessagePicker(object sender, RoutedEventArgs e)
{
if (sender is Button button && DataContext is ViewModels.WorkingCopy vm)
{
var menu = vm.CreateContextMenuForCommitMessages();
menu.Placement = PlacementMode.TopEdgeAlignedLeft;
button.OpenContextMenu(menu);
e.Handled = true;
}
}
private void OnUnstagedContextRequested(object sender, ContextRequestedEventArgs e)
{
if (DataContext is ViewModels.WorkingCopy vm)
{
var menu = vm.CreateContextMenuForUnstagedChanges();
(sender as Control)?.OpenContextMenu(menu);
e.Handled = true;
}
}
private void OnStagedContextRequested(object sender, ContextRequestedEventArgs e)
{
if (DataContext is ViewModels.WorkingCopy vm)
{
var menu = vm.CreateContextMenuForStagedChanges();
(sender as Control)?.OpenContextMenu(menu);
e.Handled = true;
}
}
2024-07-14 00:55:15 -07:00
private void OnUnstagedChangeDoubleTapped(object _, RoutedEventArgs e)
{
if (DataContext is ViewModels.WorkingCopy vm)
{
vm.StageSelected();
e.Handled = true;
}
}
2024-07-14 00:55:15 -07:00
private void OnStagedChangeDoubleTapped(object _, RoutedEventArgs e)
{
if (DataContext is ViewModels.WorkingCopy vm)
{
vm.UnstageSelected();
e.Handled = true;
}
}
2024-07-14 00:55:15 -07:00
private void OnUnstagedKeyDown(object _, KeyEventArgs e)
{
if (DataContext is ViewModels.WorkingCopy vm && e.Key == Key.Space)
{
vm.StageSelected();
e.Handled = true;
}
}
2024-07-14 00:55:15 -07:00
private void OnStagedKeyDown(object _, KeyEventArgs e)
{
if (DataContext is ViewModels.WorkingCopy vm && e.Key == Key.Space)
{
vm.UnstageSelected();
e.Handled = true;
}
}
}
}