#include "TocBackend.h"
#include "ToolbarBackend.h"
+#include "support/assert.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/filetools.h"
#include <QMenuBar>
#include <QString>
+#include <boost/shared_ptr.hpp>
+
#include <algorithm>
#include <ostream>
#include <vector>
bool optional = false)
: kind_(kind), label_(label), submenuname_(submenu), optional_(optional)
{
- BOOST_ASSERT(kind == Submenu);
+ LASSERT(kind == Submenu, /**/);
}
MenuItem(Kind kind,
/// set the description of the submenu
void submenuname(QString const & name) { submenuname_ = name; }
///
- bool hasSubmenu() const { return submenu_.isEmpty(); }
+ bool hasSubmenu() const { return !submenu_.isEmpty(); }
///
MenuDefinition const & submenu() const { return submenu_.at(0); }
MenuDefinition & submenu() { return submenu_[0]; }
void MenuDefinition::read(Lexer & lex)
{
- enum Menutags {
+ enum {
md_item = 1,
md_branches,
md_documents,
md_floatlistinsert,
md_floatinsert,
md_pasterecent,
- md_toolbars,
- md_last
+ md_toolbars
};
- struct keyword_item menutags[md_last - 1] = {
+ LexerKeyword menutags[] = {
{ "bookmarks", md_bookmarks },
{ "branches", md_branches },
{ "charstyles", md_charstyles },
{ "viewformats", md_viewformats }
};
- lex.pushTable(menutags, md_last - 1);
- if (lyxerr.debugging(Debug::PARSER))
- lex.printTable(lyxerr);
+ lex.pushTable(menutags);
+ lex.setContext("MenuDefinition::read: ");
bool quit = false;
bool optional = false;
break;
default:
- lex.printError("MenuDefinition::read: "
- "Unknown menu tag: `$$Token'");
+ lex.printError("Unknown menu tag");
break;
}
}
typedef vector<Format const *> Formats;
Formats formats;
- kb_action action;
+ FuncCode action;
switch (kind) {
case MenuItem::ImportFormats:
continue;
break;
default:
- BOOST_ASSERT(false);
+ LASSERT(false, /**/);
break;
}
// FIXME: if we had proper support for translating the
else if (cit->first == "child") {
label = qt_("Child Documents");
in_other_list = false;
- } else if (cit->first == "embedded")
- label = qt_("Embedded Files");
- else if (cit->first == "graphics")
+ } else if (cit->first == "graphics")
label = qt_("List of Graphics");
else if (cit->first == "equation")
label = qt_("List of Equations");
else if (cit->first == "index")
label = qt_("List of Indexes");
- else if (cit->first == "listing")
- label = qt_("List of Listings");
+ else if (cit->first == "listing") {
+ // FIXME: the listing navigate menu causes a crash for unknown
+ // reason. See http://bugzilla.lyx.org/show_bug.cgi?id=4613
+ // This is a temporary fix:
+ //label = qt_("List of Listings");
+ continue;
+ }
else if (cit->first == "marginalnote")
label = qt_("List of Marginal notes");
else if (cit->first == "note")
/////////////////////////////////////////////////////////////////////
Menu::Menu(GuiView * gv, QString const & name, bool top_level)
-: d(new Menu::Impl)
+: QMenu(gv), d(new Menu::Impl)
{
d->top_level_menu = top_level? new MenuDefinition : 0;
d->view = gv;
///
MenuDefinition menubar_;
- typedef QMap<GuiView *, QHash<QString, Menu *> > NameMap;
+ typedef QMap<GuiView *, QHash<QString, Menu*> > NameMap;
/// name to menu for \c menu() method.
NameMap name_map_;
*/
void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb)
{
- // The Mac menubar initialisation must be done only once!
- static bool done = false;
- if (done)
- return;
- done = true;
-
/* Since Qt 4.2, the qt/mac menu code has special code for
specifying the role of a menu entry. However, it does not
work very well with our scheme of creating menus on demand,
* the hassle, though. (JMarc)
*/
struct MacMenuEntry {
- kb_action action;
+ FuncCode action;
char const * arg;
char const * label;
QAction::MenuRole role;
};
const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
- // the special menu for Menus.
- for (size_t i = 0 ; i < num_entries ; ++i) {
- FuncRequest const func(entries[i].action,
- from_utf8(entries[i].arg));
- specialmenu_.add(MenuItem(MenuItem::Command, entries[i].label, func));
+ // the special menu for Menus. Fill it up only once.
+ if (specialmenu_.size() == 0) {
+ for (size_t i = 0 ; i < num_entries ; ++i) {
+ FuncRequest const func(entries[i].action,
+ from_utf8(entries[i].arg));
+ specialmenu_.add(MenuItem(MenuItem::Command,
+ entries[i].label, func));
+ }
}
-
+
// add the entries to a QMenu that will eventually be empty
// and therefore invisible.
QMenu * qMenu = qmb->addMenu("special");
}
-void Menus::Impl::expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
- Buffer const * buf) const
+void Menus::Impl::expand(MenuDefinition const & frommenu,
+ MenuDefinition & tomenu, Buffer const * buf) const
{
if (!tomenu.empty())
tomenu.clear();
MenuNamesEqual(name));
if (cit == menulist_.end())
lyxerr << "No submenu named " << fromqstr(name) << endl;
- BOOST_ASSERT(cit != menulist_.end());
+ LASSERT(cit != menulist_.end(), /**/);
return (*cit);
}
MenuNamesEqual(name));
if (it == menulist_.end())
lyxerr << "No submenu named " << fromqstr(name) << endl;
- BOOST_ASSERT(it != menulist_.end());
+ LASSERT(it != menulist_.end(), /**/);
return (*it);
}
+
/////////////////////////////////////////////////////////////////////
-// Menus implementation
+//
+// Menus
+//
/////////////////////////////////////////////////////////////////////
-Menus::Menus(): d(new Impl) {}
+Menus::Menus() : d(new Impl) {}
+Menus::~Menus()
+{
+ delete d;
+}
void Menus::read(Lexer & lex)
{
- enum Menutags {
- md_menu = 1,
+ enum {
+ md_menu,
md_menubar,
md_endmenuset,
- md_last
};
- struct keyword_item menutags[md_last - 1] = {
+ LexerKeyword menutags[] = {
{ "end", md_endmenuset },
{ "menu", md_menu },
{ "menubar", md_menubar }
};
- //consistency check
- if (compare_ascii_no_case(lex.getString(), "menuset")) {
- lyxerr << "Menubackend::read: ERROR wrong token:`"
- << lex.getString() << '\'' << endl;
- }
+ // consistency check
+ if (compare_ascii_no_case(lex.getString(), "menuset"))
+ LYXERR0("Menus::read: ERROR wrong token: `" << lex.getString() << '\'');
- lex.pushTable(menutags, md_last - 1);
- if (lyxerr.debugging(Debug::PARSER))
- lex.printTable(lyxerr);
+ lex.pushTable(menutags);
+ lex.setContext("Menus::read");
bool quit = false;
quit = true;
break;
default:
- lex.printError("menubackend::read: "
- "Unknown menu tag: `$$Token'");
+ lex.printError("Unknown menu tag");
break;
}
}
}
-void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view)
+void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
{
- // Clear all menubar contents before filling it.
- qmb->clear();
-
+ if (initial) {
#ifdef Q_WS_MACX
- // setup special mac specific menu item
- d->macxMenuBarInit(view, qmb);
+ // setup special mac specific menu item
+ d->macxMenuBarInit(view, qmb);
#endif
+ } else {
+ // Clear all menubar contents before filling it.
+ qmb->clear();
+ }
LYXERR(Debug::GUI, "populating menu bar" << fromqstr(d->menubar_.name()));
<< fromqstr(d->menubar_.name()));
return;
}
- else {
- LYXERR(Debug::GUI, "menu bar entries "
- << d->menubar_.size());
- }
+ LYXERR(Debug::GUI, "menu bar entries " << d->menubar_.size());
MenuDefinition menu;
Buffer * buf = 0;