bool isExportableFormat(std::string const & format) const;
///
- typedef std::vector<std::pair<InsetRef *, ParIterator> > References;
+ typedef std::vector<std::pair<Inset *, ParIterator> > References;
References & references(docstring const & label);
References const & references(docstring const & label) const;
void clearReferenceCache() const;
cap::eraseSelection(*this);
cell().insert(pos(), ar);
pos() += ar.size();
+ // FIXME audit setBuffer/updateLabels calls
+ inset().setBuffer(bv_->buffer());
}
#include "mathed/MathData.h"
#include "mathed/InsetMath.h"
#include "mathed/InsetMathHull.h"
+#include "mathed/InsetMathRef.h"
#include "mathed/MathSupport.h"
#include "support/debug.h"
docstring const oldname = lab->getParam("name");
lab->updateCommand(oldname, false);
docstring const newname = lab->getParam("name");
- if (oldname != newname) {
- // adapt the references
- for (InsetIterator itt = inset_iterator_begin(in);
- itt != i_end; ++itt) {
- if (itt->lyxCode() == REF_CODE) {
- InsetCommand & ref =
- dynamic_cast<InsetCommand &>(*itt);
- if (ref.getParam("reference") == oldname)
- ref.setParam("reference", newname);
- }
+ if (oldname == newname)
+ continue;
+ // adapt the references
+ for (InsetIterator itt = inset_iterator_begin(in);
+ itt != i_end; ++itt) {
+ if (itt->lyxCode() == REF_CODE) {
+ InsetCommand & ref =
+ static_cast<InsetCommand &>(*itt);
+ if (ref.getParam("reference") == oldname)
+ ref.setParam("reference", newname);
+ } else if (itt->lyxCode() == MATH_REF_CODE) {
+ InsetMathHull & mi =
+ static_cast<InsetMathHull &>(*itt);
+ // this is necessary to prevent an uninitialized
+ // buffer when the RefInset is in a MathBox.
+ // FIXME audit setBuffer/updateLabels calls
+ mi.setBuffer(const_cast<Buffer &>(buffer));
+ if (mi.asRefInset()->getTarget() == oldname)
+ mi.asRefInset()->changeTarget(newname);
}
}
}
docstring const oldname = lab.getParam("name");
lab.updateCommand(oldname, false);
docstring const newname = lab.getParam("name");
- if (oldname != newname) {
- // adapt the references
- for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
- if (itt->lyxCode() == REF_CODE) {
- InsetCommand & ref = dynamic_cast<InsetCommand &>(*itt);
- if (ref.getParam("reference") == oldname)
- ref.setParam("reference", newname);
- }
+ if (oldname == newname)
+ break;
+ // adapt the references
+ for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
+ if (itt->lyxCode() == REF_CODE) {
+ InsetCommand & ref = static_cast<InsetCommand &>(*itt);
+ if (ref.getParam("reference") == oldname)
+ ref.setParam("reference", newname);
+ } else if (itt->lyxCode() == MATH_REF_CODE) {
+ InsetMathHull & mi =
+ static_cast<InsetMathHull &>(*itt);
+ // this is necessary to prevent an uninitialized
+ // buffer when the RefInset is in a MathBox.
+ // FIXME audit setBuffer/updateLabels calls
+ mi.setBuffer(const_cast<Buffer &>(buffer));
+ if (mi.asRefInset()->getTarget() == oldname)
+ mi.asRefInset()->changeTarget(newname);
}
}
break;
docstring const oldkey = bib.getParam("key");
bib.updateCommand(oldkey, false);
docstring const newkey = bib.getParam("key");
- if (oldkey != newkey) {
- // adapt the references
- for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
- if (itt->lyxCode() == CITE_CODE) {
- InsetCommand & ref = dynamic_cast<InsetCommand &>(*itt);
- if (ref.getParam("key") == oldkey)
- ref.setParam("key", newkey);
- }
+ if (oldkey == newkey)
+ break;
+ // adapt the references
+ for (InsetIterator itt = inset_iterator_begin(in);
+ itt != i_end; ++itt) {
+ if (itt->lyxCode() == CITE_CODE) {
+ InsetCommand & ref =
+ static_cast<InsetCommand &>(*itt);
+ if (ref.getParam("key") == oldkey)
+ ref.setParam("key", newkey);
}
}
break;
#include "TextClass.h"
#include "TocBackend.h"
+#include "mathed/InsetMathHull.h"
+#include "mathed/InsetMathRef.h"
+
#include "frontends/alert.h"
#include "support/convert.h"
Buffer::References::iterator end = refs.end();
for (; it != end; ++it) {
buffer().undo().recordUndo(it->second);
- it->first->setParam("reference", label);
+ if (it->first->lyxCode() == MATH_REF_CODE) {
+ InsetMathHull * mi =
+ static_cast<InsetMathHull *>(it->first);
+ mi->asRefInset()->changeTarget(label);
+ } else {
+ InsetCommand * ref =
+ static_cast<InsetCommand *>(it->first);
+ ref->setParam("reference", label);
+ }
}
}
buffer().undo().endUndoGroup();
Buffer::References::const_iterator end = refs.end();
for (; it != end; ++it) {
DocIterator const ref_pit(it->second);
- toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel()));
+ if (it->first->lyxCode() == MATH_REF_CODE)
+ toc.push_back(TocItem(ref_pit, 1,
+ static_cast<InsetMathHull *>(it->first)->asRefInset()
+ ->screenLabel()));
+ else
+ toc.push_back(TocItem(ref_pit, 1,
+ static_cast<InsetRef *>(it->first)->screenLabel()));
}
}
#include "MathStream.h"
#include "MetricsInfo.h"
+#include "Buffer.h"
#include "BufferView.h"
#include "CutAndPaste.h"
#include "FuncStatus.h"
}
+void InsetMathGrid::updateLabels(ParIterator const & it, UpdateType utype)
+{
+ // pass down
+ for (idx_type idx = 0; idx < nargs(); ++idx)
+ cell(idx).updateLabels(it, utype);
+}
+
+
docstring InsetMathGrid::eolString(row_type row, bool fragile) const
{
docstring eol;
cell(i).append(grid.cell(grid.index(r, c)));
}
cur.clearSelection(); // bug 393
+ // FIXME audit setBuffer/updateLabels calls
+ cur.inset().setBuffer(*buffer_);
+ // FIXME audit setBuffer/updateLabels calls
+ cur.buffer()->updateLabels();
cur.finishUndo();
break;
}
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter & pi, int x, int y) const;
+ ///
+ void updateLabels(ParIterator const &, UpdateType);
/// extract number of columns from alignment string
static col_type guessColumns(docstring const & halign);
/// accepts some LaTeX column codes: p,m,!,@,M,<,>
if (label_[i])
label_[i]->updateLabels(it, utype);
}
+ // pass down
+ InsetMathGrid::updateLabels(it, utype);
}
}
+void InsetMathNest::updateLabels(ParIterator const & it, UpdateType utype)
+{
+ for (idx_type i = 0, n = nargs(); i != n; ++i)
+ cell(i).updateLabels(it, utype);
+}
+
+
+
bool InsetMathNest::idxNext(Cursor & cur) const
{
LASSERT(&cur.inset() == this, /**/);
void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
{
- //lyxerr << "InsetMathNest: request: " << cmd << endl;
+ //LYXERR0("InsetMathNest: request: " << cmd);
Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
}
cur.niceInsert(topaste, parseflg, false);
cur.clearSelection(); // bug 393
+ // FIXME audit setBuffer/updateLabels calls
+ cur.buffer()->updateLabels();
cur.finishUndo();
break;
}
// Prevent stale position >= size crash
// Probably not necessary anymore, see eraseSelection (gb 2005-10-09)
cur.normalize();
+ // FIXME audit setBuffer/updateLabels calls
+ cur.buffer()->updateLabels();
break;
case LFUN_COPY:
cur.posBackward();
cur.pushBackward(*cur.nextInset());
cur.niceInsert(save_selection);
+ // FIXME audit setBuffer/updateLabels calls
+ cur.buffer()->updateLabels();
#else
if (currentMode() == Inset::TEXT_MODE) {
cur.recordUndoSelection();
if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
cur.recordUndoSelection();
cur.insert(ar);
+ // FIXME audit setBuffer/updateLabels calls
+ cur.buffer()->updateLabels();
} else
cur.undispatched();
break;
/// draw decorations.
void drawDecoration(PainterInfo & pi, int x, int y) const
{ drawMarkers(pi, x, y); }
+ ///
+ void updateLabels(ParIterator const &, UpdateType);
/// identifies NestInsets
InsetMathNest * asNestInset() { return this; }
/// identifies NestInsets
#include "MathFactory.h"
#include "MathSupport.h"
#include "OutputParams.h"
+#include "ParIterator.h"
#include "sgml.h"
#include "insets/InsetCommand.h"
}
+void InsetMathRef::updateLabels(ParIterator const & it, UpdateType /*utype*/)
+{
+ if (!buffer_) {
+ LYXERR0("InsetMathRef::updateLabels: no buffer_!");
+ return;
+ }
+ // register this inset into the buffer reference cache.
+ buffer().references(getTarget()).push_back(make_pair(this, it));
+}
+
+
string const InsetMathRef::createDialogStr(string const & name) const
{
InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
}
+docstring const InsetMathRef::getTarget() const
+{
+ return asString(cell(0));
+}
+
+
+void InsetMathRef::changeTarget(docstring const & target)
+{
+ InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
+ icp["reference"] = target;
+ if (!cell(1).empty())
+ icp["name"] = asString(cell(1));
+ MathData ar;
+ Buffer & buf = buffer();
+ if (createInsetMath_fromDialogStr(
+ from_utf8(InsetCommand::params2string("ref", icp)), ar)) {
+ *this = *ar[0].nucleus()->asRefInset();
+ // FIXME audit setBuffer/updateLabels calls
+ setBuffer(buf);
+ }
+}
+
+
InsetMathRef::ref_type_info InsetMathRef::types[] = {
{ from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")), from_ascii(N_("Ref: "))},
{ from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))},
///
explicit InsetMathRef(Buffer * buf, docstring const & data);
///
+ void updateLabels(ParIterator const &, UpdateType);
+ ///
//void write(WriteStream & os) const;
///
void infoize(odocstream & os) const;
///
void validate(LaTeXFeatures & features) const;
///
+ void changeTarget(docstring const & target);
+ ///
virtual InsetMathRef * asRefInset() { return this; }
/// docbook output
///
static docstring const & getName(int type);
///
+ docstring const getTarget() const;
+ ///
InsetCode lyxCode() const { return MATH_REF_CODE; }
protected:
}
+void MathData::updateLabels(ParIterator const & it, UpdateType utype)
+{
+ // pass down
+ for (size_t i = 0, n = size(); i != n; ++i) {
+ MathAtom & at = operator[](i);
+ at.nucleus()->updateLabels(it, utype);
+ }
+}
+
+
void MathData::updateMacros(Cursor * cur, MacroContext const & mc)
{
// If we are editing a macro, we cannot update it immediately,
#include "Dimension.h"
#include "MathAtom.h"
+#include "OutputEnums.h"
+
#include "support/strfwd.h"
#include <vector>
class MathMacro;
class MetricsInfo;
class PainterInfo;
+class ParIterator;
class TextMetricsInfo;
class TextPainter;
/// attach/detach arguments to macros, updating the cur to
/// stay visually at the same position (cur==0 is allowed)
void updateMacros(Cursor * cur, MacroContext const & mc);
+ ///
+ void updateLabels(ParIterator const &, UpdateType);
protected:
/// cached values for super/subscript placement