Support Shift+F10 convention for context menu in memedit

This commit is contained in:
Deniz Sincar 2026-07-27 22:05:57 -07:00 committed by Dan Smith
parent bae48c6cd4
commit 8f442c8e09

View file

@ -1003,6 +1003,11 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor):
self._memory_rclick)
self._grid.Bind(wx.grid.EVT_GRID_CELL_BEGIN_DRAG, self._memory_drag)
self.Bind(wx.EVT_KEY_DOWN, self._keyboard_overrides)
# Bind key events on the inner grid window so the context-menu key
# (WXK_WINDOWS_MENU / Apps key) and Shift+F10 reach our handler even
# though focus lives inside the grid widget rather than on the panel.
self._grid.GetGridWindow().Bind(wx.EVT_KEY_DOWN,
self._keyboard_overrides)
row_labels = self._grid.GetGridRowLabelWindow()
row_labels.Bind(wx.EVT_LEFT_DOWN, self._row_click)
row_labels.Bind(wx.EVT_LEFT_UP, self._row_click)
@ -1153,9 +1158,37 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor):
# wx.grid.Grid() can do it.
# https://github.com/wxWidgets/wxWidgets/issues/22625
self.cb_copy(cut=False)
elif event.GetKeyCode() == wx.WXK_WINDOWS_MENU or (
event.GetKeyCode() == wx.WXK_F10 and event.ShiftDown()):
# Apps key or Shift+F10: open the context menu at the cursor cell.
# EVT_GRID_CELL_RIGHT_CLICK never fires for keyboard users, so we
# handle it here instead. Both the panel binding and the inner
# grid-window binding point here, ensuring the event is caught
# regardless of which sub-window holds focus.
self._show_context_menu_at_cursor()
else:
event.Skip()
def _show_context_menu_at_cursor(self):
"""Open the right-click context menu at the focused grid cell.
_memory_rclick() uses event.GetRow() which is only valid for actual
mouse events. This method calls the same menu-building logic but
substitutes the keyboard cursor position, so keyboard users (including
screen reader users) get full access to all context-menu actions via
the Apps key or Shift+F10.
"""
row = self._grid.GetGridCursorRow()
if row < 0:
return
# Build a fake event-like object that satisfies _memory_rclick's
# use of GetRow(), then delegate to the shared menu builder.
class _FakeGridEvent:
def GetRow(self_):
return row
self._memory_rclick(_FakeGridEvent())
def _row_click(self, event):
# In order to override the drag-to-multi-select behavior of the base
# grid, we need to basically reimplement what happens when a user