Menu id's and action id's are going to be "packed" when them arrive in command handle function.
So, for our "Pure" sub-menus example we are going to define the command function like this:
When our menu items were set with option in the optional 4th parameter its value will be placed in a tuple composed by the packed command id and its value.
We also need to write at least two command function to handle it. The first one is going to handle the value returned by the menu item which will be a boolean value usually seen it named on Wings3D code as Ask. This first function will prepare and show a dialog that will be displayed to the user make the input. After the dialog be processed and ended with an OK then we are going to generate the second command which its pair in the tuple will be a list with the values of the elements we fill on the dialog/form.
So, by using our example for the single option menu, we can have a code like this:
For more information about the dialog construction we can check the wings_dialog.erl which has a description of all elements supported(from line 40).
For the check marked options they can look like this fragment bellow, but a more "complex" example can be found in wings_view.erl source code.
To keep the preference updated for our use we need to switch its value in its respective command handle:
So, for our "Pure" sub-menus example we are going to define the command function like this:
PHP Code:
command({my_menu, id_option1}, St0) ->
%% // Make some processing and update St as needed (if so)
:
St;
command({my_menu, {my_option, opt1}}, St0) ->
%% // Make some processing and update St as needed (if so)
:
St;
command({my_menu, {my_option, opt2}}, St0) ->
%% // Make some processing and update St as needed (if so)
:
St;
command(_, St) ->
St.
When our menu items were set with option in the optional 4th parameter its value will be placed in a tuple composed by the packed command id and its value.
We also need to write at least two command function to handle it. The first one is going to handle the value returned by the menu item which will be a boolean value usually seen it named on Wings3D code as Ask. This first function will prepare and show a dialog that will be displayed to the user make the input. After the dialog be processed and ended with an OK then we are going to generate the second command which its pair in the tuple will be a list with the values of the elements we fill on the dialog/form.
So, by using our example for the single option menu, we can have a code like this:
PHP Code:
command({my_option, Ask}, #st{sel=Sel}=St) when is_atom(Ask) ->
if Sel == [] ->
wings_u:message(?__(1,"A selection is required"));
else
build_my_option_dialog(St);
end;
command({my_option, [{clear,true}]=_Ask}, St) ->
St#st{sel=[]};
command(_, St) -> St.
build_my_option_dialog(St) ->
Qs = [{hframe,[{?__(1,"Clear Selection"), false, [{key,clear}]}]}],
wings_dialog:dialog(Ask, ?__(1,"Handle Selection"), Qs,
fun(Opts) -> {my_option, Opts}} end).
For the check marked options they can look like this fragment bellow, but a more "complex" example can be found in wings_view.erl source code.
To keep the preference updated for our use we need to switch its value in its respective command handle:
PHP Code:
command({my_check_option}, St) ->
Value = wings_pref:get_value(my_check_pref, false),
wings_pref:set_value(my_check_pref, not Value),
St;
: