This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathPullRequestFilesView.xaml.cs
More file actions
91 lines (78 loc) · 3.11 KB
/
PullRequestFilesView.xaml.cs
File metadata and controls
91 lines (78 loc) · 3.11 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.ComponentModel.Composition;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using GitHub.Exports;
using GitHub.UI.Helpers;
using GitHub.ViewModels.GitHubPane;
using GitHub.VisualStudio.UI.Helpers;
namespace GitHub.VisualStudio.Views.GitHubPane
{
[ExportViewFor(typeof(IPullRequestFilesViewModel))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public partial class PullRequestFilesView : UserControl
{
public PullRequestFilesView()
{
InitializeComponent();
PreviewMouseWheel += ScrollViewerUtilities.FixMouseWheelScroll;
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
}
void changesTree_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
ApplyContextMenuBinding<TreeViewItem>(sender, e);
}
void changesTree_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var file = (e.OriginalSource as FrameworkElement)?.DataContext as IPullRequestFileNode;
(DataContext as IPullRequestFilesViewModel)?.DiffFile.Execute(file);
}
void changesTree_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
var item = (e.OriginalSource as Visual)?.GetSelfAndVisualAncestors().OfType<TreeViewItem>().FirstOrDefault();
if (item != null)
{
// Select tree view item on right click.
item.IsSelected = true;
}
}
void ApplyContextMenuBinding<TItem>(object sender, ContextMenuEventArgs e) where TItem : Control
{
var container = (Control)sender;
var item = (e.OriginalSource as Visual)?.GetSelfAndVisualAncestors().OfType<TItem>().FirstOrDefault();
e.Handled = true;
if (item != null)
{
var fileNode = item.DataContext as IPullRequestFileNode;
if (fileNode != null)
{
foreach (var menuItem in container.ContextMenu.Items.OfType<MenuItem>())
{
menuItem.CommandParameter = fileNode;
}
// HACK: MenuItem doesn't re-query ICommand.CanExecute when CommandParameter changes. Force
// this to happen by resetting its DataContext to null and then to the correct value.
container.ContextMenu.DataContext = null;
container.ContextMenu.DataContext = this.DataContext;
e.Handled = false;
}
}
}
private void changesTree_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
var file = (e.OriginalSource as FrameworkElement)?.DataContext as IPullRequestFileNode;
if (file != null)
{
(DataContext as IPullRequestFilesViewModel)?.DiffFile.Execute(file);
}
}
}
}
}