2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetERT.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
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
|
|
|
* \author Lars Gullik Bjø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
|
|
|
*/
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetERT.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2001-07-24 15:07:09 +00:00
|
|
|
#include "BufferView.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2004-11-04 19:50:04 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Language.h"
|
2007-09-29 20:02:32 +00:00
|
|
|
#include "Layout.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "LyXAction.h"
|
2009-09-10 12:07:42 +00:00
|
|
|
#include "OutputParams.h"
|
2020-06-08 21:27:49 +00:00
|
|
|
#include "xml.h"
|
2005-02-03 17:24:40 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Paragraph.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2018-04-02 02:40:00 +00:00
|
|
|
#include "support/docstream.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2007-11-13 23:50:28 +00:00
|
|
|
#include "support/lstrings.h"
|
2018-04-02 02:40:00 +00:00
|
|
|
#include "support/TempFile.h"
|
2007-11-13 23:50:28 +00:00
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
|
2017-10-16 08:12:21 +00:00
|
|
|
: InsetCollapsible(buf)
|
2008-10-26 02:25:57 +00:00
|
|
|
{
|
|
|
|
status_ = status;
|
|
|
|
}
|
2001-07-24 10:13:19 +00:00
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
2018-10-04 17:36:01 +00:00
|
|
|
InsetERT::InsetERT(InsetERT const & old)
|
|
|
|
: InsetCollapsible(old)
|
2018-04-02 02:40:00 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetERT::write(ostream & os) const
|
2000-06-28 13:35:52 +00:00
|
|
|
{
|
2003-12-12 14:02:14 +00:00
|
|
|
os << "ERT" << "\n";
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::write(os);
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetERT::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const & rp, size_t max_length) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2009-09-10 12:07:42 +00:00
|
|
|
if (!rp.inIndexEntry)
|
|
|
|
// do not output TeX code
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ParagraphList::const_iterator par = paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator end = paragraphs().end();
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
while (par != end && os.str().size() <= max_length) {
|
2009-09-10 12:07:42 +00:00
|
|
|
pos_type siz = par->size();
|
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
|
|
|
char_type const c = par->getChar(i);
|
|
|
|
// output the active characters
|
|
|
|
switch (c) {
|
|
|
|
case '|':
|
|
|
|
case '!':
|
|
|
|
case '@':
|
|
|
|
os.put(c);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++par;
|
|
|
|
}
|
|
|
|
return 0;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
void InsetERT::docbook(XMLStream & xs, OutputParams const &) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2007-10-22 18:01:21 +00:00
|
|
|
// FIXME can we do the same thing here as for LaTeX?
|
2004-03-28 22:00:22 +00:00
|
|
|
ParagraphList::const_iterator par = paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator end = paragraphs().end();
|
2003-04-02 17:11:38 +00:00
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
xs << XMLStream::ESCAPE_NONE << "<!-- ";
|
2003-04-02 17:11:38 +00:00
|
|
|
while (par != end) {
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type siz = par->size();
|
2020-06-08 21:27:49 +00:00
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
|
|
|
xs << par->getChar(i);
|
|
|
|
}
|
2003-04-02 17:11:38 +00:00
|
|
|
++par;
|
|
|
|
if (par != end) {
|
2020-06-08 21:27:49 +00:00
|
|
|
xs << "\n";
|
2001-10-15 12:21:11 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-08 21:27:49 +00:00
|
|
|
xs << XMLStream::ESCAPE_NONE << " -->";
|
2000-03-24 13:24:58 +00:00
|
|
|
}
|
2001-07-24 15:07:09 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2001-07-24 15:07:09 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2010-11-30 05:02:12 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (cmd.getArg(0) == "ert") {
|
2015-03-12 14:57:29 +00:00
|
|
|
cur.recordUndoInset(this);
|
2010-11-30 05:02:12 +00:00
|
|
|
setStatus(cur, string2params(to_utf8(cmd.argument())));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//fall-through
|
2001-07-24 15:07:09 +00:00
|
|
|
default:
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2001-07-24 15:07:09 +00:00
|
|
|
}
|
2010-11-30 05:02:12 +00:00
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
}
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2004-11-04 19:50:04 +00:00
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2018-07-10 05:11:59 +00:00
|
|
|
case LFUN_INSET_INSERT:
|
|
|
|
status.setEnabled(false);
|
|
|
|
return true;
|
2009-07-14 18:30:13 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
2010-11-29 13:30:17 +00:00
|
|
|
if (cmd.getArg(0) == "ert") {
|
|
|
|
status.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//fall through
|
|
|
|
|
2009-07-14 18:30:13 +00:00
|
|
|
default:
|
2017-10-16 08:12:21 +00:00
|
|
|
return InsetCollapsible::getStatus(cur, cmd, status);
|
2005-02-03 17:24:40 +00:00
|
|
|
}
|
2004-11-04 19:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-02 02:40:00 +00:00
|
|
|
|
2009-02-25 22:35:41 +00:00
|
|
|
docstring const InsetERT::buttonLabel(BufferView const & bv) const
|
2001-07-25 19:45:21 +00:00
|
|
|
{
|
2008-10-25 13:41:02 +00:00
|
|
|
if (decoration() == InsetLayout::CLASSIC)
|
2010-11-12 09:31:55 +00:00
|
|
|
return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
|
2007-09-02 08:38:09 +00:00
|
|
|
else
|
2010-11-12 09:31:55 +00:00
|
|
|
return getNewLabel(_("ERT"));
|
2001-07-25 19:45:21 +00:00
|
|
|
}
|
2001-07-27 12:03:36 +00:00
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2003-12-11 15:23:15 +00:00
|
|
|
if (in.empty())
|
2008-04-05 10:34:29 +00:00
|
|
|
return Collapsed;
|
2003-12-10 21:32:05 +00:00
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2003-12-10 21:32:05 +00:00
|
|
|
lex.setStream(data);
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetERT::string2params");
|
|
|
|
lex >> "ert";
|
2003-12-10 21:32:05 +00:00
|
|
|
int s;
|
|
|
|
lex >> s;
|
2008-04-05 10:34:29 +00:00
|
|
|
return static_cast<CollapseStatus>(s);
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-26 23:41:35 +00:00
|
|
|
string InsetERT::params2string(CollapseStatus status)
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2003-12-10 21:32:05 +00:00
|
|
|
ostringstream data;
|
2008-03-26 23:41:35 +00:00
|
|
|
data << "ert" << ' ' << status;
|
2003-12-10 21:32:05 +00:00
|
|
|
return data.str();
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const
|
2009-06-12 17:23:17 +00:00
|
|
|
{
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|