MCPcopy Create free account
hub / github.com/audacity/audacity / DoContextMenu

Method DoContextMenu

src/tracks/ui/CommonTrackPanelCell.cpp:46–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46unsigned CommonTrackPanelCell::DoContextMenu( const wxRect &rect,
47 wxWindow *pParent, const wxPoint *pPoint, AudacityProject *const pProject)
48{
49 const auto items = GetMenuItems( rect, pPoint, pProject );
50 if (items.empty())
51 return RefreshCode::RefreshNone;
52
53 auto &commandManager = CommandManager::Get(*pProject);
54 commandManager.UpdateMenus();
55
56 // Set up command context with extras
57 CommandContext context{ *pProject };
58 SelectedRegion region;
59 if (pPoint) {
60 auto time = ViewInfo::Get(*pProject).PositionToTime(pPoint->x, rect.x);
61 region = { time, time };
62 context.temporarySelection.pSelectedRegion = &region;
63 }
64 context.temporarySelection.pTrack = FindTrack().get();
65
66 auto flags = commandManager.GetUpdateFlags();
67
68 // Common dispatcher for the menu items
69 auto dispatcher = [&]( wxCommandEvent &evt ){
70 auto idx = evt.GetId() - 1;
71 if (idx >= 0 && idx < items.size()) {
72 if (auto &action = items[idx].action)
73 action( context );
74 else
75 commandManager.HandleTextualCommand(
76 items[idx].symbol.Internal(), context, flags, false);
77 }
78 };
79
80 wxMenu menu;
81 int ii = 1;
82 for (const auto &item: items) {
83 if ( const auto &commandID = item.symbol.Internal();
84 commandID.empty() )
85 menu.AppendSeparator();
86 else {
87 // Generate a menu item with the same shortcut key as in the toolbar
88 // menu, and as determined by keyboard preferences
89 auto label =
90 commandManager.FormatLabelForMenu( commandID, &item.symbol.Msgid() );
91 menu.Append( ii, label );
92 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, dispatcher );
93 bool enabled = item.enabled &&
94 (item.action || commandManager.GetEnabled( commandID ));
95 menu.Enable( ii, enabled );
96 }
97 ++ii;
98 }
99
100 BasicUI::Point point;
101 if (pPoint)
102 point = { pPoint->x, pPoint->y };
103 BasicMenu::Handle{ &menu }.Popup(

Callers

nothing calls this directly

Calls 15

GetFunction · 0.85
PositionToTimeMethod · 0.80
GetUpdateFlagsMethod · 0.80
GetIdMethod · 0.80
FormatLabelForMenuMethod · 0.80
BindMethod · 0.80
FindTrackFunction · 0.70
emptyMethod · 0.45
UpdateMenusMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
HandleTextualCommandMethod · 0.45

Tested by

no test coverage detected