MenuPrime

Created Diff never expires
1 removal
114 lines
1 addition
114 lines
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
//
//
// Originally intemded to display "Program"->"Edit"->"Cmds" tree
// Originally intemded to display "Program"->"Edit"->"Cmds" tree
// directly in CAS or HOME without program editing.
// directly in CAS or HOME without program editing.
//
//
// usage:
// usage:
// - called with <Shift>+<User> plus <Alpha><Shift><Space>
// - called with <Shift>+<User> plus <Alpha><Shift><Space>
// (2 times <Shift>+<User> keeps user key mode active)
// (2 times <Shift>+<User> keeps user key mode active)
// - <enter>, <OK> or touch on a command in main or sub menu returns selected item
// - <enter>, <OK> or touch on a command in main or sub menu returns selected item
// - <Esc> in main menu will close popup
// - <Esc> in main menu will close popup
// <Esc> in sub menu will return to main menu entry
// <Esc> in sub menu will return to main menu entry
// - <up>, <down> and swipe to move in popup (<left><right> are NOT usable)
// - <up>, <down> and swipe to move in popup (<left><right> are NOT usable)
// - starts with last returned sub- or mainmenu entry selected
// - starts with last returned sub- or mainmenu entry selected
// starts last visited submenu selected when ended with <Esc>
// starts last visited submenu selected when ended with <Esc>
// - adopt 'menuList' to your needs. Remove 'menuAct' and 'menuList' from this code,
// - adopt 'menuList' to your needs. Remove 'menuAct' and 'menuList' from this code,
// when you want to use different menus in different Apps.
// when you want to use different menus in different Apps.
//
//
// 'menuList' contains the menu definition in a list. Each entry is described by a
// 'menuList' contains the menu definition in a list. Each entry is described by a
// sub list with text to display as the 1st and text to return as 2nd entry.
// sub list with text to display as the 1st and text to return as 2nd entry.
// When the 2nd value is again a list, the entry is interpreted as a submenu containing
// When the 2nd value is again a list, the entry is interpreted as a submenu containing
// the sublist entries to display and return. A sample:
// the sublist entries to display and return. A sample:
// EXPORT menuList :=
// EXPORT menuList :=
// { { "display_text1", "output_text1" },
// { { "display_text1", "output_text1" },
// { "display_text2", "output_text2" },
// { "display_text2", "output_text2" },
// { "submenu1" , { "menu1_display_and_output1",
// { "submenu1" , { "menu1_display_and_output1",
// "menu1_display_and_output2",
// "menu1_display_and_output2",
// "menu1_display_and_output3"
// "menu1_display_and_output3"
// }
// }
// },
// },
// { "submenu2" , { "menu2_display_and_output1",
// { "submenu2" , { "menu2_display_and_output1",
// "menu2_display_and_output2"
// "menu2_display_and_output2"
// }
// }
// }
// }
// };
// };
//
//
// Stay healthy!
// Stay healthy!
// Frank P. Mar 2021
// Frank P. Mar 2021
// hisory:
// hisory:
// V 0.01 Feb 2019 - initial
// V 0.01 Feb 2019 - initial
// V 1.0 Mar 2021 - menuAct added to remember last choose
// V 1.0 Mar 2021 - menuAct added to remember last choose
// - menuList both display and return text as list of lists
// - menuList both display and return text as list of lists
// (inspired by ramon_ea1gth CSTMENU)
// (inspired by ramon_ea1gth CSTMENU)
//
//
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// { "km/l <-> l/100km", "kml()" },
// { "km/l <-> l/100km", "kml()" },


EXPORT menuAct := {1,0};
EXPORT menuAct := {1,0};
EXPORT menuList :=
EXPORT menuList :=
{ { "evalc" , "evalc()"
{ { "evalc" , "evalc()"
},{ "re" , "re()"
},{ "re" , "re()"
},{ "im" , "im()"
},{ "im" , "im()"
},{ "csolve" , "csolve()"
},{ "csolve" , "csolve()"
},{ "rectangular to polar" , "RectangularPolar()"
},{ "rectangular to polar" , "RectangularPolar()"
},{ "polar to rectangular" , "PolarRectangular()"
},{ "polar to rectangular" , "PolarRectangular()"
}
}
};
};


KEY KSA_Math()
KEY KSA_Math


BEGIN
BEGIN
LOCAL choose_list, choose_title, ch, ret, i;
LOCAL choose_list, choose_title, ch, ret, i;
/////////////////////////// check the menu entries ///////////////////////////////////
/////////////////////////// check the menu entries ///////////////////////////////////
FOR i FROM 1 TO SIZE(menuList) STEP 1 DO
FOR i FROM 1 TO SIZE(menuList) STEP 1 DO
// 1st entry is a string and 2nd entry is a string or a list and 2nd entry not empty
// 1st entry is a string and 2nd entry is a string or a list and 2nd entry not empty
IF ( TYPE(menuList(i,1)) == 2 ) AND ( (TYPE(menuList(i,2)) == 2) OR ( TYPE(menuList(i,2)) == 6 ) ) AND SIZE(menuList(i,2)) THEN
IF ( TYPE(menuList(i,1)) == 2 ) AND ( (TYPE(menuList(i,2)) == 2) OR ( TYPE(menuList(i,2)) == 6 ) ) AND SIZE(menuList(i,2)) THEN
// OK
// OK
ELSE
ELSE
MSGBOX(" INVALID MENU ENTRY: " + STRING(menuList(i)) );
MSGBOX(" INVALID MENU ENTRY: " + STRING(menuList(i)) );
RETURN "";
RETURN "";
END;
END;
END;
END;


WHILE 1 DO
WHILE 1 DO
//////////////////////// prepare the choose arguments //////////////////////////////
//////////////////////// prepare the choose arguments //////////////////////////////
// string as 2nd argument => in main or a submenue entry and that is not active
// string as 2nd argument => in main or a submenue entry and that is not active
IF (TYPE(menuList(menuAct(1),2)) == 2) OR ( (TYPE(menuList(menuAct(1),2)) == 6) AND (menuAct(2) == 0) ) THEN
IF (TYPE(menuList(menuAct(1),2)) == 2) OR ( (TYPE(menuList(menuAct(1),2)) == 6) AND (menuAct(2) == 0) ) THEN
choose_list := MAKELIST(menuList(X,1), X,1,SIZE(menuList));
choose_list := MAKELIST(menuList(X,1), X,1,SIZE(menuList));
choose_title := "Commands";
choose_title := "Commands";
ch := menuAct(1);
ch := menuAct(1);
END;
END;
// at a submenue entry and it is active
// at a submenue entry and it is active
IF ( TYPE(menuList(menuAct(1),2)) == 6 ) AND (menuAct(2) > 0) THEN
IF ( TYPE(menuList(menuAct(1),2)) == 6 ) AND (menuAct(2) > 0) THEN
choose_list := menuList(menuAct(1),2);
choose_list := menuList(menuAct(1),2);
choose_title := menuList(menuAct(1),1);
choose_title := menuList(menuAct(1),1);
ch := menuAct(2);
ch := menuAct(2);
END;
END;


////////////////////////////// choose a menu entry //////////////////////////////////
////////////////////////////// choose a menu entry //////////////////////////////////
ret:=choose(ch,choose_title,choose_list);
ret:=choose(ch,choose_title,choose_list);


IF menuAct(2) == 0 THEN
IF menuAct(2) == 0 THEN
///////////////////////////// handle main level ///////////////////////////////////
///////////////////////////// handle main level ///////////////////////////////////
menuAct(1) := ch; // remember main selection
menuAct(1) := ch; // remember main selection
IF ret==0 THEN // choose ended with esc
IF ret==0 THEN // choose ended with esc
RETURN "";
RETURN "";
ELSE
ELSE
IF TYPE(menuList(menuAct(1),2)) == 2 THEN // a string as 2nd entry
IF TYPE(menuList(menuAct(1),2)) == 2 THEN // a string as 2nd entry
RETURN menuList(menuAct(1),2); // return selected entry
RETURN menuList(menuAct(1),2); // return selected entry
END;
END;
IF TYPE(menuList(menuAct(1),2)) == 6 THEN // a list as 2nd entry
IF TYPE(menuList(menuAct(1),2)) == 6 THEN // a list as 2nd entry
menuAct(2) := 1; // activate submenu
menuAct(2) := 1; // activate submenu
END;
END;
END; // something selected?
END; // something selected?
ELSE
ELSE
//////////////////////////////// and sub level ///////////////////////////////////
//////////////////////////////// and sub level ///////////////////////////////////
menuAct(2) := ch; // remember sub selection
menuAct(2) := ch; // remember sub selection
IF ret==0 THEN // no entry selected
IF ret==0 THEN // no entry selected
menuAct(2) := 0; // back to main level
menuAct(2) := 0; // back to main level
ELSE
ELSE
RETURN choose_list(menuAct(2)); // return with selection
RETURN choose_list(menuAct(2)); // return with selection
END;
END;
END; // in sub menu?
END; // in sub menu?
END; // while choosing
END; // while choosing
END; // menu
END; // menu