MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / FindItem

Method FindItem

source/script_menu.cpp:410–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408
409
410UserMenuItem *UserMenu::FindItem(LPTSTR aNameOrPos, UserMenuItem *&aPrevItem, bool &aByPos)
411{
412 int index_to_find = -1;
413 size_t length = _tcslen(aNameOrPos);
414 // Check if the caller identified the menu item by position/index rather than by name.
415 // This should be reasonably backwards-compatible, as any scripts that want literally
416 // "1&" as menu item text would have to actually write "1&&".
417 if (length > 1
418 && aNameOrPos[length - 1] == '&' // Use the same convention as MenuSelect: 1&, 2&, 3&...
419 && aNameOrPos[length - 2] != '&') // Not &&, which means one literal &.
420 index_to_find = ATOI(aNameOrPos) - 1; // Yields -1 if aParam3 doesn't start with a number.
421 aByPos = index_to_find > -1;
422 // Find the item.
423 int current_index = 0;
424 UserMenuItem *menu_item_prev = NULL, *menu_item;
425 for (menu_item = mFirstMenuItem
426 ; menu_item
427 ; menu_item_prev = menu_item, menu_item = menu_item->mNextMenuItem, ++current_index)
428 if (current_index == index_to_find // Found by index.
429 || !lstrcmpi(menu_item->mName, aNameOrPos)) // Found by case-insensitive text match.
430 break;
431 aPrevItem = menu_item_prev;
432 return menu_item;
433}
434
435
436

Callers

nothing calls this directly

Calls 1

ATOIFunction · 0.85

Tested by

no test coverage detected