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