Skip to content

Commit

Permalink
Switch context menu location as it is done by Windows Explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
topeterk committed Sep 11, 2023
1 parent 4f1ee53 commit bfd50ae
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
7 changes: 0 additions & 7 deletions DataClasses/RowData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,10 @@ internal void OpenShellContextMenu(Point? mousePosition)
{
if (Owner != null)
{
#if CONTEXT_MENU_EXPLORER_BEHAVIOR
// Snap context menu left aligned to the ListViewItem with a small padding, but keep it vertically centered
Rect rectChild = Owner.GetDataGridViewChildRect(this);
position = Owner.GetRelativeChildPositionTo(Owner.GetDataGridView());
position.Offset(Owner.Left + rectChild.Left + 10D, Owner.Top + rectChild.Top + (rectChild.Height / 2D));
#else
// Snap context menu left and top aligned to the ListViewItem
Rect rectChild = Owner.GetDataGridViewChildRect(this);
position = Owner.GetRelativeChildPositionTo(Owner.GetDataGridView());
position.Offset(Owner.Left + rectChild.Left, Owner.Top + rectChild.Top);
#endif
}
}

Expand Down
11 changes: 1 addition & 10 deletions UserInterface/Menu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,21 +1174,12 @@ private void ListViewItem_MouseLeave(object sender, MouseEventArgs e)

private void ListViewItem_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
ListViewItem lvi = (ListViewItem)sender;
RowData itemData = (RowData)lvi.Content;

#if CONTEXT_MENU_EXPLORER_BEHAVIOR
// At mouse location
Point position = Mouse.GetPosition(this);
position.Offset(Left, Top);
#else
// Snap context menu above the ListViewItem, but horizontally follow the mouse
Point position = this.GetRelativeChildPositionTo(lvi);
position.Offset(Left + Mouse.GetPosition(lvi).X, Top);
#endif

isShellContextMenuOpen = true;
itemData.OpenShellContextMenu(position);
((RowData)((ListViewItem)sender).Content).OpenShellContextMenu(position);
isShellContextMenuOpen = false;
}
}
Expand Down

0 comments on commit bfd50ae

Please sign in to comment.