4
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ Map has a level specification option. You could set that at Infinity. $\endgroup$ Jul 4, 2014 at 16:23
  • 2
    $\begingroup$ Or use recursion, like this answer $\endgroup$ Jul 4, 2014 at 16:31
  • $\begingroup$ @SjoerdC.deVries Thanks, this looks promising $\endgroup$
    – shrx
    Jul 4, 2014 at 17:08

2 Answers 2

5
$\begingroup$

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.

$\endgroup$
3
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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