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
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-07-29 15:34:18 +00:00
|
|
|
#include <algorithm>
|
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"
|
2000-10-04 09:54:31 +00:00
|
|
|
#include "lastfiles.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"
|
2000-10-16 13:27:56 +00:00
|
|
|
#include "converter.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"
|
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"
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2000-10-04 09:54:31 +00:00
|
|
|
extern BufferList bufferlist;
|
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:
|
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-07-23 22:42:12 +00:00
|
|
|
MenuItem::~MenuItem()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
|
|
Menu & Menu::add(MenuItem const & i)
|
2000-07-24 13:53:19 +00:00
|
|
|
{
|
|
|
|
items_.push_back(i);
|
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,
|
|
|
|
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,
|
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,
|
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] = {
|
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 },
|
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
|
|
|
|
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();
|
2000-07-24 13:53:19 +00:00
|
|
|
add(MenuItem(MenuItem::Submenu, mlabel, mname));
|
|
|
|
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
|
|
|
|
// it is used for debugging only.
|
|
|
|
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 `"
|
|
|
|
<< shortcut << '\'' << endl;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
void expandLastfiles(Menu & tomenu)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
label, action));
|
|
|
|
}
|
|
|
|
}
|
2001-04-04 21:35:36 +00:00
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
void expandDocuments(Menu & tomenu)
|
|
|
|
{
|
|
|
|
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!"),
|
|
|
|
LFUN_NOACTION));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
string label = MakeDisplayPath(*docit, 30);
|
|
|
|
if (ii < 10)
|
|
|
|
label = tostr(ii) + ". " + label + '|' + tostr(ii);
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf)
|
2000-10-04 09:54:31 +00:00
|
|
|
{
|
2002-07-22 20:12:08 +00:00
|
|
|
if (!buf && kind != MenuItem::ImportFormats) {
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
_("No Documents Open!"), LFUN_NOACTION));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef vector<Format const *> Formats;
|
|
|
|
Formats formats;
|
|
|
|
kb_action action;
|
|
|
|
|
|
|
|
switch (kind) {
|
|
|
|
case MenuItem::ImportFormats:
|
|
|
|
formats = Importer::GetImportableFormats();
|
|
|
|
action = LFUN_IMPORT;
|
|
|
|
break;
|
|
|
|
case MenuItem::ViewFormats:
|
|
|
|
formats = Exporter::GetExportableFormats(buf, true);
|
|
|
|
action = LFUN_PREVIEW;
|
|
|
|
break;
|
|
|
|
case MenuItem::UpdateFormats:
|
|
|
|
formats = Exporter::GetExportableFormats(buf, true);
|
|
|
|
action = LFUN_UPDATE;
|
2000-10-04 09:54:31 +00:00
|
|
|
break;
|
2002-07-22 20:12:08 +00:00
|
|
|
default:
|
|
|
|
formats = Exporter::GetExportableFormats(buf, false);
|
|
|
|
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
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
if (kind == MenuItem::ImportFormats)
|
|
|
|
if ((*fit)->name() == "text")
|
|
|
|
label = _("Ascii text as lines");
|
|
|
|
else if ((*fit)->name() == "textparagraph")
|
|
|
|
label = _("Ascii text as paragraphs");
|
|
|
|
if (!(*fit)->shortcut().empty())
|
|
|
|
label += "|" + (*fit)->shortcut();
|
|
|
|
int const action2 = lyxaction.
|
|
|
|
getPseudoAction(action, (*fit)->name());
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action2));
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
void expandFloatListInsert(Menu & tomenu)
|
|
|
|
{
|
|
|
|
FloatList::const_iterator cit = floatList.begin();
|
|
|
|
FloatList::const_iterator end = floatList.end();
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
int const action = lyxaction
|
|
|
|
.getPseudoAction(LFUN_FLOAT_LIST, cit->second.type());
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
_(cit->second.listName()),
|
|
|
|
action));
|
|
|
|
}
|
|
|
|
}
|
2000-10-04 09:54:31 +00:00
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
|
2002-07-22 20:12:08 +00:00
|
|
|
void expandFloatInsert(Menu & tomenu)
|
|
|
|
{
|
|
|
|
FloatList::const_iterator cit = floatList.begin();
|
|
|
|
FloatList::const_iterator end = floatList.end();
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
// normal float
|
|
|
|
int const action =
|
|
|
|
lyxaction.getPseudoAction(LFUN_INSET_FLOAT,
|
|
|
|
cit->second.type());
|
|
|
|
string const label = _(cit->second.name());
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
|
|
|
|
Menu::size_type const max_number_of_items = 25;
|
|
|
|
|
|
|
|
void expandToc2(Menu & tomenu, toc::Toc const & toc_list,
|
|
|
|
toc::Toc::size_type from, toc::Toc::size_type to, int depth)
|
|
|
|
{
|
|
|
|
int shortcut_count = 0;
|
|
|
|
if (to - from <= max_number_of_items) {
|
|
|
|
for (toc::Toc::size_type i = from; i < to; ++i) {
|
|
|
|
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) {
|
|
|
|
label += "|" + tostr(shortcut_count);
|
|
|
|
}
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command, label, action));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
toc::Toc::size_type pos = from;
|
|
|
|
while (pos < to) {
|
|
|
|
toc::Toc::size_type new_pos = pos + 1;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void expandToc(Menu & tomenu, Buffer const * buf)
|
|
|
|
{
|
|
|
|
toc::TocList toc_list = toc::getTocList(buf);
|
|
|
|
toc::TocList::const_iterator cit = toc_list.begin();
|
|
|
|
toc::TocList::const_iterator end = toc_list.end();
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
// Handle this later
|
|
|
|
if (cit->first == "TOC") continue;
|
|
|
|
|
|
|
|
// All the rest is for floats
|
|
|
|
Menu * menu = new Menu;
|
|
|
|
toc::Toc::const_iterator ccit = cit->second.begin();
|
|
|
|
toc::Toc::const_iterator eend = cit->second.end();
|
|
|
|
for (; ccit != eend; ++ccit) {
|
|
|
|
string const label = limit_string_length(ccit->str);
|
|
|
|
menu->add(MenuItem(MenuItem::Command,
|
|
|
|
label, ccit->action()));
|
|
|
|
}
|
|
|
|
MenuItem item(MenuItem::Submenu,
|
|
|
|
floatList[cit->first]->second.name());
|
|
|
|
item.submenu(menu);
|
|
|
|
tomenu.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle normal TOC
|
|
|
|
cit = toc_list.find("TOC");
|
|
|
|
if (cit == end) {
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
_("No Table of contents")));
|
|
|
|
} else {
|
|
|
|
expandToc2(tomenu, cit->second, 0, cit->second.size(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
Buffer const * buf) 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()) {
|
|
|
|
case MenuItem::Lastfiles:
|
|
|
|
expandLastfiles(tomenu);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MenuItem::Documents:
|
|
|
|
expandDocuments(tomenu);
|
|
|
|
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:
|
|
|
|
expandFormats(cit->kind(), tomenu, buf);
|
|
|
|
break;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
case MenuItem::FloatListInsert:
|
2002-07-22 20:12:08 +00:00
|
|
|
expandFloatListInsert(tomenu);
|
|
|
|
break;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
case MenuItem::FloatInsert:
|
2002-07-22 20:12:08 +00:00
|
|
|
expandFloatInsert(tomenu);
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-07-24 22:32:03 +00:00
|
|
|
case MenuItem::Toc:
|
|
|
|
expandToc(tomenu, buf);
|
|
|
|
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()),
|
|
|
|
*item.submenu(), buf);
|
2002-07-23 22:42:12 +00:00
|
|
|
tomenu.add(item);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-10-04 09:54:31 +00:00
|
|
|
default:
|
|
|
|
tomenu.add(*cit);
|
|
|
|
}
|
|
|
|
}
|
2000-11-03 13:26:55 +00:00
|
|
|
|
|
|
|
// Check whether the shortcuts are unique
|
|
|
|
if (lyxerr.debugging(Debug::GUI))
|
2002-07-23 22:42:12 +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
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
void MenuBackend::defaults()
|
|
|
|
{
|
2000-07-24 21:49:58 +00:00
|
|
|
menulist_.clear();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
lyxerr[Debug::GUI] << "MenuBackend::defaults: using default values"
|
2000-07-24 13:53:19 +00:00
|
|
|
<< endl;
|
|
|
|
|
|
|
|
Menu file("file");
|
2000-07-24 21:49:58 +00:00
|
|
|
file
|
2000-07-26 09:09:31 +00:00
|
|
|
.add(MenuItem(MenuItem::Command, _("New...|N"), "buffer-new"))
|
2002-03-27 00:05:28 +00:00
|
|
|
.add(MenuItem(MenuItem::Command, _("Open...|O"), "file-open"))
|
2000-07-26 09:09:31 +00:00
|
|
|
.add(MenuItem(MenuItem::Submenu, _("Import|I"), "import"))
|
|
|
|
.add(MenuItem(MenuItem::Command, _("Quit|Q"), "lyx-quit"))
|
2000-07-24 21:49:58 +00:00
|
|
|
.add(MenuItem(MenuItem::Separator))
|
|
|
|
.add(MenuItem(MenuItem::Lastfiles));
|
2000-07-24 13:53:19 +00:00
|
|
|
add(file);
|
|
|
|
|
|
|
|
Menu import("import");
|
2000-07-24 21:49:58 +00:00
|
|
|
import
|
|
|
|
.add(MenuItem(MenuItem::Command,
|
2000-07-26 09:09:31 +00:00
|
|
|
_("LaTeX...|L"), "buffer-import latex"))
|
2000-07-24 21:49:58 +00:00
|
|
|
.add(MenuItem(MenuItem::Command,
|
2000-07-26 09:09:31 +00:00
|
|
|
_("LinuxDoc...|L"), "buffer-import linuxdoc"));
|
2000-07-24 13:53:19 +00:00
|
|
|
add(import);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
Menu edit("edit");
|
2000-07-24 21:49:58 +00:00
|
|
|
edit
|
2000-07-26 09:09:31 +00:00
|
|
|
.add(MenuItem(MenuItem::Command, _("Cut"), "cut"))
|
|
|
|
.add(MenuItem(MenuItem::Command, _("Copy"), "copy"))
|
|
|
|
.add(MenuItem(MenuItem::Command, _("Paste"), "paste"))
|
|
|
|
.add(MenuItem(MenuItem::Command, _("Emphasize"), "font-emph"));
|
2000-07-24 13:53:19 +00:00
|
|
|
add(edit);
|
|
|
|
|
|
|
|
Menu documents("documents");
|
|
|
|
documents.add(MenuItem(MenuItem::Documents));
|
|
|
|
add(documents);
|
|
|
|
|
2002-07-20 21:50:05 +00:00
|
|
|
menubar_.add(MenuItem(MenuItem::Submenu, _("File|F"), "file"))
|
2000-07-26 09:09:31 +00:00
|
|
|
.add(MenuItem(MenuItem::Submenu, _("Edit|E"), "edit"))
|
2000-07-26 07:09:53 +00:00
|
|
|
.add(MenuItem(MenuItem::Submenu,
|
2000-07-26 09:09:31 +00:00
|
|
|
_("Documents|D"), "documents"));
|
2002-07-20 21:50:05 +00:00
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
lyx::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));
|
|
|
|
lyx::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_;
|
|
|
|
}
|