2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetCommand.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* 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
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "InsetCommand.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2007-05-01 08:26:40 +00:00
|
|
|
|
#include "Buffer.h"
|
2003-02-26 15:01:10 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
|
#include "FuncRequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2007-02-20 18:02:46 +00:00
|
|
|
|
#include "gettext.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
2003-02-26 15:01:10 +00:00
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
2006-10-19 16:51:30 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
InsetCommand::InsetCommand(InsetCommandParams const & p,
|
|
|
|
|
string const & mailer_name)
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
|
: p_(p),
|
2003-12-11 15:23:15 +00:00
|
|
|
|
mailer_name_(mailer_name),
|
2006-12-04 04:31:18 +00:00
|
|
|
|
mouse_hover_(false),
|
2005-07-17 14:32:59 +00:00
|
|
|
|
updateButtonLabel_(true)
|
2001-07-24 15:07:09 +00:00
|
|
|
|
{}
|
2000-08-04 13:12:30 +00:00
|
|
|
|
|
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
InsetCommand::~InsetCommand()
|
|
|
|
|
{
|
|
|
|
|
if (!mailer_name_.empty())
|
|
|
|
|
InsetCommandMailer(mailer_name_, *this).hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-06-12 08:52:36 +00:00
|
|
|
|
{
|
2006-04-05 23:56:29 +00:00
|
|
|
|
if (updateButtonLabel_) {
|
2005-07-17 14:32:59 +00:00
|
|
|
|
updateButtonLabel_ = false;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
button_.update(getScreenLabel(*mi.base.bv->buffer()),
|
2003-06-12 08:52:36 +00:00
|
|
|
|
editable() != NOT_EDITABLE);
|
|
|
|
|
}
|
|
|
|
|
button_.metrics(mi, dim);
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool const changed = dim_ != dim;
|
2003-07-18 07:47:07 +00:00
|
|
|
|
dim_ = dim;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return changed;
|
2003-06-12 08:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-04 04:31:18 +00:00
|
|
|
|
bool InsetCommand::setMouseHover(bool mouse_hover)
|
|
|
|
|
{
|
|
|
|
|
mouse_hover_ = mouse_hover;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-12 08:52:36 +00:00
|
|
|
|
void InsetCommand::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2006-12-04 04:31:18 +00:00
|
|
|
|
button_.setRenderState(mouse_hover_);
|
2003-06-12 08:52:36 +00:00
|
|
|
|
button_.draw(pi, x, y);
|
2003-06-03 15:10:14 +00:00
|
|
|
|
}
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
void InsetCommand::setParams(InsetCommandParams const & p)
|
2000-08-04 13:12:30 +00:00
|
|
|
|
{
|
2003-09-18 22:26:46 +00:00
|
|
|
|
p_ = p;
|
2005-07-17 14:32:59 +00:00
|
|
|
|
updateButtonLabel_ = true;
|
2000-08-04 13:12:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetCommand::latex(Buffer const &, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-01 08:26:40 +00:00
|
|
|
|
int InsetCommand::plaintext(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2007-05-01 08:26:40 +00:00
|
|
|
|
docstring const str = "[" + buf.B_("LaTeX Command: ") + from_utf8(getCmdName()) + "]";
|
2007-02-20 18:02:46 +00:00
|
|
|
|
os << str;
|
|
|
|
|
return str.size();
|
2000-04-24 20:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetCommand::docbook(Buffer const &, odocstream &,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-02-26 15:01:10 +00:00
|
|
|
|
{
|
2003-03-07 15:58:02 +00:00
|
|
|
|
switch (cmd.action) {
|
2004-05-17 08:52:21 +00:00
|
|
|
|
case LFUN_INSET_REFRESH:
|
2005-07-17 14:32:59 +00:00
|
|
|
|
updateButtonLabel_ = true;
|
2004-05-17 08:52:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
|
InsetCommandParams p(p_.getCmdName());
|
2006-10-21 00:16:43 +00:00
|
|
|
|
InsetCommandMailer::string2params(mailer_name_, to_utf8(cmd.argument()), p);
|
2005-05-09 17:29:22 +00:00
|
|
|
|
if (p.getCmdName().empty())
|
|
|
|
|
cur.noUpdate();
|
|
|
|
|
else
|
2004-02-16 11:58:51 +00:00
|
|
|
|
setParams(p);
|
|
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
2003-02-26 19:28:38 +00:00
|
|
|
|
|
2006-09-01 15:41:38 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
string const name = to_utf8(cmd.argument());
|
2006-09-01 15:41:38 +00:00
|
|
|
|
InsetCommandMailer(name, *this).updateDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
}
|
2003-02-26 15:01:10 +00:00
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE: {
|
2007-09-10 16:04:21 +00:00
|
|
|
|
if (!cur.selection())
|
|
|
|
|
edit(cur, true);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-12-11 15:23:15 +00:00
|
|
|
|
}
|
2003-03-09 09:38:47 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
2003-02-26 15:01:10 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-11 11:52:05 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetCommand::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
|
FuncStatus & status) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
// suppress these
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_ERT_INSERT:
|
2005-04-22 08:57:22 +00:00
|
|
|
|
status.enabled(false);
|
|
|
|
|
return true;
|
|
|
|
|
// we handle these
|
|
|
|
|
case LFUN_INSET_REFRESH:
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
status.enabled(true);
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
|
return Inset::getStatus(cur, cmd, status);
|
2005-04-22 08:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-10 16:04:21 +00:00
|
|
|
|
void InsetCommand::edit(Cursor & cur, bool)
|
|
|
|
|
{
|
|
|
|
|
if (!mailer_name_.empty())
|
|
|
|
|
InsetCommandMailer(mailer_name_, *this).showDialog(&cur.bv());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-09 14:21:11 +00:00
|
|
|
|
void InsetCommand::replaceContents(std::string const & from, string const & to)
|
|
|
|
|
{
|
|
|
|
|
if (getContents() == from)
|
|
|
|
|
setContents(to);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
InsetCommandMailer::InsetCommandMailer(string const & name,
|
|
|
|
|
InsetCommand & inset)
|
|
|
|
|
: name_(name), inset_(inset)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetCommandMailer::inset2string(Buffer const &) const
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
2003-02-27 13:26:07 +00:00
|
|
|
|
return params2string(name(), inset_.params());
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
void InsetCommandMailer::string2params(string const & name,
|
|
|
|
|
string const & in,
|
2003-02-25 14:51:38 +00:00
|
|
|
|
InsetCommandParams & params)
|
|
|
|
|
{
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
|
params.clear();
|
2003-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream data(in);
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Lexer lex(0,0);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
lex.setStream(data);
|
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string n;
|
|
|
|
|
lex >> n;
|
|
|
|
|
if (!lex || n != name)
|
|
|
|
|
return print_mailer_error("InsetCommandMailer", in, 1, name);
|
2003-03-07 14:08:10 +00:00
|
|
|
|
|
2003-03-10 03:11:54 +00:00
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// by Text::readInset
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string id;
|
|
|
|
|
lex >> id;
|
|
|
|
|
if (!lex || id != "LatexCommand")
|
|
|
|
|
return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand");
|
|
|
|
|
|
|
|
|
|
params.read(lex);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string const
|
|
|
|
|
InsetCommandMailer::params2string(string const & name,
|
2003-02-27 13:26:07 +00:00
|
|
|
|
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";
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return data.str();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|