diff --git a/src/Text3.cpp b/src/Text3.cpp index 533afd2232..71293f8030 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -2841,19 +2841,13 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, for (; pit <= lastpit; ++pit) { if (pars_[pit].layout() != lay) break; - InsetList::const_iterator it = pars_[pit].insetList().begin(); - InsetList::const_iterator end = pars_[pit].insetList().end(); - for (; it != end; ++it) { - if (it->inset->lyxCode() == ARG_CODE) { - InsetArgument const * ins = - static_cast(it->inset); + for (auto const & table : pars_[pit].insetList()) + if (InsetArgument const * ins = table.inset->asInsetArgument()) if (ins->name() == arg) { // we have this already enable = false; break; } - } - } } } else enable = false; diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index c013cca03f..dc347a6539 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -22,7 +22,7 @@ #include "Paragraph.h" #include "TextClass.h" -#include "insets/InsetText.h" +#include "insets/InsetArgument.h" #include "support/debug.h" #include "support/docstream.h" @@ -181,18 +181,14 @@ bool TocBackend::updateItem(DocIterator const & dit_in) // FIXME: This is supposed to accomplish the same as the body of // InsetText::iterateForToc(), probably Paragraph & par = toc_item->dit().paragraph(); - InsetList::const_iterator it = par.insetList().begin(); - InsetList::const_iterator end = par.insetList().end(); - for (; it != end; ++it) { - Inset & inset = *it->inset; - if (inset.lyxCode() == ARG_CODE) { + for (auto const & table : par.insetList()) + if (InsetArgument const * arg = table.inset->asInsetArgument()) { tocstring = par.labelString(); if (!tocstring.empty()) tocstring += ' '; - inset.asInsetText()->text().forOutliner(tocstring,TOC_ENTRY_LENGTH); + arg->text().forOutliner(tocstring,TOC_ENTRY_LENGTH); break; } - } int const toclevel = toc_item->dit().text()-> getTocLevel(toc_item->dit().pit()); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 9ba894513c..df94fe43b7 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -40,6 +40,7 @@ class Dimension; class DocIterator; class FuncRequest; class FuncStatus; +class InsetArgument; class InsetCollapsable; class InsetCommand; class InsetIterator; @@ -154,6 +155,8 @@ public: virtual InsetCommand * asInsetCommand() { return 0; } /// is this inset based on the InsetCommand class? virtual InsetCommand const * asInsetCommand() const { return 0; } + /// is this inset based on the InsetArgument class? + virtual InsetArgument const * asInsetArgument() const { return nullptr; } /// the real dispatcher void dispatch(Cursor & cur, FuncRequest & cmd); diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index 2acf71fa1a..cff8cec4fe 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -225,19 +225,13 @@ bool InsetArgument::getStatus(Cursor & cur, FuncRequest const & cmd, Layout::LaTeXArgMap::const_iterator const lait = args.find(type); if (lait != args.end()) { flag.setEnabled(true); - InsetList::const_iterator it = cur.paragraph().insetList().begin(); - InsetList::const_iterator end = cur.paragraph().insetList().end(); - for (; it != end; ++it) { - if (it->inset->lyxCode() == ARG_CODE) { - InsetArgument const * ins = - static_cast(it->inset); + for (auto const & table : cur.paragraph().insetList()) + if (InsetArgument const * ins = table.inset->asInsetArgument()) if (ins->name() == type) { // we have this already flag.setEnabled(false); return true; } - } - } } else flag.setEnabled(false); return true; diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index 3e200e3b1c..cd03612862 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -29,6 +29,9 @@ public: /// InsetArgument(Buffer *, std::string const &); + /// + InsetArgument const * asInsetArgument() const { return this; } + /// Outputting the parameter of a LaTeX command void latexArgument(otexstream & os, OutputParams const & runparams_in, docstring const & ldelim, docstring const & rdelim, diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 471e72c74a..afa672dbcf 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -371,22 +371,14 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd, Layout::LaTeXArgMap::const_iterator const lait = args.find(arg); if (lait != args.end()) { status.setEnabled(true); - ParagraphList::const_iterator pit = paragraphs().begin(); - for (; pit != paragraphs().end(); ++pit) { - InsetList::const_iterator it = pit->insetList().begin(); - InsetList::const_iterator end = pit->insetList().end(); - for (; it != end; ++it) { - if (it->inset->lyxCode() == ARG_CODE) { - InsetArgument const * ins = - static_cast(it->inset); + for (Paragraph const & par : paragraphs()) + for (auto const & table : par.insetList()) + if (InsetArgument const * ins = table.inset->asInsetArgument()) if (ins->name() == arg) { // we have this already status.setEnabled(false); return true; } - } - } - } } else status.setEnabled(false); return true; @@ -876,16 +868,12 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active, } // if we find an optarg, we'll save it for use later. - InsetText const * arginset = 0; - InsetList::const_iterator it = par.insetList().begin(); - InsetList::const_iterator end = par.insetList().end(); - for (; it != end; ++it) { - Inset & inset = *it->inset; - dit.pos() = it->pos; - //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl; - inset.addToToc(dit, doing_output, utype, backend); - if (inset.lyxCode() == ARG_CODE) - arginset = inset.asInsetText(); + InsetArgument const * arginset = nullptr; + for (auto const & table : par.insetList()) { + dit.pos() = table.pos; + table.inset->addToToc(dit, doing_output, utype, backend); + if (InsetArgument const * x = table.inset->asInsetArgument()) + arginset = x; } // End custom AddToToc in paragraph layouts diff --git a/src/output_latex.cpp b/src/output_latex.cpp index c8a6bc4ee9..69c21fb964 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -534,9 +534,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os, InsetList::const_iterator it = par.insetList().begin(); InsetList::const_iterator end = par.insetList().end(); for (; it != end; ++it) { - if (it->inset->lyxCode() == ARG_CODE) { - InsetArgument const * ins = - static_cast(it->inset); + if (InsetArgument const * ins = it->inset->asInsetArgument()) { if (ins->name().empty()) LYXERR0("Error: Unnamed argument inset!"); else { @@ -618,6 +616,7 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi getArgInsets(os, runparams, latexargs, ilist, required, prefix); } + namespace { // output the proper paragraph start according to latextype.