2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetExternal.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.
|
2001-03-12 11:22:26 +00:00
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
* \author Asger Alstrup Nielsen
|
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
|
|
|
*/
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetExternal.h"
|
2003-10-07 20:25:10 +00:00
|
|
|
#include "insets/ExternalSupport.h"
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/RenderButton.h"
|
|
|
|
#include "insets/RenderGraphic.h"
|
|
|
|
#include "insets/RenderPreview.h"
|
2003-05-23 14:36:26 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2008-03-27 22:26:24 +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 "Exporter.h"
|
2006-10-12 14:10:13 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2003-05-23 14:36:26 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2008-02-19 09:10:59 +00:00
|
|
|
#include "LyX.h" // use_gui
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "OutputParams.h"
|
2009-11-21 23:26:10 +00:00
|
|
|
#include "output_latex.h"
|
2016-07-31 02:42:01 +00:00
|
|
|
#include "output_xhtml.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2015-10-04 18:48:31 +00:00
|
|
|
#include "TocBackend.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2008-03-16 05:10:41 +00:00
|
|
|
#include "frontends/alert.h"
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "frontends/Application.h"
|
2008-03-16 05:10:41 +00:00
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
#include "graphics/PreviewLoader.h"
|
|
|
|
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2008-03-16 05:10:41 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
2003-10-22 22:26:47 +00:00
|
|
|
#include "support/filetools.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2011-07-14 17:00:35 +00:00
|
|
|
#include "support/lassert.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-09-04 01:44:16 +00:00
|
|
|
#include "support/lyxlib.h"
|
2014-06-09 11:05:50 +00:00
|
|
|
#include "support/TempFile.h"
|
2003-06-04 09:16:29 +00:00
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2011-07-14 17:00:35 +00:00
|
|
|
#include <vector>
|
2003-10-07 20:25:10 +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;
|
2000-06-15 15:44:39 +00:00
|
|
|
|
2003-06-05 22:46:49 +00:00
|
|
|
namespace {
|
|
|
|
|
2003-12-10 21:32:05 +00:00
|
|
|
unsigned int const defaultLyxScale = 100;
|
|
|
|
|
2007-07-09 10:56:49 +00:00
|
|
|
string defaultTemplateName;
|
2003-06-05 22:46:49 +00:00
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2003-06-05 22:46:49 +00:00
|
|
|
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
namespace lyx {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2008-03-16 05:10:41 +00:00
|
|
|
namespace Alert = frontend::Alert;
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
namespace external {
|
|
|
|
|
2016-01-26 20:49:08 +00:00
|
|
|
TempName::TempName()
|
2003-06-11 11:01:34 +00:00
|
|
|
{
|
|
|
|
// must have an extension for the converter code to work correctly.
|
2016-01-26 20:49:08 +00:00
|
|
|
support::TempFile f("lyxextXXXXXX.tmp");
|
|
|
|
// Let f go out of scope here and delete the file ourselves in
|
|
|
|
// ~TempName(), since otherwise external processes would not be able
|
|
|
|
// to use the file on windows (bug 9925). This is not as safe as
|
|
|
|
// keeping a support::TempFile member would be, but the best we can do.
|
|
|
|
f.setAutoRemove(false);
|
|
|
|
tempname_ = f.name();
|
2003-06-11 11:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-26 20:49:08 +00:00
|
|
|
TempName::TempName(TempName const & that)
|
2003-06-11 11:01:34 +00:00
|
|
|
{
|
2014-06-09 11:05:50 +00:00
|
|
|
*this = that;
|
2003-09-25 10:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
TempName::~TempName()
|
2003-09-25 10:49:13 +00:00
|
|
|
{
|
2016-01-26 20:49:08 +00:00
|
|
|
tempname_.removeFile();
|
2003-09-25 10:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-17 15:32:12 +00:00
|
|
|
TempName & TempName::operator=(TempName const & other)
|
2003-09-25 10:49:13 +00:00
|
|
|
{
|
2014-06-09 11:05:50 +00:00
|
|
|
if (this != &other) {
|
2017-01-08 22:11:04 +00:00
|
|
|
if (!tempname_.empty())
|
|
|
|
tempname_.removeFile();
|
2016-01-26 20:49:08 +00:00
|
|
|
support::TempFile f("lyxextXXXXXX.tmp");
|
|
|
|
f.setAutoRemove(false);
|
2017-07-03 17:53:14 +00:00
|
|
|
tempname_ = f.name();
|
2014-06-09 11:05:50 +00:00
|
|
|
}
|
2003-09-25 10:49:13 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-06-09 11:05:50 +00:00
|
|
|
|
|
|
|
support::FileName TempName::operator()() const
|
|
|
|
{
|
2016-01-26 20:49:08 +00:00
|
|
|
return tempname_;
|
2014-06-09 11:05:50 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
} // namespace external
|
|
|
|
|
2003-09-25 10:49:13 +00:00
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
InsetExternalParams::InsetExternalParams()
|
2008-06-13 07:34:55 +00:00
|
|
|
: display(true),
|
2016-06-09 14:51:07 +00:00
|
|
|
preview_mode(PREVIEW_OFF),
|
2003-12-10 21:32:05 +00:00
|
|
|
lyxscale(defaultLyxScale),
|
2007-07-09 10:56:49 +00:00
|
|
|
draft(false)
|
|
|
|
{
|
|
|
|
if (defaultTemplateName.empty()) {
|
|
|
|
external::TemplateManager const & etm =
|
|
|
|
external::TemplateManager::get();
|
2009-10-09 12:40:34 +00:00
|
|
|
if (!etm.getTemplates().empty())
|
|
|
|
templatename_ = etm.getTemplates().begin()->first;
|
2007-07-09 10:56:49 +00:00
|
|
|
} else
|
|
|
|
templatename_ = defaultTemplateName;
|
|
|
|
}
|
2003-09-25 10:49:13 +00:00
|
|
|
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void clearIfNotFound(T & data, external::TransformID value,
|
|
|
|
vector<external::TransformID> const & ids)
|
|
|
|
{
|
|
|
|
typedef vector<external::TransformID>::const_iterator
|
|
|
|
const_iterator;
|
|
|
|
|
|
|
|
const_iterator it = ids.begin();
|
|
|
|
const_iterator end = ids.end();
|
2007-12-12 19:28:07 +00:00
|
|
|
it = find(it, end, value);
|
2003-10-07 22:59:58 +00:00
|
|
|
if (it == end)
|
|
|
|
data = T();
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
void InsetExternalParams::settemplate(string const & name)
|
2003-09-25 10:49:13 +00:00
|
|
|
{
|
|
|
|
templatename_ = name;
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
external::TemplateManager const & etm =
|
|
|
|
external::TemplateManager::get();
|
|
|
|
external::Template const * const et = etm.getTemplateByName(name);
|
|
|
|
if (!et)
|
|
|
|
// Be safe. Don't lose data.
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ascertain which transforms the template supports.
|
|
|
|
// Empty all those that it doesn't.
|
|
|
|
vector<external::TransformID> const & ids = et->transformIds;
|
|
|
|
clearIfNotFound(clipdata, external::Clip, ids);
|
|
|
|
clearIfNotFound(extradata, external::Extra, ids);
|
|
|
|
clearIfNotFound(resizedata, external::Resize, ids);
|
|
|
|
clearIfNotFound(rotationdata, external::Rotate, ids);
|
2008-06-13 07:34:55 +00:00
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
//
|
2008-06-13 07:34:55 +00:00
|
|
|
preview_mode = et->preview_mode;
|
2003-06-11 11:01:34 +00:00
|
|
|
}
|
2003-06-05 22:46:49 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetExternalParams::write(Buffer const & buf, ostream & os) const
|
2003-09-30 13:51:00 +00:00
|
|
|
{
|
|
|
|
os << "External\n"
|
|
|
|
<< "\ttemplate " << templatename() << '\n';
|
|
|
|
|
2008-04-18 17:06:03 +00:00
|
|
|
if (!filename.empty())
|
2010-04-21 01:19:25 +00:00
|
|
|
os << "\tfilename " << filename.outputFileName(buf.filePath()) << '\n';
|
2008-04-20 03:08:11 +00:00
|
|
|
|
2008-06-13 07:34:55 +00:00
|
|
|
if (!display)
|
|
|
|
os << "\tdisplay false\n";
|
2003-09-30 13:51:00 +00:00
|
|
|
|
|
|
|
if (lyxscale != defaultLyxScale)
|
2005-01-06 15:40:49 +00:00
|
|
|
os << "\tlyxscale " << convert<string>(lyxscale) << '\n';
|
2003-10-07 22:59:58 +00:00
|
|
|
|
2003-12-11 11:16:19 +00:00
|
|
|
if (draft)
|
|
|
|
os << "\tdraft\n";
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
if (!clipdata.bbox.empty())
|
|
|
|
os << "\tboundingBox " << clipdata.bbox << '\n';
|
|
|
|
if (clipdata.clip)
|
|
|
|
os << "\tclip\n";
|
|
|
|
|
|
|
|
external::ExtraData::const_iterator it = extradata.begin();
|
|
|
|
external::ExtraData::const_iterator end = extradata.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (!it->second.empty())
|
|
|
|
os << "\textra " << it->first << " \""
|
|
|
|
<< it->second << "\"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rotationdata.no_rotation()) {
|
2005-01-04 10:59:49 +00:00
|
|
|
os << "\trotateAngle " << rotationdata.adjAngle() << '\n';
|
2003-10-07 22:59:58 +00:00
|
|
|
if (rotationdata.origin() != external::RotationData::DEFAULT)
|
|
|
|
os << "\trotateOrigin "
|
|
|
|
<< rotationdata.originString() << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!resizedata.no_resize()) {
|
2005-01-27 21:05:44 +00:00
|
|
|
double const scl = convert<double>(resizedata.scale);
|
2005-01-04 10:59:49 +00:00
|
|
|
if (!float_equal(scl, 0.0, 0.05)) {
|
|
|
|
if (!float_equal(scl, 100.0, 0.05))
|
2003-10-07 22:59:58 +00:00
|
|
|
os << "\tscale "
|
|
|
|
<< resizedata.scale << '\n';
|
|
|
|
} else {
|
|
|
|
if (!resizedata.width.zero())
|
|
|
|
os << "\twidth "
|
|
|
|
<< resizedata.width.asString() << '\n';
|
|
|
|
if (!resizedata.height.zero())
|
|
|
|
os << "\theight "
|
|
|
|
<< resizedata.height.asString() << '\n';
|
|
|
|
}
|
|
|
|
if (resizedata.keepAspectRatio)
|
|
|
|
os << "\tkeepAspectRatio\n";
|
|
|
|
}
|
2003-09-30 13:51:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
2003-09-30 13:51:00 +00:00
|
|
|
{
|
2008-04-03 20:55:09 +00:00
|
|
|
enum {
|
2003-09-30 13:51:00 +00:00
|
|
|
EX_TEMPLATE = 1,
|
|
|
|
EX_FILENAME,
|
|
|
|
EX_DISPLAY,
|
|
|
|
EX_LYXSCALE,
|
2003-12-11 11:16:19 +00:00
|
|
|
EX_DRAFT,
|
2003-10-07 22:59:58 +00:00
|
|
|
EX_BOUNDINGBOX,
|
|
|
|
EX_CLIP,
|
|
|
|
EX_EXTRA,
|
|
|
|
EX_HEIGHT,
|
|
|
|
EX_KEEPASPECTRATIO,
|
|
|
|
EX_ROTATEANGLE,
|
|
|
|
EX_ROTATEORIGIN,
|
|
|
|
EX_SCALE,
|
|
|
|
EX_WIDTH,
|
2003-09-30 13:51:00 +00:00
|
|
|
EX_END
|
|
|
|
};
|
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword external_tags[] = {
|
2003-09-30 13:51:00 +00:00
|
|
|
{ "\\end_inset", EX_END },
|
2003-10-07 22:59:58 +00:00
|
|
|
{ "boundingBox", EX_BOUNDINGBOX },
|
|
|
|
{ "clip", EX_CLIP },
|
2003-09-30 13:51:00 +00:00
|
|
|
{ "display", EX_DISPLAY},
|
2003-12-11 11:16:19 +00:00
|
|
|
{ "draft", EX_DRAFT},
|
2003-10-07 22:59:58 +00:00
|
|
|
{ "extra", EX_EXTRA },
|
2003-09-30 13:51:00 +00:00
|
|
|
{ "filename", EX_FILENAME},
|
2003-10-07 22:59:58 +00:00
|
|
|
{ "height", EX_HEIGHT },
|
|
|
|
{ "keepAspectRatio", EX_KEEPASPECTRATIO },
|
2003-09-30 13:51:00 +00:00
|
|
|
{ "lyxscale", EX_LYXSCALE},
|
2003-10-07 22:59:58 +00:00
|
|
|
{ "rotateAngle", EX_ROTATEANGLE },
|
|
|
|
{ "rotateOrigin", EX_ROTATEORIGIN },
|
|
|
|
{ "scale", EX_SCALE },
|
|
|
|
{ "template", EX_TEMPLATE },
|
|
|
|
{ "width", EX_WIDTH }
|
2003-09-30 13:51:00 +00:00
|
|
|
};
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
PushPopHelper pph(lex, external_tags);
|
2003-09-30 13:51:00 +00:00
|
|
|
|
|
|
|
bool found_end = false;
|
|
|
|
bool read_error = false;
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
switch (lex.lex()) {
|
|
|
|
case EX_TEMPLATE:
|
|
|
|
lex.next();
|
|
|
|
templatename_ = lex.getString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_FILENAME: {
|
2007-01-21 21:46:33 +00:00
|
|
|
lex.eatLine();
|
2003-09-30 13:51:00 +00:00
|
|
|
string const name = lex.getString();
|
2016-01-10 18:46:01 +00:00
|
|
|
filename = buffer.getReferencedFileName(name);
|
2003-09-30 13:51:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-13 17:16:27 +00:00
|
|
|
|
2003-09-30 13:51:00 +00:00
|
|
|
case EX_DISPLAY: {
|
|
|
|
lex.next();
|
2008-06-13 07:34:55 +00:00
|
|
|
display = lex.getString() != "false";
|
2003-09-30 13:51:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-13 17:16:27 +00:00
|
|
|
case EX_LYXSCALE: {
|
2003-09-30 13:51:00 +00:00
|
|
|
lex.next();
|
2017-03-13 17:16:27 +00:00
|
|
|
int const ls = lex.getInteger();
|
|
|
|
// negative values are not accepted.
|
|
|
|
if (ls >= 0)
|
|
|
|
lyxscale = ls;
|
|
|
|
else
|
|
|
|
lex.printError("ExternalInset::read: Wrong lyxscale: $$Token");
|
2003-09-30 13:51:00 +00:00
|
|
|
break;
|
2017-03-13 17:16:27 +00:00
|
|
|
}
|
2003-09-30 13:51:00 +00:00
|
|
|
|
2003-12-11 11:16:19 +00:00
|
|
|
case EX_DRAFT:
|
|
|
|
draft = true;
|
|
|
|
break;
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
case EX_BOUNDINGBOX:
|
|
|
|
lex.next();
|
2015-07-16 20:04:08 +00:00
|
|
|
clipdata.bbox.xl = Length(lex.getString());
|
2003-10-07 22:59:58 +00:00
|
|
|
lex.next();
|
2015-07-16 20:04:08 +00:00
|
|
|
clipdata.bbox.yb = Length(lex.getString());
|
2003-10-07 22:59:58 +00:00
|
|
|
lex.next();
|
2015-07-16 20:04:08 +00:00
|
|
|
clipdata.bbox.xr = Length(lex.getString());
|
2003-10-07 22:59:58 +00:00
|
|
|
lex.next();
|
2015-07-16 20:04:08 +00:00
|
|
|
clipdata.bbox.yt = Length(lex.getString());
|
2003-10-07 22:59:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_CLIP:
|
|
|
|
clipdata.clip = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_EXTRA: {
|
|
|
|
lex.next();
|
|
|
|
string const name = lex.getString();
|
|
|
|
lex.next();
|
|
|
|
extradata.set(name, lex.getString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EX_HEIGHT:
|
|
|
|
lex.next();
|
2007-04-28 12:58:49 +00:00
|
|
|
resizedata.height = Length(lex.getString());
|
2003-10-07 22:59:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_KEEPASPECTRATIO:
|
|
|
|
resizedata.keepAspectRatio = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_ROTATEANGLE:
|
|
|
|
lex.next();
|
2005-01-04 10:59:49 +00:00
|
|
|
rotationdata.angle = lex.getString();
|
2003-10-07 22:59:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_ROTATEORIGIN:
|
|
|
|
lex.next();
|
|
|
|
rotationdata.origin(lex.getString());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_SCALE:
|
|
|
|
lex.next();
|
2005-01-04 10:59:49 +00:00
|
|
|
resizedata.scale = lex.getString();
|
2003-10-07 22:59:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_WIDTH:
|
|
|
|
lex.next();
|
2007-04-28 12:58:49 +00:00
|
|
|
resizedata.width = Length(lex.getString());
|
2003-10-07 22:59:58 +00:00
|
|
|
break;
|
|
|
|
|
2003-09-30 13:51:00 +00:00
|
|
|
case EX_END:
|
|
|
|
found_end = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-11-17 15:32:12 +00:00
|
|
|
lex.printError("ExternalInset::read: Wrong tag: $$Token");
|
2003-09-30 13:51:00 +00:00
|
|
|
read_error = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_end || read_error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
if (!found_end)
|
2003-12-10 21:32:05 +00:00
|
|
|
lex.printError("ExternalInsetParams::read: Missing \\end_inset.");
|
2003-09-30 13:51:00 +00:00
|
|
|
|
|
|
|
// This is a trick to make sure that the data are self-consistent.
|
|
|
|
settemplate(templatename_);
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
if (lyxerr.debugging(Debug::EXTERNAL)) {
|
|
|
|
lyxerr << "InsetExternalParams::read:\n";
|
|
|
|
write(buffer, lyxerr);
|
|
|
|
}
|
2003-09-30 13:51:00 +00:00
|
|
|
|
|
|
|
return !read_error;
|
|
|
|
}
|
2003-09-30 13:58:49 +00:00
|
|
|
|
|
|
|
|
2015-10-04 18:48:31 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
docstring screenLabel(InsetExternalParams const & params,
|
|
|
|
Buffer const & buffer)
|
|
|
|
{
|
|
|
|
external::Template const * const ptr =
|
|
|
|
external::getTemplatePtr(params);
|
|
|
|
if (!ptr)
|
|
|
|
// FIXME UNICODE
|
|
|
|
return bformat((_("External template %1$s is not installed")),
|
|
|
|
from_utf8(params.templatename()));
|
|
|
|
// FIXME UNICODE
|
|
|
|
docstring gui = _(ptr->guiName);
|
|
|
|
gui += ": ";
|
|
|
|
|
|
|
|
if (params.filename.empty())
|
|
|
|
gui += "???";
|
|
|
|
else
|
|
|
|
gui += from_utf8(params.filename.relFileName(buffer.filePath()));
|
|
|
|
|
|
|
|
return gui;
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2015-10-04 18:48:31 +00:00
|
|
|
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetExternal::InsetExternal(Buffer * buf)
|
|
|
|
: Inset(buf), renderer_(new RenderButton)
|
2008-03-25 16:08:39 +00:00
|
|
|
{
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
2010-10-24 19:25:36 +00:00
|
|
|
// Mouse hover is not copied and remains empty
|
2003-06-04 09:16:29 +00:00
|
|
|
InsetExternal::InsetExternal(InsetExternal const & other)
|
2007-04-29 13:39:47 +00:00
|
|
|
: Inset(other),
|
2003-06-04 09:16:29 +00:00
|
|
|
params_(other.params_),
|
2004-04-13 17:25:23 +00:00
|
|
|
renderer_(other.renderer_->clone(this))
|
|
|
|
{}
|
2003-06-04 09:16:29 +00:00
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
InsetExternal::~InsetExternal()
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
hideDialogs("external", this);
|
2010-10-24 19:25:36 +00:00
|
|
|
|
|
|
|
map<BufferView const *, bool>::iterator it = mouse_hover_.begin();
|
|
|
|
map<BufferView const *, bool>::iterator end = mouse_hover_.end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
if (it->second)
|
|
|
|
it->first->clearLastInset(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-14 12:34:46 +00:00
|
|
|
bool InsetExternal::setMouseHover(BufferView const * bv, bool mouse_hover) const
|
2010-10-24 19:25:36 +00:00
|
|
|
{
|
|
|
|
mouse_hover_[bv] = mouse_hover;
|
|
|
|
return true;
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-09 19:27:07 +00:00
|
|
|
void InsetExternal::statusChanged() const
|
2003-06-04 09:16:29 +00:00
|
|
|
{
|
2007-11-17 15:32:12 +00:00
|
|
|
updateFrontend();
|
2003-06-04 09:16:29 +00:00
|
|
|
}
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-03-05 11:30:35 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
2008-04-27 16:20:12 +00:00
|
|
|
case LFUN_INSET_EDIT: {
|
2008-03-24 04:27:43 +00:00
|
|
|
InsetExternalParams p = params();
|
|
|
|
if (!cmd.argument().empty())
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), buffer(), p);
|
2008-02-27 20:43:16 +00:00
|
|
|
external::editExternal(p, buffer());
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-06-11 11:01:34 +00:00
|
|
|
}
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
2003-10-07 20:25:10 +00:00
|
|
|
InsetExternalParams p;
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), buffer(), p);
|
2010-12-08 09:24:04 +00:00
|
|
|
cur.recordUndo();
|
2008-02-27 20:43:16 +00:00
|
|
|
setParams(p);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
}
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2008-03-27 22:26:24 +00:00
|
|
|
cur.bv().updateDialog("external",
|
|
|
|
params2string(params(), cur.bv().buffer()));
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset::doDispatch(cur, cmd);
|
2003-03-07 15:58:02 +00:00
|
|
|
}
|
2003-03-05 11:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2005-04-22 08:57:22 +00:00
|
|
|
|
2008-04-27 16:20:12 +00:00
|
|
|
case LFUN_INSET_EDIT:
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2005-04-22 08:57:22 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
return Inset::getStatus(cur, cmd, flag);
|
2005-04-22 08:57:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-04 18:48:31 +00:00
|
|
|
void InsetExternal::addToToc(DocIterator const & cpit, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType, TocBackend & backend) const
|
2015-10-04 18:48:31 +00:00
|
|
|
{
|
|
|
|
docstring str = screenLabel(params_, buffer());
|
2017-01-13 10:06:48 +00:00
|
|
|
TocBuilder & b = backend.builder("external");
|
2017-01-09 16:37:50 +00:00
|
|
|
b.pushItem(cpit, str, output_active);
|
|
|
|
b.pop();
|
2015-10-04 18:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-10 00:20:12 +00:00
|
|
|
bool InsetExternal::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
|
|
|
bv->showDialog("external", params2string(params(), bv->buffer()),
|
|
|
|
const_cast<InsetExternal *>(this));
|
|
|
|
return true;
|
2003-11-04 12:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-06-04 09:16:29 +00:00
|
|
|
{
|
2003-06-10 11:54:31 +00:00
|
|
|
renderer_->metrics(mi, dim);
|
2003-06-04 09:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
2010-10-24 19:25:36 +00:00
|
|
|
if (renderer_->asButton())
|
|
|
|
renderer_->setRenderState(mouse_hover_[pi.base.bv]);
|
2003-06-10 11:54:31 +00:00
|
|
|
renderer_->draw(pi, x, y);
|
2003-06-04 09:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
graphics::Params get_grfx_params(InsetExternalParams const & eparams)
|
2003-06-04 09:16:29 +00:00
|
|
|
{
|
2003-10-22 22:26:47 +00:00
|
|
|
graphics::Params gparams;
|
2003-06-04 09:16:29 +00:00
|
|
|
|
2008-04-20 03:08:11 +00:00
|
|
|
gparams.filename = eparams.filename;
|
2003-06-04 09:16:29 +00:00
|
|
|
gparams.scale = eparams.lyxscale;
|
2003-10-07 22:59:58 +00:00
|
|
|
if (eparams.clipdata.clip)
|
|
|
|
gparams.bb = eparams.clipdata.bbox;
|
2005-01-27 21:05:44 +00:00
|
|
|
gparams.angle = convert<double>(eparams.rotationdata.adjAngle());
|
2008-06-13 07:34:55 +00:00
|
|
|
gparams.display = eparams.display;
|
2003-06-04 09:16:29 +00:00
|
|
|
|
|
|
|
return gparams;
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2003-06-04 09:16:29 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
static bool isPreviewWanted(InsetExternalParams const & params)
|
|
|
|
{
|
2008-06-13 07:34:55 +00:00
|
|
|
return params.display && params.filename.isReadableFile();
|
2008-02-27 20:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static docstring latexString(InsetExternal const & inset)
|
|
|
|
{
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
odocstringstream ods;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexstream os(ods);
|
2008-02-27 20:43:16 +00:00
|
|
|
// We don't need to set runparams.encoding since it is not used by
|
|
|
|
// latex().
|
|
|
|
OutputParams runparams(0);
|
|
|
|
runparams.flavor = OutputParams::LATEX;
|
|
|
|
inset.latex(os, runparams);
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
return ods.str();
|
2008-02-27 20:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void add_preview_and_start_loading(RenderMonitoredPreview & renderer,
|
|
|
|
InsetExternal const & inset,
|
|
|
|
Buffer const & buffer)
|
|
|
|
{
|
|
|
|
InsetExternalParams const & params = inset.params();
|
|
|
|
|
2014-05-20 10:19:26 +00:00
|
|
|
if (RenderPreview::previewText() && isPreviewWanted(params)) {
|
2008-02-27 20:43:16 +00:00
|
|
|
renderer.setAbsFile(params.filename);
|
|
|
|
docstring const snippet = latexString(inset);
|
|
|
|
renderer.addPreview(snippet, buffer);
|
|
|
|
renderer.startLoading(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
InsetExternalParams const & InsetExternal::params() const
|
2003-07-23 09:17:04 +00:00
|
|
|
{
|
|
|
|
return params_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-21 01:53:47 +00:00
|
|
|
void InsetExternal::updatePreview()
|
|
|
|
{
|
|
|
|
setParams(params_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetExternal::setParams(InsetExternalParams const & p)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2003-09-25 10:49:13 +00:00
|
|
|
params_ = p;
|
2003-06-04 09:16:29 +00:00
|
|
|
|
2004-01-02 21:25:02 +00:00
|
|
|
// Subsequent calls to the InsetExternal::Params default constructor
|
|
|
|
// will use this.
|
|
|
|
defaultTemplateName = params_.templatename();
|
|
|
|
|
2008-06-13 07:34:55 +00:00
|
|
|
if (!external::getTemplatePtr(params_) || params_.filename.empty()
|
|
|
|
|| !params_.display
|
|
|
|
|| !lyxrc.display_graphics
|
|
|
|
|| params_.preview_mode == PREVIEW_OFF
|
|
|
|
|| (params_.preview_mode == PREVIEW_INSTANT
|
2014-05-20 10:19:26 +00:00
|
|
|
&& !RenderPreview::previewText())) {
|
2003-10-25 20:09:52 +00:00
|
|
|
RenderButton * button_ptr = renderer_->asButton();
|
2003-06-12 08:52:36 +00:00
|
|
|
if (!button_ptr) {
|
2003-11-03 17:47:28 +00:00
|
|
|
renderer_.reset(new RenderButton);
|
|
|
|
button_ptr = renderer_->asButton();
|
2003-06-12 08:52:36 +00:00
|
|
|
}
|
2017-05-24 09:28:08 +00:00
|
|
|
button_ptr->update(screenLabel(params_, buffer()), true, false);
|
2008-06-13 07:34:55 +00:00
|
|
|
return;
|
2007-11-17 15:32:12 +00:00
|
|
|
}
|
2003-06-12 08:52:36 +00:00
|
|
|
|
2008-06-13 07:34:55 +00:00
|
|
|
switch (params_.preview_mode) {
|
|
|
|
case PREVIEW_OFF:
|
|
|
|
// Already taken care of above.
|
|
|
|
LASSERT(false, return);
|
|
|
|
break;
|
|
|
|
case PREVIEW_INSTANT: {
|
2017-03-09 21:44:07 +00:00
|
|
|
renderer_ = make_unique<RenderMonitoredPreview>(this);
|
2015-10-09 19:37:43 +00:00
|
|
|
RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview();
|
2017-05-28 11:25:53 +00:00
|
|
|
// This connection is closed at the same time as this is destroyed.
|
2017-03-09 21:44:07 +00:00
|
|
|
preview_ptr->connect([=]() { fileChanged(); });
|
2008-06-13 07:34:55 +00:00
|
|
|
add_preview_and_start_loading(*preview_ptr, *this, buffer());
|
|
|
|
break;
|
2017-03-09 21:44:07 +00:00
|
|
|
}
|
2008-06-13 07:34:55 +00:00
|
|
|
case PREVIEW_GRAPHICS: {
|
2003-10-25 20:09:52 +00:00
|
|
|
RenderGraphic * graphic_ptr = renderer_->asGraphic();
|
2003-06-12 08:52:36 +00:00
|
|
|
if (!graphic_ptr) {
|
2004-04-13 17:25:23 +00:00
|
|
|
renderer_.reset(new RenderGraphic(this));
|
2003-11-03 17:47:28 +00:00
|
|
|
graphic_ptr = renderer_->asGraphic();
|
2003-06-12 08:52:36 +00:00
|
|
|
}
|
2003-07-23 09:17:04 +00:00
|
|
|
graphic_ptr->update(get_grfx_params(params_));
|
2003-10-22 22:26:47 +00:00
|
|
|
break;
|
2003-06-12 08:52:36 +00:00
|
|
|
}
|
2003-10-22 22:26:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::fileChanged() const
|
|
|
|
{
|
2007-11-17 15:32:12 +00:00
|
|
|
Buffer const * const buffer = updateFrontend();
|
|
|
|
if (!buffer)
|
2003-10-22 22:26:47 +00:00
|
|
|
return;
|
|
|
|
|
2003-10-25 20:09:52 +00:00
|
|
|
RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(ptr, return);
|
2003-10-22 22:26:47 +00:00
|
|
|
|
2007-11-17 15:32:12 +00:00
|
|
|
ptr->removePreview(*buffer);
|
|
|
|
add_preview_and_start_loading(*ptr, *this, *buffer);
|
2002-03-21 17:09:55 +00:00
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetExternal::write(ostream & os) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
params_.write(buffer(), os);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetExternal::read(Lexer & lex)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2003-10-07 20:25:10 +00:00
|
|
|
InsetExternalParams params;
|
2008-04-20 03:08:11 +00:00
|
|
|
if (params.read(buffer(), lex))
|
2008-02-27 20:43:16 +00:00
|
|
|
setParams(params);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetExternal::latex(otexstream & os, OutputParams const & runparams) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2003-12-11 11:16:19 +00:00
|
|
|
if (params_.draft) {
|
2006-10-19 16:51:30 +00:00
|
|
|
// FIXME UNICODE
|
2003-12-11 11:16:19 +00:00
|
|
|
os << "\\fbox{\\ttfamily{}"
|
2010-04-21 01:19:25 +00:00
|
|
|
<< from_utf8(params_.filename.outputFileName(buffer().filePath()))
|
2003-12-11 11:16:19 +00:00
|
|
|
<< "}\n";
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2003-12-11 11:16:19 +00:00
|
|
|
}
|
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
// "nice" means that the buffer is exported to LaTeX format but not
|
|
|
|
// run through the LaTeX compiler.
|
|
|
|
// If we're running through the LaTeX compiler, we should write the
|
2007-03-14 20:23:54 +00:00
|
|
|
// generated files in the buffer's temporary directory.
|
2007-02-10 11:03:26 +00:00
|
|
|
bool const external_in_tmpdir = !runparams.nice;
|
|
|
|
bool const dryrun = runparams.dryrun || runparams.inComment;
|
2003-06-04 09:16:29 +00:00
|
|
|
|
2003-05-23 14:36:26 +00:00
|
|
|
// If the template has specified a PDFLaTeX output, then we try and
|
|
|
|
// use that.
|
2003-11-05 12:06:20 +00:00
|
|
|
if (runparams.flavor == OutputParams::PDFLATEX) {
|
2003-10-07 20:25:10 +00:00
|
|
|
external::Template const * const et_ptr =
|
|
|
|
external::getTemplatePtr(params_);
|
2003-06-11 14:30:04 +00:00
|
|
|
if (!et_ptr)
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2003-10-01 10:16:00 +00:00
|
|
|
external::Template const & et = *et_ptr;
|
2003-06-11 14:30:04 +00:00
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
external::Template::Formats::const_iterator cit =
|
2003-05-23 14:36:26 +00:00
|
|
|
et.formats.find("PDFLaTeX");
|
2006-10-19 21:00:33 +00:00
|
|
|
|
|
|
|
if (cit != et.formats.end()) {
|
2014-05-16 12:21:48 +00:00
|
|
|
external::writeExternal(params_, "PDFLaTeX",
|
|
|
|
buffer(), os,
|
|
|
|
*(runparams.exportdata),
|
|
|
|
external_in_tmpdir,
|
|
|
|
dryrun);
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2007-05-28 22:27:45 +00:00
|
|
|
}
|
2003-05-23 14:36:26 +00:00
|
|
|
}
|
2007-02-10 11:08:05 +00:00
|
|
|
|
2014-05-16 12:21:48 +00:00
|
|
|
external::writeExternal(params_, "LaTeX", buffer(), os,
|
|
|
|
*(runparams.exportdata),
|
|
|
|
external_in_tmpdir,
|
|
|
|
dryrun);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetExternal::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const & runparams, size_t) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2013-03-09 17:42:56 +00:00
|
|
|
// this is too slow for constant use
|
|
|
|
if (runparams.for_tooltip)
|
|
|
|
return 0;
|
|
|
|
|
2016-07-31 03:48:27 +00:00
|
|
|
bool const external_in_tmpdir = !runparams.nice;
|
|
|
|
bool const dryrun = runparams.dryrun || runparams.inComment;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexstream ots(os);
|
2014-05-16 12:21:48 +00:00
|
|
|
ots << '\n'; // output external material on a new line
|
|
|
|
external::writeExternal(params_, "Ascii", buffer(), ots,
|
2016-07-31 03:48:27 +00:00
|
|
|
*(runparams.exportdata), external_in_tmpdir, dryrun);
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE;
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetExternal::docbook(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2016-07-31 03:48:27 +00:00
|
|
|
bool const external_in_tmpdir = !runparams.nice;
|
|
|
|
bool const dryrun = runparams.dryrun || runparams.inComment;
|
2014-05-16 12:21:48 +00:00
|
|
|
odocstringstream ods;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexstream ots(ods);
|
2014-05-16 12:21:48 +00:00
|
|
|
external::writeExternal(params_, "DocBook", buffer(), ots,
|
2016-07-31 03:48:27 +00:00
|
|
|
*(runparams.exportdata), external_in_tmpdir, dryrun);
|
2014-05-16 12:21:48 +00:00
|
|
|
os << ods.str();
|
|
|
|
return int(count(ods.str().begin(), ods.str().end(), '\n'));
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-31 02:42:01 +00:00
|
|
|
docstring InsetExternal::xhtml(XHTMLStream & xs,
|
|
|
|
OutputParams const & runparams) const
|
2009-07-13 06:34:05 +00:00
|
|
|
{
|
2016-07-31 02:42:01 +00:00
|
|
|
bool const external_in_tmpdir = !runparams.nice;
|
|
|
|
bool const dryrun = runparams.dryrun || runparams.inComment;
|
|
|
|
odocstringstream ods;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexstream ots(ods);
|
2016-07-31 02:42:01 +00:00
|
|
|
external::writeExternal(params_, "XHTML", buffer(), ots,
|
|
|
|
*(runparams.exportdata), external_in_tmpdir, dryrun);
|
|
|
|
xs << XHTMLStream::ESCAPE_NONE << ods.str();
|
2009-06-18 20:44:38 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetExternal::validate(LaTeXFeatures & features) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2003-12-11 11:16:19 +00:00
|
|
|
if (params_.draft)
|
|
|
|
return;
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
external::Template const * const et_ptr =
|
|
|
|
external::getTemplatePtr(params_);
|
2003-06-11 14:30:04 +00:00
|
|
|
if (!et_ptr)
|
|
|
|
return;
|
2003-10-01 10:16:00 +00:00
|
|
|
external::Template const & et = *et_ptr;
|
2003-06-11 14:30:04 +00:00
|
|
|
|
2006-03-28 18:49:46 +00:00
|
|
|
string format;
|
|
|
|
switch (features.runparams().flavor) {
|
|
|
|
case OutputParams::LATEX:
|
2011-08-10 02:23:44 +00:00
|
|
|
case OutputParams::DVILUATEX:
|
2006-03-28 18:49:46 +00:00
|
|
|
format = "LaTeX";
|
|
|
|
break;
|
2010-11-23 16:07:42 +00:00
|
|
|
case OutputParams::LUATEX:
|
2006-03-28 18:49:46 +00:00
|
|
|
case OutputParams::PDFLATEX:
|
2009-04-08 07:55:55 +00:00
|
|
|
case OutputParams::XETEX:
|
2006-03-28 18:49:46 +00:00
|
|
|
format = "PDFLaTeX";
|
|
|
|
break;
|
|
|
|
case OutputParams::XML:
|
|
|
|
format = "DocBook";
|
|
|
|
break;
|
2009-11-02 15:15:47 +00:00
|
|
|
case OutputParams::HTML:
|
|
|
|
format = "html";
|
|
|
|
break;
|
2009-11-16 17:37:51 +00:00
|
|
|
case OutputParams::TEXT:
|
|
|
|
format = "text";
|
|
|
|
break;
|
2012-06-05 02:01:26 +00:00
|
|
|
case OutputParams::LYX:
|
|
|
|
format = "lyx";
|
|
|
|
break;
|
2006-03-28 18:49:46 +00:00
|
|
|
}
|
2003-10-07 20:25:10 +00:00
|
|
|
external::Template::Formats::const_iterator cit =
|
2006-03-28 18:49:46 +00:00
|
|
|
et.formats.find(format);
|
2008-04-13 12:50:35 +00:00
|
|
|
|
|
|
|
if (cit == et.formats.end()) {
|
|
|
|
// If the template has not specified a PDFLaTeX output,
|
|
|
|
// we try the LaTeX format.
|
|
|
|
if (format == "PDFLaTeX") {
|
|
|
|
cit = et.formats.find("LaTeX");
|
|
|
|
if (cit == et.formats.end())
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2011-10-31 20:27:21 +00:00
|
|
|
// FIXME: We don't need that always, see InsetGraphics
|
2005-07-10 09:31:27 +00:00
|
|
|
features.require("lyxdot");
|
|
|
|
|
2005-04-05 11:00:09 +00:00
|
|
|
vector<string>::const_iterator it = cit->second.requirements.begin();
|
|
|
|
vector<string>::const_iterator end = cit->second.requirements.end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
features.require(*it);
|
2003-09-04 17:01:00 +00:00
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
external::TemplateManager & etm = external::TemplateManager::get();
|
2003-09-23 17:04:25 +00:00
|
|
|
|
2016-09-25 10:37:40 +00:00
|
|
|
for (string const & name : cit->second.preambleNames) {
|
|
|
|
docstring const preamble = etm.getPreambleDefByName(name);
|
2003-09-23 17:04:25 +00:00
|
|
|
if (!preamble.empty())
|
2007-01-20 17:08:39 +00:00
|
|
|
features.addPreambleSnippet(preamble);
|
2003-09-23 17:04:25 +00:00
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-22 20:50:35 +00:00
|
|
|
void InsetExternal::addPreview(DocIterator const & /*inset_pos*/,
|
2017-03-09 21:44:07 +00:00
|
|
|
graphics::PreviewLoader & ploader) const
|
2003-10-22 22:26:47 +00:00
|
|
|
{
|
2003-10-25 20:09:52 +00:00
|
|
|
RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
|
|
|
|
if (!ptr)
|
2003-10-22 22:26:47 +00:00
|
|
|
return;
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
if (isPreviewWanted(params())) {
|
2006-11-26 21:30:39 +00:00
|
|
|
ptr->setAbsFile(params_.filename);
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring const snippet = latexString(*this);
|
2003-10-25 20:09:52 +00:00
|
|
|
ptr->addPreview(snippet, ploader);
|
2003-10-22 22:26:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetExternal::contextMenuName() const
|
2008-04-28 05:12:28 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-external";
|
2008-04-28 05:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
void InsetExternal::string2params(string const & in, Buffer const & buffer,
|
|
|
|
InsetExternalParams & params)
|
2003-03-05 11:30:35 +00:00
|
|
|
{
|
2003-10-07 20:25:10 +00:00
|
|
|
params = InsetExternalParams();
|
2003-04-24 20:02:49 +00:00
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2003-03-07 14:08:10 +00:00
|
|
|
lex.setStream(data);
|
2003-03-05 11:30:35 +00:00
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
string name;
|
|
|
|
lex >> name;
|
2008-03-27 22:26:24 +00:00
|
|
|
if (!lex || name != "external") {
|
|
|
|
LYXERR0("InsetExternal::string2params(" << in << ")\n"
|
|
|
|
"Expected arg 1 to be \"external\"\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-03-05 11:30:35 +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;
|
2008-03-27 22:26:24 +00:00
|
|
|
if (!lex || id != "External") {
|
|
|
|
LYXERR0("InsetExternal::string2params(" << in << ")\n"
|
|
|
|
"Expected arg 2 to be \"External\"\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-03-05 11:30:35 +00:00
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
params.read(buffer, lex);
|
2003-03-05 11:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
string InsetExternal::params2string(InsetExternalParams const & params,
|
|
|
|
Buffer const & buffer)
|
2003-03-05 11:30:35 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
2008-03-27 22:26:24 +00:00
|
|
|
data << "external" << ' ';
|
2003-09-30 13:51:00 +00:00
|
|
|
params.write(buffer, data);
|
2003-03-05 11:30:35 +00:00
|
|
|
data << "\\end_inset\n";
|
2003-09-15 11:00:00 +00:00
|
|
|
return data.str();
|
2003-03-05 11:30:35 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|