2003-04-02 18:08:05 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file ToolbarBackend.cpp
|
2003-04-02 18:08:05 +00:00
|
|
|
* 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 Jean-Marc Lasgouttes
|
|
|
|
* \author John Levon
|
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.
|
2003-04-02 18:08:05 +00:00
|
|
|
*/
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2003-04-02 18:08:05 +00:00
|
|
|
#include "ToolbarBackend.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2000-07-19 12:30:49 +00:00
|
|
|
#include "debug.h"
|
2003-04-08 19:17:00 +00:00
|
|
|
#include "gettext.h"
|
2007-04-19 19:43:15 +00:00
|
|
|
#include "LyXAction.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-04-08 19:17:00 +00:00
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
#include <boost/bind.hpp>
|
2007-04-19 21:26:38 +00:00
|
|
|
#include <algorithm>
|
2000-03-12 10:36:28 +00:00
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
#include "frontends/controllers/ControlMath.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using support::compare_ascii_no_case;
|
|
|
|
using support::getVectorFromString;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2003-05-13 16:24:49 +00:00
|
|
|
using std::make_pair;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
using std::vector;
|
2007-04-19 19:43:15 +00:00
|
|
|
using std::find_if;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
|
|
|
2001-11-09 13:44:48 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
class ToolbarNamesEqual : public std::unary_function<ToolbarInfo, bool> {
|
|
|
|
public:
|
|
|
|
ToolbarNamesEqual(string const & name)
|
|
|
|
: name_(name) {}
|
2007-04-21 17:38:43 +00:00
|
|
|
bool operator()(ToolbarInfo const & tbinfo) const
|
2007-04-19 19:43:15 +00:00
|
|
|
{
|
2007-04-21 17:38:43 +00:00
|
|
|
return tbinfo.name == name_;
|
2007-04-19 19:43:15 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
string name_;
|
2001-11-09 13:44:48 +00:00
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace anon
|
2001-11-09 13:44:48 +00:00
|
|
|
|
2000-11-21 15:46:13 +00:00
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
ToolbarBackend toolbarbackend;
|
|
|
|
|
|
|
|
|
|
|
|
ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & label)
|
|
|
|
: type_(type), func_(func), label_(label)
|
2000-03-12 10:36:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
|
2007-08-31 10:31:19 +00:00
|
|
|
: type_(type), label_(label), name_(name)
|
2000-03-12 10:36:28 +00:00
|
|
|
{
|
2007-04-19 19:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ToolbarItem::~ToolbarItem()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void ToolbarInfo::add(ToolbarItem const & item)
|
|
|
|
{
|
|
|
|
items.push_back(item);
|
|
|
|
items.back().func_.origin = FuncRequest::TOOLBAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
ToolbarInfo & ToolbarInfo::read(Lexer & lex)
|
2007-04-19 19:43:15 +00:00
|
|
|
{
|
|
|
|
enum tooltags {
|
|
|
|
TO_COMMAND = 1,
|
|
|
|
TO_ENDTOOLBAR,
|
|
|
|
TO_SEPARATOR,
|
|
|
|
TO_LAYOUTS,
|
|
|
|
TO_MINIBUFFER,
|
|
|
|
TO_TABLEINSERT,
|
2007-04-19 20:29:27 +00:00
|
|
|
TO_POPUPMENU,
|
|
|
|
TO_ICONPALETTE,
|
2007-04-19 19:43:15 +00:00
|
|
|
TO_LAST
|
|
|
|
};
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
struct keyword_item toolTags[TO_LAST - 1] = {
|
|
|
|
{ "end", TO_ENDTOOLBAR },
|
2007-04-19 20:29:27 +00:00
|
|
|
{ "iconpalette", TO_ICONPALETTE },
|
2007-04-19 19:43:15 +00:00
|
|
|
{ "item", TO_COMMAND },
|
|
|
|
{ "layouts", TO_LAYOUTS },
|
|
|
|
{ "minibuffer", TO_MINIBUFFER },
|
2007-04-19 20:29:27 +00:00
|
|
|
{ "popupmenu", TO_POPUPMENU },
|
2007-04-19 19:43:15 +00:00
|
|
|
{ "separator", TO_SEPARATOR },
|
|
|
|
{ "tableinsert", TO_TABLEINSERT }
|
|
|
|
};
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
//consistency check
|
2002-07-16 21:17:10 +00:00
|
|
|
if (compare_ascii_no_case(lex.getString(), "toolbar")) {
|
2007-04-19 19:43:15 +00:00
|
|
|
lyxerr << "ToolbarInfo::read: ERROR wrong token:`"
|
2001-08-06 19:12:46 +00:00
|
|
|
<< lex.getString() << '\'' << endl;
|
|
|
|
}
|
2000-03-12 10:36:28 +00:00
|
|
|
|
2003-04-09 19:53:10 +00:00
|
|
|
lex.next(true);
|
2007-04-19 19:43:15 +00:00
|
|
|
name = lex.getString();
|
2003-04-09 19:53:10 +00:00
|
|
|
|
2004-04-21 00:19:27 +00:00
|
|
|
lex.next(true);
|
2007-04-19 19:43:15 +00:00
|
|
|
gui_name = lex.getString();
|
|
|
|
|
|
|
|
// FIXME what to do here?
|
2007-03-26 13:43:49 +00:00
|
|
|
if (!lex) {
|
2007-04-19 19:43:15 +00:00
|
|
|
lyxerr << "ToolbarInfo::read: Malformed toolbar "
|
2004-04-21 00:19:27 +00:00
|
|
|
"description " << lex.getString() << endl;
|
2007-04-19 19:43:15 +00:00
|
|
|
return *this;
|
2004-04-21 00:19:27 +00:00
|
|
|
}
|
2003-06-17 15:33:49 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
bool quit = false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
lex.pushTable(toolTags, TO_LAST - 1);
|
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::PARSER))
|
|
|
|
lex.printTable(lyxerr);
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
while (lex.isOK() && !quit) {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (lex.lex()) {
|
2007-04-19 19:43:15 +00:00
|
|
|
case TO_COMMAND:
|
2001-07-23 09:11:14 +00:00
|
|
|
if (lex.next(true)) {
|
2006-11-23 16:31:48 +00:00
|
|
|
docstring const tooltip = translateIfPossible(lex.getDocString());
|
2003-04-08 19:17:00 +00:00
|
|
|
lex.next(true);
|
2003-09-21 18:57:15 +00:00
|
|
|
string const func_arg = lex.getString();
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::PARSER)
|
2007-04-19 19:43:15 +00:00
|
|
|
<< "ToolbarInfo::read TO_COMMAND func: `"
|
2003-09-21 18:57:15 +00:00
|
|
|
<< func_arg << '\'' << endl;
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
FuncRequest func =
|
|
|
|
lyxaction.lookupFunc(func_arg);
|
2007-04-19 19:43:15 +00:00
|
|
|
add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
|
2000-03-12 10:36:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-04-15 01:06:13 +00:00
|
|
|
case TO_MINIBUFFER:
|
2007-04-19 19:43:15 +00:00
|
|
|
add(ToolbarItem(ToolbarItem::MINIBUFFER,
|
|
|
|
FuncRequest(kb_action(ToolbarItem::MINIBUFFER))));
|
2003-04-15 01:06:13 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
case TO_SEPARATOR:
|
2007-04-19 19:43:15 +00:00
|
|
|
add(ToolbarItem(ToolbarItem::SEPARATOR,
|
|
|
|
FuncRequest(kb_action(ToolbarItem::SEPARATOR))));
|
2000-03-12 10:36:28 +00:00
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2007-04-19 20:29:27 +00:00
|
|
|
case TO_POPUPMENU:
|
|
|
|
if (lex.next(true)) {
|
|
|
|
string const name = lex.getString();
|
|
|
|
lex.next(true);
|
|
|
|
docstring const label = lex.getDocString();
|
|
|
|
add(ToolbarItem(ToolbarItem::POPUPMENU, name, label));
|
|
|
|
}
|
|
|
|
break;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-04-19 20:29:27 +00:00
|
|
|
case TO_ICONPALETTE:
|
|
|
|
if (lex.next(true)) {
|
|
|
|
string const name = lex.getString();
|
|
|
|
lex.next(true);
|
|
|
|
docstring const label = lex.getDocString();
|
|
|
|
add(ToolbarItem(ToolbarItem::ICONPALETTE, name, label));
|
|
|
|
}
|
|
|
|
break;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
case TO_LAYOUTS:
|
2007-04-19 19:43:15 +00:00
|
|
|
add(ToolbarItem(ToolbarItem::LAYOUTS,
|
|
|
|
FuncRequest(kb_action(ToolbarItem::LAYOUTS))));
|
2000-03-12 10:36:28 +00:00
|
|
|
break;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
case TO_TABLEINSERT:
|
2007-05-06 07:26:51 +00:00
|
|
|
if (lex.next(true)) {
|
|
|
|
docstring const tooltip = lex.getDocString();
|
|
|
|
add(ToolbarItem(ToolbarItem::TABLEINSERT,
|
|
|
|
FuncRequest(kb_action(ToolbarItem::TABLEINSERT)), tooltip));
|
|
|
|
}
|
2007-04-19 19:43:15 +00:00
|
|
|
break;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
case TO_ENDTOOLBAR:
|
|
|
|
quit = true;
|
|
|
|
break;
|
2007-04-19 19:43:15 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
default:
|
2007-04-19 19:43:15 +00:00
|
|
|
lex.printError("ToolbarInfo::read: "
|
2000-03-12 10:36:28 +00:00
|
|
|
"Unknown toolbar tag: `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-04-09 19:53:10 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
lex.popTable();
|
2007-04-19 19:43:15 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ToolbarBackend::ToolbarBackend()
|
|
|
|
{
|
2000-03-12 10:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void ToolbarBackend::readToolbars(Lexer & lex)
|
2007-04-19 19:43:15 +00:00
|
|
|
{
|
|
|
|
enum tooltags {
|
|
|
|
TO_TOOLBAR = 1,
|
|
|
|
TO_ENDTOOLBARSET,
|
|
|
|
TO_LAST
|
|
|
|
};
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
struct keyword_item toolTags[TO_LAST - 1] = {
|
|
|
|
{ "end", TO_ENDTOOLBARSET },
|
|
|
|
{ "toolbar", TO_TOOLBAR }
|
|
|
|
};
|
|
|
|
|
|
|
|
//consistency check
|
|
|
|
if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
|
|
|
|
lyxerr << "ToolbarBackend::readToolbars: ERROR wrong token:`"
|
|
|
|
<< lex.getString() << '\'' << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
lex.pushTable(toolTags, TO_LAST - 1);
|
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::PARSER))
|
|
|
|
lex.printTable(lyxerr);
|
|
|
|
|
|
|
|
bool quit = false;
|
|
|
|
while (lex.isOK() && !quit) {
|
|
|
|
switch (lex.lex()) {
|
|
|
|
case TO_TOOLBAR: {
|
2007-04-21 17:38:43 +00:00
|
|
|
ToolbarInfo tbinfo;
|
|
|
|
tbinfo.read(lex);
|
|
|
|
toolbars.push_back(tbinfo);
|
2007-04-19 19:43:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TO_ENDTOOLBARSET:
|
|
|
|
quit = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lex.printError("ToolbarBackend::readToolbars: "
|
|
|
|
"Unknown toolbar tag: `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lex.popTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void ToolbarBackend::readToolbarSettings(Lexer & lex)
|
2003-06-11 19:21:46 +00:00
|
|
|
{
|
|
|
|
//consistency check
|
|
|
|
if (compare_ascii_no_case(lex.getString(), "toolbars")) {
|
2007-04-19 19:43:15 +00:00
|
|
|
lyxerr << "ToolbarBackend::readToolbarSettings: ERROR wrong token:`"
|
2003-06-11 19:21:46 +00:00
|
|
|
<< lex.getString() << '\'' << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
lex.next(true);
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
string name = lex.getString();
|
|
|
|
lex.next(true);
|
|
|
|
|
|
|
|
if (!compare_ascii_no_case(name, "end"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Toolbars::iterator tcit = toolbars.begin();
|
|
|
|
Toolbars::iterator tend = toolbars.end();
|
|
|
|
for (; tcit != tend; ++tcit) {
|
2004-04-21 12:14:14 +00:00
|
|
|
if (tcit->name == name)
|
2003-06-11 19:21:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tcit == tend) {
|
|
|
|
lyxerr << "ToolbarBackend: undefined toolbar "
|
|
|
|
<< name << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
tcit->flags = static_cast<ToolbarInfo::Flags>(0);
|
2003-06-11 19:21:46 +00:00
|
|
|
string flagstr = lex.getString();
|
|
|
|
lex.next(true);
|
|
|
|
vector<string> flags = getVectorFromString(flagstr);
|
|
|
|
|
|
|
|
vector<string>::const_iterator cit = flags.begin();
|
|
|
|
vector<string>::const_iterator end = flags.end();
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
int flag = 0;
|
|
|
|
if (!compare_ascii_no_case(*cit, "off"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::OFF;
|
2003-06-11 19:21:46 +00:00
|
|
|
else if (!compare_ascii_no_case(*cit, "on"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::ON;
|
2003-06-11 19:21:46 +00:00
|
|
|
else if (!compare_ascii_no_case(*cit, "math"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::MATH;
|
2003-06-11 19:21:46 +00:00
|
|
|
else if (!compare_ascii_no_case(*cit, "table"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::TABLE;
|
2006-10-29 11:13:46 +00:00
|
|
|
else if (!compare_ascii_no_case(*cit, "review"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::REVIEW;
|
2003-06-11 19:21:46 +00:00
|
|
|
else if (!compare_ascii_no_case(*cit, "top"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::TOP;
|
2003-06-11 19:21:46 +00:00
|
|
|
else if (!compare_ascii_no_case(*cit, "bottom"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::BOTTOM;
|
2003-06-11 19:21:46 +00:00
|
|
|
else if (!compare_ascii_no_case(*cit, "left"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::LEFT;
|
2003-06-11 19:21:46 +00:00
|
|
|
else if (!compare_ascii_no_case(*cit, "right"))
|
2007-04-19 19:43:15 +00:00
|
|
|
flag = ToolbarInfo::RIGHT;
|
2003-06-11 19:21:46 +00:00
|
|
|
else {
|
2007-04-19 19:43:15 +00:00
|
|
|
lyxerr << "ToolbarBackend::readToolbarSettings: unrecognised token:`"
|
2003-06-11 19:21:46 +00:00
|
|
|
<< *cit << '\'' << endl;
|
|
|
|
}
|
2007-04-19 19:43:15 +00:00
|
|
|
tcit->flags = static_cast<ToolbarInfo::Flags>(tcit->flags | flag);
|
2003-06-11 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usedtoolbars.push_back(*tcit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-09 20:33:32 +00:00
|
|
|
ToolbarInfo const * ToolbarBackend::getDefinedToolbarInfo(string const & name) const
|
2000-03-12 10:36:28 +00:00
|
|
|
{
|
2007-07-09 20:33:32 +00:00
|
|
|
Toolbars::const_iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name));
|
|
|
|
if (it == toolbars.end())
|
|
|
|
return 0;
|
|
|
|
return &(*it);
|
2000-03-12 10:36:28 +00:00
|
|
|
}
|
2003-04-08 19:17:00 +00:00
|
|
|
|
|
|
|
|
2007-07-09 20:33:32 +00:00
|
|
|
ToolbarInfo * ToolbarBackend::getUsedToolbarInfo(string const &name)
|
2003-04-08 19:17:00 +00:00
|
|
|
{
|
2007-07-09 20:33:32 +00:00
|
|
|
Toolbars::iterator it = find_if(usedtoolbars.begin(), usedtoolbars.end(), ToolbarNamesEqual(name));
|
|
|
|
if (it == usedtoolbars.end())
|
|
|
|
return 0;
|
|
|
|
return &(*it);
|
2003-04-08 19:17:00 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|