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

Function FindPathName

src/widgets/BasicMenu.cpp:59–90  ·  view source on GitHub ↗

Find a path name for the id in the given menu, but only if it, and each sub-menu above it, is uniquely named among peer items

Source from the content-addressed store, hash-verified

57// Find a path name for the id in the given menu, but only if it, and
58// each sub-menu above it, is uniquely named among peer items
59std::optional< wxArrayStringEx > FindPathName( wxMenu &theMenu, int id )
60{
61 wxMenuItem *pItem = nullptr;
62 wxMenu *pSubMenu = nullptr;
63 if ( !( pItem = theMenu.FindItem( id, &pSubMenu ) ) )
64 return std::nullopt;
65
66 // Gather path components, checking uniqueness at each level
67 wxArrayStringEx names;
68 for ( ; pSubMenu; pSubMenu = pSubMenu->GetParent() ) {
69 const auto &items = pSubMenu->GetMenuItems();
70 const auto begin = items.begin(), end = items.end();
71 if ( !names.empty() ) {
72 // Update pItem on second and later passes
73 if ( const auto iter = std::find_if( begin, end,
74 [&]( auto pNewItem ){
75 return pNewItem->GetSubMenu() == pItem->GetMenu(); } );
76 iter == end )
77 return std::nullopt;
78 else
79 pItem = *iter;
80 }
81 auto name = pItem->GetItemLabelText();
82 if ( 1 != std::count_if( begin, end, [&](auto item){
83 return item->GetItemLabelText() == name; } ) )
84 // nonuniqueness
85 return std::nullopt;
86 names.push_back( name );
87 }
88 std::reverse( names.begin(), names.end() );
89 return { names };
90}
91
92//! Singleton object listens to global wxEvent stream
93struct Watcher : wxEventFilter

Callers 1

FilterEventMethod · 0.85

Calls 7

FindItemMethod · 0.80
GetParentMethod · 0.45
GetMenuItemsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected