2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#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"
|
|
|
|
#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"
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
|
|
extern LyXAction lyxaction;
|
2000-10-04 09:54:31 +00:00
|
|
|
extern LastFiles * lastfiles;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2000-07-25 10:46:18 +00:00
|
|
|
MenuItem::MenuItem(Kind kind, string const & label,
|
|
|
|
string const & command, bool optional)
|
|
|
|
: 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 `"
|
|
|
|
<< command << "' does not exist." << endl;
|
|
|
|
}
|
2000-07-25 10:46:18 +00:00
|
|
|
if (optional_)
|
|
|
|
lyxerr[Debug::GUI] << "Optional item "
|
|
|
|
<< command << endl;
|
2000-07-24 13:53:19 +00:00
|
|
|
break;
|
|
|
|
case Submenu:
|
|
|
|
submenu_ = command;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 },
|
2000-07-25 10:46:18 +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
|
|
|
|
|
|
|
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: {
|
|
|
|
lex.next();
|
2001-05-04 10:36:36 +00:00
|
|
|
string const name = _(lex.GetString());
|
2000-07-24 13:53:19 +00:00
|
|
|
lex.next();
|
2000-10-11 21:06:43 +00:00
|
|
|
string const command = lex.GetString();
|
2000-07-25 10:46:18 +00:00
|
|
|
add(MenuItem(MenuItem::Command, name,
|
|
|
|
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;
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_submenu: {
|
|
|
|
lex.next();
|
2000-10-11 21:06:43 +00:00
|
|
|
string mlabel = _(lex.GetString());
|
2000-07-24 13:53:19 +00:00
|
|
|
lex.next();
|
2000-07-24 21:49:58 +00:00
|
|
|
string 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:
|
|
|
|
lex.printError("menubar::read: "
|
|
|
|
"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) {
|
|
|
|
if (!compare_no_case(it2->shortcut(), shortcut)) {
|
|
|
|
lyxerr << "Menu warning: menu entries "
|
|
|
|
<< '"' << it1->fulllabel()
|
|
|
|
<< "\" and \"" << it2->fulllabel()
|
|
|
|
<< "\" share the same shortcut."
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
return *p1 < *p2;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-04-04 21:35:36 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
void Menu::expand(Menu & tomenu, Buffer * buf) const
|
2000-10-04 09:54:31 +00:00
|
|
|
{
|
|
|
|
for (const_iterator cit = begin();
|
|
|
|
cit != end() ; ++cit) {
|
|
|
|
switch ((*cit).kind()) {
|
|
|
|
case MenuItem::Lastfiles: {
|
|
|
|
int ii = 1;
|
2001-05-04 10:36:36 +00:00
|
|
|
LastFiles::const_iterator lfit = lastfiles->begin();
|
|
|
|
LastFiles::const_iterator end = lastfiles->end();
|
|
|
|
|
|
|
|
for (; lfit != end && ii < 10; ++lfit, ++ii) {
|
2001-04-04 21:35:36 +00:00
|
|
|
string const label = tostr(ii) + ". "
|
2000-10-04 09:54:31 +00:00
|
|
|
+ MakeDisplayPath((*lfit), 30)
|
|
|
|
+ '|' + tostr(ii);
|
2001-04-04 21:35:36 +00:00
|
|
|
int const action = lyxaction.
|
2000-10-04 09:54:31 +00:00
|
|
|
getPseudoAction(LFUN_FILE_OPEN,
|
|
|
|
(*lfit));
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
label, action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MenuItem::Documents: {
|
2001-05-04 10:36:36 +00:00
|
|
|
typedef vector<string> Strings;
|
|
|
|
|
|
|
|
Strings const names = bufferlist.getFileNames();
|
2000-10-04 09:54:31 +00:00
|
|
|
|
|
|
|
if (names.empty()) {
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
_("No Documents Open!"),
|
|
|
|
LFUN_NOACTION));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
Strings::const_iterator docit = names.begin();
|
|
|
|
Strings::const_iterator end = names.end();
|
|
|
|
for (; docit != end ; ++docit) {
|
|
|
|
int const action = lyxaction
|
|
|
|
.getPseudoAction(LFUN_SWITCHBUFFER,
|
|
|
|
*docit);
|
2001-04-04 21:35:36 +00:00
|
|
|
string const label =
|
|
|
|
MakeDisplayPath(*docit, 30);
|
2000-10-04 09:54:31 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
label, action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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:
|
|
|
|
case MenuItem::ExportFormats: {
|
2001-05-04 10:36:36 +00:00
|
|
|
typedef vector<Format const *> Formats;
|
|
|
|
|
|
|
|
Formats formats;
|
|
|
|
|
2000-10-04 09:54:31 +00:00
|
|
|
kb_action action;
|
2000-11-13 10:35:02 +00:00
|
|
|
switch ((*cit).kind()) {
|
|
|
|
case MenuItem::ImportFormats:
|
|
|
|
formats = Importer::GetImportableFormats();
|
|
|
|
action = LFUN_IMPORT;
|
|
|
|
break;
|
|
|
|
case MenuItem::ViewFormats:
|
|
|
|
formats = Exporter::GetExportableFormats(buf, true);
|
2000-10-04 09:54:31 +00:00
|
|
|
action = LFUN_PREVIEW;
|
2000-11-13 10:35:02 +00:00
|
|
|
break;
|
|
|
|
case MenuItem::UpdateFormats:
|
|
|
|
formats = Exporter::GetExportableFormats(buf, true);
|
2000-10-04 09:54:31 +00:00
|
|
|
action = LFUN_UPDATE;
|
2000-11-13 10:35:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
formats = Exporter::GetExportableFormats(buf, false);
|
2000-10-04 09:54:31 +00:00
|
|
|
action = LFUN_EXPORT;
|
|
|
|
}
|
2001-01-24 15:33:06 +00:00
|
|
|
sort(formats.begin(), formats.end(), compare_format());
|
2000-11-06 11:20:22 +00:00
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
Formats::const_iterator fit = formats.begin();
|
|
|
|
Formats::const_iterator end = formats.end();
|
|
|
|
|
|
|
|
for (; fit != end ; ++fit) {
|
2000-11-13 10:35:02 +00:00
|
|
|
if ((*fit)->dummy())
|
2000-11-06 11:20:22 +00:00
|
|
|
continue;
|
2000-11-13 10:35:02 +00:00
|
|
|
string label = (*fit)->prettyname();
|
|
|
|
if ((*cit).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();
|
2001-04-04 21:35:36 +00:00
|
|
|
int const action2 = lyxaction.
|
2001-05-04 10:36:36 +00:00
|
|
|
getPseudoAction(action,
|
|
|
|
(*fit)->name());
|
2000-11-06 11:20:22 +00:00
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
label, action2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
case MenuItem::FloatListInsert:
|
|
|
|
{
|
|
|
|
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());
|
2001-05-31 16:48:26 +00:00
|
|
|
string label = _("List of ");
|
2001-05-04 10:36:36 +00:00
|
|
|
label += cit->second.name();
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
label, action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MenuItem::FloatInsert:
|
|
|
|
{
|
|
|
|
FloatList::const_iterator cit = floatList.begin();
|
|
|
|
FloatList::const_iterator end = floatList.end();
|
|
|
|
for (; cit != end; ++cit) {
|
2001-05-31 16:48:26 +00:00
|
|
|
// normal float
|
2001-05-04 10:36:36 +00:00
|
|
|
int const action = lyxaction
|
|
|
|
.getPseudoAction(LFUN_INSET_FLOAT,
|
|
|
|
cit->second.type());
|
|
|
|
string const label = cit->second.name();
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
label, action));
|
2001-05-31 16:48:26 +00:00
|
|
|
|
|
|
|
// and the wide version
|
|
|
|
int const action2 = lyxaction
|
|
|
|
.getPseudoAction(LFUN_INSET_WIDE_FLOAT,
|
|
|
|
cit->second.type());
|
|
|
|
string const label2 = _("Wide ") + label;
|
|
|
|
tomenu.add(MenuItem(MenuItem::Command,
|
|
|
|
label2, action2));
|
2001-05-04 10:36:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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))
|
|
|
|
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(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::compare_memfun(&MenuItem::submenu, 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
|
|
|
|
if (compare_no_case(lex.GetString(), "menuset"))
|
|
|
|
lyxerr << "Menubackend::read: ERROR wrong token:`"
|
|
|
|
<< lex.GetString() << '\'' << endl;
|
|
|
|
|
|
|
|
lex.pushTable(menutags, md_last - 1);
|
|
|
|
if (lyxerr.debugging(Debug::PARSER))
|
|
|
|
lex.printTable(lyxerr);
|
|
|
|
|
|
|
|
bool quit = false;
|
2000-07-26 14:08:09 +00:00
|
|
|
bool menubar = false;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
|
|
while (lex.IsOK() && !quit) {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (lex.lex()) {
|
2000-07-26 14:08:09 +00:00
|
|
|
case md_menubar:
|
|
|
|
menubar = true;
|
|
|
|
// fallback to md_menu
|
2000-07-24 13:53:19 +00:00
|
|
|
case md_menu: {
|
|
|
|
lex.next();
|
|
|
|
string name = lex.GetString();
|
2000-07-26 14:08:09 +00:00
|
|
|
if (hasMenu(name)) {
|
|
|
|
if (getMenu(name).menubar() == menubar) {
|
|
|
|
getMenu(name).read(lex);
|
|
|
|
} else {
|
|
|
|
lex.printError("Cannot append to menu `$$Token' unless it is of the same type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Menu menu(name, menubar);
|
|
|
|
menu.read(lex);
|
|
|
|
add(menu);
|
|
|
|
}
|
|
|
|
menubar = false;
|
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
|
|
|
|
|
|
|
lyxerr[Debug::GUI] << "MenuBackend::defaults: using default values"
|
|
|
|
<< 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"))
|
|
|
|
.add(MenuItem(MenuItem::Command, _("Open...|O"), "buffer-open"))
|
|
|
|
.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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Menu main("main", true);
|
2000-07-24 21:49:58 +00:00
|
|
|
main
|
2000-07-26 09:09:31 +00:00
|
|
|
.add(MenuItem(MenuItem::Submenu, _("File|F"), "file"))
|
|
|
|
.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"));
|
2000-07-24 13:53:19 +00:00
|
|
|
add(main);
|
|
|
|
|
|
|
|
Menu main_nobuffer("main_nobuffer", true);
|
2000-07-26 09:09:31 +00:00
|
|
|
main_nobuffer.add(MenuItem(MenuItem::Submenu, _("File|F"), "file"));
|
2000-07-24 13:53:19 +00:00
|
|
|
add(main_nobuffer);
|
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
2000-11-04 10:00:12 +00:00
|
|
|
for (const_iterator cit = begin();
|
2000-07-24 13:53:19 +00:00
|
|
|
cit != end() ; ++cit)
|
|
|
|
lyxerr << "Menu name: " << cit->name()
|
|
|
|
<< ", Menubar: " << cit->menubar()
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|