#include "InsetExternal.h"
#include "insets/ExternalSupport.h"
-#include "insets/ExternalTemplate.h"
#include "insets/RenderButton.h"
#include "insets/RenderGraphic.h"
#include "insets/RenderPreview.h"
#include "LyXRC.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
+#include "output_latex.h"
#include "frontends/alert.h"
#include "frontends/Application.h"
#include "graphics/PreviewLoader.h"
+#include "support/convert.h"
#include "support/debug.h"
#include "support/ExceptionMessage.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
-#include "support/convert.h"
#include "support/Translator.h"
#include <boost/bind.hpp>
namespace {
-lyx::external::DisplayType const defaultDisplayType = lyx::external::NoDisplay;
-
unsigned int const defaultLyxScale = 100;
string defaultTemplateName;
TempName::TempName()
{
FileName const tempname = FileName::tempName("lyxext");
- // FIXME: This is unsafe
- tempname.removeFile();
// must have an extension for the converter code to work correctly.
tempname_ = FileName(tempname.absFilename() + ".tmp");
}
return *this;
}
-
-namespace {
-
-/// The translator between the Display enum and corresponding lyx string.
-Translator<DisplayType, string> const initTranslator()
-{
- Translator<DisplayType, string> translator(DefaultDisplay, "default");
-
- // Fill the display translator
- translator.addPair(MonochromeDisplay, "monochrome");
- translator.addPair(GrayscaleDisplay, "grayscale");
- translator.addPair(ColorDisplay, "color");
- translator.addPair(PreviewDisplay, "preview");
- translator.addPair(NoDisplay, "none");
-
- return translator;
-}
-
-} // namespace anon
-
-
-Translator<DisplayType, string> const & displayTranslator()
-{
- static Translator<DisplayType, string> const translator =
- initTranslator();
- return translator;
-}
-
} // namespace external
InsetExternalParams::InsetExternalParams()
- : display(defaultDisplayType),
+ : display(true),
lyxscale(defaultLyxScale),
draft(false)
{
if (defaultTemplateName.empty()) {
external::TemplateManager const & etm =
external::TemplateManager::get();
- templatename_ = etm.getTemplates().begin()->first;
+ if (!etm.getTemplates().empty())
+ templatename_ = etm.getTemplates().begin()->first;
} else
templatename_ = defaultTemplateName;
}
clearIfNotFound(extradata, external::Extra, ids);
clearIfNotFound(resizedata, external::Resize, ids);
clearIfNotFound(rotationdata, external::Rotate, ids);
+
+ //
+ preview_mode = et->preview_mode;
}
if (!filename.empty())
os << "\tfilename " << filename.outputFilename(buf.filePath()) << '\n';
- if (display != defaultDisplayType)
- os << "\tdisplay "
- << external::displayTranslator().find(display)
- << '\n';
+ if (!display)
+ os << "\tdisplay false\n";
if (lyxscale != defaultLyxScale)
os << "\tlyxscale " << convert<string>(lyxscale) << '\n';
case EX_DISPLAY: {
lex.next();
- string const name = lex.getString();
- display = external::displayTranslator().find(name);
+ display = lex.getString() != "false";
break;
}
}
-InsetExternal::InsetExternal(Buffer & buf)
- : renderer_(new RenderButton)
+InsetExternal::InsetExternal(Buffer * buf)
+ : Inset(buf), renderer_(new RenderButton)
{
- Inset::setBuffer(buf);
}
params2string(params(), cur.bv().buffer()));
break;
- case LFUN_MOUSE_RELEASE:
- if (!cur.selection() && cmd.button() == mouse_button::button1)
- cur.bv().showDialog("external",
- params2string(params(), cur.bv().buffer()),
- this);
- break;
-
default:
Inset::doDispatch(cur, cmd);
}
case LFUN_INSET_EDIT:
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
- flag.enabled(true);
+ flag.setEnabled(true);
return true;
default:
}
-void InsetExternal::edit(Cursor & cur, bool, EntryDirection)
+bool InsetExternal::showInsetDialog(BufferView * bv) const
{
- cur.bv().showDialog("external",
- params2string(params(), cur.bv().buffer()),
- this);
+ bv->showDialog("external", params2string(params(), bv->buffer()),
+ const_cast<InsetExternal *>(this));
+ return true;
}
namespace {
-enum RenderType {
- RENDERBUTTON,
- RENDERGRAPHIC,
- RENDERPREVIEW
-};
-
-
-RenderType getRenderType(InsetExternalParams const & p)
-{
- if (!external::getTemplatePtr(p) ||
- p.filename.empty() ||
- p.display == external::NoDisplay)
- return RENDERBUTTON;
-
- if (p.display == external::PreviewDisplay) {
- if (RenderPreview::status() != LyXRC::PREVIEW_OFF)
- return RENDERPREVIEW;
- return RENDERBUTTON;
- }
-
- if (p.display == external::DefaultDisplay &&
- lyxrc.display_graphics == graphics::NoDisplay)
- return RENDERBUTTON;
- return RENDERGRAPHIC;
-}
-
-
graphics::Params get_grfx_params(InsetExternalParams const & eparams)
{
graphics::Params gparams;
if (eparams.clipdata.clip)
gparams.bb = eparams.clipdata.bbox;
gparams.angle = convert<double>(eparams.rotationdata.adjAngle());
-
- switch (eparams.display) {
- case external::DefaultDisplay:
- gparams.display = graphics::DefaultDisplay;
- break;
- case external::MonochromeDisplay:
- gparams.display = graphics::MonochromeDisplay;
- break;
- case external::GrayscaleDisplay:
- gparams.display = graphics::GrayscaleDisplay;
- break;
- case external::ColorDisplay:
- gparams.display = graphics::ColorDisplay;
- break;
- case external::NoDisplay:
- gparams.display = graphics::NoDisplay;
- break;
- default:
- LASSERT(false, /**/);
- }
- if (gparams.display == graphics::DefaultDisplay)
- gparams.display = graphics::DisplayType(lyxrc.display_graphics);
- // Override the above if we're not using a gui
- if (!use_gui)
- gparams.display = graphics::NoDisplay;
+ gparams.display = eparams.display;
return gparams;
}
static bool isPreviewWanted(InsetExternalParams const & params)
{
- return params.display == external::PreviewDisplay &&
- params.filename.isReadableFile();
+ return params.display && params.filename.isReadableFile();
}
}
+void InsetExternal::updatePreview()
+{
+ setParams(params_);
+}
+
+
void InsetExternal::setParams(InsetExternalParams const & p)
{
params_ = p;
// will use this.
defaultTemplateName = params_.templatename();
- switch (getRenderType(params_)) {
- case RENDERBUTTON: {
+ 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)) {
RenderButton * button_ptr = renderer_->asButton();
if (!button_ptr) {
renderer_.reset(new RenderButton);
button_ptr = renderer_->asButton();
}
-
button_ptr->update(screenLabel(params_, buffer()), true);
- break;
+ return;
}
- case RENDERGRAPHIC: {
+ 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: {
RenderGraphic * graphic_ptr = renderer_->asGraphic();
if (!graphic_ptr) {
renderer_.reset(new RenderGraphic(this));
graphic_ptr = renderer_->asGraphic();
}
-
graphic_ptr->update(get_grfx_params(params_));
-
- break;
- }
-
- case RENDERPREVIEW: {
- RenderMonitoredPreview * preview_ptr =
- renderer_->asMonitoredPreview();
- if (!preview_ptr) {
- 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;
}
}
}
+docstring InsetExternal::xhtml(XHTMLStream & /*xs*/,
+ OutputParams const & /*rp*/) const
+{
+// external::writeExternal(params_, "XHTML", buffer(), os,
+// *(runparams.exportdata), false,
+// runparams.dryrun || runparams.inComment);
+ return docstring();
+}
+
+
void InsetExternal::validate(LaTeXFeatures & features) const
{
if (params_.draft)
format = "LaTeX";
break;
case OutputParams::PDFLATEX:
+ case OutputParams::XETEX:
format = "PDFLaTeX";
break;
case OutputParams::XML:
format = "DocBook";
break;
+ case OutputParams::HTML:
+ format = "html";
+ break;
+ case OutputParams::TEXT:
+ format = "text";
+ break;
}
external::Template::Formats::const_iterator cit =
et.formats.find(format);
}
-void InsetExternal::addPreview(graphics::PreviewLoader & ploader) const
+void InsetExternal::addPreview(DocIterator const & /*inset_pos*/,
+ graphics::PreviewLoader & ploader) const
{
RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
if (!ptr)
}
+docstring InsetExternal::contextMenu(BufferView const &, int, int) const
+{
+ return from_ascii("context-external");
+}
+
+
void InsetExternal::string2params(string const & in, Buffer const & buffer,
InsetExternalParams & params)
{