2003-04-02 18:08:05 +00:00
|
|
|
/**
|
|
|
|
* \file ToolbarBackend.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 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"
|
2003-09-04 03:54:04 +00:00
|
|
|
#include "funcrequest.h"
|
2000-03-12 10:36:28 +00:00
|
|
|
#include "LyXAction.h"
|
2000-07-24 13:53:19 +00:00
|
|
|
#include "lyxlex.h"
|
2000-07-19 12:30:49 +00:00
|
|
|
#include "debug.h"
|
2003-04-08 19:17:00 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-04-08 19:17:00 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
|
|
|
|
#include "frontends/controllers/ControlMath.h"
|
2000-03-12 10:36:28 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::compare_ascii_no_case;
|
|
|
|
using lyx::support::getVectorFromString;
|
2006-04-08 22:31:11 +00:00
|
|
|
using lyx::support::libFileSearch;
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::subst;
|
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;
|
|
|
|
|
|
|
|
|
2003-04-02 18:08:05 +00:00
|
|
|
ToolbarBackend toolbarbackend;
|
2000-03-12 10:36:28 +00:00
|
|
|
|
2001-11-09 13:44:48 +00:00
|
|
|
namespace {
|
|
|
|
|
2003-04-09 19:53:10 +00:00
|
|
|
enum tooltags {
|
2001-11-09 13:44:48 +00:00
|
|
|
TO_ADD = 1,
|
|
|
|
TO_ENDTOOLBAR,
|
|
|
|
TO_SEPARATOR,
|
|
|
|
TO_LAYOUTS,
|
2003-04-15 01:06:13 +00:00
|
|
|
TO_MINIBUFFER,
|
2001-11-09 13:44:48 +00:00
|
|
|
TO_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
struct keyword_item toolTags[TO_LAST - 1] = {
|
|
|
|
{ "end", TO_ENDTOOLBAR },
|
2003-04-08 19:17:00 +00:00
|
|
|
{ "item", TO_ADD },
|
2001-11-09 13:44:48 +00:00
|
|
|
{ "layouts", TO_LAYOUTS },
|
2003-04-15 01:06:13 +00:00
|
|
|
{ "minibuffer", TO_MINIBUFFER },
|
2001-11-09 13:44:48 +00:00
|
|
|
{ "separator", TO_SEPARATOR }
|
|
|
|
};
|
|
|
|
|
2002-01-14 12:56:05 +00:00
|
|
|
} // end of anon namespace
|
2001-11-09 13:44:48 +00:00
|
|
|
|
2000-11-21 15:46:13 +00:00
|
|
|
|
2003-04-02 18:08:05 +00:00
|
|
|
ToolbarBackend::ToolbarBackend()
|
2000-03-12 10:36:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-02 18:08:05 +00:00
|
|
|
void ToolbarBackend::read(LyXLex & lex)
|
2000-03-12 10:36:28 +00:00
|
|
|
{
|
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")) {
|
2003-04-02 18:08:05 +00:00
|
|
|
lyxerr << "ToolbarBackend::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);
|
|
|
|
|
|
|
|
Toolbar tb;
|
|
|
|
tb.name = lex.getString();
|
2004-04-21 00:19:27 +00:00
|
|
|
lex.next(true);
|
|
|
|
if (!lex.isOK()) {
|
|
|
|
lyxerr << "ToolbarBackend::read: Malformed toolbar "
|
|
|
|
"description " << lex.getString() << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tb.gui_name = lex.getString();
|
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()) {
|
2000-03-12 10:36:28 +00:00
|
|
|
case TO_ADD:
|
2001-07-23 09:11:14 +00:00
|
|
|
if (lex.next(true)) {
|
2003-04-08 19:17:00 +00:00
|
|
|
string const tooltip = _(lex.getString());
|
|
|
|
lex.next(true);
|
2003-09-21 18:57:15 +00:00
|
|
|
string const func_arg = lex.getString();
|
2001-05-03 15:38:24 +00:00
|
|
|
lyxerr[Debug::PARSER]
|
2003-04-02 18:08:05 +00:00
|
|
|
<< "ToolbarBackend::read TO_ADD 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);
|
|
|
|
add(tb, 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:
|
2003-09-21 18:57:15 +00:00
|
|
|
add(tb, FuncRequest(kb_action(MINIBUFFER)));
|
2003-04-15 01:06:13 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
case TO_SEPARATOR:
|
2003-09-21 18:57:15 +00:00
|
|
|
add(tb, FuncRequest(kb_action(SEPARATOR)));
|
2000-03-12 10:36:28 +00:00
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
case TO_LAYOUTS:
|
2003-09-21 18:57:15 +00:00
|
|
|
add(tb, FuncRequest(kb_action(LAYOUTS)));
|
2000-03-12 10:36:28 +00:00
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
case TO_ENDTOOLBAR:
|
|
|
|
quit = true;
|
|
|
|
break;
|
|
|
|
default:
|
2003-04-02 18:08:05 +00:00
|
|
|
lex.printError("ToolbarBackend::read: "
|
2000-03-12 10:36:28 +00:00
|
|
|
"Unknown toolbar tag: `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-04-09 19:53:10 +00:00
|
|
|
|
|
|
|
toolbars.push_back(tb);
|
|
|
|
|
2000-03-12 10:36:28 +00:00
|
|
|
lex.popTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-11 19:21:46 +00:00
|
|
|
void ToolbarBackend::readToolbars(LyXLex & lex)
|
|
|
|
{
|
|
|
|
//consistency check
|
|
|
|
if (compare_ascii_no_case(lex.getString(), "toolbars")) {
|
|
|
|
lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
|
|
|
|
<< 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
tcit->flags = static_cast<Flags>(0);
|
|
|
|
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"))
|
|
|
|
flag = OFF;
|
|
|
|
else if (!compare_ascii_no_case(*cit, "on"))
|
|
|
|
flag = ON;
|
|
|
|
else if (!compare_ascii_no_case(*cit, "math"))
|
|
|
|
flag = MATH;
|
|
|
|
else if (!compare_ascii_no_case(*cit, "table"))
|
|
|
|
flag = TABLE;
|
|
|
|
else if (!compare_ascii_no_case(*cit, "top"))
|
|
|
|
flag = TOP;
|
|
|
|
else if (!compare_ascii_no_case(*cit, "bottom"))
|
|
|
|
flag = BOTTOM;
|
|
|
|
else if (!compare_ascii_no_case(*cit, "left"))
|
|
|
|
flag = LEFT;
|
|
|
|
else if (!compare_ascii_no_case(*cit, "right"))
|
|
|
|
flag = RIGHT;
|
|
|
|
else {
|
|
|
|
lyxerr << "ToolbarBackend::read: unrecognised token:`"
|
|
|
|
<< *cit << '\'' << endl;
|
|
|
|
}
|
|
|
|
tcit->flags = static_cast<Flags>(tcit->flags | flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
usedtoolbars.push_back(*tcit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-21 18:57:15 +00:00
|
|
|
void ToolbarBackend::add(Toolbar & tb,
|
|
|
|
FuncRequest const & func, string const & tooltip)
|
2000-03-12 10:36:28 +00:00
|
|
|
{
|
2003-09-21 18:57:15 +00:00
|
|
|
tb.items.push_back(make_pair(func, tooltip));
|
2004-11-08 10:54:29 +00:00
|
|
|
tb.items.back().first.origin = FuncRequest::UI;
|
2000-03-12 10:36:28 +00:00
|
|
|
}
|
2003-04-08 19:17:00 +00:00
|
|
|
|
|
|
|
|
2003-09-21 18:57:15 +00:00
|
|
|
string const ToolbarBackend::getIcon(FuncRequest const & f)
|
2003-04-08 19:17:00 +00:00
|
|
|
{
|
2004-05-19 15:11:37 +00:00
|
|
|
using lyx::frontend::find_xpm;
|
|
|
|
|
2003-04-08 19:17:00 +00:00
|
|
|
string fullname;
|
|
|
|
|
2006-05-07 10:51:19 +00:00
|
|
|
switch (f.action) {
|
|
|
|
case LFUN_MATH_INSERT:
|
2003-04-10 02:33:42 +00:00
|
|
|
if (!f.argument.empty())
|
|
|
|
fullname = find_xpm(f.argument.substr(1));
|
2006-05-07 10:51:19 +00:00
|
|
|
break;
|
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
case LFUN_MATH_BIGDELIM:
|
2003-04-10 02:33:42 +00:00
|
|
|
fullname = find_xpm(f.argument);
|
2006-05-07 10:51:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-04-08 19:17:00 +00:00
|
|
|
string const name = lyxaction.getActionName(f.action);
|
|
|
|
string xpm_name(name);
|
|
|
|
|
|
|
|
if (!f.argument.empty())
|
|
|
|
xpm_name = subst(name + ' ' + f.argument, ' ', '_');
|
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
fullname = libFileSearch("images", xpm_name, "xpm");
|
2003-04-08 19:17:00 +00:00
|
|
|
|
2003-04-09 02:23:47 +00:00
|
|
|
if (fullname.empty()) {
|
|
|
|
// try without the argument
|
2006-04-08 22:31:11 +00:00
|
|
|
fullname = libFileSearch("images", name, "xpm");
|
2003-04-09 02:23:47 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-08 19:17:00 +00:00
|
|
|
|
|
|
|
if (!fullname.empty()) {
|
|
|
|
lyxerr[Debug::GUI] << "Full icon name is `"
|
|
|
|
<< fullname << '\'' << endl;
|
|
|
|
return fullname;
|
|
|
|
}
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
|
|
lyxerr[Debug::GUI] << "Cannot find icon for command \""
|
|
|
|
<< lyxaction.getActionName(f.action)
|
2003-09-21 18:57:15 +00:00
|
|
|
<< '(' << f.argument << ")\"" << endl;
|
2006-04-08 22:31:11 +00:00
|
|
|
return libFileSearch("images", "unknown", "xpm");
|
2003-04-08 19:17:00 +00:00
|
|
|
}
|