commit 68be651e890d643359062aa9cb980ffcc4812840
Author: Guillaume Munch <[email protected]>
Date: Sun Oct 4 19:48:31 2015 +0100
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().
diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp
index 145a23b..8e90a3b 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<docstring>(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 9290d9c..e18f1bc 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 075a005..44baa5b 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 1c3d124..daa5831 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<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()),
@@ -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 a6167b5..e1fe944 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 &);