mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
menubackend changes to prepare for toc migration
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4768 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4d5046100f
commit
f8a96d50fb
@ -1,3 +1,13 @@
|
||||
2002-07-24 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* MenuBackend.C (expand): move from Menu to MenuBackend; pass a
|
||||
Menu as first parameter. Now, this calls itself recursively to
|
||||
expand a whole tree (this will be useful for TOC handling)
|
||||
|
||||
* MenuBackend.h (submenuname): returns the name of the submenu.
|
||||
(submenu): returns the submenu itself, provided it has been
|
||||
created by MenuBackend::expand
|
||||
|
||||
2002-07-23 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* paragraph_pimpl.C (simpleTeXSpecialChars): close fonts before
|
||||
|
@ -74,12 +74,16 @@ MenuItem::MenuItem(Kind kind, string const & label,
|
||||
<< command << endl;
|
||||
break;
|
||||
case Submenu:
|
||||
submenu_ = command;
|
||||
submenuname_ = command;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MenuItem::~MenuItem()
|
||||
{}
|
||||
|
||||
|
||||
string const MenuItem::label() const
|
||||
{
|
||||
return token(label_, '|', 0);
|
||||
@ -394,10 +398,11 @@ void expandFloatInsert(Menu & tomenu)
|
||||
} // 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);
|
||||
@ -422,6 +427,15 @@ void Menu::expand(Menu & tomenu, Buffer const * buf) const
|
||||
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);
|
||||
}
|
||||
@ -429,14 +443,15 @@ void Menu::expand(Menu & tomenu, Buffer const * buf) const
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,9 +20,11 @@
|
||||
|
||||
#include "LString.h"
|
||||
#include <vector>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class LyXLex;
|
||||
class Buffer;
|
||||
class Menu;
|
||||
|
||||
///
|
||||
class MenuItem {
|
||||
@ -72,8 +74,10 @@ public:
|
||||
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)
|
||||
@ -85,10 +89,13 @@ public:
|
||||
/// 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_;
|
||||
///
|
||||
@ -96,9 +103,11 @@ private:
|
||||
///
|
||||
int action_;
|
||||
///
|
||||
string submenu_;
|
||||
string submenuname_;
|
||||
///
|
||||
bool optional_;
|
||||
///
|
||||
boost::shared_ptr<Menu> submenu_;
|
||||
};
|
||||
|
||||
|
||||
@ -116,12 +125,6 @@ public:
|
||||
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_; }
|
||||
///
|
||||
@ -173,6 +176,13 @@ public:
|
||||
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();
|
||||
|
@ -1,3 +1,8 @@
|
||||
2002-07-24 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* Menubar_pimpl.C (create_submenu): updates due to changes in
|
||||
menubackend.
|
||||
|
||||
2002-07-22 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* XMiniBuffer.h: add connection objects, and use them
|
||||
|
@ -153,7 +153,7 @@ void Menubar::Pimpl::openByName(string const & name)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -340,29 +340,20 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
|
||||
|
||||
|
||||
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';
|
||||
@ -378,10 +369,10 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
||||
<< "'" << 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() ||
|
||||
@ -389,7 +380,7 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
||||
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;
|
||||
|
||||
@ -439,10 +430,10 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
||||
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())
|
||||
@ -453,9 +444,9 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
||||
}
|
||||
|
||||
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";
|
||||
@ -463,10 +454,10 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
||||
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;
|
||||
}
|
||||
@ -477,7 +468,7 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
||||
break;
|
||||
|
||||
case MenuItem::Toc:
|
||||
add_toc(menu, extra_label, smn, win);
|
||||
add_toc(menuid, extra_label, smn, win);
|
||||
break;
|
||||
|
||||
case MenuItem::Documents:
|
||||
@ -494,7 +485,7 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
||||
|
||||
}
|
||||
}
|
||||
return menu;
|
||||
return menuid;
|
||||
}
|
||||
|
||||
|
||||
@ -521,10 +512,14 @@ void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button)
|
||||
|
||||
// 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,
|
||||
|
@ -58,8 +58,7 @@ private:
|
||||
std::vector<int> & smn, Window win);
|
||||
///
|
||||
int create_submenu(Window win, XFormsView * view,
|
||||
string const & menuname,
|
||||
std::vector<int> & smn);
|
||||
Menu const & menu, std::vector<int> & smn);
|
||||
|
||||
//
|
||||
void makeMenubar(Menu const &menu);
|
||||
|
Loading…
Reference in New Issue
Block a user