• To: mathgroup at smc.vnet.net
• From: Leonid Shifrin <lshifr at gmail.com>
• Date: Tue, 9 Jun 2009 03:58:22 -0400 (EDT)
• References: <200906081018.GAA26491@smc.vnet.net>

```Hi Chris,

Below is the closest analog I found (I am not a UI person and you will
probably get better solutions from others, but still) : suppose your menu
data is in such a structure:

In[1] =

{{"Africa",
{{"Algeria", {"Algiers",  "Oran"}},
{"Angola", {"Luanda", "Huambo"}}}
},
{"North America",
{{"United States", {"New York", "Washington"}},
}};

In[2] =

Example:

In[3] =
Clear[h];

Out[3] =

{{"Africa", {{"Algeria", {"Algiers" :> h["Algiers"],
"Oran" :> h["Oran"]}}, {"Angola", {"Luanda" :> h["Luanda"],
"Huambo" :>    h["Huambo"]}}}}, {"North America", {{"United States",
{"New York" :> h["New York"],
"Washington" :> h["Washington"]}}, {"Canada", {"Toronto" :>
h["Toronto"], "Montreal" :> h["Montreal"]}}}}}

Another auxilliary function will transform the structure as needed in

In[4] =

Fold[Function[{expr, fandlevel},
With[{fn = fandlevel[[1]]},
Apply[# :> fn[##] &, expr, fandlevel[[2]]]]], itemsAndActions,
List /@ Range[2*menuDepth - 3, 1, -2]}]];

Example:

In[5] =
Clear[f,g];

Out[5] =

{"Africa" :>
g["Africa", {"Algeria" :>
f["Algeria", {"Algiers" :> h["Algiers"], "Oran" :> h["Oran"]}],
"Angola" :>
f["Angola", {"Luanda" :> h["Luanda"],
"Huambo" :> h["Huambo"]}]}],
"North America" :>
g["North America", {"United States" :>
f["United States", {"New York" :> h["New York"],
"Washington" :> h["Washington"]}],
"Montreal" :> h["Montreal"]}]}]}

Module[{name , subname, sub, subsub, subBack, makeSub, subsubBack,
makeSubSub, subsubname = "Cities"},
subBack[] := (sub = ""; name = "Continent");
subsubBack[] := (subsub = ""; subname = "Country");
subsubBack[];
subBack[];
makeSub[nm_String, actions_List] :=
(name = nm;
Prepend[actions, "Back" :> (subsubBack[]; subBack[])]]);
makeSubSub[nm_String, actions_List] :=
(subname = nm;
Prepend[actions, "Back" :> subsubBack[]]]);

It is less generic than the previous two. It is possible to write it in a
more generic way to allow it to automatically adjust to the input menu
structure, but the code will look more complex. It will however then become
more elegant and robust. In particular, it is possible to generate functions
like makeSub, makeSubSub automatically, as well as variables <sub>,
<subsub>. Note that all functions rely on a particular list data structure
used to store the menu items.

The usage (for example):

Print["The city you chose is ", #] &]

Hope this helps.

Regards,
Leonid

On Mon, Jun 8, 2009 at 3:18 AM, Chris Degnen <degnen at cwgsy.net> wrote:

> Hi,  Any suggestions for creating a multi-level menu, such as this:
>