From 68be651e890d643359062aa9cb980ffcc4812840 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Sun, 4 Oct 2015 19:48:31 +0100 Subject: [PATCH] Add TOC of external materials. (#7790, partial) Known issues (non-regressions): * The TOC is not updated immediately after an external material inset is inserted. See TocBackend::updateItem(). --- src/TocBackend.cpp | 4 +++ src/TocBackend.h | 1 + src/frontends/qt4/qt_helpers.cpp | 2 ++ src/insets/InsetExternal.cpp | 61 ++++++++++++++++++++------------ src/insets/InsetExternal.h | 3 ++ 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 145a23b3cc..8e90a3bb12 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -80,6 +80,8 @@ docstring const TocItem::asString() const return prefix + str_; } +namespace { + // convert a DocIterator into an argument to LFUN_PARAGRAPH_GOTO docstring paragraph_goto_arg(DocIterator const & dit) { @@ -88,6 +90,8 @@ docstring paragraph_goto_arg(DocIterator const & dit) convert(s.pos()); } +} // namespace anon + FuncRequest TocItem::action() const { if (action_.action() == LFUN_UNKNOWN_ACTION) { diff --git a/src/TocBackend.h b/src/TocBackend.h index 9290d9c527..e18f1bc094 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -56,6 +56,7 @@ enum TocType { LISTING,//"listings" FLOAT,//"figure", "table", "algorithm", user-defined (from layout?) MATH_MACRO,//"math-macro" + EXTERNAL,//"external" SENSELESS,//"senseless" TOC_TYPE_COUNT } diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 075a00562a..44baa5b980 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -608,6 +608,8 @@ QString guiName(string const & type, BufferParams const & bp) return qt_("Graphics"); if (type == "equation") return qt_("Equations"); + if (type == "external") + return qt_("External material"); if (type == "footnote") return qt_("Footnotes"); if (type == "listing") diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 1c3d124746..daa5831107 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -30,6 +30,7 @@ #include "MetricsInfo.h" #include "OutputParams.h" #include "output_latex.h" +#include "TocBackend.h" #include "frontends/alert.h" #include "frontends/Application.h" @@ -372,6 +373,33 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex) } +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) { @@ -460,6 +488,17 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd, } +void InsetExternal::addToToc(DocIterator const & cpit, bool output_active, + UpdateType) const +{ + DocIterator pit = cpit; + pit.push_back(CursorSlice(const_cast(*this))); + shared_ptr 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()), @@ -498,28 +537,6 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams) 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 diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h index a6167b5dd9..e1fe9447b9 100644 --- a/src/insets/InsetExternal.h +++ b/src/insets/InsetExternal.h @@ -120,6 +120,9 @@ public: bool setMouseHover(BufferView const * bv, bool mouse_hover) const; /// bool clickable(int, int) const { return true; } + /// + void addToToc(DocIterator const & di, bool output_active, + UpdateType utype) const; private: /// InsetExternal(InsetExternal const &);