]> git.lyx.org Git - features.git/commitdiff
Simplify before clean-up before following bugfix
authorGuillaume MM <gm@lyx.org>
Fri, 12 May 2017 21:13:38 +0000 (23:13 +0200)
committerGuillaume MM <gm@lyx.org>
Sat, 13 May 2017 14:12:25 +0000 (16:12 +0200)
src/Text3.cpp
src/TocBackend.cpp
src/insets/Inset.h
src/insets/InsetArgument.cpp
src/insets/InsetArgument.h
src/insets/InsetText.cpp
src/output_latex.cpp

index 533afd22329c11bc43f6ff213583fb4b1ae4291c..71293f80301152055633644007ce08bab5740db3 100644 (file)
@@ -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<InsetArgument const *>(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;
index c013cca03f7e2f71caa8194d868cc7dfb2dcfa2c..dc347a6539bf26ae192ddf8eb29142f66f93fb92 100644 (file)
@@ -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());
index 9ba894513c8034f31e34c03d34c209bfb4c1af15..df94fe43b74f5070369dafe9dc7baf72260a9d04 100644 (file)
@@ -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);
index 2acf71fa1a756171cc31b9cd0aa211b02200ed15..cff8cec4fe1695e63d4f0399f128ce3fc2d9a2c7 100644 (file)
@@ -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<InsetArgument const *>(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;
index 3e200e3b1c173bc1dfbecd74b7b35fe8364f42d3..cd036128623c8f03a201dc8ea769b5602a8998c8 100644 (file)
@@ -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,
index 471e72c74adbd56b7458e839dbd9ce6cf8fc1589..afa672dbcffa8e109420fdc5a2c81db08ed35291 100644 (file)
@@ -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<InsetArgument const *>(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
index c8a6bc4ee9f343822fb5a5cf0ddf6d1e0948756b..69c21fb964e234f3c737e5420fd03c6f81f36b19 100644 (file)
@@ -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<InsetArgument const *>(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.