Simplify before clean-up before following bugfix

This commit is contained in:
Guillaume MM 2017-05-12 23:13:38 +02:00
parent c76cbead59
commit 1ac48c7cba
7 changed files with 25 additions and 48 deletions

View File

@ -2841,19 +2841,13 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
for (; pit <= lastpit; ++pit) { for (; pit <= lastpit; ++pit) {
if (pars_[pit].layout() != lay) if (pars_[pit].layout() != lay)
break; break;
InsetList::const_iterator it = pars_[pit].insetList().begin(); for (auto const & table : pars_[pit].insetList())
InsetList::const_iterator end = pars_[pit].insetList().end(); if (InsetArgument const * ins = table.inset->asInsetArgument())
for (; it != end; ++it) {
if (it->inset->lyxCode() == ARG_CODE) {
InsetArgument const * ins =
static_cast<InsetArgument const *>(it->inset);
if (ins->name() == arg) { if (ins->name() == arg) {
// we have this already // we have this already
enable = false; enable = false;
break; break;
} }
}
}
} }
} else } else
enable = false; enable = false;

View File

@ -22,7 +22,7 @@
#include "Paragraph.h" #include "Paragraph.h"
#include "TextClass.h" #include "TextClass.h"
#include "insets/InsetText.h" #include "insets/InsetArgument.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/docstream.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 // FIXME: This is supposed to accomplish the same as the body of
// InsetText::iterateForToc(), probably // InsetText::iterateForToc(), probably
Paragraph & par = toc_item->dit().paragraph(); Paragraph & par = toc_item->dit().paragraph();
InsetList::const_iterator it = par.insetList().begin(); for (auto const & table : par.insetList())
InsetList::const_iterator end = par.insetList().end(); if (InsetArgument const * arg = table.inset->asInsetArgument()) {
for (; it != end; ++it) {
Inset & inset = *it->inset;
if (inset.lyxCode() == ARG_CODE) {
tocstring = par.labelString(); tocstring = par.labelString();
if (!tocstring.empty()) if (!tocstring.empty())
tocstring += ' '; tocstring += ' ';
inset.asInsetText()->text().forOutliner(tocstring,TOC_ENTRY_LENGTH); arg->text().forOutliner(tocstring,TOC_ENTRY_LENGTH);
break; break;
} }
}
int const toclevel = toc_item->dit().text()-> int const toclevel = toc_item->dit().text()->
getTocLevel(toc_item->dit().pit()); getTocLevel(toc_item->dit().pit());

View File

@ -40,6 +40,7 @@ class Dimension;
class DocIterator; class DocIterator;
class FuncRequest; class FuncRequest;
class FuncStatus; class FuncStatus;
class InsetArgument;
class InsetCollapsable; class InsetCollapsable;
class InsetCommand; class InsetCommand;
class InsetIterator; class InsetIterator;
@ -154,6 +155,8 @@ public:
virtual InsetCommand * asInsetCommand() { return 0; } virtual InsetCommand * asInsetCommand() { return 0; }
/// is this inset based on the InsetCommand class? /// is this inset based on the InsetCommand class?
virtual InsetCommand const * asInsetCommand() const { return 0; } 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 /// the real dispatcher
void dispatch(Cursor & cur, FuncRequest & cmd); void dispatch(Cursor & cur, FuncRequest & cmd);

View File

@ -225,19 +225,13 @@ bool InsetArgument::getStatus(Cursor & cur, FuncRequest const & cmd,
Layout::LaTeXArgMap::const_iterator const lait = args.find(type); Layout::LaTeXArgMap::const_iterator const lait = args.find(type);
if (lait != args.end()) { if (lait != args.end()) {
flag.setEnabled(true); flag.setEnabled(true);
InsetList::const_iterator it = cur.paragraph().insetList().begin(); for (auto const & table : cur.paragraph().insetList())
InsetList::const_iterator end = cur.paragraph().insetList().end(); if (InsetArgument const * ins = table.inset->asInsetArgument())
for (; it != end; ++it) {
if (it->inset->lyxCode() == ARG_CODE) {
InsetArgument const * ins =
static_cast<InsetArgument const *>(it->inset);
if (ins->name() == type) { if (ins->name() == type) {
// we have this already // we have this already
flag.setEnabled(false); flag.setEnabled(false);
return true; return true;
} }
}
}
} else } else
flag.setEnabled(false); flag.setEnabled(false);
return true; return true;

View File

@ -29,6 +29,9 @@ public:
/// ///
InsetArgument(Buffer *, std::string const &); InsetArgument(Buffer *, std::string const &);
///
InsetArgument const * asInsetArgument() const { return this; }
/// Outputting the parameter of a LaTeX command /// Outputting the parameter of a LaTeX command
void latexArgument(otexstream & os, OutputParams const & runparams_in, void latexArgument(otexstream & os, OutputParams const & runparams_in,
docstring const & ldelim, docstring const & rdelim, docstring const & ldelim, docstring const & rdelim,

View File

@ -371,22 +371,14 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
Layout::LaTeXArgMap::const_iterator const lait = args.find(arg); Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
if (lait != args.end()) { if (lait != args.end()) {
status.setEnabled(true); status.setEnabled(true);
ParagraphList::const_iterator pit = paragraphs().begin(); for (Paragraph const & par : paragraphs())
for (; pit != paragraphs().end(); ++pit) { for (auto const & table : par.insetList())
InsetList::const_iterator it = pit->insetList().begin(); if (InsetArgument const * ins = table.inset->asInsetArgument())
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);
if (ins->name() == arg) { if (ins->name() == arg) {
// we have this already // we have this already
status.setEnabled(false); status.setEnabled(false);
return true; return true;
} }
}
}
}
} else } else
status.setEnabled(false); status.setEnabled(false);
return true; 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. // if we find an optarg, we'll save it for use later.
InsetText const * arginset = 0; InsetArgument const * arginset = nullptr;
InsetList::const_iterator it = par.insetList().begin(); for (auto const & table : par.insetList()) {
InsetList::const_iterator end = par.insetList().end(); dit.pos() = table.pos;
for (; it != end; ++it) { table.inset->addToToc(dit, doing_output, utype, backend);
Inset & inset = *it->inset; if (InsetArgument const * x = table.inset->asInsetArgument())
dit.pos() = it->pos; arginset = x;
//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
inset.addToToc(dit, doing_output, utype, backend);
if (inset.lyxCode() == ARG_CODE)
arginset = inset.asInsetText();
} }
// End custom AddToToc in paragraph layouts // End custom AddToToc in paragraph layouts

View File

@ -534,9 +534,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
InsetList::const_iterator it = par.insetList().begin(); InsetList::const_iterator it = par.insetList().begin();
InsetList::const_iterator end = par.insetList().end(); InsetList::const_iterator end = par.insetList().end();
for (; it != end; ++it) { for (; it != end; ++it) {
if (it->inset->lyxCode() == ARG_CODE) { if (InsetArgument const * ins = it->inset->asInsetArgument()) {
InsetArgument const * ins =
static_cast<InsetArgument const *>(it->inset);
if (ins->name().empty()) if (ins->name().empty())
LYXERR0("Error: Unnamed argument inset!"); LYXERR0("Error: Unnamed argument inset!");
else { else {
@ -618,6 +616,7 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi
getArgInsets(os, runparams, latexargs, ilist, required, prefix); getArgInsets(os, runparams, latexargs, ilist, required, prefix);
} }
namespace { namespace {
// output the proper paragraph start according to latextype. // output the proper paragraph start according to latextype.