Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a file with the following structure:

GAME
{
    version = 0.23.5
    linkURL = 
    Mode = 1
    PARAMETERS
    {
        FLIGHT
        {
            CanQuickSave = True
            CanQuickLoad = True
        }
    }
    SCENARIO
    {
        name = ScenarioDiscoverableObjects
        scene = 7, 8, 5
         = 703987854
        sizeCurve
        {
            key = 0 0 1.5 1.5
            key = 0.3 0.45 0.875 0.875
        }
    }
}

I'd like to create a nested menu for easy visualization of the file's contents. I've managed to parse the file to the following structure:

data = {"GAME", {"version", "0.23.5"}, {"linkURL", ""}, {"Mode", 
  "1"}, {"PARAMETERS", {"FLIGHT", {"CanQuickSave", 
    "True"}, {"CanQuickLoad", "True"}}}, {"SCENARIO", {"name", 
   "ScenarioDiscoverableObjects"}, {"scene", "7, 8, 5"}, {"", 
   "703987854"}, {"sizeCurve", {"key", "0 0 1.5 1.5"}, {"key", 
    "0.3 0.45 0.875 0.875"}}}}

I then started to make the menu using OpenerView:

OpenerView[{First[#], Column[Rest[#]]}] &@data

However, I can't manage to apply this function over all levels of data.

edit: Here's a screenshot of what I'm trying to achieve:

menu screenshot

share|improve this question
    
Map has a level specification option. You could set that at Infinity. –  Sjoerd C. de Vries Jul 4 at 16:23
2  
Or use recursion, like this answer –  Sjoerd C. de Vries Jul 4 at 16:31
    
@SjoerdC.deVries Thanks, this looks promising –  shrx Jul 4 at 17:08
add comment

2 Answers 2

I think this fits your needs:

f[x : {_, _}] := OpenerView[x]
f[{x_, y_, z__}] := OpenerView[{x, Column[{y, z}]}]
f[x_] := x
MapAll[f, data]

enter image description here

Map scans from top to bottom that's why I've used it not ReplaceAll which scans from bottom to top.

share|improve this answer
add comment
up vote 3 down vote accepted

Following the example provided by @SjoerdC.deVries, here's how I solved it:

menu[s_String] := s
menu[l_List] := OpenerView[{First[l], Column[menu /@ Rest[l]]}]
menu[data]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.