4

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

shrx
  • 7,807
  • 2
  • 22
  • 55

2 Answers2

5

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.

Kuba
  • 136,707
  • 13
  • 279
  • 740
3

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]
shrx
  • 7,807
  • 2
  • 22
  • 55