2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetcommand.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetcommand.h"
|
2003-02-26 15:01:10 +00:00
|
|
|
|
#include "BufferView.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2003-02-26 15:01:10 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2003-02-26 15:01:10 +00:00
|
|
|
|
|
2003-02-27 13:26:07 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
#include "Lsstream.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
|
2002-02-16 15:59:55 +00:00
|
|
|
|
: p_(p.getCmdName(), p.getContents(), p.getOptions())
|
2001-07-24 15:07:09 +00:00
|
|
|
|
{}
|
2000-08-04 13:12:30 +00:00
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
void InsetCommand::setParams(InsetCommandParams const & p)
|
2000-08-04 13:12:30 +00:00
|
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
|
p_.setCmdName(p.getCmdName());
|
|
|
|
|
p_.setContents(p.getContents());
|
|
|
|
|
p_.setOptions(p.getOptions());
|
2000-08-04 13:12:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetCommand::latex(Buffer const *, ostream & os,
|
2000-07-15 23:51:46 +00:00
|
|
|
|
bool /*fragile*/, bool/*fs*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << getCommand();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetCommand::ascii(Buffer const *, ostream &, int) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetCommand::linuxdoc(Buffer const *, ostream &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int InsetCommand::docbook(Buffer const *, ostream &, bool) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
|
|
|
2003-02-26 15:01:10 +00:00
|
|
|
|
dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
|
|
|
|
|
{
|
2003-03-04 14:31:04 +00:00
|
|
|
|
if (cmd.action != LFUN_INSET_MODIFY)
|
2003-02-26 19:28:38 +00:00
|
|
|
|
return UNDISPATCHED;
|
|
|
|
|
|
2003-02-26 15:01:10 +00:00
|
|
|
|
InsetCommandParams p;
|
|
|
|
|
InsetCommandMailer::string2params(cmd.argument, p);
|
|
|
|
|
if (p.getCmdName().empty())
|
|
|
|
|
return UNDISPATCHED;
|
|
|
|
|
|
|
|
|
|
setParams(p);
|
|
|
|
|
if (view())
|
|
|
|
|
view()->updateInset(this, true);
|
|
|
|
|
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
InsetCommandMailer::InsetCommandMailer(string const & name,
|
|
|
|
|
InsetCommand & inset)
|
|
|
|
|
: name_(name), inset_(inset)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetCommandMailer::inset2string() const
|
|
|
|
|
{
|
2003-02-27 13:26:07 +00:00
|
|
|
|
return params2string(name(), inset_.params());
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCommandMailer::string2params(string const & in,
|
|
|
|
|
InsetCommandParams & params)
|
|
|
|
|
{
|
|
|
|
|
params.setCmdName(string());
|
|
|
|
|
params.setContents(string());
|
|
|
|
|
params.setOptions(string());
|
|
|
|
|
|
2003-02-27 13:26:07 +00:00
|
|
|
|
string name;
|
|
|
|
|
string body = split(in, name, ' ');
|
|
|
|
|
|
|
|
|
|
if (body.empty())
|
2003-02-25 14:51:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-02-27 13:26:07 +00:00
|
|
|
|
istringstream data(body);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
|
lex.setStream(data);
|
|
|
|
|
|
|
|
|
|
params.read(lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const
|
2003-02-27 13:26:07 +00:00
|
|
|
|
InsetCommandMailer::params2string(string const & name,
|
|
|
|
|
InsetCommandParams const & params)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
2003-02-27 13:26:07 +00:00
|
|
|
|
data << name << ' ';
|
2003-02-25 14:51:38 +00:00
|
|
|
|
params.write(data);
|
|
|
|
|
data << "\\end_inset\n";
|
|
|
|
|
|
|
|
|
|
return data.str();
|
|
|
|
|
}
|