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
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \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
|
|
|
|
*/
|
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"
|
2005-02-03 17:24:40 +00:00
|
|
|
|
#include "LyXAction.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-29 19:53:54 +00:00
|
|
|
|
#include "TextClass.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"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.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 {
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2003-12-12 14:02:14 +00:00
|
|
|
|
InsetERT::InsetERT(BufferParams const & bp, CollapseStatus status)
|
|
|
|
|
: InsetCollapsable(bp, status)
|
2007-11-03 00:35:07 +00:00
|
|
|
|
{}
|
2001-07-24 10:13:19 +00:00
|
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetERT::InsetERT(InsetERT const & in)
|
2003-12-02 07:15:42 +00:00
|
|
|
|
: InsetCollapsable(in)
|
2007-11-03 00:35:07 +00:00
|
|
|
|
{}
|
2001-07-27 12:03:36 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetERT::clone() const
|
2001-07-27 12:03:36 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetERT(*this);
|
2001-07-27 12:03:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
|
InsetERT::~InsetERT()
|
|
|
|
|
{
|
2003-07-14 17:50:00 +00:00
|
|
|
|
InsetERTMailer(*this).hideDialog();
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetERT::write(Buffer const & buf, ostream & os) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2003-12-12 14:02:14 +00:00
|
|
|
|
os << "ERT" << "\n";
|
|
|
|
|
InsetCollapsable::write(buf, os);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-09 18:52:00 +00:00
|
|
|
|
docstring const 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-22 18:01:21 +00:00
|
|
|
|
int InsetERT::latex(Buffer const & buf, odocstream & os,
|
|
|
|
|
OutputParams const & op) const
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2007-10-22 18:01:21 +00:00
|
|
|
|
return InsetCollapsable::latex(buf, os, op);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetERT::plaintext(Buffer const &, odocstream &,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetERT::docbook(Buffer const &, odocstream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
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
|
|
|
|
{
|
2007-09-13 14:29:44 +00:00
|
|
|
|
BufferParams const & bp = cur.buffer().params();
|
|
|
|
|
LayoutPtr const layout =
|
Fix bug 4037 and related problems. The patch has been cleaned up a bit
from the one posted to the list.
The basic idea has two parts. First, we hard code an "empty layout"
(called PlainLayout, for want of a better name) in TextClass and read it
before doing anything else. It can therefore be customized by classes,
if they want---say, to make it left-aligned. Second, InsetText's are
divided into three types: (i) normal ones, that use the "default" layout
defined by the text class; (ii) highly restrictive ones, such as ERT and
(not quite an inset) table cells, which demand the empty layout; (iii)
middling ones, which default to an empty layout and use the empty layout
in place of the default. (This is so we don't get the same problem we
had with ERT in e.g. footnotes.) The type of inset is signaled by new
methods InsetText::forceEmptyLayout() and InsetText::useEmptyLayout().
(The latter might better be called: useEmptyLayoutInsteadOfDefault(),
but that's silly.) The old InsetText::forceDefaultParagraphs() has been
split into these, plus a new method InsetText::allowParagraphCustomization().
A lot of the changes just adapt to this change.
The other big change is in GuiToolbar: We want to show LyXDefault and
the "default" layout only when they're active.
There are a handful of places where I'm not entirely sure whether we
should be using forceEmptyLayout or !allowParagraphCustomization() or
both. The InsetCaption is one of these. These places, and some others,
are marked with FIXMEs, so I'd appreciate it if people would search
through the patch and let me know whether these need changing. If they
don't, the FIXMEs can be deleted.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22966 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-12 17:31:07 +00:00
|
|
|
|
bp.getTextClass().emptyLayout();
|
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) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2007-09-02 08:38:09 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
if (cmd.button() != mouse_button::button3)
|
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
|
|
|
|
else
|
|
|
|
|
// This makes the cursor leave the
|
|
|
|
|
// inset when it collapses on mouse-3
|
|
|
|
|
cur.undispatched();
|
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_QUOTE_INSERT: {
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// We need to bypass the fancy quotes in Text
|
2006-05-05 20:23:12 +00:00
|
|
|
|
FuncRequest f(LFUN_SELF_INSERT, "\"");
|
2006-03-27 14:13:48 +00:00
|
|
|
|
dispatch(cur, f);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-01-15 17:34:44 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetCollapsable::CollapseStatus st;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
|
2005-05-06 20:00:31 +00:00
|
|
|
|
setStatus(cur, st);
|
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.
|
2007-10-28 23:32:18 +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:
|
2005-04-22 08:57:22 +00:00
|
|
|
|
status.enabled(true);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-12 14:02:14 +00:00
|
|
|
|
void InsetERT::setButtonLabel()
|
2001-07-25 19:45:21 +00:00
|
|
|
|
{
|
2007-09-02 08:38:09 +00:00
|
|
|
|
if (decoration() == Classic)
|
|
|
|
|
setLabel(isOpen() ? _("ERT") : getNewLabel(_("ERT")));
|
|
|
|
|
else
|
|
|
|
|
setLabel(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-05-30 06:48:24 +00:00
|
|
|
|
void InsetERT::draw(PainterInfo & pi, int x, int y) const
|
2001-07-31 09:53:40 +00:00
|
|
|
|
{
|
2007-08-21 21:29:13 +00:00
|
|
|
|
const_cast<InsetERT &>(*this).setButtonLabel();
|
2003-12-02 07:15:42 +00:00
|
|
|
|
InsetCollapsable::draw(pi, x, y);
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-10 22:12:07 +00:00
|
|
|
|
bool InsetERT::showInsetDialog(BufferView * bv) const
|
2001-08-06 14:55:02 +00:00
|
|
|
|
{
|
2003-07-14 17:50:00 +00:00
|
|
|
|
InsetERTMailer(const_cast<InsetERT &>(*this)).showDialog(bv);
|
2001-08-06 14:55:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
string const InsetERTMailer::name_("ert");
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
InsetERTMailer::InsetERTMailer(InsetERT & inset)
|
2003-03-07 14:08:10 +00:00
|
|
|
|
: inset_(inset)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetERTMailer::inset2string(Buffer const &) const
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
return params2string(inset_.status());
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetERTMailer::string2params(string const & in,
|
2003-12-10 21:32:05 +00:00
|
|
|
|
InsetCollapsable::CollapseStatus & status)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status = InsetCollapsable::Collapsed;
|
2003-12-11 15:23:15 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
2003-02-27 13:26:07 +00:00
|
|
|
|
|
2003-12-10 21:32:05 +00:00
|
|
|
|
istringstream data(in);
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Lexer lex(0,0);
|
2003-12-10 21:32:05 +00:00
|
|
|
|
lex.setStream(data);
|
2003-02-27 13:26:07 +00:00
|
|
|
|
|
2003-12-10 21:32:05 +00:00
|
|
|
|
string name;
|
|
|
|
|
lex >> name;
|
2003-12-11 15:23:15 +00:00
|
|
|
|
if (name != name_)
|
|
|
|
|
return print_mailer_error("InsetERTMailer", in, 1, name_);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
2003-12-10 21:32:05 +00:00
|
|
|
|
int s;
|
|
|
|
|
lex >> s;
|
2007-03-26 13:43:49 +00:00
|
|
|
|
if (lex)
|
2003-12-10 21:32:05 +00:00
|
|
|
|
status = static_cast<InsetCollapsable::CollapseStatus>(s);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-02 07:15:42 +00:00
|
|
|
|
string const
|
|
|
|
|
InsetERTMailer::params2string(InsetCollapsable::CollapseStatus status)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
2003-12-10 21:32:05 +00:00
|
|
|
|
ostringstream data;
|
|
|
|
|
data << name_ << ' ' << status;
|
|
|
|
|
return data.str();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|