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"
|
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"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-09-04 01:44:16 +00:00
|
|
|
#include "support/lyxlib.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
#include "support/Translator.h"
|
2000-11-28 06:46:06 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
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
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
TempName::TempName()
|
2003-06-11 11:01:34 +00:00
|
|
|
{
|
2007-12-16 09:52:36 +00:00
|
|
|
FileName const tempname = FileName::tempName("lyxext");
|
2003-06-11 11:01:34 +00:00
|
|
|
// must have an extension for the converter code to work correctly.
|
2007-12-12 19:57:42 +00:00
|
|
|
tempname_ = FileName(tempname.absFilename() + ".tmp");
|
2003-06-11 11:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
TempName::TempName(TempName const &)
|
2003-06-11 11:01:34 +00:00
|
|
|
{
|
2003-09-25 10:49:13 +00:00
|
|
|
tempname_ = TempName()();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
TempName::~TempName()
|
2003-09-25 10:49:13 +00:00
|
|
|
{
|
2007-11-28 09:01:49 +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
|
|
|
{
|
|
|
|
if (this != &other)
|
|
|
|
tempname_ = TempName()();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
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),
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
//
|
|
|
|
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())
|
2008-02-27 20:43:16 +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();
|
|
|
|
filename.set(name, buffer.filePath());
|
|
|
|
break;
|
|
|
|
}
|
2008-01-08 16:42:28 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EX_LYXSCALE:
|
|
|
|
lex.next();
|
|
|
|
lyxscale = lex.getInteger();
|
|
|
|
break;
|
|
|
|
|
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();
|
|
|
|
clipdata.bbox.xl = lex.getInteger();
|
|
|
|
lex.next();
|
|
|
|
clipdata.bbox.yb = lex.getInteger();
|
|
|
|
lex.next();
|
|
|
|
clipdata.bbox.xr = lex.getInteger();
|
|
|
|
lex.next();
|
|
|
|
clipdata.bbox.yt = lex.getInteger();
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
boost::signals::trackable(),
|
|
|
|
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);
|
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
|
|
|
{
|
2003-03-07 15:58:02 +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);
|
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
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2003-06-11 14:30:04 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring screenLabel(InsetExternalParams const & params,
|
2003-08-28 07:41:31 +00:00
|
|
|
Buffer const & buffer)
|
2003-06-11 14:30:04 +00:00
|
|
|
{
|
2003-10-07 20:25:10 +00:00
|
|
|
external::Template const * const ptr =
|
|
|
|
external::getTemplatePtr(params);
|
2003-06-11 14:30:04 +00:00
|
|
|
if (!ptr)
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
2007-12-12 19:57:42 +00:00
|
|
|
return bformat((_("External template %1$s is not installed")),
|
2006-10-21 00:16:43 +00:00
|
|
|
from_utf8(params.templatename()));
|
2006-10-11 19:40:50 +00:00
|
|
|
// FIXME UNICODE
|
2007-06-23 07:50:13 +00:00
|
|
|
docstring gui = _(ptr->guiName);
|
2006-10-21 00:16:43 +00:00
|
|
|
return from_utf8(external::doSubstitution(params, buffer,
|
2007-06-23 07:50:13 +00:00
|
|
|
to_utf8(gui), false));
|
2003-06-11 14:30:04 +00:00
|
|
|
}
|
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
odocstringstream os;
|
|
|
|
// 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);
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void add_preview_and_start_loading(RenderMonitoredPreview & renderer,
|
|
|
|
InsetExternal const & inset,
|
|
|
|
Buffer const & buffer)
|
|
|
|
{
|
|
|
|
InsetExternalParams const & params = inset.params();
|
|
|
|
|
|
|
|
if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
|
|
|
|
isPreviewWanted(params)) {
|
|
|
|
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
|
|
|
|
&& RenderPreview::status() == LyXRC::PREVIEW_OFF)) {
|
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
|
|
|
}
|
2008-02-27 20:43:16 +00:00
|
|
|
button_ptr->update(screenLabel(params_, buffer()), true);
|
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: {
|
|
|
|
RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview();
|
|
|
|
renderer_.reset(new RenderMonitoredPreview(this));
|
|
|
|
preview_ptr = renderer_->asMonitoredPreview();
|
|
|
|
preview_ptr->fileChanged(boost::bind(&InsetExternal::fileChanged, this));
|
|
|
|
if (preview_ptr->monitoring())
|
|
|
|
preview_ptr->stopMonitoring();
|
|
|
|
add_preview_and_start_loading(*preview_ptr, *this, buffer());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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();
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(ptr, /**/);
|
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
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetExternal::latex(odocstream & 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{}"
|
2008-02-27 20:43:16 +00:00
|
|
|
<< from_utf8(params_.filename.outputFilename(buffer().filePath()))
|
2003-12-11 11:16:19 +00:00
|
|
|
<< "}\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
return 0;
|
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()) {
|
2003-10-07 20:25:10 +00:00
|
|
|
return external::writeExternal(params_, "PDFLaTeX",
|
2008-02-27 20:43:16 +00:00
|
|
|
buffer(), os,
|
2007-05-28 22:27:45 +00:00
|
|
|
*(runparams.exportdata),
|
|
|
|
external_in_tmpdir,
|
|
|
|
dryrun);
|
|
|
|
}
|
2003-05-23 14:36:26 +00:00
|
|
|
}
|
2007-02-10 11:08:05 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
return external::writeExternal(params_, "LaTeX", buffer(), os,
|
2007-05-28 22:27:45 +00:00
|
|
|
*(runparams.exportdata),
|
|
|
|
external_in_tmpdir,
|
|
|
|
dryrun);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetExternal::plaintext(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2007-02-18 10:57:23 +00:00
|
|
|
os << '\n'; // output external material on a new line
|
2008-02-27 20:43:16 +00:00
|
|
|
external::writeExternal(params_, "Ascii", buffer(), os,
|
2007-05-28 22:27:45 +00:00
|
|
|
*(runparams.exportdata), false,
|
|
|
|
runparams.dryrun || runparams.inComment);
|
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
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
return external::writeExternal(params_, "DocBook", buffer(), os,
|
2006-04-05 23:56:29 +00:00
|
|
|
*(runparams.exportdata), false,
|
2007-05-28 22:27:45 +00:00
|
|
|
runparams.dryrun || runparams.inComment);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 23:26:10 +00:00
|
|
|
docstring InsetExternal::xhtml(XHTMLStream & /*xs*/,
|
2009-07-13 06:34:05 +00:00
|
|
|
OutputParams const & /*rp*/) const
|
|
|
|
{
|
2009-06-18 20:44:38 +00:00
|
|
|
// external::writeExternal(params_, "XHTML", buffer(), os,
|
|
|
|
// *(runparams.exportdata), false,
|
|
|
|
// runparams.dryrun || runparams.inComment);
|
|
|
|
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:
|
|
|
|
format = "LaTeX";
|
|
|
|
break;
|
|
|
|
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;
|
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
|
|
|
|
2005-07-10 09:31:27 +00:00
|
|
|
// FIXME: We don't need that always
|
|
|
|
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
|
|
|
|
2005-04-05 11:00:09 +00:00
|
|
|
it = cit->second.preambleNames.begin();
|
|
|
|
end = cit->second.preambleNames.end();
|
2003-09-23 17:04:25 +00:00
|
|
|
for (; it != end; ++it) {
|
|
|
|
string const preamble = etm.getPreambleDefByName(*it);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
void InsetExternal::addPreview(graphics::PreviewLoader & ploader) const
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-28 05:12:28 +00:00
|
|
|
docstring InsetExternal::contextMenu(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
return from_ascii("context-external");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|