--- In [email protected], Brother Gabriel-Marie <brgabr...@...> wrote:
>
> Hello, y'all! I want to dynamically build a pp menu from the
> contents of an ini file. Based on the ini below, it should have
> three submenus corresponding to section1, section2 and section3
> but not section4. When I click on the item in the menu, it should
> open the corresponding file. The menu name should be the same as
> the ini key name. Where do I start?
Might want your script to transform the ini file into a file menu, save the
file menu, and then show it with menu.showfile(yourfilemenu).
A file menu of your sample data would look like this:
@"section1" format startsubmenu
george1=win.debug("somefolder/somefile.ext")
george2=win.debug("somefolder/somefile2.ext")
george3=win.debug("somefolder/somefile3.ext")
format endsubmenu
@"section2" format startsubmenu
harry1=win.debug("somefolder/somefile4.ext")
harry2=win.debug("somefolder/somefile5.ext")
harry3=win.debug("somefolder/somefile6.ext")
format endsubmenu
@"section3" format startsubmenu
mike1=win.debug("somefolder/somefile7.ext")
mike2=win.debug("somefolder/somefile8.ext")
mike3=win.debug("somefolder/somefile9.ext")
format endsubmenu
@"section4" format startsubmenu
item=win.debug("somethingelse")
item1=win.debug("anotherinfo")
format endsubmenu
To open the strings as files, you would use "do" instead of win.debug.
The transformation can be done with two regex.pcrereplace's. Let me know if you
want me to post them. :-)
Another approach would be to process each line in the ini file and use cl
commands to create a command list, insert items, setlabel, and addleft for each
item. A wrinkle would be to process the lines surrounded with brackets as start
or end and startsubmenu (format) commands. At the conclusion you'd need to
append a final format endsubmenu. Then use menu.show to show the dynamic
command list as a menu.
In your message you said of your sample "but not section4", no idea what that
criteria was about, but if you know you want to specify either which sections
should be included or excluded, it is up your script to provide for that,
regardless of the approach.
Instead of processing the ini file line by line, you could process it section
by section. The ini plugin has a service to enum_sections and another to
enum_keys in a section. And finally one to get a value for a key in a section.
To individually get each value in each section would add some overhead, because
the file would be re-read each each time a value is requested.
Regards,
Sheri