Menus: dumping the menu structure

Macro file: dump_menu.lym

This application dumps the menu structure into a HTML browser window. Beyond acting as an example, this script is quite useful to visualize the menu structure and to determine insert points when installing new items.

Source code

module Examples
  #  Dumps an item and it's children recursively
  def self.dump_children(space, menu, item)
    s = ""
    s += "<tr><td><tt>#{space}#{item}</tt></td><td>#{menu.action(item).title}</td><td>#{menu.action(item).shortcut}</td></tr>\n"
    menu.items(item).each { |child| s += dump_children("&nbsp;&nbsp;#{space}", menu, child) }
    return s
  #  Gets the menu object
  app = RBA::Application.instance
  mw = app.main_window
  menu =
  #  Creates the HTML page
  s = "<h1>Menu item structure</h1>\n"
  s += "<table>\n"
  s += "<tr><td><b>Path</b></td><td><b>Title</b></td><td><b>Shortcut</b></td></tr>\n"
  menu.items("").each { |item| s += dump_children("", menu, item) }
  s += "</table>\n"
  #  And shows this base in the HTML browser dialog
  text = RBA::BrowserSource::new_html( s )
  browser = RBA::BrowserDialog::new
  browser.set_source( text )
  browser.set_home( "int:" )