@@ -16,35 +16,54 @@ namespace Menu {
1616 class UserMenu :public menuNode {
1717 public:
1818 menu* subMenu=NULL ;
19- UserMenu (constMEM menuNodeShadow& shadow):menuNode(shadow) {}
20- UserMenu (constMEM menuNodeShadow& shadow,menu& subMenu):menuNode(shadow),subMenu(&subMenu) {}
21- UserMenu (constText* text,idx_t size,menu& subMenu,action a=noAction,eventMask e=noEvent,styles style=wrapStyle)
19+ const char *backTitle=NULL ;
20+ UserMenu (constMEM menuNodeShadow& shadow,const char *backTitle=NULL )
21+ :menuNode(shadow),backTitle(backTitle) {}
22+ UserMenu (constMEM menuNodeShadow& shadow,menu& subMenu,const char *backTitle=NULL )
23+ :menuNode(shadow),subMenu(&subMenu),backTitle(backTitle) {}
24+ UserMenu (const char * text,idx_t size,menu& subMenu,action a=noAction,eventMask e=noEvent,styles style=wrapStyle)
2225 :menuNode(text,size,NULL ,a,e,style,(systemStyles)(_menuData|_canNav)),subMenu(&subMenu) {}
26+ UserMenu (const char * text,idx_t size,const char *backTitle,menu& subMenu,action a=noAction,eventMask e=noEvent,styles style=wrapStyle)
27+ :menuNode(text,size,NULL ,a,e,style,(systemStyles)(_menuData|_canNav)),subMenu(&subMenu),backTitle(backTitle) {}
28+
29+ inline idx_t sz () const override {return menuNode::sz ()+(backTitle?1 :0 );}
2330
2431 prompt& operator [](idx_t i) const override {return *(prompt*)this ;}
2532 virtual Used printItem (menuOut& out, int idx,int len)=0;
2633 Used printTo (navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t p) override {
2734 if (root.navFocus !=this ) return menuNode::printTo (root,sel,out,idx,len,p);
28- return idx<0 ?
29- menuNode::printTo (root,sel,out,idx,len,p):// print the title
30- printItem (out,out.tops [root.level ]+idx,len);
35+ if (idx<0 ) return menuNode::printTo (root,sel,out,idx,len,p);// print the title
36+ if (backTitle&&idx==sz ()-1 ) return out.printText (backTitle,len);
37+ trace (MENU_DEBUG_OUT<<" {" <<idx<<" }" );
38+ return printItem (out,out.tops [root.level ]+idx/* -(backTitle?1:0)*/ ,len);
3139 }
3240 void doNav (navNode& nav,navCmd cmd) {
33- if (nav.root ->navFocus ==this &&cmd.cmd ==enterCmd) {
34- _trace (MENU_DEBUG_OUT<<" no sub levels! submenu:" <<(subMenu?" yes" :" no" )<<" level:" <<nav.root ->level <<" \n " );
35- // just send the event, but do not open (as this menu is representing the item)
36- // nav.root->path[nav.root->level-1].event(enterEvent);
37- // nav.event(enterEvent);
38- // if(enterEvent&&) operator()(enterEvent, nav, *this);
39- nav.event (enterEvent);
40- if (subMenu) {
41- assert (nav.root ->level <nav.root ->maxDepth );
42- nav.root ->active ().dirty =true ;
43- nav.root ->level ++;
44- nav.root ->navFocus =nav.root ->node ().target =subMenu;
45- nav.root ->node ().sel =0 ;
41+ if (nav.root ->navFocus ==this ) {
42+ trace (MENU_DEBUG_OUT<<" submenu:" <<(subMenu?" yes" :" no" )<<" level:" <<nav.root ->level <<" \n " );
43+ switch (cmd.cmd ) {
44+ case selCmd:
45+ case idxCmd:
46+ trace (MENU_DEBUG_OUT<<" idxCmd " <<cmd.param <<endl);
47+ nav.sel =cmd.param ;
48+ case enterCmd:
49+ _trace (MENU_DEBUG_OUT<<" enterCmd" );
50+ if (backTitle&&nav.sel ==sz ()-1 ) nav.root ->exit ();
51+ else {
52+ nav.event (enterEvent);
53+ if (subMenu) {
54+ _trace (MENU_DEBUG_OUT<<" edit item" );
55+ assert (nav.root ->level <nav.root ->maxDepth );
56+ nav.root ->active ().dirty =true ;
57+ nav.root ->level ++;
58+ nav.root ->navFocus =nav.root ->node ().target =subMenu;
59+ nav.root ->node ().sel =0 ;
60+ }
61+ }
62+ return ;
63+ default :break ;
4664 }
47- } else menuNode::doNav (nav,cmd);
65+ }
66+ menuNode::doNav (nav,cmd);
4867 }
4968 };
5069
0 commit comments