2 * \file GuiPopupMenu.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "GuiPopupMenu.h"
17 #include "GuiApplication.h"
19 #include "qt_helpers.h"
23 #include "support/debug.h"
28 GuiPopupMenu::GuiPopupMenu(GuiView * owner, MenuItem const & mi,
30 : QMenu(owner), owner_(owner)
32 name_ = mi.submenuname();
37 connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView()));
41 void GuiPopupMenu::updateView()
43 LYXERR(Debug::GUI, "GuiPopupMenu::updateView()"
44 << "\tTriggered menu: " << fromqstr(name_));
51 // Here, We make sure that theLyXFunc points to the correct LyXView.
52 theLyXFunc().setLyXView(owner_);
54 Menus const & menus = guiApp->menus();
55 Menu const & fromLyxMenu = menus.getMenu(name_);
56 menus.expand(fromLyxMenu, topLevelMenu_, owner_->buffer());
58 if (!menus.hasMenu(topLevelMenu_.name())) {
59 LYXERR(Debug::GUI, "\tWARNING: menu seems empty"
60 << fromqstr(topLevelMenu_.name()));
62 populate(this, &topLevelMenu_);
66 void GuiPopupMenu::populate(QMenu * qMenu, Menu * menu)
68 LYXERR(Debug::GUI, "populating menu " << fromqstr(menu->name()));
69 if (menu->size() == 0) {
70 LYXERR(Debug::GUI, "\tERROR: empty menu " << fromqstr(menu->name()));
73 LYXERR(Debug::GUI, " ***** menu entries " << menu->size());
75 Menu::const_iterator m = menu->begin();
76 Menu::const_iterator end = menu->end();
78 for (; m != end; ++m) {
80 if (m->kind() == MenuItem::Separator) {
82 qMenu->addSeparator();
83 LYXERR(Debug::GUI, "adding Menubar Separator");
85 } else if (m->kind() == MenuItem::Submenu) {
87 LYXERR(Debug::GUI, "** creating New Sub-Menu "
88 << fromqstr(label(*m)));
89 QMenu * subMenu = qMenu->addMenu(label(*m));
90 populate(subMenu, m->submenu());
92 } else { // we have a MenuItem::Command
94 LYXERR(Debug::GUI, "creating Menu Item "
95 << fromqstr(m->label()));
97 Action * action = new Action(*owner_,
98 QIcon(), label(*m), m->func(), QString());
99 qMenu->addAction(action);
105 QString GuiPopupMenu::label(MenuItem const & mi) const
107 QString label = mi.label();
108 label.replace("&", "&&");
110 QString shortcut = mi.shortcut();
111 if (!shortcut.isEmpty()) {
112 int pos = label.indexOf(shortcut);
114 //label.insert(pos, 1, char_type('&'));
115 label.replace(pos, 0, "&");
118 QString const binding = mi.binding();
119 if (!binding.isEmpty())
120 label += '\t' + binding;
126 } // namespace frontend
129 #include "GuiPopupMenu_moc.cpp"