2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
2000-07-24 13:53:19 +00:00
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-04 10:36:36 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-07-24 13:53:19 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#include "MenuBackend.h"
|
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "LyXAction.h"
|
|
|
|
#include "debug.h"
|
2000-07-26 07:09:53 +00:00
|
|
|
#include "gettext.h"
|
2003-02-15 21:03:40 +00:00
|
|
|
#include "kbmap.h"
|
2000-10-04 09:54:31 +00:00
|
|
|
#include "lastfiles.h"
|
2003-02-15 21:03:40 +00:00
|
|
|
#include "lyxfunc.h"
|
2001-12-18 10:47:06 +00:00
|
|
|
#include "lyx_main.h" // for lastfiles
|
2000-10-04 09:54:31 +00:00
|
|
|
#include "bufferlist.h"
|
2002-08-27 15:51:19 +00:00
|
|
|
#include "buffer.h"
|
2003-02-28 09:49:49 +00:00
|
|
|
#include "format.h"
|
2000-10-04 09:54:31 +00:00
|
|
|
#include "exporter.h"
|
2000-11-13 10:35:02 +00:00
|
|
|
#include "importer.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
#include "FloatList.h"
|
2002-07-24 22:32:03 +00:00
|
|
|
#include "toc.h"
|
2003-06-17 15:33:49 +00:00
|
|
|
#include "CutAndPaste.h"
|
2003-02-15 21:03:40 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
#include "support/LAssert.h"
|
2000-10-04 09:54:31 +00:00
|
|
|
#include "support/filetools.h"
|
2000-10-11 21:06:43 +00:00
|
|
|
#include "support/lyxfunctional.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
#include "support/tostr.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2000-10-04 09:54:31 +00:00
|
|
|
extern BufferList bufferlist;
|
2003-02-15 21:03:40 +00:00
|
|
|
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
using std::endl;
|
2000-10-04 09:54:31 +00:00
|
|
|
using std::vector;
|
2002-07-25 02:23:13 +00:00
|
|
|
using std::max;
|
2000-10-04 09:54:31 +00:00
|
|
|
using std::pair;
|
2000-10-12 15:17:42 +00:00
|
|
|
using std::find_if;
|
2000-10-16 13:27:56 +00:00
|
|
|
using std::sort;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
|
|
// This is the global menu definition
|
|
|
|
MenuBackend menubackend;
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
MenuItem::MenuItem(Kind kind, string const & label,
|
|
|
|
string const & command, bool optional)
|
2000-07-25 10:46:18 +00:00
|
|
|
: kind_(kind), label_(label), optional_(optional)
|
2000-07-24 13:53:19 +00:00
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (kind) {
|
2000-07-24 13:53:19 +00:00
|
|
|
case Separator:
|
|
|
|
case Documents:
|
|
|
|
case Lastfiles:
|
2000-08-31 11:51:59 +00:00
|
|
|
case Toc:
|
2000-08-30 03:40:51 +00:00
|
|
|
case ViewFormats:
|
|
|
|
case UpdateFormats:
|
|
|
|
case ExportFormats:
|
2000-11-06 11:20:22 +00:00
|
|
|
case ImportFormats:
|
2001-05-04 10:36:36 +00:00
|
|
|
case FloatListInsert:
|
|
|
|
case FloatInsert:
|
2003-06-17 15:33:49 +00:00
|
|
|
case PasteRecent:
|
2003-08-17 11:28:23 +00:00
|
|
|
case Branches:
|
2000-07-24 13:53:19 +00:00
|
|
|
break;
|
|
|
|
case Command:
|
|
|
|
action_ = lyxaction.LookupFunc(command);
|
|
|
|
|
|
|
|
if (action_ == LFUN_UNKNOWN_ACTION) {
|
|
|
|
lyxerr << "MenuItem(): LyX command `"
|
2002-03-21 17:27:08 +00:00
|
|
|
<< command << "' does not exist." << endl;
|
2000-07-24 13:53:19 +00:00
|
|
|
}
|
2000-07-25 10:46:18 +00:00
|
|
|
if (optional_)
|
2002-03-21 17:27:08 +00:00
|
|
|
lyxerr[Debug::GUI] << "Optional item "
|
|
|
|
<< command << endl;
|
2000-07-24 13:53:19 +00:00
|
|
|
break;
|
|
|
|
case Submenu:
|
2002-07-23 22:42:12 +00:00
|
|
|
submenuname_ = command;
|
2000-07-24 13:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-20 17:23:17 +00:00
|
|
|
|
2002-08-21 07:22:45 +00:00
|
|
|
MenuItem::MenuItem(Kind kind, string const & label, int action, bool optional)
|
2002-08-21 06:32:10 +00:00
|
|
|
: kind_(kind), label_(label), action_(action), submenuname_(),
|
|
|
|
optional_(optional)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-07-23 22:42:12 +00:00
|
|
|
MenuItem::~MenuItem()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-08-21 06:39:45 +00:00
|
|
|
void MenuItem::submenu(Menu * menu)
|
|
|
|
{
|
|
|
|
submenu_.reset(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
string const MenuItem::label() const
|
|
|
|
{
|
|
|
|
return token(label_, '|', 0);
|
2001-07-29 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2001-12-20 17:23:17 +00:00
|
|
|
|
2001-07-29 17:39:01 +00:00
|
|
|
string const MenuItem::shortcut() const
|
2002-03-21 17:27:08 +00:00
|
|
|
{
|
|
|
|
return token(label_, '|', 1);
|
2001-07-29 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
string const MenuItem::binding() const
|
|
|
|
{
|
|
|
|
if (kind_ != Command)
|
|
|
|
return string();
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
// Get the keys bound to this action, but keep only the
|
|
|
|
// first one later
|
|
|
|
string bindings = toplevel_keymap->findbinding(action_);
|
|
|
|
|
|
|
|
if (!bindings.empty()) {
|
|
|
|
return bindings.substr(1, bindings.find(']') - 1);
|
|
|
|
} else
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
Menu & Menu::add(MenuItem const & i, LyXView const * view)
|
2000-07-24 13:53:19 +00:00
|
|
|
{
|
2003-02-15 21:03:40 +00:00
|
|
|
if (!view) {
|
|
|
|
items_.push_back(i);
|
|
|
|
return *this;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
switch (i.kind()) {
|
|
|
|
case MenuItem::Command:
|
|
|
|
{
|
|
|
|
FuncStatus status =
|
|
|
|
view->getLyXFunc().getStatus(i.action());
|
|
|
|
if (status.unknown()
|
|
|
|
|| (status.disabled() && i.optional()))
|
|
|
|
break;
|
|
|
|
items_.push_back(i);
|
|
|
|
items_.back().status(status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MenuItem::Submenu:
|
|
|
|
{
|
|
|
|
if (i.submenu()) {
|
|
|
|
bool disabled = true;
|
|
|
|
for (const_iterator cit = i.submenu()->begin();
|
|
|
|
cit != i.submenu()->end(); ++cit) {
|
|
|
|
if ((cit->kind() == MenuItem::Command
|
|
|
|
|| cit->kind() == MenuItem::Submenu)
|
|
|
|
&& !cit->status().disabled()) {
|
|
|
|
disabled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!disabled || !i.optional()) {
|
|
|
|
items_.push_back(i);
|
|
|
|
items_.back().status().disabled(disabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
items_.push_back(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MenuItem::Separator:
|
|
|
|
if (!items_.empty()
|
|
|
|
&& items_.back().kind() != MenuItem::Separator)
|
|
|
|
items_.push_back(i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
items_.push_back(i);
|
2003-03-04 09:27:27 +00:00
|
|
|
}
|
2003-02-15 21:03:40 +00:00
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
return *this;
|
2000-07-24 13:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 14:08:09 +00:00
|
|
|
Menu & Menu::read(LyXLex & lex)
|
2000-07-24 13:53:19 +00:00
|
|
|
{
|
|
|
|
enum Menutags {
|
|
|
|
md_item = 1,
|
2003-08-17 11:28:23 +00:00
|
|
|
md_branches,
|
2000-07-24 13:53:19 +00:00
|
|
|
md_documents,
|
|
|
|
md_endmenu,
|
2000-08-30 03:40:51 +00:00
|
|
|
md_exportformats,
|
2000-11-06 11:20:22 +00:00
|
|
|
md_importformats,
|
2000-07-24 13:53:19 +00:00
|
|
|
md_lastfiles,
|
2000-07-25 10:46:18 +00:00
|
|
|
md_optitem,
|
2003-02-15 21:03:40 +00:00
|
|
|
md_optsubmenu,
|
2000-07-24 13:53:19 +00:00
|
|
|
md_separator,
|
2000-08-31 11:51:59 +00:00
|
|
|
md_submenu,
|
|
|
|
md_toc,
|
2000-08-30 03:40:51 +00:00
|
|
|
md_updateformats,
|
|
|
|
md_viewformats,
|
2001-05-04 10:36:36 +00:00
|
|
|
md_floatlistinsert,
|
|
|
|
md_floatinsert,
|
2003-06-17 15:33:49 +00:00
|
|
|
md_pasterecent,
|
2000-07-24 13:53:19 +00:00
|
|
|
md_last
|
|
|
|
};
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
struct keyword_item menutags[md_last - 1] = {
|
2003-08-17 11:28:23 +00:00
|
|
|
{ "branches", md_branches },
|
2000-07-24 13:53:19 +00:00
|
|
|
{ "documents", md_documents },
|
|
|
|
{ "end", md_endmenu },
|
2000-08-30 03:40:51 +00:00
|
|
|
{ "exportformats", md_exportformats },
|
2001-05-04 10:36:36 +00:00
|
|
|
{ "floatinsert", md_floatinsert },
|
|
|
|
{ "floatlistinsert", md_floatlistinsert },
|
2000-11-06 11:20:22 +00:00
|
|
|
{ "importformats", md_importformats },
|
2000-07-24 13:53:19 +00:00
|
|
|
{ "item", md_item },
|
|
|
|
{ "lastfiles", md_lastfiles },
|
2002-03-21 17:27:08 +00:00
|
|
|
{ "optitem", md_optitem },
|
2003-02-15 21:03:40 +00:00
|
|
|
{ "optsubmenu", md_optsubmenu },
|
2003-06-17 15:33:49 +00:00
|
|
|
{ "pasterecent", md_pasterecent },
|
2000-07-24 13:53:19 +00:00
|
|
|
{ "separator", md_separator },
|
2000-08-30 03:40:51 +00:00
|
|
|
{ "submenu", md_submenu },
|
2000-08-31 11:51:59 +00:00
|
|
|
{ "toc", md_toc },
|
2000-08-30 03:40:51 +00:00
|
|
|
{ "updateformats", md_updateformats },
|
|
|
|
{ "viewformats", md_viewformats }
|
2000-07-24 13:53:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
lex.pushTable(menutags, md_last - 1);
|
|
|
|
if (lyxerr.debugging(Debug::PARSER))
|
|
|
|
lex.printTable(lyxerr);
|
|
|
|
|
|
|
|
bool quit = false;
|
2000-07-25 10:46:18 +00:00
|
|
|
bool optional = false;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
while (lex.isOK() && !quit) {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (lex.lex()) {
|
2000-07-25 10:46:18 +00:00
|
|
|
case md_optitem:
|
|
|
|
optional = true;
|
|
|
|
// fallback to md_item
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_item: {
|
2001-07-23 09:11:14 +00:00
|
|
|
lex.next(true);
|
2001-08-06 19:12:46 +00:00
|
|
|
string const name = _(lex.getString());
|
2001-07-23 09:11:14 +00:00
|
|
|
lex.next(true);
|
2001-08-06 19:12:46 +00:00
|
|
|
string const command = lex.getString();
|
2002-03-21 17:27:08 +00:00
|
|
|
add(MenuItem(MenuItem::Command, name,
|
2000-07-25 10:46:18 +00:00
|
|
|
command, optional));
|
|
|
|
optional = false;
|
2000-07-24 13:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-08-31 11:51:59 +00:00
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_separator:
|
|
|
|
add(MenuItem(MenuItem::Separator));
|
|
|
|
break;
|
2000-08-31 11:51:59 +00:00
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_lastfiles:
|
|
|
|
add(MenuItem(MenuItem::Lastfiles));
|
|
|
|
break;
|
2000-08-31 11:51:59 +00:00
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_documents:
|
|
|
|
add(MenuItem(MenuItem::Documents));
|
|
|
|
break;
|
2000-08-31 11:51:59 +00:00
|
|
|
|
|
|
|
case md_toc:
|
|
|
|
add(MenuItem(MenuItem::Toc));
|
|
|
|
break;
|
|
|
|
|
2000-08-30 03:40:51 +00:00
|
|
|
case md_viewformats:
|
|
|
|
add(MenuItem(MenuItem::ViewFormats));
|
|
|
|
break;
|
2000-08-31 11:51:59 +00:00
|
|
|
|
2000-08-30 03:40:51 +00:00
|
|
|
case md_updateformats:
|
|
|
|
add(MenuItem(MenuItem::UpdateFormats));
|
|
|
|
break;
|
2000-08-31 11:51:59 +00:00
|
|
|
|
2000-08-30 03:40:51 +00:00
|
|
|
case md_exportformats:
|
|
|
|
add(MenuItem(MenuItem::ExportFormats));
|
|
|
|
break;
|
2000-08-31 11:51:59 +00:00
|
|
|
|
2000-11-06 11:20:22 +00:00
|
|
|
case md_importformats:
|
|
|
|
add(MenuItem(MenuItem::ImportFormats));
|
|
|
|
break;
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
case md_floatlistinsert:
|
|
|
|
add(MenuItem(MenuItem::FloatListInsert));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case md_floatinsert:
|
|
|
|
add(MenuItem(MenuItem::FloatInsert));
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
case md_pasterecent:
|
|
|
|
add(MenuItem(MenuItem::PasteRecent));
|
|
|
|
break;
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
case md_branches:
|
|
|
|
add(MenuItem(MenuItem::Branches));
|
|
|
|
break;
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
case md_optsubmenu:
|
|
|
|
optional = true;
|
|
|
|
// fallback to md_submenu
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_submenu: {
|
2001-07-23 09:11:14 +00:00
|
|
|
lex.next(true);
|
2001-08-06 19:12:46 +00:00
|
|
|
string const mlabel = _(lex.getString());
|
2001-07-23 09:11:14 +00:00
|
|
|
lex.next(true);
|
2001-08-06 19:12:46 +00:00
|
|
|
string const mname = lex.getString();
|
2003-02-15 21:03:40 +00:00
|
|
|
add(MenuItem(MenuItem::Submenu, mlabel, mname,
|
|
|
|
optional));
|
|
|
|
optional = false;
|
2000-07-24 13:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-08-31 11:51:59 +00:00
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_endmenu:
|
|
|
|
quit = true;
|
|
|
|
break;
|
2000-08-31 11:51:59 +00:00
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
default:
|
2002-07-20 21:50:05 +00:00
|
|
|
lex.printError("Menu::read: "
|
2000-07-24 13:53:19 +00:00
|
|
|
"Unknown menu tag: `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lex.popTable();
|
2000-07-26 14:08:09 +00:00
|
|
|
return *this;
|
2000-07-24 13:53:19 +00:00
|
|
|
}
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
2000-11-03 13:26:55 +00:00
|
|
|
void Menu::checkShortcuts() const
|
|
|
|
{
|
|
|
|
// This is a quadratic algorithm, but we do not care because
|
2003-07-22 09:15:55 +00:00
|
|
|
// menus are short enough
|
2000-11-03 13:26:55 +00:00
|
|
|
for (const_iterator it1 = begin(); it1 != end(); ++it1) {
|
|
|
|
string shortcut = it1->shortcut();
|
|
|
|
if (shortcut.empty())
|
|
|
|
continue;
|
|
|
|
if (!contains(it1->label(), shortcut))
|
|
|
|
lyxerr << "Menu warning: menu entry \""
|
|
|
|
<< it1->label()
|
|
|
|
<< "\" does not contain shortcut `"
|
2003-07-22 09:15:55 +00:00
|
|
|
<< shortcut << "'." << endl;
|
2000-11-03 13:26:55 +00:00
|
|
|
for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
|
2002-07-16 21:17:10 +00:00
|
|
|
if (!compare_ascii_no_case(it2->shortcut(), shortcut)) {
|
2000-11-03 13:26:55 +00:00
|
|
|
lyxerr << "Menu warning: menu entries "
|
|
|
|
<< '"' << it1->fulllabel()
|
|
|
|
<< "\" and \"" << it2->fulllabel()
|
|
|
|
<< "\" share the same shortcut."
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-20 17:23:17 +00:00
|
|
|
|
2001-04-04 21:35:36 +00:00
|
|
|
namespace {
|
|
|
|
|
2001-01-24 15:33:06 +00:00
|
|
|
class compare_format {
|
|
|
|
public:
|
|
|
|
bool operator()(Format const * p1, Format const * p2) {
|
2002-03-21 17:27:08 +00:00
|
|
|
return *p1 < *p2;
|
2001-01-24 15:33:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
string const limit_string_length(string const & str)
|
|
|
|
{
|
|
|
|
string::size_type const max_item_length = 45;
|
|
|
|
|
|
|
|
if (str.size() > max_item_length)
|
|
|
|
return str.substr(0, max_item_length - 3) + "...";
|
|
|
|
else
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
void expandLastfiles(Menu & tomenu, LyXView const * view)
|
2002-07-22 20:12:08 +00:00
|
|
|
{
|
|
|
|
int ii = 1;
|
|
|
|
LastFiles::const_iterator lfit = lastfiles->begin();
|
|
|
|
LastFiles::const_iterator end = lastfiles->end();
|
|
|
|
|
|
|
|
for (; lfit != end && ii < 10; ++lfit, ++ii) {
|
|
|
|
string const label = tostr(ii) + ". "
|
|
|
|
+ MakeDisplayPath((*lfit), 30)
|
|
|
|
+ '|' + tostr(ii);
|
|
|
|
int const action = lyxaction.
|
|
|
|
getPseudoAction(LFUN_FILE_OPEN,
|
|
|
|
(*lfit));
|
2003-02-15 21:03:40 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action), view);
|
2002-07-22 20:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-04 21:35:36 +00:00
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
void expandDocuments(Menu & tomenu, LyXView const * view)
|
2002-07-22 20:12:08 +00:00
|
|
|
{
|
|
|
|
typedef vector<string> Strings;
|
|
|
|
Strings const names = bufferlist.getFileNames();
|
2001-04-04 21:35:36 +00:00
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
if (names.empty()) {
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"),
|
2003-02-15 21:03:40 +00:00
|
|
|
LFUN_NOACTION), view);
|
2002-07-22 20:12:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-08-21 07:30:57 +00:00
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
int ii = 1;
|
|
|
|
Strings::const_iterator docit = names.begin();
|
|
|
|
Strings::const_iterator end = names.end();
|
|
|
|
for (; docit != end; ++docit, ++ii) {
|
|
|
|
int const action =
|
|
|
|
lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *docit);
|
2003-04-15 01:06:13 +00:00
|
|
|
string label = MakeDisplayPath(*docit, 20);
|
2002-07-22 20:12:08 +00:00
|
|
|
if (ii < 10)
|
|
|
|
label = tostr(ii) + ". " + label + '|' + tostr(ii);
|
2003-02-15 21:03:40 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action), view);
|
2002-07-22 20:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
void expandFormats(MenuItem::Kind kind, Menu & tomenu, LyXView const * view)
|
2000-10-04 09:54:31 +00:00
|
|
|
{
|
2003-02-15 21:03:40 +00:00
|
|
|
if (!view->buffer() && kind != MenuItem::ImportFormats) {
|
2002-07-22 20:12:08 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-02-15 21:03:40 +00:00
|
|
|
_("No Documents Open!"), LFUN_NOACTION),
|
|
|
|
view);
|
2002-07-22 20:12:08 +00:00
|
|
|
return;
|
2002-08-21 07:30:57 +00:00
|
|
|
}
|
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
typedef vector<Format const *> Formats;
|
|
|
|
Formats formats;
|
|
|
|
kb_action action;
|
2002-08-21 07:30:57 +00:00
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
switch (kind) {
|
|
|
|
case MenuItem::ImportFormats:
|
|
|
|
formats = Importer::GetImportableFormats();
|
|
|
|
action = LFUN_IMPORT;
|
|
|
|
break;
|
|
|
|
case MenuItem::ViewFormats:
|
2003-02-15 21:03:40 +00:00
|
|
|
formats = Exporter::GetExportableFormats(view->buffer(), true);
|
2002-07-22 20:12:08 +00:00
|
|
|
action = LFUN_PREVIEW;
|
|
|
|
break;
|
|
|
|
case MenuItem::UpdateFormats:
|
2003-02-15 21:03:40 +00:00
|
|
|
formats = Exporter::GetExportableFormats(view->buffer(), true);
|
2002-07-22 20:12:08 +00:00
|
|
|
action = LFUN_UPDATE;
|
2000-10-04 09:54:31 +00:00
|
|
|
break;
|
2002-07-22 20:12:08 +00:00
|
|
|
default:
|
2003-02-15 21:03:40 +00:00
|
|
|
formats = Exporter::GetExportableFormats(view->buffer(), false);
|
2002-07-22 20:12:08 +00:00
|
|
|
action = LFUN_EXPORT;
|
|
|
|
}
|
|
|
|
sort(formats.begin(), formats.end(), compare_format());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
Formats::const_iterator fit = formats.begin();
|
|
|
|
Formats::const_iterator end = formats.end();
|
|
|
|
for (; fit != end ; ++fit) {
|
|
|
|
if ((*fit)->dummy())
|
|
|
|
continue;
|
|
|
|
string label = (*fit)->prettyname();
|
|
|
|
// we need to hide the default graphic export formats
|
|
|
|
// from the external menu, because we need them only
|
|
|
|
// for the internal lyx-view and external latex run
|
|
|
|
if (label == "EPS" || label == "XPM" || label == "PNG")
|
|
|
|
continue;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-01-16 10:41:14 +00:00
|
|
|
if (kind == MenuItem::ImportFormats) {
|
2002-07-22 20:12:08 +00:00
|
|
|
if ((*fit)->name() == "text")
|
2003-01-06 14:02:24 +00:00
|
|
|
label = _("ASCII text as lines");
|
2002-07-22 20:12:08 +00:00
|
|
|
else if ((*fit)->name() == "textparagraph")
|
2003-01-06 14:02:24 +00:00
|
|
|
label = _("ASCII text as paragraphs");
|
2003-01-16 10:41:14 +00:00
|
|
|
label += "...";
|
|
|
|
}
|
2002-07-22 20:12:08 +00:00
|
|
|
if (!(*fit)->shortcut().empty())
|
2002-11-27 10:30:28 +00:00
|
|
|
label += '|' + (*fit)->shortcut();
|
2002-07-22 20:12:08 +00:00
|
|
|
int const action2 = lyxaction.
|
|
|
|
getPseudoAction(action, (*fit)->name());
|
2003-02-15 21:03:40 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action2),
|
|
|
|
view);
|
2002-07-22 20:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
void expandFloatListInsert(Menu & tomenu, LyXView const * view)
|
2002-07-22 20:12:08 +00:00
|
|
|
{
|
2003-02-15 21:03:40 +00:00
|
|
|
if (!view->buffer()) {
|
2002-08-27 15:51:19 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-02-15 21:03:40 +00:00
|
|
|
_("No Documents Open!"), LFUN_NOACTION),
|
|
|
|
view);
|
2002-08-27 15:51:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
FloatList const & floats =
|
|
|
|
view->buffer()->params.getLyXTextClass().floats();
|
2002-08-27 15:51:19 +00:00
|
|
|
FloatList::const_iterator cit = floats.begin();
|
|
|
|
FloatList::const_iterator end = floats.end();
|
2002-07-22 20:12:08 +00:00
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
int const action = lyxaction
|
|
|
|
.getPseudoAction(LFUN_FLOAT_LIST, cit->second.type());
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-02-15 21:03:40 +00:00
|
|
|
_(cit->second.listName()), action),
|
|
|
|
view);
|
2002-07-22 20:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-04 09:54:31 +00:00
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
void expandFloatInsert(Menu & tomenu, LyXView const * view)
|
2002-07-22 20:12:08 +00:00
|
|
|
{
|
2003-02-15 21:03:40 +00:00
|
|
|
if (!view->buffer()) {
|
2002-08-27 15:51:19 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-02-15 21:03:40 +00:00
|
|
|
_("No Documents Open!"), LFUN_NOACTION),
|
|
|
|
view);
|
2002-08-27 15:51:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
FloatList const & floats =
|
|
|
|
view->buffer()->params.getLyXTextClass().floats();
|
2002-08-27 15:51:19 +00:00
|
|
|
FloatList::const_iterator cit = floats.begin();
|
|
|
|
FloatList::const_iterator end = floats.end();
|
2002-07-22 20:12:08 +00:00
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
// normal float
|
|
|
|
int const action =
|
|
|
|
lyxaction.getPseudoAction(LFUN_INSET_FLOAT,
|
|
|
|
cit->second.type());
|
|
|
|
string const label = _(cit->second.name());
|
2003-02-15 21:03:40 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action),
|
|
|
|
view);
|
2002-07-22 20:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
|
|
|
|
Menu::size_type const max_number_of_items = 25;
|
|
|
|
|
2003-07-27 13:18:55 +00:00
|
|
|
void expandToc2(Menu & tomenu,
|
|
|
|
lyx::toc::Toc const & toc_list,
|
|
|
|
lyx::toc::Toc::size_type from,
|
|
|
|
lyx::toc::Toc::size_type to, int depth)
|
2002-07-24 22:32:03 +00:00
|
|
|
{
|
|
|
|
int shortcut_count = 0;
|
|
|
|
if (to - from <= max_number_of_items) {
|
2003-07-27 13:18:55 +00:00
|
|
|
for (lyx::toc::Toc::size_type i = from; i < to; ++i) {
|
2002-07-24 22:32:03 +00:00
|
|
|
int const action = toc_list[i].action();
|
|
|
|
string label(4 * max(0, toc_list[i].depth - depth),' ');
|
|
|
|
label += limit_string_length(toc_list[i].str);
|
|
|
|
if (toc_list[i].depth == depth
|
|
|
|
&& ++shortcut_count <= 9) {
|
2002-11-27 10:30:28 +00:00
|
|
|
label += '|' + tostr(shortcut_count);
|
2002-07-24 22:32:03 +00:00
|
|
|
}
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action));
|
|
|
|
}
|
|
|
|
} else {
|
2003-07-27 13:18:55 +00:00
|
|
|
lyx::toc::Toc::size_type pos = from;
|
2002-07-24 22:32:03 +00:00
|
|
|
while (pos < to) {
|
2003-07-27 13:18:55 +00:00
|
|
|
lyx::toc::Toc::size_type new_pos = pos + 1;
|
2002-07-24 22:32:03 +00:00
|
|
|
while (new_pos < to &&
|
|
|
|
toc_list[new_pos].depth > depth)
|
|
|
|
++new_pos;
|
|
|
|
|
|
|
|
int const action = toc_list[pos].action();
|
|
|
|
string label(4 * max(0, toc_list[pos].depth - depth), ' ');
|
|
|
|
label += limit_string_length(toc_list[pos].str);
|
|
|
|
if (toc_list[pos].depth == depth &&
|
|
|
|
++shortcut_count <= 9)
|
|
|
|
label += '|' + tostr(shortcut_count);
|
|
|
|
|
|
|
|
if (new_pos == pos + 1) {
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
label, action));
|
|
|
|
} else {
|
|
|
|
MenuItem item(MenuItem::Submenu, label);
|
|
|
|
item.submenu(new Menu);
|
|
|
|
expandToc2(*item.submenu(),
|
|
|
|
toc_list, pos, new_pos, depth + 1);
|
|
|
|
tomenu.add(item);
|
|
|
|
}
|
|
|
|
pos = new_pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
void expandToc(Menu & tomenu, LyXView const * view)
|
2002-07-24 22:32:03 +00:00
|
|
|
{
|
2003-02-15 21:03:40 +00:00
|
|
|
// To make things very cleanly, we would have to pass view to
|
|
|
|
// all MenuItem constructors and to expandToc2. However, we
|
|
|
|
// know that all the entries in a TOC will be have status_ ==
|
|
|
|
// OK, so we avoid this unnecessary overhead (JMarc)
|
|
|
|
|
|
|
|
if (!view->buffer()) {
|
2002-09-10 11:50:13 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-02-15 21:03:40 +00:00
|
|
|
_("No Documents Open!"), LFUN_NOACTION),
|
|
|
|
view);
|
2002-09-10 11:50:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-27 13:18:55 +00:00
|
|
|
lyx::toc::TocList toc_list = lyx::toc::getTocList(view->buffer());
|
|
|
|
lyx::toc::TocList::const_iterator cit = toc_list.begin();
|
|
|
|
lyx::toc::TocList::const_iterator end = toc_list.end();
|
2002-07-24 22:32:03 +00:00
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
// Handle this later
|
2002-10-24 09:52:26 +00:00
|
|
|
if (cit->first == "TOC")
|
|
|
|
continue;
|
2002-07-24 22:32:03 +00:00
|
|
|
|
|
|
|
// All the rest is for floats
|
|
|
|
Menu * menu = new Menu;
|
2003-07-27 13:18:55 +00:00
|
|
|
lyx::toc::Toc::const_iterator ccit = cit->second.begin();
|
|
|
|
lyx::toc::Toc::const_iterator eend = cit->second.end();
|
2002-07-24 22:32:03 +00:00
|
|
|
for (; ccit != eend; ++ccit) {
|
|
|
|
string const label = limit_string_length(ccit->str);
|
|
|
|
menu->add(MenuItem(MenuItem::Command,
|
|
|
|
label, ccit->action()));
|
|
|
|
}
|
2002-12-09 10:12:03 +00:00
|
|
|
string const & floatName = cit->first;
|
|
|
|
// Is the _(...) really needed here? (Lgb)
|
|
|
|
MenuItem item(MenuItem::Submenu, _(floatName));
|
2002-07-24 22:32:03 +00:00
|
|
|
item.submenu(menu);
|
|
|
|
tomenu.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle normal TOC
|
|
|
|
cit = toc_list.find("TOC");
|
|
|
|
if (cit == end) {
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-02-15 21:03:40 +00:00
|
|
|
_("No Table of contents")),
|
|
|
|
view);
|
2002-07-24 22:32:03 +00:00
|
|
|
} else {
|
|
|
|
expandToc2(tomenu, cit->second, 0, cit->second.size(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
void expandPasteRecent(Menu & tomenu, LyXView const * view)
|
|
|
|
{
|
|
|
|
vector<string> const selL =
|
|
|
|
CutAndPaste::availableSelections(*view->buffer());
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
vector<string>::const_iterator cit = selL.begin();
|
|
|
|
vector<string>::const_iterator end = selL.end();
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
for (unsigned int index = 0; cit != end; ++cit, ++index) {
|
|
|
|
int const action = lyxaction.getPseudoAction(LFUN_PASTE,
|
|
|
|
tostr(index));
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, *cit, action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
void expandBranches(Menu & tomenu, LyXView const * view)
|
|
|
|
{
|
|
|
|
BufferParams const & params = view->buffer()->params;
|
|
|
|
|
|
|
|
std::list<Branch>::const_iterator cit = params.branchlist.begin();
|
|
|
|
std::list<Branch>::const_iterator end = params.branchlist.end();
|
|
|
|
|
|
|
|
for (int ii = 1; cit != end; ++cit, ++ii) {
|
|
|
|
string label = cit->getBranch();
|
|
|
|
int const action = lyxaction.
|
|
|
|
getPseudoAction(LFUN_INSERT_BRANCH,
|
|
|
|
(cit->getBranch()));
|
|
|
|
if (ii < 10)
|
|
|
|
label = tostr(ii) + ". " + label + "|" + tostr(ii);
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action), view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2002-07-23 22:42:12 +00:00
|
|
|
void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
|
2003-02-15 21:03:40 +00:00
|
|
|
LyXView const * view) const
|
2002-07-22 20:12:08 +00:00
|
|
|
{
|
2002-07-23 22:42:12 +00:00
|
|
|
for (Menu::const_iterator cit = frommenu.begin();
|
|
|
|
cit != frommenu.end() ; ++cit) {
|
2002-07-22 20:12:08 +00:00
|
|
|
switch (cit->kind()) {
|
2002-08-21 07:30:57 +00:00
|
|
|
case MenuItem::Lastfiles:
|
2003-02-15 21:03:40 +00:00
|
|
|
expandLastfiles(tomenu, view);
|
2002-07-22 20:12:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MenuItem::Documents:
|
2003-02-15 21:03:40 +00:00
|
|
|
expandDocuments(tomenu, view);
|
2002-07-22 20:12:08 +00:00
|
|
|
break;
|
2000-10-04 09:54:31 +00:00
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
case MenuItem::ImportFormats:
|
2000-10-04 09:54:31 +00:00
|
|
|
case MenuItem::ViewFormats:
|
|
|
|
case MenuItem::UpdateFormats:
|
2002-07-22 20:12:08 +00:00
|
|
|
case MenuItem::ExportFormats:
|
2003-02-15 21:03:40 +00:00
|
|
|
expandFormats(cit->kind(), tomenu, view);
|
2002-07-22 20:12:08 +00:00
|
|
|
break;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
case MenuItem::FloatListInsert:
|
2003-02-15 21:03:40 +00:00
|
|
|
expandFloatListInsert(tomenu, view);
|
2002-07-22 20:12:08 +00:00
|
|
|
break;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
case MenuItem::FloatInsert:
|
2003-02-15 21:03:40 +00:00
|
|
|
expandFloatInsert(tomenu, view);
|
2002-07-22 20:12:08 +00:00
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
case MenuItem::PasteRecent:
|
|
|
|
expandPasteRecent(tomenu, view);
|
|
|
|
break;
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
case MenuItem::Branches:
|
|
|
|
expandBranches(tomenu, view);
|
|
|
|
break;
|
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
case MenuItem::Toc:
|
2003-02-15 21:03:40 +00:00
|
|
|
expandToc(tomenu, view);
|
2002-07-24 22:32:03 +00:00
|
|
|
break;
|
|
|
|
|
2002-07-23 22:42:12 +00:00
|
|
|
case MenuItem::Submenu: {
|
|
|
|
MenuItem item(*cit);
|
2002-07-24 22:32:03 +00:00
|
|
|
item.submenu(new Menu(cit->submenuname()));
|
|
|
|
expand(getMenu(cit->submenuname()),
|
2003-02-15 21:03:40 +00:00
|
|
|
*item.submenu(), view);
|
|
|
|
tomenu.add(item, view);
|
2002-07-23 22:42:12 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-08-21 07:30:57 +00:00
|
|
|
|
2000-10-04 09:54:31 +00:00
|
|
|
default:
|
2003-02-15 21:03:40 +00:00
|
|
|
tomenu.add(*cit, view);
|
2000-10-04 09:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-03 13:26:55 +00:00
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
// we do not want the menu to end with a separator
|
|
|
|
if (!tomenu.empty()
|
|
|
|
&& tomenu.items_.back().kind() == MenuItem::Separator)
|
|
|
|
tomenu.items_.pop_back();
|
|
|
|
|
2000-11-03 13:26:55 +00:00
|
|
|
// Check whether the shortcuts are unique
|
2003-07-22 09:15:55 +00:00
|
|
|
tomenu.checkShortcuts();
|
2000-10-04 09:54:31 +00:00
|
|
|
}
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
2000-12-06 13:41:44 +00:00
|
|
|
bool Menu::hasSubmenu(string const & name) const
|
|
|
|
{
|
|
|
|
return find_if(begin(), end(),
|
2002-07-23 22:42:12 +00:00
|
|
|
lyx::compare_memfun(&MenuItem::submenuname,
|
|
|
|
name)) != end();
|
2000-12-06 13:41:44 +00:00
|
|
|
}
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
void MenuBackend::read(LyXLex & lex)
|
|
|
|
{
|
|
|
|
enum Menutags {
|
|
|
|
md_menu = 1,
|
|
|
|
md_menubar,
|
|
|
|
md_endmenuset,
|
|
|
|
md_last
|
|
|
|
};
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
struct keyword_item menutags[md_last - 1] = {
|
2000-07-24 13:53:19 +00:00
|
|
|
{ "end", md_endmenuset },
|
|
|
|
{ "menu", md_menu },
|
|
|
|
{ "menubar", md_menubar }
|
|
|
|
};
|
|
|
|
|
|
|
|
//consistency check
|
2002-07-16 21:17:10 +00:00
|
|
|
if (compare_ascii_no_case(lex.getString(), "menuset")) {
|
2000-07-24 13:53:19 +00:00
|
|
|
lyxerr << "Menubackend::read: ERROR wrong token:`"
|
2001-08-06 19:12:46 +00:00
|
|
|
<< lex.getString() << '\'' << endl;
|
|
|
|
}
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
|
|
lex.pushTable(menutags, md_last - 1);
|
|
|
|
if (lyxerr.debugging(Debug::PARSER))
|
|
|
|
lex.printTable(lyxerr);
|
|
|
|
|
|
|
|
bool quit = false;
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
while (lex.isOK() && !quit) {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (lex.lex()) {
|
2002-03-21 17:27:08 +00:00
|
|
|
case md_menubar:
|
2002-07-20 21:50:05 +00:00
|
|
|
menubar_.read(lex);
|
|
|
|
break;
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_menu: {
|
2001-07-23 09:11:14 +00:00
|
|
|
lex.next(true);
|
2001-08-06 19:12:46 +00:00
|
|
|
string const name = lex.getString();
|
2000-07-26 14:08:09 +00:00
|
|
|
if (hasMenu(name)) {
|
2002-07-20 21:50:05 +00:00
|
|
|
getMenu(name).read(lex);
|
2002-03-21 17:27:08 +00:00
|
|
|
} else {
|
2002-07-20 21:50:05 +00:00
|
|
|
Menu menu(name);
|
2000-07-26 14:08:09 +00:00
|
|
|
menu.read(lex);
|
|
|
|
add(menu);
|
|
|
|
}
|
2000-07-24 13:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case md_endmenuset:
|
|
|
|
quit = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lex.printError("menubackend::read: "
|
|
|
|
"Unknown menu tag: `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lex.popTable();
|
|
|
|
}
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
|
|
void MenuBackend::add(Menu const & menu)
|
2000-07-24 13:53:19 +00:00
|
|
|
{
|
|
|
|
menulist_.push_back(menu);
|
|
|
|
}
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
|
|
bool MenuBackend::hasMenu(string const & name) const
|
2000-07-24 13:53:19 +00:00
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
return find_if(begin(), end(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::compare_memfun(&Menu::name, name)) != end();
|
2000-07-24 13:53:19 +00:00
|
|
|
}
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
|
|
Menu const & MenuBackend::getMenu(string const & name) const
|
2000-07-24 13:53:19 +00:00
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
const_iterator cit = find_if(begin(), end(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::compare_memfun(&Menu::name, name));
|
2002-09-06 01:41:01 +00:00
|
|
|
if (cit == end())
|
|
|
|
lyxerr << "No submenu named " << name << endl;
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(cit != end());
|
2000-10-11 21:06:43 +00:00
|
|
|
return (*cit);
|
2000-07-24 13:53:19 +00:00
|
|
|
}
|
2000-07-26 14:08:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
Menu & MenuBackend::getMenu(string const & name)
|
|
|
|
{
|
2001-04-24 15:25:26 +00:00
|
|
|
MenuList::iterator it =
|
|
|
|
find_if(menulist_.begin(), menulist_.end(),
|
|
|
|
lyx::compare_memfun(&Menu::name, name));
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(it != menulist_.end());
|
2000-10-11 21:06:43 +00:00
|
|
|
return (*it);
|
2000-07-26 14:08:09 +00:00
|
|
|
}
|
2002-07-20 21:50:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
Menu const & MenuBackend::getMenubar() const
|
|
|
|
{
|
|
|
|
return menubar_;
|
|
|
|
}
|