2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QLPopupMenu.C
|
|
|
|
* 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-03-12 17:44:38 +00:00
|
|
|
#include <boost/current_function.hpp>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
// Qt defines a macro 'signals' that clashes with a boost namespace.
|
|
|
|
// All is well if the namespace is visible first.
|
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"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "QLPopupMenu.h"
|
|
|
|
#include "QLMenubar.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "MenuBackend.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
|
|
|
using std::make_pair;
|
|
|
|
using std::string;
|
|
|
|
using std::pair;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
QLPopupMenu::QLPopupMenu(QLMenubar * owner,
|
2006-03-05 17:24:44 +00:00
|
|
|
MenuItem const & mi, bool topLevelMenu)
|
2006-03-15 11:27:32 +00:00
|
|
|
: owner_(owner)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
name_ = mi.submenuname();
|
|
|
|
|
|
|
|
setTitle(toqstr(getLabel(mi)));
|
|
|
|
|
|
|
|
if (topLevelMenu)
|
|
|
|
connect(this, SIGNAL(aboutToShow()), this, SLOT(update()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLPopupMenu::update()
|
|
|
|
{
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION << endl;
|
|
|
|
LYXERR(Debug::GUI) << "\tTriggered menu: " << lyx::to_utf8(name_) << endl;
|
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.
|
|
|
|
theLyXFunc().setLyXView(owner_->view());
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
Menu const & fromLyxMenu = owner_->backend().getMenu(name_);
|
2006-09-29 21:40:56 +00:00
|
|
|
owner_->backend().expand(fromLyxMenu, topLevelMenu_, owner_->view()->buffer());
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-15 11:27:32 +00:00
|
|
|
if (!owner_->backend().hasMenu(topLevelMenu_.name())) {
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "\tWARNING: menu seems empty" << lyx::to_utf8(topLevelMenu_.name()) << endl;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void QLPopupMenu::populate(QMenu* qMenu, Menu * menu)
|
|
|
|
{
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "populating menu " << lyx::to_utf8(menu->name()) ;
|
2006-03-05 17:24:44 +00:00
|
|
|
if (menu->size() == 0) {
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "\tERROR: empty menu " << lyx::to_utf8(menu->name()) << endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << " ***** menu entries " << menu->size() << endl;
|
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-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "adding Menubar Separator" << endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
} else if (m->kind() == MenuItem::Submenu) {
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "** creating New Sub-Menu " << lyx::to_utf8(getLabel(*m)) << endl;
|
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-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "creating Menu Item " << lyx::to_utf8(m->label()) << endl;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
docstring label = getLabel(*m);
|
2006-03-05 17:24:44 +00:00
|
|
|
addBinding(label, *m);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
Action * action = new Action(*(owner_->view()),
|
2006-10-09 12:30:55 +00:00
|
|
|
label, m->func());
|
2006-03-05 17:24:44 +00:00
|
|
|
qMenu->addAction(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
docstring const QLPopupMenu::getLabel(MenuItem const & mi)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-09-09 22:27:22 +00:00
|
|
|
docstring const shortcut = mi.shortcut();
|
|
|
|
docstring label = support::subst(mi.label(),
|
|
|
|
lyx::from_ascii("&"),
|
|
|
|
lyx::from_ascii("&&"));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
if (!shortcut.empty()) {
|
2006-09-09 22:27:22 +00:00
|
|
|
docstring::size_type pos = label.find(shortcut);
|
|
|
|
if (pos != docstring::npos)
|
|
|
|
label.insert(pos, 1, char_type('&'));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
void QLPopupMenu::addBinding(docstring & label, MenuItem const & mi)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-01-04 17:10:24 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
docstring const binding(mi.binding(false));
|
|
|
|
#else
|
|
|
|
docstring const binding(mi.binding(true));
|
|
|
|
#endif
|
2006-12-13 14:13:01 +00:00
|
|
|
if (!binding.empty()) {
|
|
|
|
label += '\t' + binding;
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
|
|
#include "QLPopupMenu_moc.cpp"
|