Here's an approach. I haven't fully fleshed it out, but it will get you started. Of course, there is room for improvement and I'm probably missing some built-in predicates that would make it simpler.
In a class declaration (.cl) file:
Code: Select all
predicates
getMenuItem : (vpiDomains::menu MenuItemList, vpiDomains::menuTag SeekTag) -> vpiDomains::menuItem.
% Raise exception if SeekTag is not in MenuItemList
getWindowMenuItem : (window, vpiDomains::menuTag) -> vpiDomains::menuItem.
toggleMenuCheck : (window, vpiDomains::menuTag).
getMenuCheckedState : (window, vpiDomains::menuTag) -> boolean.
In the implementation (.pro) file:
Code: Select all
open core, vpiDomains
clauses
getMenuCheckedState(W, Tag) = CheckedState :-
txt(Tag, _Text, _Key, _Enabled, State, _MoreItems) = getWindowMenuItem(W, Tag),
!,
if State = b_false then
CheckedState = false % NOTE that this predicate is using two different boolean domains
else
CheckedState = true
end if.
getMenuCheckedState(_, Tag) = _ :-
Msg = string::format("Unable to retrieve MenuItem with tag = '%'", Tag),
exception::raise_user(Msg).
toggleMenuCheck(W, Tag) :-
if State = getMenuCheckedState(W, Tag) then
if State = false then
NewState = b_true % NOTE that this predicate is using two different boolean domains
else
NewState = b_false
end if,
vpi::menuCheck(W:getVpiWindow(), Tag, NewState)
else
exception::raise_user("Unable to get State from getMenuCheckedState(Win,Tag)")
end if.
getWindowMenuItem(W, SeekTag) = MenuItem :-
Menu = vpi::menuGet(W:getVpiWindow()),
MenuItem = getMenuItem(Menu, SeekTag).
getMenuItem(Menu, SeekTag) = MenuItem :-
Menu = dynMenu(MenuItemList),
MItemSubList in MenuItemList,
MenuItem = tryGetTaggedItem([MItemSubList], SeekTag),
!.
getMenuItem(_Menu, SeekTag) = _ :-
Msg = string::format("Unable to find tag '%' in menu", SeekTag),
exception::raise_user(Msg).
class predicates
tryGetTaggedItem : (menuItem_list, menuTag) -> menuItem determ.
clauses
tryGetTaggedItem([Item | _T], SeekTag) = Item :-
Item = txt(SeekTag, _Text, _Key, _Enabled, _State, _MoreItems),
!.
tryGetTaggedItem([H | _T], SeekTag) = U :-
H = txt(_Tag, _Text, _Key, _Enabled, _State, MoreItems),
U = tryGetTaggedItem(MoreItems, SeekTag),
!.
tryGetTaggedItem([_H | T], SeekTag) = U :-
U = tryGetTaggedItem(T, SeekTag).
Some test code in the TaskWindow:
Code: Select all
predicates
onTestChecktest : window::menuItemListener.
clauses
onTestChecktest(Source, MenuTag) :-
g_Menu::toggleMenuCheck(Source, MenuTag), % toggle the checked flag
Resp = g_Menu::getMenuCheckedState(Source, MenuTag), % get the new checked status
stdio::write("\n Checked state: ", toString(Resp)). % show the new state