-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathCommitChanges.axaml.cs
More file actions
75 lines (65 loc) · 2.8 KB
/
CommitChanges.axaml.cs
File metadata and controls
75 lines (65 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Text;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.VisualTree;
namespace SourceGit.Views
{
public partial class CommitChanges : UserControl
{
public CommitChanges()
{
InitializeComponent();
}
private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e)
{
e.Handled = true;
if (sender is not ChangeCollectionView { SelectedChanges: { Count: > 0 } changes } view)
return;
var detailView = this.FindAncestorOfType<CommitDetail>();
if (detailView == null)
return;
var container = view.FindDescendantOfType<ChangeCollectionContainer>();
if (container is { SelectedItems.Count: 1, SelectedItem: ViewModels.ChangeTreeNode { IsFolder: true } node })
detailView.CreateChangeContextMenuByFolder(node, changes)?.Open(view);
else if (changes.Count > 1)
detailView.CreateMultipleChangesContextMenu(changes)?.Open(view);
else
detailView.CreateChangeContextMenu(changes[0])?.Open(view);
}
private async void OnChangeCollectionViewKeyDown(object sender, KeyEventArgs e)
{
if (DataContext is not ViewModels.CommitDetail vm)
return;
if (sender is not ChangeCollectionView { SelectedChanges: { Count: > 0 } selectedChanges } view)
return;
var cmdKey = OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control;
if (e.Key == Key.C && e.KeyModifiers.HasFlag(cmdKey))
{
var builder = new StringBuilder();
var copyAbsPath = e.KeyModifiers.HasFlag(KeyModifiers.Shift);
var container = view.FindDescendantOfType<ChangeCollectionContainer>();
if (container is { SelectedItems.Count: 1, SelectedItem: ViewModels.ChangeTreeNode { IsFolder: true } node })
{
builder.Append(copyAbsPath ? vm.GetAbsPath(node.FullPath) : node.FullPath);
}
else if (selectedChanges.Count == 1)
{
builder.Append(copyAbsPath ? vm.GetAbsPath(selectedChanges[0].Path) : selectedChanges[0].Path);
}
else
{
foreach (var c in selectedChanges)
builder.AppendLine(copyAbsPath ? vm.GetAbsPath(c.Path) : c.Path);
}
await this.CopyTextAsync(builder.ToString());
e.Handled = true;
}
else if (e.Key == Key.F && e.KeyModifiers == cmdKey)
{
CommitChangeSearchBox.Focus();
e.Handled = true;
}
}
}
}