mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +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>
|
2002-07-23 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||||
|
|
||||||
* paragraph_pimpl.C (simpleTeXSpecialChars): close fonts before
|
* paragraph_pimpl.C (simpleTeXSpecialChars): close fonts before
|
||||||
|
@ -74,12 +74,16 @@ MenuItem::MenuItem(Kind kind, string const & label,
|
|||||||
<< command << endl;
|
<< command << endl;
|
||||||
break;
|
break;
|
||||||
case Submenu:
|
case Submenu:
|
||||||
submenu_ = command;
|
submenuname_ = command;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MenuItem::~MenuItem()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
string const MenuItem::label() const
|
string const MenuItem::label() const
|
||||||
{
|
{
|
||||||
return token(label_, '|', 0);
|
return token(label_, '|', 0);
|
||||||
@ -394,10 +398,11 @@ void expandFloatInsert(Menu & tomenu)
|
|||||||
} // namespace anon
|
} // 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();
|
for (Menu::const_iterator cit = frommenu.begin();
|
||||||
cit != end() ; ++cit) {
|
cit != frommenu.end() ; ++cit) {
|
||||||
switch (cit->kind()) {
|
switch (cit->kind()) {
|
||||||
case MenuItem::Lastfiles:
|
case MenuItem::Lastfiles:
|
||||||
expandLastfiles(tomenu);
|
expandLastfiles(tomenu);
|
||||||
@ -422,6 +427,15 @@ void Menu::expand(Menu & tomenu, Buffer const * buf) const
|
|||||||
expandFloatInsert(tomenu);
|
expandFloatInsert(tomenu);
|
||||||
break;
|
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:
|
default:
|
||||||
tomenu.add(*cit);
|
tomenu.add(*cit);
|
||||||
}
|
}
|
||||||
@ -429,14 +443,15 @@ void Menu::expand(Menu & tomenu, Buffer const * buf) const
|
|||||||
|
|
||||||
// Check whether the shortcuts are unique
|
// Check whether the shortcuts are unique
|
||||||
if (lyxerr.debugging(Debug::GUI))
|
if (lyxerr.debugging(Debug::GUI))
|
||||||
checkShortcuts();
|
tomenu.checkShortcuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Menu::hasSubmenu(string const & name) const
|
bool Menu::hasSubmenu(string const & name) const
|
||||||
{
|
{
|
||||||
return find_if(begin(), end(),
|
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 "LString.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
class LyXLex;
|
class LyXLex;
|
||||||
class Buffer;
|
class Buffer;
|
||||||
|
class Menu;
|
||||||
|
|
||||||
///
|
///
|
||||||
class MenuItem {
|
class MenuItem {
|
||||||
@ -72,8 +74,10 @@ public:
|
|||||||
int action,
|
int action,
|
||||||
bool optional = false)
|
bool optional = false)
|
||||||
: kind_(kind), label_(label),
|
: 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
|
/// The label of a given menuitem
|
||||||
string const label() const;
|
string const label() const;
|
||||||
/// The keyboard shortcut (usually underlined in the entry)
|
/// The keyboard shortcut (usually underlined in the entry)
|
||||||
@ -85,10 +89,13 @@ public:
|
|||||||
/// the action (if relevant)
|
/// the action (if relevant)
|
||||||
int action() const { return action_; }
|
int action() const { return action_; }
|
||||||
/// the description of the submenu (if relevant)
|
/// 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
|
/// returns true if the entry should be ommited when disabled
|
||||||
bool optional() const { return optional_; }
|
bool optional() const { return optional_; }
|
||||||
|
///
|
||||||
|
Menu & submenu() const { return *submenu_.get(); }
|
||||||
private:
|
private:
|
||||||
|
friend class MenuBackend;
|
||||||
///
|
///
|
||||||
Kind kind_;
|
Kind kind_;
|
||||||
///
|
///
|
||||||
@ -96,9 +103,11 @@ private:
|
|||||||
///
|
///
|
||||||
int action_;
|
int action_;
|
||||||
///
|
///
|
||||||
string submenu_;
|
string submenuname_;
|
||||||
///
|
///
|
||||||
bool optional_;
|
bool optional_;
|
||||||
|
///
|
||||||
|
boost::shared_ptr<Menu> submenu_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -116,12 +125,6 @@ public:
|
|||||||
Menu & add(MenuItem const &);
|
Menu & add(MenuItem const &);
|
||||||
///
|
///
|
||||||
Menu & read(LyXLex &);
|
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_; }
|
string const & name() const { return name_; }
|
||||||
///
|
///
|
||||||
@ -173,6 +176,13 @@ public:
|
|||||||
Menu const & getMenubar() const;
|
Menu const & getMenubar() const;
|
||||||
///
|
///
|
||||||
bool empty() const { return menulist_.empty(); }
|
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 {
|
const_iterator begin() const {
|
||||||
return menulist_.begin();
|
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>
|
2002-07-22 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||||
|
|
||||||
* XMiniBuffer.h: add connection objects, and use them
|
* 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();
|
for (ButtonList::const_iterator cit = buttonlist_.begin();
|
||||||
cit != buttonlist_.end(); ++cit) {
|
cit != buttonlist_.end(); ++cit) {
|
||||||
if ((*cit)->item_->submenu() == name) {
|
if ((*cit)->item_->submenuname() == name) {
|
||||||
MenuCallback((*cit)->obj_, 1);
|
MenuCallback((*cit)->obj_, 1);
|
||||||
return;
|
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,
|
int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
||||||
string const & menu_name,
|
Menu const & menu, vector<int> & smn)
|
||||||
vector<int> & smn)
|
|
||||||
{
|
{
|
||||||
if (!menubackend_->hasMenu(menu_name)) {
|
int const menuid = get_new_submenu(smn, win);
|
||||||
lyxerr << "ERROR:create_submenu: Unknown menu `"
|
fl_setpup_softedge(menuid, true);
|
||||||
<< menu_name << "'" << endl;
|
fl_setpup_bw(menuid, -1);
|
||||||
return -1;
|
lyxerr[Debug::GUI] << "Adding menu " << menuid
|
||||||
}
|
|
||||||
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
|
|
||||||
<< " in deletion list" << endl;
|
<< " in deletion list" << endl;
|
||||||
|
|
||||||
// Compute the size of the largest label (because xforms is
|
// Compute the size of the largest label (because xforms is
|
||||||
// not able to support shortcuts correctly...)
|
// not able to support shortcuts correctly...)
|
||||||
int max_width = 0;
|
int max_width = 0;
|
||||||
string widest_label;
|
string widest_label;
|
||||||
Menu::const_iterator end = md.end();
|
Menu::const_iterator end = menu.end();
|
||||||
for (Menu::const_iterator i = md.begin(); i != end; ++i) {
|
for (Menu::const_iterator i = menu.begin(); i != end; ++i) {
|
||||||
MenuItem const & item = (*i);
|
MenuItem const & item = (*i);
|
||||||
if (item.kind() == MenuItem::Command) {
|
if (item.kind() == MenuItem::Command) {
|
||||||
string const label = item.label() + '\t';
|
string const label = item.label() + '\t';
|
||||||
@ -378,10 +369,10 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
|||||||
<< "'" << endl;
|
<< "'" << endl;
|
||||||
|
|
||||||
// Compute where to put separators
|
// 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 it = extra_labels.begin();
|
||||||
vector<string>::iterator last = it;
|
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)
|
if (i->kind() == MenuItem::Separator)
|
||||||
*last = "%l";
|
*last = "%l";
|
||||||
else if (!i->optional() ||
|
else if (!i->optional() ||
|
||||||
@ -389,7 +380,7 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
|||||||
last = it;
|
last = it;
|
||||||
|
|
||||||
it = extra_labels.begin();
|
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);
|
MenuItem const & item = (*i);
|
||||||
string & extra_label = *it;
|
string & extra_label = *it;
|
||||||
|
|
||||||
@ -439,10 +430,10 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
|||||||
if (!shortcut.empty()) {
|
if (!shortcut.empty()) {
|
||||||
shortcut += lowercase(shortcut[0]);
|
shortcut += lowercase(shortcut[0]);
|
||||||
label += "%h";
|
label += "%h";
|
||||||
fl_addtopup(menu, label.c_str(),
|
fl_addtopup(menuid, label.c_str(),
|
||||||
shortcut.c_str());
|
shortcut.c_str());
|
||||||
} else
|
} else
|
||||||
fl_addtopup(menu, label.c_str());
|
fl_addtopup(menuid, label.c_str());
|
||||||
|
|
||||||
lyxerr[Debug::GUI] << "Command: \""
|
lyxerr[Debug::GUI] << "Command: \""
|
||||||
<< lyxaction.getActionName(item.action())
|
<< lyxaction.getActionName(item.action())
|
||||||
@ -453,9 +444,9 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case MenuItem::Submenu: {
|
case MenuItem::Submenu: {
|
||||||
int submenu = create_submenu(win, view,
|
int submenuid = create_submenu(win, view,
|
||||||
item.submenu(), smn);
|
item.submenu(), smn);
|
||||||
if (submenu == -1)
|
if (submenuid == -1)
|
||||||
return -1;
|
return -1;
|
||||||
string label = item.label();
|
string label = item.label();
|
||||||
label += extra_label + "%m";
|
label += extra_label + "%m";
|
||||||
@ -463,10 +454,10 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
|||||||
if (!shortcut.empty()) {
|
if (!shortcut.empty()) {
|
||||||
shortcut += lowercase(shortcut[0]);
|
shortcut += lowercase(shortcut[0]);
|
||||||
label += "%h";
|
label += "%h";
|
||||||
fl_addtopup(menu, label.c_str(),
|
fl_addtopup(menuid, label.c_str(),
|
||||||
submenu, shortcut.c_str());
|
submenuid, shortcut.c_str());
|
||||||
} else {
|
} else {
|
||||||
fl_addtopup(menu, label.c_str(), submenu);
|
fl_addtopup(menuid, label.c_str(), submenuid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -477,7 +468,7 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MenuItem::Toc:
|
case MenuItem::Toc:
|
||||||
add_toc(menu, extra_label, smn, win);
|
add_toc(menuid, extra_label, smn, win);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MenuItem::Documents:
|
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
|
// set tabstop length
|
||||||
fl_set_tabstop(menu_tabstop);
|
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;
|
vector<int> submenus;
|
||||||
int menu = iteminfo->pimpl_->
|
int menu = iteminfo->pimpl_->
|
||||||
create_submenu(FL_ObjWin(ob), view,
|
create_submenu(FL_ObjWin(ob), view, tomenu, submenus);
|
||||||
item->submenu(), submenus);
|
|
||||||
if (menu != -1) {
|
if (menu != -1) {
|
||||||
// place popup
|
// place popup
|
||||||
fl_setpup_position(view->getForm()->x + ob->x,
|
fl_setpup_position(view->getForm()->x + ob->x,
|
||||||
|
@ -58,8 +58,7 @@ private:
|
|||||||
std::vector<int> & smn, Window win);
|
std::vector<int> & smn, Window win);
|
||||||
///
|
///
|
||||||
int create_submenu(Window win, XFormsView * view,
|
int create_submenu(Window win, XFormsView * view,
|
||||||
string const & menuname,
|
Menu const & menu, std::vector<int> & smn);
|
||||||
std::vector<int> & smn);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
void makeMenubar(Menu const &menu);
|
void makeMenubar(Menu const &menu);
|
||||||
|
Loading…
Reference in New Issue
Block a user