<< command << endl;
break;
case Submenu:
- submenu_ = command;
+ submenuname_ = command;
break;
}
}
+MenuItem::~MenuItem()
+{}
+
+
string const MenuItem::label() const
{
return token(label_, '|', 0);
} // namespace anon
-void Menu::expand(Menu & tomenu, Buffer const * buf) const
+void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
+ Buffer const * buf) const
{
- for (const_iterator cit = begin();
- cit != end() ; ++cit) {
+ for (Menu::const_iterator cit = frommenu.begin();
+ cit != frommenu.end() ; ++cit) {
switch (cit->kind()) {
case MenuItem::Lastfiles:
expandLastfiles(tomenu);
expandFloatInsert(tomenu);
break;
+ case MenuItem::Submenu: {
+ MenuItem item(*cit);
+ item.submenu_.reset(new Menu(cit->submenuname_));
+ expand(getMenu(cit->submenuname_),
+ *item.submenu_, buf);
+ tomenu.add(item);
+ }
+ break;
+
default:
tomenu.add(*cit);
}
// Check whether the shortcuts are unique
if (lyxerr.debugging(Debug::GUI))
- checkShortcuts();
+ tomenu.checkShortcuts();
}
bool Menu::hasSubmenu(string const & name) const
{
return find_if(begin(), end(),
- lyx::compare_memfun(&MenuItem::submenu, name)) != end();
+ lyx::compare_memfun(&MenuItem::submenuname,
+ name)) != end();
}
#include "LString.h"
#include <vector>
+#include <boost/shared_ptr.hpp>
class LyXLex;
class Buffer;
+class Menu;
///
class MenuItem {
int action,
bool optional = false)
: kind_(kind), label_(label),
- action_(action), submenu_(), optional_(optional) {}
+ action_(action), submenuname_(), optional_(optional) {}
+ /// This one is just to please boost::shared_ptr<>
+ ~MenuItem();
/// The label of a given menuitem
string const label() const;
/// The keyboard shortcut (usually underlined in the entry)
/// the action (if relevant)
int action() const { return action_; }
/// the description of the submenu (if relevant)
- string const & submenu() const { return submenu_; }
+ string const & submenuname() const { return submenuname_; }
/// returns true if the entry should be ommited when disabled
bool optional() const { return optional_; }
+ ///
+ Menu & submenu() const { return *submenu_.get(); }
private:
+ friend class MenuBackend;
///
Kind kind_;
///
///
int action_;
///
- string submenu_;
+ string submenuname_;
///
bool optional_;
+ ///
+ boost::shared_ptr<Menu> submenu_;
};
Menu & add(MenuItem const &);
///
Menu & read(LyXLex &);
- /// Expands some special entries of the menu
- /** The entries with the following kind are expanded to a
- sequence of Command MenuItems: Lastfiles, Documents,
- ViewFormats, ExportFormats, UpdateFormats
- */
- void expand(Menu & tomenu, Buffer const *) const;
///
string const & name() const { return name_; }
///
Menu const & getMenubar() const;
///
bool empty() const { return menulist_.empty(); }
+ /// Expands some special entries of the menu
+ /** The entries with the following kind are expanded to a
+ sequence of Command MenuItems: Lastfiles, Documents,
+ ViewFormats, ExportFormats, UpdateFormats
+ */
+ void expand(Menu const & frommenu, Menu & tomenu,
+ Buffer const *) const;
///
const_iterator begin() const {
return menulist_.begin();
{
for (ButtonList::const_iterator cit = buttonlist_.begin();
cit != buttonlist_.end(); ++cit) {
- if ((*cit)->item_->submenu() == name) {
+ if ((*cit)->item_->submenuname() == name) {
MenuCallback((*cit)->obj_, 1);
return;
}
int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
- string const & menu_name,
- vector<int> & smn)
+ Menu const & menu, vector<int> & smn)
{
- if (!menubackend_->hasMenu(menu_name)) {
- lyxerr << "ERROR:create_submenu: Unknown menu `"
- << menu_name << "'" << endl;
- return -1;
- }
- Menu md;
- menubackend_->getMenu(menu_name).expand(md, owner_->buffer());
-
- int const menu = get_new_submenu(smn, win);
- fl_setpup_softedge(menu, true);
- fl_setpup_bw(menu, -1);
- lyxerr[Debug::GUI] << "Adding menu " << menu
+ int const menuid = get_new_submenu(smn, win);
+ fl_setpup_softedge(menuid, true);
+ fl_setpup_bw(menuid, -1);
+ lyxerr[Debug::GUI] << "Adding menu " << menuid
<< " in deletion list" << endl;
// Compute the size of the largest label (because xforms is
// not able to support shortcuts correctly...)
int max_width = 0;
string widest_label;
- Menu::const_iterator end = md.end();
- for (Menu::const_iterator i = md.begin(); i != end; ++i) {
+ Menu::const_iterator end = menu.end();
+ for (Menu::const_iterator i = menu.begin(); i != end; ++i) {
MenuItem const & item = (*i);
if (item.kind() == MenuItem::Command) {
string const label = item.label() + '\t';
<< "'" << endl;
// Compute where to put separators
- vector<string> extra_labels(md.size());
+ vector<string> extra_labels(menu.size());
vector<string>::iterator it = extra_labels.begin();
vector<string>::iterator last = it;
- for (Menu::const_iterator i = md.begin(); i != end; ++i, ++it)
+ for (Menu::const_iterator i = menu.begin(); i != end; ++i, ++it)
if (i->kind() == MenuItem::Separator)
*last = "%l";
else if (!i->optional() ||
last = it;
it = extra_labels.begin();
- for (Menu::const_iterator i = md.begin(); i != end; ++i, ++it) {
+ for (Menu::const_iterator i = menu.begin(); i != end; ++i, ++it) {
MenuItem const & item = (*i);
string & extra_label = *it;
if (!shortcut.empty()) {
shortcut += lowercase(shortcut[0]);
label += "%h";
- fl_addtopup(menu, label.c_str(),
+ fl_addtopup(menuid, label.c_str(),
shortcut.c_str());
} else
- fl_addtopup(menu, label.c_str());
+ fl_addtopup(menuid, label.c_str());
lyxerr[Debug::GUI] << "Command: \""
<< lyxaction.getActionName(item.action())
}
case MenuItem::Submenu: {
- int submenu = create_submenu(win, view,
+ int submenuid = create_submenu(win, view,
item.submenu(), smn);
- if (submenu == -1)
+ if (submenuid == -1)
return -1;
string label = item.label();
label += extra_label + "%m";
if (!shortcut.empty()) {
shortcut += lowercase(shortcut[0]);
label += "%h";
- fl_addtopup(menu, label.c_str(),
- submenu, shortcut.c_str());
+ fl_addtopup(menuid, label.c_str(),
+ submenuid, shortcut.c_str());
} else {
- fl_addtopup(menu, label.c_str(), submenu);
+ fl_addtopup(menuid, label.c_str(), submenuid);
}
break;
}
break;
case MenuItem::Toc:
- add_toc(menu, extra_label, smn, win);
+ add_toc(menuid, extra_label, smn, win);
break;
case MenuItem::Documents:
}
}
- return menu;
+ return menuid;
}
// set tabstop length
fl_set_tabstop(menu_tabstop);
+
+ MenuBackend const * menubackend_ = iteminfo->pimpl_->menubackend_;
+ Menu tomenu;
+ Menu const frommenu = menubackend_->getMenu(item->submenuname());
+ menubackend_->expand(frommenu, tomenu, view->buffer());
vector<int> submenus;
int menu = iteminfo->pimpl_->
- create_submenu(FL_ObjWin(ob), view,
- item->submenu(), submenus);
+ create_submenu(FL_ObjWin(ob), view, tomenu, submenus);
if (menu != -1) {
// place popup
fl_setpup_position(view->getForm()->x + ob->x,