2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiPopupMenu.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
#include "GuiView.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-17 09:14:58 +00:00
|
|
|
#include "Action.h"
|
2007-12-25 22:27:32 +00:00
|
|
|
#include "GuiApplication.h"
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiPopupMenu.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-12-25 21:34:53 +00:00
|
|
|
|
2007-09-19 22:37:22 +00:00
|
|
|
#include "LyXFunc.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "MenuBackend.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-12-25 20:51:05 +00:00
|
|
|
GuiPopupMenu::GuiPopupMenu(GuiView * owner, MenuItem const & mi,
|
2007-09-28 23:14:33 +00:00
|
|
|
bool topLevelMenu)
|
2007-12-25 20:51:05 +00:00
|
|
|
: QMenu(owner), owner_(owner)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
name_ = mi.submenuname();
|
|
|
|
|
|
|
|
setTitle(toqstr(getLabel(mi)));
|
|
|
|
|
|
|
|
if (topLevelMenu)
|
2007-09-05 11:55:03 +00:00
|
|
|
connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView()));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 20:28:26 +00:00
|
|
|
void GuiPopupMenu::updateView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "GuiPopupMenu::updateView()"
|
|
|
|
<< "\tTriggered menu: " << to_utf8(name_));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
clear();
|
2006-03-20 17:25:02 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
if (name_.empty())
|
|
|
|
return;
|
|
|
|
|
2006-12-03 13:09:57 +00:00
|
|
|
// Here, We make sure that theLyXFunc points to the correct LyXView.
|
2007-12-25 20:51:05 +00:00
|
|
|
theLyXFunc().setLyXView(owner_);
|
2006-12-03 13:09:57 +00:00
|
|
|
|
2007-12-25 22:27:32 +00:00
|
|
|
MenuBackend const & menubackend = guiApp->menuBackend();
|
2007-12-25 20:51:05 +00:00
|
|
|
Menu const & fromLyxMenu = menubackend.getMenu(name_);
|
|
|
|
menubackend.expand(fromLyxMenu, topLevelMenu_, owner_->buffer());
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2007-12-25 20:51:05 +00:00
|
|
|
if (!menubackend.hasMenu(topLevelMenu_.name())) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "\tWARNING: menu seems empty"
|
|
|
|
<< to_utf8(topLevelMenu_.name()));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-03-15 11:27:32 +00:00
|
|
|
populate(this, &topLevelMenu_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
|
|
|
void GuiPopupMenu::populate(QMenu * qMenu, Menu * menu)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "populating menu " << to_utf8(menu->name()));
|
2006-03-05 17:24:44 +00:00
|
|
|
if (menu->size() == 0) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "\tERROR: empty menu " << to_utf8(menu->name()));
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, " ***** menu entries " << menu->size());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
Menu::const_iterator m = menu->begin();
|
|
|
|
Menu::const_iterator end = menu->end();
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
for (; m != end; ++m) {
|
|
|
|
|
|
|
|
if (m->kind() == MenuItem::Separator) {
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
qMenu->addSeparator();
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "adding Menubar Separator");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
} else if (m->kind() == MenuItem::Submenu) {
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "** creating New Sub-Menu "
|
|
|
|
<< to_utf8(getLabel(*m)));
|
2006-03-05 17:24:44 +00:00
|
|
|
QMenu * subMenu = qMenu->addMenu(toqstr(getLabel(*m)));
|
|
|
|
populate(subMenu, m->submenu());
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} else { // we have a MenuItem::Command
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "creating Menu Item "
|
|
|
|
<< to_utf8(m->label()));
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2008-01-07 10:53:04 +00:00
|
|
|
docstring const label = getLabel(*m);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2007-12-25 20:51:05 +00:00
|
|
|
Action * action = new Action(*(owner_),
|
2007-10-15 22:43:55 +00:00
|
|
|
QIcon(), toqstr(label), m->func(), QString());
|
2006-03-05 17:24:44 +00:00
|
|
|
qMenu->addAction(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
docstring const GuiPopupMenu::getLabel(MenuItem const & mi)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-01-07 10:53:04 +00:00
|
|
|
docstring label = support::subst(mi.label(),
|
|
|
|
from_ascii("&"), from_ascii("&&"));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-01-07 10:53:04 +00:00
|
|
|
docstring const shortcut = mi.shortcut();
|
2006-03-05 17:24:44 +00:00
|
|
|
if (!shortcut.empty()) {
|
2007-11-23 21:39:51 +00:00
|
|
|
size_t pos = label.find(shortcut);
|
2006-09-09 22:27:22 +00:00
|
|
|
if (pos != docstring::npos)
|
|
|
|
label.insert(pos, 1, char_type('&'));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 10:53:04 +00:00
|
|
|
docstring const binding = mi.binding();
|
2007-08-31 05:53:55 +00:00
|
|
|
if (!binding.empty())
|
2006-12-13 14:13:01 +00:00
|
|
|
label += '\t' + binding;
|
2008-01-07 10:53:04 +00:00
|
|
|
|
|
|
|
return label;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiPopupMenu_moc.cpp"
|