2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file MenuBackend.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Asger Alstrup
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Dekel Tsur
|
|
|
|
|
* \author Martin Vermeer
|
2000-07-24 13:53:19 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
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"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
|
|
|
|
|
#include "BranchList.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferlist.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2000-07-24 13:53:19 +00:00
|
|
|
|
#include "debug.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "exporter.h"
|
|
|
|
|
#include "Floating.h"
|
|
|
|
|
#include "FloatList.h"
|
|
|
|
|
#include "format.h"
|
2000-07-26 07:09:53 +00:00
|
|
|
|
#include "gettext.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "importer.h"
|
2003-02-15 21:03:40 +00:00
|
|
|
|
#include "kbmap.h"
|
2006-04-05 22:56:18 +00:00
|
|
|
|
#include "session.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "LyXAction.h"
|
2001-12-18 10:47:06 +00:00
|
|
|
|
#include "lyx_main.h" // for lastfiles
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
#include "lyxlex.h"
|
2002-07-24 22:32:03 +00:00
|
|
|
|
#include "toc.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
|
2000-10-04 09:54:31 +00:00
|
|
|
|
#include "support/filetools.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2005-01-06 16:39:35 +00:00
|
|
|
|
#include "support/convert.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
|
|
2004-01-31 15:30:24 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include <algorithm>
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::compare_ascii_no_case;
|
|
|
|
|
using lyx::support::contains;
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using lyx::support::makeDisplayPath;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::token;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2004-01-31 15:30:24 +00:00
|
|
|
|
using boost::bind;
|
|
|
|
|
|
2003-11-03 17:47:28 +00:00
|
|
|
|
using std::auto_ptr;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
using std::endl;
|
2004-01-31 15:30:24 +00:00
|
|
|
|
using std::equal_to;
|
2000-10-12 15:17:42 +00:00
|
|
|
|
using std::find_if;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::max;
|
2000-10-16 13:27:56 +00:00
|
|
|
|
using std::sort;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::vector;
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
|
|
|
|
extern BufferList bufferlist;
|
|
|
|
|
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
|
|
|
|
|
|
2004-01-31 15:30:24 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class MenuNamesEqual : public std::unary_function<Menu, bool> {
|
|
|
|
|
public:
|
|
|
|
|
MenuNamesEqual(string const & name)
|
|
|
|
|
: name_(name) {}
|
|
|
|
|
bool operator()(Menu const & menu) const
|
|
|
|
|
{
|
|
|
|
|
return menu.name() == name_;
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
string name_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
// This is the global menu definition
|
|
|
|
|
MenuBackend menubackend;
|
|
|
|
|
|
|
|
|
|
|
2003-09-21 18:57:15 +00:00
|
|
|
|
MenuItem::MenuItem(Kind kind)
|
|
|
|
|
: kind_(kind), optional_(false)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
MenuItem::MenuItem(Kind kind, string const & label,
|
2003-09-21 18:57:15 +00:00
|
|
|
|
string const & submenu, bool optional)
|
|
|
|
|
: kind_(kind), label_(label),
|
|
|
|
|
submenuname_(submenu), optional_(optional)
|
2000-07-24 13:53:19 +00:00
|
|
|
|
{
|
2003-09-21 18:57:15 +00:00
|
|
|
|
BOOST_ASSERT(kind == Submenu);
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-12-20 17:23:17 +00:00
|
|
|
|
|
2003-09-21 18:57:15 +00:00
|
|
|
|
MenuItem::MenuItem(Kind kind, string const & label,
|
|
|
|
|
FuncRequest const & func, bool optional)
|
|
|
|
|
: kind_(kind), label_(label), func_(func), optional_(optional)
|
2004-11-08 10:54:29 +00:00
|
|
|
|
{
|
|
|
|
|
func_.origin = FuncRequest::UI;
|
|
|
|
|
}
|
2002-08-21 06:32:10 +00:00
|
|
|
|
|
|
|
|
|
|
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-09-21 18:57:15 +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
|
2004-07-02 10:03:22 +00:00
|
|
|
|
kb_keymap::Bindings bindings = toplevel_keymap->findbindings(func_);
|
2003-02-15 21:03:40 +00:00
|
|
|
|
|
2004-07-02 10:03:22 +00:00
|
|
|
|
if (bindings.size()) {
|
|
|
|
|
return bindings.begin()->print();
|
2003-09-21 23:00:47 +00:00
|
|
|
|
} else {
|
2003-10-09 13:33:19 +00:00
|
|
|
|
lyxerr[Debug::KBMAP]
|
2004-07-02 10:03:22 +00:00
|
|
|
|
<< "No binding for "
|
2003-10-09 13:33:19 +00:00
|
|
|
|
<< lyxaction.getActionName(func_.action)
|
|
|
|
|
<< '(' << func_.argument << ')' << endl;
|
2003-02-15 21:03:40 +00:00
|
|
|
|
return string();
|
2003-09-21 23:00:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
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()) {
|
2004-03-18 13:57:20 +00:00
|
|
|
|
|
|
|
|
|
case MenuItem::Command: {
|
2003-02-15 21:03:40 +00:00
|
|
|
|
FuncStatus status =
|
2003-09-21 18:57:15 +00:00
|
|
|
|
view->getLyXFunc().getStatus(i.func());
|
2003-02-15 21:03:40 +00:00
|
|
|
|
if (status.unknown()
|
2004-03-18 13:57:20 +00:00
|
|
|
|
|| (!status.enabled() && i.optional()))
|
2003-02-15 21:03:40 +00:00
|
|
|
|
break;
|
|
|
|
|
items_.push_back(i);
|
|
|
|
|
items_.back().status(status);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
|
|
|
|
|
|
case MenuItem::Submenu: {
|
2003-02-15 21:03:40 +00:00
|
|
|
|
if (i.submenu()) {
|
2004-03-18 13:57:20 +00:00
|
|
|
|
bool enabled = false;
|
2003-02-15 21:03:40 +00:00
|
|
|
|
for (const_iterator cit = i.submenu()->begin();
|
|
|
|
|
cit != i.submenu()->end(); ++cit) {
|
|
|
|
|
if ((cit->kind() == MenuItem::Command
|
|
|
|
|
|| cit->kind() == MenuItem::Submenu)
|
2004-03-18 13:57:20 +00:00
|
|
|
|
&& cit->status().enabled()) {
|
|
|
|
|
enabled = true;
|
2003-02-15 21:03:40 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (enabled || !i.optional()) {
|
2003-02-15 21:03:40 +00:00
|
|
|
|
items_.push_back(i);
|
2004-03-18 13:57:20 +00:00
|
|
|
|
items_.back().status().enabled(enabled);
|
2003-02-15 21:03:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
items_.push_back(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
|
case MenuItem::Separator:
|
|
|
|
|
if (!items_.empty()
|
|
|
|
|
&& items_.back().kind() != MenuItem::Separator)
|
|
|
|
|
items_.push_back(i);
|
|
|
|
|
break;
|
2004-03-18 13:57:20 +00:00
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
|
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,
|
2003-11-12 14:38:26 +00:00
|
|
|
|
md_charstyles,
|
2000-07-24 13:53:19 +00:00
|
|
|
|
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 },
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{ "charstyles", md_charstyles },
|
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();
|
2003-09-21 23:00:47 +00:00
|
|
|
|
FuncRequest func = lyxaction.lookupFunc(command);
|
|
|
|
|
add(MenuItem(MenuItem::Command, name, func, optional));
|
2000-07-25 10:46:18 +00:00
|
|
|
|
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
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
case md_charstyles:
|
|
|
|
|
add(MenuItem(MenuItem::CharStyles));
|
|
|
|
|
break;
|
|
|
|
|
|
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
|
|
|
|
|
2004-08-14 18:06:10 +00:00
|
|
|
|
MenuItem const & Menu::operator[](size_type i) const
|
|
|
|
|
{
|
|
|
|
|
return items_[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Menu::hasFunc(FuncRequest const & func) const
|
|
|
|
|
{
|
|
|
|
|
return find_if(begin(), end(),
|
|
|
|
|
bind(std::equal_to<FuncRequest>(),
|
|
|
|
|
bind(&MenuItem::func, _1),
|
|
|
|
|
func)) != end();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2004-08-14 18:06:10 +00:00
|
|
|
|
void MenuBackend::specialMenu(string const &name)
|
|
|
|
|
{
|
2004-10-05 10:11:42 +00:00
|
|
|
|
if (hasMenu(name))
|
2004-08-14 18:06:10 +00:00
|
|
|
|
specialmenu_ = &getMenu(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2006-04-05 22:56:18 +00:00
|
|
|
|
lyx::Session::LastFiles const & lf = LyX::cref().session().lastFiles();
|
|
|
|
|
lyx::Session::LastFiles::const_iterator lfit = lf.begin();
|
2003-10-14 21:30:23 +00:00
|
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
|
int ii = 1;
|
|
|
|
|
|
2006-04-05 22:56:18 +00:00
|
|
|
|
for (; lfit != lf.end() && ii < 10; ++lfit, ++ii) {
|
2005-01-06 15:40:49 +00:00
|
|
|
|
string const label = convert<string>(ii) + ". "
|
2006-04-08 22:31:11 +00:00
|
|
|
|
+ makeDisplayPath((*lfit), 30)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
+ '|' + convert<string>(ii);
|
2003-09-21 18:57:15 +00:00
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))), view);
|
2002-07-22 20:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-04 21:35:36 +00:00
|
|
|
|
|
2005-01-06 15:40:49 +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-09-21 18:57:15 +00:00
|
|
|
|
FuncRequest(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) {
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string label = makeDisplayPath(*docit, 20);
|
2002-07-22 20:12:08 +00:00
|
|
|
|
if (ii < 10)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
label = convert<string>(ii) + ". " + label + '|' + convert<string>(ii);
|
2006-05-05 20:23:12 +00:00
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BUFFER_SWITCH, *docit)), 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-09-21 18:57:15 +00:00
|
|
|
|
_("No Documents Open!"),
|
|
|
|
|
FuncRequest(LFUN_NOACTION)),
|
2003-02-15 21:03:40 +00:00
|
|
|
|
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();
|
2006-05-05 20:23:12 +00:00
|
|
|
|
action = LFUN_BUFFER_IMPORT;
|
2002-07-22 20:12:08 +00:00
|
|
|
|
break;
|
|
|
|
|
case MenuItem::ViewFormats:
|
2006-04-09 00:26:19 +00:00
|
|
|
|
formats = Exporter::getExportableFormats(*view->buffer(), true);
|
2006-05-05 20:23:12 +00:00
|
|
|
|
action = LFUN_BUFFER_VIEW;
|
2002-07-22 20:12:08 +00:00
|
|
|
|
break;
|
|
|
|
|
case MenuItem::UpdateFormats:
|
2006-04-09 00:26:19 +00:00
|
|
|
|
formats = Exporter::getExportableFormats(*view->buffer(), true);
|
2006-05-05 20:23:12 +00:00
|
|
|
|
action = LFUN_BUFFER_UPDATE;
|
2000-10-04 09:54:31 +00:00
|
|
|
|
break;
|
2002-07-22 20:12:08 +00:00
|
|
|
|
default:
|
2006-04-09 00:26:19 +00:00
|
|
|
|
formats = Exporter::getExportableFormats(*view->buffer(), false);
|
2006-05-05 20:23:12 +00:00
|
|
|
|
action = LFUN_BUFFER_EXPORT;
|
2002-07-22 20:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
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")
|
2005-05-21 13:26:13 +00:00
|
|
|
|
label = _("Plain Text as Lines");
|
2002-07-22 20:12:08 +00:00
|
|
|
|
else if ((*fit)->name() == "textparagraph")
|
2005-05-21 13:26:13 +00:00
|
|
|
|
label = _("Plain Text as Paragraphs");
|
2003-01-16 10:41:14 +00:00
|
|
|
|
label += "...";
|
2006-02-03 21:47:25 +00:00
|
|
|
|
} else if (kind == MenuItem::ExportFormats) {
|
|
|
|
|
// exporting to LyX does not make sense
|
|
|
|
|
// FIXME: Introduce noexport flag
|
|
|
|
|
if ((*fit)->name() == "lyx")
|
|
|
|
|
continue;
|
2003-01-16 10:41:14 +00:00
|
|
|
|
}
|
2002-07-22 20:12:08 +00:00
|
|
|
|
if (!(*fit)->shortcut().empty())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
label += '|' + (*fit)->shortcut();
|
2003-09-21 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label,
|
|
|
|
|
FuncRequest(action, (*fit)->name())),
|
2003-02-15 21:03:40 +00:00
|
|
|
|
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-09-21 18:57:15 +00:00
|
|
|
|
_("No Documents Open!"),
|
|
|
|
|
FuncRequest(LFUN_NOACTION)),
|
2003-02-15 21:03:40 +00:00
|
|
|
|
view);
|
2002-08-27 15:51:19 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
|
FloatList const & floats =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
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) {
|
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-09-21 18:57:15 +00:00
|
|
|
|
_(cit->second.listName()),
|
|
|
|
|
FuncRequest(LFUN_FLOAT_LIST,
|
|
|
|
|
cit->second.type())),
|
2003-02-15 21:03:40 +00:00
|
|
|
|
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-09-21 18:57:15 +00:00
|
|
|
|
_("No Documents Open!"),
|
|
|
|
|
FuncRequest(LFUN_NOACTION)),
|
2003-02-15 21:03:40 +00:00
|
|
|
|
view);
|
2002-08-27 15:51:19 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-15 21:03:40 +00:00
|
|
|
|
FloatList const & floats =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
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
|
|
|
|
|
string const label = _(cit->second.name());
|
2003-09-21 18:57:15 +00:00
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label,
|
2006-05-05 20:23:12 +00:00
|
|
|
|
FuncRequest(LFUN_FLOAT_INSERT,
|
2003-09-21 18:57:15 +00:00
|
|
|
|
cit->second.type())),
|
2003-02-15 21:03:40 +00:00
|
|
|
|
view);
|
2002-07-22 20:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
void expandCharStyleInsert(Menu & tomenu, LyXView const * view)
|
|
|
|
|
{
|
|
|
|
|
if (!view->buffer()) {
|
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
|
_("No Documents Open!"),
|
|
|
|
|
FuncRequest(LFUN_NOACTION)),
|
|
|
|
|
view);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-01-31 15:30:24 +00:00
|
|
|
|
CharStyles & charstyles =
|
2003-11-12 14:38:26 +00:00
|
|
|
|
view->buffer()->params().getLyXTextClass().charstyles();
|
|
|
|
|
CharStyles::iterator cit = charstyles.begin();
|
|
|
|
|
CharStyles::iterator end = charstyles.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
|
string const label = cit->name;
|
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label,
|
2006-05-05 20:23:12 +00:00
|
|
|
|
FuncRequest(LFUN_CHARSTYLE_INSERT,
|
2003-11-12 14:38:26 +00:00
|
|
|
|
cit->name)), view);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
2005-05-12 10:16:04 +00:00
|
|
|
|
|
|
|
|
|
// check whether depth is smaller than the smallest depth in toc.
|
|
|
|
|
int min_depth = 1000;
|
2005-06-09 09:58:08 +00:00
|
|
|
|
for (lyx::toc::Toc::size_type i = from; i < to; ++i)
|
2006-04-22 18:48:28 +00:00
|
|
|
|
min_depth = std::min(min_depth, toc_list[i].depth());
|
2005-05-12 10:16:04 +00:00
|
|
|
|
if (min_depth > depth)
|
|
|
|
|
depth = min_depth;
|
|
|
|
|
|
|
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
|
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) {
|
2006-04-22 18:48:28 +00:00
|
|
|
|
string label(4 * max(0, toc_list[i].depth() - depth),' ');
|
|
|
|
|
label += limit_string_length(toc_list[i].str());
|
|
|
|
|
if (toc_list[i].depth() == depth
|
2003-10-25 09:20:51 +00:00
|
|
|
|
&& shortcut_count < 9) {
|
2005-01-06 15:40:49 +00:00
|
|
|
|
if (label.find(convert<string>(shortcut_count + 1)) != string::npos)
|
|
|
|
|
label += '|' + convert<string>(++shortcut_count);
|
2002-07-24 22:32:03 +00:00
|
|
|
|
}
|
2003-09-21 18:57:15 +00:00
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label,
|
|
|
|
|
FuncRequest(toc_list[i].action())));
|
2002-07-24 22:32:03 +00:00
|
|
|
|
}
|
|
|
|
|
} 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 &&
|
2006-04-22 18:48:28 +00:00
|
|
|
|
toc_list[new_pos].depth() > depth)
|
2002-07-24 22:32:03 +00:00
|
|
|
|
++new_pos;
|
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
|
string label(4 * max(0, toc_list[pos].depth() - depth), ' ');
|
|
|
|
|
label += limit_string_length(toc_list[pos].str());
|
|
|
|
|
if (toc_list[pos].depth() == depth &&
|
2003-10-25 09:20:51 +00:00
|
|
|
|
shortcut_count < 9) {
|
2005-01-06 15:40:49 +00:00
|
|
|
|
if (label.find(convert<string>(shortcut_count + 1)) != string::npos)
|
|
|
|
|
label += '|' + convert<string>(++shortcut_count);
|
2003-10-25 09:20:51 +00:00
|
|
|
|
}
|
2002-07-24 22:32:03 +00:00
|
|
|
|
if (new_pos == pos + 1) {
|
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-09-21 18:57:15 +00:00
|
|
|
|
label, FuncRequest(toc_list[pos].action())));
|
2002-07-24 22:32:03 +00:00
|
|
|
|
} 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)
|
|
|
|
|
|
2005-07-28 14:36:16 +00:00
|
|
|
|
|
|
|
|
|
Buffer const * buf = view->buffer();
|
|
|
|
|
if (!buf) {
|
2002-09-10 11:50:13 +00:00
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-09-21 18:57:15 +00:00
|
|
|
|
_("No Documents Open!"),
|
|
|
|
|
FuncRequest(LFUN_NOACTION)),
|
2003-02-15 21:03:40 +00:00
|
|
|
|
view);
|
2002-09-10 11:50:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-28 14:36:16 +00:00
|
|
|
|
FloatList const & floatlist = buf->params().getLyXTextClass().floats();
|
2006-04-22 18:48:28 +00:00
|
|
|
|
lyx::toc::TocList const & toc_list = lyx::toc::getTocList(*buf);
|
2003-07-27 13:18:55 +00:00
|
|
|
|
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
|
2003-11-03 17:47:28 +00:00
|
|
|
|
auto_ptr<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) {
|
2006-04-22 18:48:28 +00:00
|
|
|
|
string const label = limit_string_length(ccit->str());
|
2002-07-24 22:32:03 +00:00
|
|
|
|
menu->add(MenuItem(MenuItem::Command,
|
2003-09-21 18:57:15 +00:00
|
|
|
|
label,
|
|
|
|
|
FuncRequest(ccit->action())));
|
2002-07-24 22:32:03 +00:00
|
|
|
|
}
|
2005-07-28 14:36:16 +00:00
|
|
|
|
string const & floatName = floatlist.getType(cit->first).listName();
|
2002-12-09 10:12:03 +00:00
|
|
|
|
MenuItem item(MenuItem::Submenu, _(floatName));
|
2003-11-03 17:47:28 +00:00
|
|
|
|
item.submenu(menu.release());
|
2002-07-24 22:32:03 +00:00
|
|
|
|
tomenu.add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle normal TOC
|
|
|
|
|
cit = toc_list.find("TOC");
|
|
|
|
|
if (cit == end) {
|
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
2003-09-21 23:00:47 +00:00
|
|
|
|
_("No Table of contents"),
|
|
|
|
|
FuncRequest()),
|
2003-02-15 21:03:40 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2003-08-18 12:27:49 +00:00
|
|
|
|
if (!view || !view->buffer())
|
|
|
|
|
return;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
vector<string> const sel =
|
|
|
|
|
lyx::cap::availableSelections(*view->buffer());
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
vector<string>::const_iterator cit = sel.begin();
|
|
|
|
|
vector<string>::const_iterator end = sel.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) {
|
2003-09-21 18:57:15 +00:00
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, *cit,
|
2005-01-06 15:40:49 +00:00
|
|
|
|
FuncRequest(LFUN_PASTE, convert<string>(index))));
|
2003-06-17 15:33:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
|
void expandBranches(Menu & tomenu, LyXView const * view)
|
|
|
|
|
{
|
2003-08-18 12:27:49 +00:00
|
|
|
|
if (!view || !view->buffer())
|
|
|
|
|
return;
|
|
|
|
|
|
2005-10-25 15:21:49 +00:00
|
|
|
|
BufferParams const & params = view->buffer()->getMasterBuffer()->params();
|
2003-08-17 11:28:23 +00:00
|
|
|
|
|
2005-10-25 15:21:49 +00:00
|
|
|
|
BranchList::const_iterator cit = params.branchlist().begin();
|
|
|
|
|
BranchList::const_iterator end = params.branchlist().end();
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
|
for (int ii = 1; cit != end; ++cit, ++ii) {
|
|
|
|
|
string label = cit->getBranch();
|
|
|
|
|
if (ii < 10)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
label = convert<string>(ii) + ". " + label + "|" + convert<string>(ii);
|
2003-09-21 18:57:15 +00:00
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label,
|
2006-05-05 20:23:12 +00:00
|
|
|
|
FuncRequest(LFUN_BRANCH_INSERT,
|
2003-09-21 18:57:15 +00:00
|
|
|
|
cit->getBranch())), view);
|
2003-08-17 11:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2006-03-15 15:07:20 +00:00
|
|
|
|
if (!tomenu.empty())
|
|
|
|
|
tomenu.clear();
|
|
|
|
|
|
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
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
case MenuItem::CharStyles:
|
|
|
|
|
expandCharStyleInsert(tomenu, view);
|
|
|
|
|
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
|
|
|
|
|
2004-08-14 18:06:10 +00:00
|
|
|
|
case MenuItem::Separator:
|
2003-02-15 21:03:40 +00:00
|
|
|
|
tomenu.add(*cit, view);
|
2004-08-14 18:06:10 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MenuItem::Command:
|
2004-10-05 10:11:42 +00:00
|
|
|
|
if (!specialmenu_
|
2004-08-14 18:06:10 +00:00
|
|
|
|
|| !specialmenu_->hasFunc(cit->func()))
|
|
|
|
|
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-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
|
|
|
|
{
|
2004-01-31 15:30:24 +00:00
|
|
|
|
return find_if(begin(), end(), MenuNamesEqual(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
|
|
|
|
{
|
2004-01-31 15:30:24 +00:00
|
|
|
|
const_iterator cit = find_if(begin(), end(), MenuNamesEqual(name));
|
2002-09-06 01:41:01 +00:00
|
|
|
|
if (cit == end())
|
|
|
|
|
lyxerr << "No submenu named " << name << endl;
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_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)
|
|
|
|
|
{
|
2004-01-31 15:30:24 +00:00
|
|
|
|
iterator it = find_if(begin(), end(), MenuNamesEqual(name));
|
|
|
|
|
if (it == end())
|
|
|
|
|
lyxerr << "No submenu named " << name << endl;
|
|
|
|
|
BOOST_ASSERT(it != 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_;
|
|
|
|
|
}
|