Submenus / family tree / multidim array / subitems
Posted: Tue Oct 11, 2011 5:00 pm
I have a project where you click on one thing which opens up another sets of buttons or keywords - and by clicking those another set opens up etc etc.
All my values are semicolon separated. I have put the submenu in [ ]
Took me an hour to do, so now hopefully I save someone else that hour. Maybe someone like to use it - go ahead to whatever you want to. Works cross platform, but as always it works best on a Mac.
All my values are semicolon separated. I have put the submenu in [ ]
Took me an hour to do, so now hopefully I save someone else that hour. Maybe someone like to use it - go ahead to whatever you want to. Works cross platform, but as always it works best on a Mac.
Code: Select all
original.s="Fruit[Red[Apple;Plum];Green[Apple[Granny Smith;Winterfresh];Pear;Cactus];Yellow[Banana;Corn]];"
original.s+"Vegetable[Round[Tomato[Baby;Plum;Flat;Beef];Potato];Long[Cucumber]];"
original.s+"Others[Diary[Milk;Cream;Butter];Flour[Wheat;Whole grain]]"
Procedure.s clean_result(gadget,result.s)
For i=1 To Len(result)
If Mid(result,i,1)="["
inbracks+1
ElseIf Mid(result,i,1)="]"
inbracks-1
ElseIf inbracks=0
realresult.s+Mid(result,i,1)
EndIf
Next
ClearGadgetItems(gadget)
For i=1 To CountString(realresult.s,";")+1
AddGadgetItem(gadget,-1,StringField(realresult.s,i,";"))
Next
ProcedureReturn result
EndProcedure
Procedure.s clean_submenu(result.s,subresult.l)
inbacks.b=0
For i=1 To Len(result)
If counter=subresult
realresult.s+Mid(result,i,1)
EndIf
If Mid(result,i,1)="["
inbracks+1
ElseIf Mid(result,i,1)="]"
inbracks-1
ElseIf Mid(result,i,1)=";" And inbracks=0
counter+1
EndIf
Next
If FindString(realresult,"[")
For i=Len(realresult) To 1 Step -1
If Mid(realresult,i,1)="]"
Break
EndIf
Next
realresult=Mid(realresult,FindString(realresult,"[")+1,i-FindString(realresult,"[")-1)
Else
realresult=""
EndIf
ProcedureReturn realresult
EndProcedure
OpenWindow(0,0,0,640,480,"")
ListIconGadget(0,0,0,100,480,"Go",100)
ListIconGadget(1,120,0,100,480,"Go",100)
ListIconGadget(2,240,0,100,480,"Go",100)
ListIconGadget(3,360,0,100,480,"Go",100)
;Set first menu
result.s=clean_result(0,original.s)
Repeat
eventid=WaitWindowEvent()
If eventid=#PB_Event_Gadget
If EventGadget()=0
result=clean_result(1,clean_submenu(original,GetGadgetState(0)))
ElseIf EventGadget()=1
result=clean_result(2,clean_submenu(clean_submenu(original,GetGadgetState(0)),GetGadgetState(1)))
ElseIf EventGadget()=2
result=clean_result(3,clean_submenu(clean_submenu(clean_submenu(original,GetGadgetState(0)),GetGadgetState(1)),GetGadgetState(2)))
EndIf
EndIf
Until eventid=#PB_Event_CloseWindow