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-10-29 04:59:22 -07:00
|
|
|
private void OnMainLayoutSizeChanged(object sender, SizeChangedEventArgs e)
|
|
|
|
{
|
|
|
|
var grid = sender as Grid;
|
|
|
|
if (grid == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var layout = ViewModels.Preference.Instance.Layout;
|
|
|
|
var width = grid.Bounds.Width;
|
|
|
|
var maxLeft = width - 304;
|
|
|
|
|
|
|
|
if (layout.WorkingCopyLeftWidth.Value - maxLeft > 1.0)
|
|
|
|
layout.WorkingCopyLeftWidth = new GridLength(maxLeft, GridUnitType.Pixel);
|
|
|
|
}
|
|
|
|
|
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;
|
2024-11-03 23:31:55 -08:00
|
|
|
menu?.Open(button);
|
2024-05-28 06:19:53 -07:00
|
|
|
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-11-03 23:31:55 -08:00
|
|
|
if (DataContext is ViewModels.WorkingCopy vm && sender is Control control)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-28 06:19:53 -07:00
|
|
|
var menu = vm.CreateContextMenuForUnstagedChanges();
|
2024-11-03 23:31:55 -08:00
|
|
|
menu?.Open(control);
|
2024-05-28 06:19:53 -07:00
|
|
|
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-11-03 23:31:55 -08:00
|
|
|
if (DataContext is ViewModels.WorkingCopy vm && sender is Control control)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-28 06:19:53 -07:00
|
|
|
var menu = vm.CreateContextMenuForStagedChanges();
|
2024-11-03 23:31:55 -08:00
|
|
|
menu?.Open(control);
|
2024-05-28 06:19:53 -07:00
|
|
|
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-09-12 01:33:56 -07:00
|
|
|
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
|
|
|
|
vm.StageSelected(next);
|
|
|
|
UnstagedChangesView.Focus();
|
2024-05-28 06:19:53 -07:00
|
|
|
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-09-12 01:33:56 -07:00
|
|
|
var next = StagedChangesView.GetNextChangeWithoutSelection();
|
|
|
|
vm.UnstageSelected(next);
|
|
|
|
StagedChangesView.Focus();
|
2024-05-28 06:19:53 -07:00
|
|
|
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-08-28 19:10:28 -07:00
|
|
|
if (DataContext is ViewModels.WorkingCopy vm)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-08-28 19:10:28 -07:00
|
|
|
if (e.Key is Key.Space or Key.Enter)
|
|
|
|
{
|
2024-09-12 01:33:56 -07:00
|
|
|
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
|
|
|
|
vm.StageSelected(next);
|
|
|
|
UnstagedChangesView.Focus();
|
2024-08-28 19:10:28 -07:00
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.Key is Key.Delete or Key.Back && vm.SelectedUnstaged is { Count: > 0 } selected)
|
|
|
|
{
|
|
|
|
vm.Discard(selected);
|
|
|
|
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-08-28 06:17:07 -07:00
|
|
|
if (DataContext is ViewModels.WorkingCopy vm && e.Key is Key.Space or Key.Enter)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-09-12 01:33:56 -07:00
|
|
|
var next = StagedChangesView.GetNextChangeWithoutSelection();
|
|
|
|
vm.UnstageSelected(next);
|
|
|
|
StagedChangesView.Focus();
|
2024-02-17 23:44:05 -08:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
2024-09-11 03:22:05 -07:00
|
|
|
|
2024-09-12 01:33:56 -07:00
|
|
|
private void OnStageSelectedButtonClicked(object _, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (DataContext is ViewModels.WorkingCopy vm)
|
|
|
|
{
|
|
|
|
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
|
|
|
|
vm.StageSelected(next);
|
|
|
|
UnstagedChangesView.Focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnUnstageSelectedButtonClicked(object _, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (DataContext is ViewModels.WorkingCopy vm)
|
|
|
|
{
|
|
|
|
var next = StagedChangesView.GetNextChangeWithoutSelection();
|
|
|
|
vm.UnstageSelected(next);
|
|
|
|
StagedChangesView.Focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-10-27 20:00:11 -07:00
|
|
|
private void OnOpenOpenAIHelper(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2024-11-03 23:31:55 -08:00
|
|
|
if (DataContext is ViewModels.WorkingCopy vm && sender is Control control)
|
2024-10-27 20:00:11 -07:00
|
|
|
{
|
|
|
|
var menu = vm.CreateContextForOpenAI();
|
2024-11-03 23:31:55 -08:00
|
|
|
menu?.Open(control);
|
2024-10-27 20:00:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-10-18 01:20:45 -07:00
|
|
|
private void OnOpenConventionalCommitHelper(object _, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (DataContext is ViewModels.WorkingCopy vm)
|
|
|
|
{
|
2024-10-23 00:28:09 -07:00
|
|
|
var dialog = new ConventionalCommitMessageBuilder()
|
|
|
|
{
|
|
|
|
DataContext = new ViewModels.ConventionalCommitMessageBuilder(vm)
|
2024-10-18 01:20:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
App.OpenDialog(dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
}
|