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"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.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 {
|
|
|
|
|
2008-03-04 22:28:18 +00:00
|
|
|
InsetERT::InsetERT(Buffer const & buf, CollapseStatus status)
|
2008-10-26 02:25:57 +00:00
|
|
|
: InsetCollapsable(buf)
|
|
|
|
{
|
|
|
|
status_ = status;
|
|
|
|
}
|
2001-07-24 10:13:19 +00:00
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
InsetERT::~InsetERT()
|
|
|
|
{
|
2008-03-27 00:07:54 +00:00
|
|
|
hideDialogs("ert", this);
|
2001-08-06 14:55:02 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetERT::editMessage() const
|
2000-04-04 00:19:15 +00:00
|
|
|
{
|
2006-09-09 18:52:00 +00:00
|
|
|
return _("Opened ERT Inset");
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetERT::latex(odocstream & os, OutputParams const & op) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
return InsetCollapsable::latex(os, op);
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetERT::plaintext(odocstream &, OutputParams const &) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2007-02-18 18:55:11 +00:00
|
|
|
return 0; // do not output TeX code
|
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
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
BufferParams const & bp = cur.buffer()->params();
|
2008-08-01 20:57:27 +00:00
|
|
|
Layout const layout = bp.documentClass().plainLayout();
|
2004-11-24 21:58:42 +00:00
|
|
|
//lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl;
|
2002-08-19 10:11:13 +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:
|
2006-02-27 12:22:36 +00:00
|
|
|
// Force any new text to latex_language
|
2007-11-03 00:35:07 +00:00
|
|
|
// FIXME: This should not be necessary but
|
2006-02-27 12:22:36 +00:00
|
|
|
// new paragraphs that are created by pressing enter at the
|
|
|
|
// start of an existing paragraph get the buffer language
|
|
|
|
// and not latex_language, so we take this brute force
|
|
|
|
// approach.
|
2008-03-06 20:01:30 +00:00
|
|
|
cur.current_font.fontInfo() = layout.font;
|
|
|
|
cur.real_current_font.fontInfo() = layout.font;
|
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
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
2007-10-13 19:06:09 +00:00
|
|
|
case LFUN_CLIPBOARD_PASTE:
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
case LFUN_PASTE:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_PRIMARY_SELECTION_PASTE:
|
2007-10-13 19:06:09 +00:00
|
|
|
case LFUN_QUOTE_INSERT:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2005-04-22 08:57:22 +00:00
|
|
|
return true;
|
|
|
|
|
2005-02-03 17:24:40 +00:00
|
|
|
// this one is difficult to get right. As a half-baked
|
|
|
|
// solution, we consider only the first action of the sequence
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_COMMAND_SEQUENCE: {
|
2005-02-03 17:24:40 +00:00
|
|
|
// argument contains ';'-terminated commands
|
2006-10-21 00:16:43 +00:00
|
|
|
string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
|
2005-02-03 17:24:40 +00:00
|
|
|
FuncRequest func(lyxaction.lookupFunc(firstcmd));
|
|
|
|
func.origin = cmd.origin;
|
|
|
|
return getStatus(cur, func, status);
|
|
|
|
}
|
|
|
|
|
2004-11-04 19:50:04 +00:00
|
|
|
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)
|
2009-02-25 22:35:41 +00:00
|
|
|
return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
|
2007-09-02 08:38:09 +00:00
|
|
|
else
|
2009-02-25 22:35:41 +00:00
|
|
|
return getNewLabel(_("ERT"));
|
2001-07-25 19:45:21 +00:00
|
|
|
}
|
2001-07-27 12:03:36 +00:00
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
bool InsetERT::insetAllowed(InsetCode /* code */) const
|
2003-12-02 07:15:42 +00:00
|
|
|
{
|
2005-02-03 17:24:40 +00:00
|
|
|
return false;
|
2003-12-02 07:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-10 22:12:07 +00:00
|
|
|
bool InsetERT::showInsetDialog(BufferView * bv) const
|
2001-08-06 14:55:02 +00:00
|
|
|
{
|
2009-02-21 16:27:00 +00:00
|
|
|
bv->showDialog("ert", params2string(status(*bv)),
|
2008-03-26 23:41:35 +00:00
|
|
|
const_cast<InsetERT *>(this));
|
2001-08-06 14:55:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06-12 17:23:17 +00:00
|
|
|
docstring InsetERT::xhtml(odocstream &, OutputParams const &) const
|
|
|
|
{
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|