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"
|
2005-02-03 17:24:40 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Paragraph.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "TextClass.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
#include "frontends/alert.h"
|
2008-03-26 23:41:35 +00:00
|
|
|
#include "frontends/Application.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2007-11-13 23:50:28 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
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)
|
2009-12-23 16:06:31 +00:00
|
|
|
: InsetCollapsable(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
|
|
|
|
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";
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::write(os);
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-10 12:07:42 +00:00
|
|
|
int InsetERT::plaintext(odocstream & os, OutputParams const & rp) 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();
|
|
|
|
|
|
|
|
while (par != end) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetERT::docbook(odocstream & os, 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
|
|
|
|
2001-10-15 12:21:11 +00:00
|
|
|
int lines = 0;
|
2003-04-02 17:11:38 +00:00
|
|
|
while (par != end) {
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type siz = par->size();
|
2005-02-03 17:24:40 +00:00
|
|
|
for (pos_type i = 0; i < siz; ++i)
|
2006-10-19 16:51:30 +00:00
|
|
|
os.put(par->getChar(i));
|
2003-04-02 17:11:38 +00:00
|
|
|
++par;
|
|
|
|
if (par != end) {
|
2001-10-15 12:21:11 +00:00
|
|
|
os << "\n";
|
2004-04-01 10:21:29 +00:00
|
|
|
++lines;
|
2001-10-15 12:21:11 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-10-15 12:21:11 +00:00
|
|
|
return lines;
|
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()) {
|
2004-01-15 17:34:44 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
2008-03-27 23:37:59 +00:00
|
|
|
setStatus(cur, string2params(to_utf8(cmd.argument())));
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2004-01-15 17:34:44 +00:00
|
|
|
}
|
2001-07-24 15:07:09 +00:00
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
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()) {
|
2009-07-14 18:30:13 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
status.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, status);
|
2005-02-03 17:24:40 +00:00
|
|
|
}
|
2004-11-04 19:50:04 +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-07 15:31:05 +00:00
|
|
|
return isOpen(bv) ? _("TeX") : getNewLabel(_("TeX"));
|
2007-09-02 08:38:09 +00:00
|
|
|
else
|
2010-11-07 15:31:05 +00:00
|
|
|
return getNewLabel(_("TeX"));
|
2001-07-25 19:45:21 +00:00
|
|
|
}
|
2001-07-27 12:03:36 +00:00
|
|
|
|
|
|
|
|
2008-03-27 23:37:59 +00:00
|
|
|
InsetCollapsable::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
|
|
|
|
|
|
|
|
2009-11-19 21:52:18 +00:00
|
|
|
docstring InsetERT::xhtml(XHTMLStream &, OutputParams const &) const
|
2009-06-12 17:23:17 +00:00
|
|
|
{
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|