X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetExternal.cpp;h=ea51664978c33fca4dee8ea53e9d1791182b3240;hb=dbb1ac30e9a87007af7c53f0f93ec9e21826f90b;hp=1fafc96a6e26500e353513de873a7ebf9f63969b;hpb=8195925175605a47d55f53a4d313ccf48a6b29d1;p=lyx.git diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 1fafc96a6e..ea51664978 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -29,24 +29,25 @@ #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/bind.h" #include "support/convert.h" #include "support/debug.h" #include "support/ExceptionMessage.h" #include "support/filetools.h" #include "support/gettext.h" +#include "support/lassert.h" #include "support/lstrings.h" #include "support/lyxlib.h" -#include "support/Translator.h" - -#include #include +#include using namespace std; using namespace lyx::support; @@ -70,7 +71,7 @@ TempName::TempName() { FileName const tempname = FileName::tempName("lyxext"); // must have an extension for the converter code to work correctly. - tempname_ = FileName(tempname.absFilename() + ".tmp"); + tempname_ = FileName(tempname.absFileName() + ".tmp"); } @@ -104,7 +105,8 @@ InsetExternalParams::InsetExternalParams() 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; } @@ -159,7 +161,7 @@ void InsetExternalParams::write(Buffer const & buf, ostream & os) const << "\ttemplate " << templatename() << '\n'; if (!filename.empty()) - os << "\tfilename " << filename.outputFilename(buf.filePath()) << '\n'; + os << "\tfilename " << filename.outputFileName(buf.filePath()) << '\n'; if (!display) os << "\tdisplay false\n"; @@ -363,13 +365,13 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex) } -InsetExternal::InsetExternal(Buffer & buf) - : renderer_(new RenderButton) +InsetExternal::InsetExternal(Buffer * buf) + : Inset(buf), renderer_(new RenderButton) { - Inset::setBuffer(buf); } +// Mouse hover is not copied and remains empty InsetExternal::InsetExternal(InsetExternal const & other) : Inset(other), boost::signals::trackable(), @@ -381,6 +383,19 @@ InsetExternal::InsetExternal(InsetExternal const & other) InsetExternal::~InsetExternal() { hideDialogs("external", this); + + map::iterator it = mouse_hover_.begin(); + map::iterator end = mouse_hover_.end(); + for (; it != end; ++it) + if (it->second) + it->first->clearLastInset(this); +} + + +bool InsetExternal::setMouseHover(BufferView const * bv, bool mouse_hover) +{ + mouse_hover_[bv] = mouse_hover; + return true; } @@ -392,7 +407,7 @@ void InsetExternal::statusChanged() const void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd) { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_INSET_EDIT: { InsetExternalParams p = params(); @@ -405,6 +420,7 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_MODIFY: { InsetExternalParams p; string2params(to_utf8(cmd.argument()), buffer(), p); + cur.recordUndo(); setParams(p); break; } @@ -414,13 +430,6 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd) 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); } @@ -430,7 +439,7 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd) bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_INSET_EDIT: case LFUN_INSET_MODIFY: @@ -444,11 +453,11 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd, } -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(this)); + return true; } @@ -460,6 +469,8 @@ void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const void InsetExternal::draw(PainterInfo & pi, int x, int y) const { + if (renderer_->asButton()) + renderer_->setRenderState(mouse_hover_[pi.base.bv]); renderer_->draw(pi, x, y); } @@ -492,8 +503,14 @@ docstring screenLabel(InsetExternalParams const & params, from_utf8(params.templatename())); // FIXME UNICODE docstring gui = _(ptr->guiName); - return from_utf8(external::doSubstitution(params, buffer, - to_utf8(gui), false)); + gui += ": "; + + if (params.filename.empty()) + gui += "???"; + else + gui += from_utf8(params.filename.relFileName(buffer.filePath())); + + return gui; } } // namespace anon @@ -507,13 +524,15 @@ static bool isPreviewWanted(InsetExternalParams const & params) static docstring latexString(InsetExternal const & inset) { - odocstringstream os; + TexRow texrow; + odocstringstream ods; + otexstream os(ods, texrow); // 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(); + return ods.str(); } @@ -539,6 +558,12 @@ InsetExternalParams const & InsetExternal::params() const } +void InsetExternal::updatePreview() +{ + setParams(params_); +} + + void InsetExternal::setParams(InsetExternalParams const & p) { params_ = p; @@ -571,7 +596,7 @@ void InsetExternal::setParams(InsetExternalParams const & p) RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview(); renderer_.reset(new RenderMonitoredPreview(this)); preview_ptr = renderer_->asMonitoredPreview(); - preview_ptr->fileChanged(boost::bind(&InsetExternal::fileChanged, this)); + preview_ptr->fileChanged(bind(&InsetExternal::fileChanged, this)); if (preview_ptr->monitoring()) preview_ptr->stopMonitoring(); add_preview_and_start_loading(*preview_ptr, *this, buffer()); @@ -618,14 +643,14 @@ void InsetExternal::read(Lexer & lex) } -int InsetExternal::latex(odocstream & os, OutputParams const & runparams) const +void InsetExternal::latex(otexstream & os, OutputParams const & runparams) const { if (params_.draft) { // FIXME UNICODE os << "\\fbox{\\ttfamily{}" - << from_utf8(params_.filename.outputFilename(buffer().filePath())) + << from_utf8(params_.filename.outputFileName(buffer().filePath())) << "}\n"; - return 1; + return; } // "nice" means that the buffer is exported to LaTeX format but not @@ -641,25 +666,28 @@ int InsetExternal::latex(odocstream & os, OutputParams const & runparams) const external::Template const * const et_ptr = external::getTemplatePtr(params_); if (!et_ptr) - return 0; + return; external::Template const & et = *et_ptr; external::Template::Formats::const_iterator cit = et.formats.find("PDFLaTeX"); if (cit != et.formats.end()) { - return external::writeExternal(params_, "PDFLaTeX", - buffer(), os, - *(runparams.exportdata), - external_in_tmpdir, - dryrun); + int l = external::writeExternal(params_, "PDFLaTeX", + buffer(), os.os(), + *(runparams.exportdata), + external_in_tmpdir, + dryrun); + os.texrow().newlines(l); + return; } } - return external::writeExternal(params_, "LaTeX", buffer(), os, - *(runparams.exportdata), - external_in_tmpdir, - dryrun); + int l = external::writeExternal(params_, "LaTeX", buffer(), os.os(), + *(runparams.exportdata), + external_in_tmpdir, + dryrun); + os.texrow().newlines(l); } @@ -683,6 +711,16 @@ int InsetExternal::docbook(odocstream & os, } +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) @@ -697,14 +735,26 @@ void InsetExternal::validate(LaTeXFeatures & features) const string format; switch (features.runparams().flavor) { case OutputParams::LATEX: + case OutputParams::DVILUATEX: format = "LaTeX"; break; + case OutputParams::LUATEX: 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; + case OutputParams::LYX: + format = "lyx"; + break; } external::Template::Formats::const_iterator cit = et.formats.find(format); @@ -720,7 +770,7 @@ void InsetExternal::validate(LaTeXFeatures & features) const return; } - // FIXME: We don't need that always + // FIXME: We don't need that always, see InsetGraphics features.require("lyxdot"); vector::const_iterator it = cit->second.requirements.begin(); @@ -740,7 +790,8 @@ void InsetExternal::validate(LaTeXFeatures & features) const } -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) @@ -754,9 +805,9 @@ void InsetExternal::addPreview(graphics::PreviewLoader & ploader) const } -docstring InsetExternal::contextMenu(BufferView const &, int, int) const +string InsetExternal::contextMenuName() const { - return from_ascii("context-external"); + return "context-external"; }