+/////////////////////////////////////////////////////////////////////
+// Menu::Impl definition and implementation
+/////////////////////////////////////////////////////////////////////
+
+struct Menu::Impl
+{
+ /// populates the menu or one of its submenu
+ /// This is used as a recursive function
+ void populate(QMenu & qMenu, MenuDefinition const & menu);
+
+ /// Only needed for top level menus.
+ MenuDefinition * top_level_menu;
+ /// our owning view
+ GuiView * view;
+ /// the name of this menu
+ QString name;
+};
+
+
+
+/// Get a MenuDefinition item label from the menu backend
+static QString label(MenuItem const & mi)
+{
+ QString label = mi.label();
+ label.replace("&", "&&");
+
+ QString shortcut = mi.shortcut();
+ if (!shortcut.isEmpty()) {
+ int pos = label.indexOf(shortcut);
+ if (pos != -1)
+ //label.insert(pos, 1, char_type('&'));
+ label.replace(pos, 0, "&");
+ }
+
+ QString const binding = mi.binding();
+ if (!binding.isEmpty())
+ label += '\t' + binding;
+
+ return label;
+}
+
+void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
+{
+ LYXERR(Debug::GUI, "populating menu " << menu.name());
+ if (menu.size() == 0) {
+ LYXERR(Debug::GUI, "\tERROR: empty menu " << menu.name());
+ return;
+ }
+ LYXERR(Debug::GUI, " ***** menu entries " << menu.size());
+ MenuDefinition::const_iterator m = menu.begin();
+ MenuDefinition::const_iterator end = menu.end();
+ for (; m != end; ++m) {
+ if (m->kind() == MenuItem::Separator)
+ qMenu.addSeparator();
+ else if (m->kind() == MenuItem::Submenu) {
+ QMenu * subMenu = qMenu.addMenu(label(*m));
+ populate(*subMenu, m->submenu());
+ subMenu->setEnabled(m->status().enabled());
+ } else {
+ // we have a MenuItem::Command
+ qMenu.addAction(new Action(view, QIcon(), label(*m),
+ m->func(), QString(), &qMenu));
+ }
+ }
+}
+
+/////////////////////////////////////////////////////////////////////
+// Menu implementation
+/////////////////////////////////////////////////////////////////////
+
+Menu::Menu(GuiView * gv, QString const & name, bool top_level)
+: QMenu(gv), d(new Menu::Impl)
+{
+ d->top_level_menu = top_level? new MenuDefinition : 0;
+ d->view = gv;
+ d->name = name;
+ setTitle(name);
+ if (d->top_level_menu)
+ connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView()));
+}
+
+
+Menu::~Menu()
+{
+ delete d->top_level_menu;
+ delete d;
+}
+
+
+void Menu::updateView()
+{
+ guiApp->menus().updateMenu(this);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+// Menus::Impl definition and implementation
+/////////////////////////////////////////////////////////////////////
+