#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_latex.h"
+#include "texstream.h"
+#include "TocBackend.h"
#include "frontends/alert.h"
#include "frontends/Application.h"
#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
+#include "support/TempFile.h"
#include <sstream>
#include <vector>
TempName::TempName()
{
- FileName const tempname = FileName::tempName("lyxext");
// must have an extension for the converter code to work correctly.
- tempname_ = FileName(tempname.absFileName() + ".tmp");
+ 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();
}
-TempName::TempName(TempName const &)
+TempName::TempName(TempName const & that)
{
- tempname_ = TempName()();
+ *this = that;
}
TempName & TempName::operator=(TempName const & other)
{
- if (this != &other)
- tempname_ = TempName()();
+ if (this != &other) {
+ tempname_.removeFile();
+ support::TempFile f("lyxextXXXXXX.tmp");
+ f.setAutoRemove(false);
+ tempname_ = f.name();
+ }
return *this;
}
+
+support::FileName TempName::operator()() const
+{
+ return tempname_;
+}
+
} // namespace external
InsetExternalParams::InsetExternalParams()
: display(true),
+ preview_mode(PREVIEW_OFF),
lyxscale(defaultLyxScale),
draft(false)
{
case EX_FILENAME: {
lex.eatLine();
string const name = lex.getString();
- filename.set(name, buffer.filePath());
+ filename = buffer.getReferencedFileName(name);
break;
}
case EX_BOUNDINGBOX:
lex.next();
- clipdata.bbox.xl = lex.getInteger();
+ clipdata.bbox.xl = Length(lex.getString());
lex.next();
- clipdata.bbox.yb = lex.getInteger();
+ clipdata.bbox.yb = Length(lex.getString());
lex.next();
- clipdata.bbox.xr = lex.getInteger();
+ clipdata.bbox.xr = Length(lex.getString());
lex.next();
- clipdata.bbox.yt = lex.getInteger();
+ clipdata.bbox.yt = Length(lex.getString());
break;
case EX_CLIP:
if (lyxerr.debugging(Debug::EXTERNAL)) {
lyxerr << "InsetExternalParams::read:\n";
+ // false positive
+ // coverity[NEGATIVE_RETURNS]
write(buffer, lyxerr);
}
}
+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;
+}
+
+} // namespace anon
+
+
+
InsetExternal::InsetExternal(Buffer * buf)
: Inset(buf), renderer_(new RenderButton)
{
// Mouse hover is not copied and remains empty
InsetExternal::InsetExternal(InsetExternal const & other)
: Inset(other),
- boost::signals::trackable(),
+ boost::signals2::trackable(),
params_(other.params_),
renderer_(other.renderer_->clone(this))
{}
}
+void InsetExternal::addToToc(DocIterator const & cpit, bool output_active,
+ UpdateType) const
+{
+ DocIterator pit = cpit;
+ pit.push_back(CursorSlice(const_cast<InsetExternal &>(*this)));
+ shared_ptr<Toc> toc = buffer().tocBackend().toc("external");
+ docstring str = screenLabel(params_, buffer());
+ toc->push_back(TocItem(pit, 0, str, output_active));
+}
+
+
bool InsetExternal::showInsetDialog(BufferView * bv) const
{
bv->showDialog("external", params2string(params(), bv->buffer()),
return gparams;
}
-
-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;
-}
-
} // namespace anon
static docstring latexString(InsetExternal const & inset)
{
- TexRow texrow;
odocstringstream ods;
- otexstream os(ods, texrow);
+ otexstream os(ods, false);
// We don't need to set runparams.encoding since it is not used by
// latex().
OutputParams runparams(0);
LASSERT(false, return);
break;
case PREVIEW_INSTANT: {
- RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview();
renderer_.reset(new RenderMonitoredPreview(this));
- preview_ptr = renderer_->asMonitoredPreview();
+ RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview();
preview_ptr->fileChanged(bind(&InsetExternal::fileChanged, this));
if (preview_ptr->monitoring())
preview_ptr->stopMonitoring();
if (runparams.for_tooltip)
return 0;
- TexRow texrow;
- otexstream ots(os, texrow);
+ otexstream ots(os, false);
ots << '\n'; // output external material on a new line
external::writeExternal(params_, "Ascii", buffer(), ots,
*(runparams.exportdata), false,
int InsetExternal::docbook(odocstream & os,
OutputParams const & runparams) const
{
- TexRow texrow;
odocstringstream ods;
- otexstream ots(ods, texrow);
+ otexstream ots(ods, false);
external::writeExternal(params_, "DocBook", buffer(), ots,
*(runparams.exportdata), false,
runparams.dryrun || runparams.inComment);