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

Method UpdateOptions

source/script_menu.cpp:682–745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

680
681
682ResultType UserMenu::UpdateOptions(UserMenuItem *aMenuItem, LPTSTR aOptions)
683{
684 UINT new_type = aMenuItem->mMenuType; // Set default.
685
686 LPTSTR next_option, option_end;
687 bool adding;
688 TCHAR orig_char;
689
690 // See GuiType::ControlParseOptions() for comments about how the options are parsed.
691 for (next_option = aOptions; *next_option; next_option = option_end)
692 {
693 next_option = omit_leading_whitespace(next_option);
694 if (*next_option == '-')
695 {
696 adding = false;
697 ++next_option;
698 }
699 else
700 {
701 adding = true;
702 if (*next_option == '+')
703 ++next_option;
704 }
705
706 if (!*next_option)
707 break;
708 if ( !(option_end = StrChrAny(next_option, _T(" \t"))) )
709 option_end = next_option + _tcslen(next_option);
710 if (option_end == next_option)
711 continue;
712
713 orig_char = *option_end;
714 *option_end = '\0';
715 // End generic option-parsing code; begin menu options.
716 if (!_tcsicmp(next_option, _T("Radio"))) if (adding) new_type |= MFT_RADIOCHECK; else new_type &= ~MFT_RADIOCHECK;
717 else if (mMenuType == MENU_TYPE_BAR && !_tcsicmp(next_option, _T("Right"))) if (adding) new_type |= MFT_RIGHTJUSTIFY; else new_type &= ~MFT_RIGHTJUSTIFY;
718 else if (!_tcsicmp(next_option, _T("Break"))) if (adding) new_type |= MFT_MENUBREAK; else new_type &= ~MFT_MENUBREAK;
719 else if (!_tcsicmp(next_option, _T("BarBreak"))) if (adding) new_type |= MFT_MENUBARBREAK; else new_type &= ~MFT_MENUBARBREAK;
720 else if (ctoupper(*next_option) == 'P')
721 aMenuItem->mPriority = ATOI(next_option + 1); // invalid priority options are not detected, due to rarity and for brevity. Hence, eg Pxyz, is equivalent to P0.
722 else
723 {
724 *option_end = orig_char;
725 if (!ValueError(ERR_INVALID_OPTION, next_option, FAIL_OR_OK)) // invalid option
726 return FAIL;
727 // Otherwise, user wants to continue.
728 }
729 *option_end = orig_char;
730 }
731
732 if (new_type != aMenuItem->mMenuType)
733 {
734 if (mMenu)
735 {
736 MENUITEMINFO mii;
737 mii.cbSize = sizeof(mii);
738 mii.fMask = MIIM_FTYPE;
739 mii.fType = new_type;

Callers

nothing calls this directly

Calls 5

omit_leading_whitespaceFunction · 0.85
StrChrAnyFunction · 0.85
ctoupperFunction · 0.85
ATOIFunction · 0.85
ValueErrorFunction · 0.85

Tested by

no test coverage detected