#include "LyX.h"
#include "OutputParams.h"
#include "output_xhtml.h"
+#include "Paragraph.h"
#include "ParIterator.h"
#include "sgml.h"
#include "texstream.h"
InsetRef::InsetRef(Buffer * buf, InsetCommandParams const & p)
- : InsetCommand(buf, p), broken_(false)
+ : InsetCommand(buf, p), broken_(false), active_(true)
{}
InsetRef::InsetRef(InsetRef const & ir)
- : InsetCommand(ir), broken_(false)
+ : InsetCommand(ir), broken_(false), active_(true)
{}
}
+docstring InsetRef::layoutName() const
+{
+ return from_ascii("Ref");
+}
+
+
+void InsetRef::changeTarget(docstring const & new_label)
+{
+ // With change tracking, we insert a new ref
+ // and delete the old one
+ if (buffer().masterParams().track_changes) {
+ InsetCommandParams icp(REF_CODE, "ref");
+ icp["reference"] = new_label;
+ string const data = InsetCommand::params2string(icp);
+ lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
+ lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD));
+ } else
+ setParam("reference", new_label);
+}
+
+
+
void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
{
string const inset = cmd.getArg(0);
pstring = "caps";
else if (arg == "toggle-noprefix")
pstring = "noprefix";
+ else if (arg == "changetarget") {
+ string const oldtarget = cmd.getArg(2);
+ string const newtarget = cmd.getArg(3);
+ if (!oldtarget.empty() && !newtarget.empty()
+ && getParam("reference") == from_utf8(oldtarget))
+ changeTarget(from_utf8(newtarget));
+ cur.forceBufferUpdate();
+ return;
+ }
}
// otherwise not for us
if (pstring.empty())
string const arg = cmd.getArg(1);
string pstring;
+ if (arg == "changetarget")
+ return true;
if (arg == "toggle-plural")
pstring = "plural";
else if (arg == "toggle-caps")
}
-void InsetRef::updateBuffer(ParIterator const & it, UpdateType)
+void InsetRef::updateBuffer(ParIterator const & it, UpdateType, bool const /*deleted*/)
{
docstring const & ref = getParam("reference");
+
+ // Check if this one is active (i.e., neither deleted with change-tracking
+ // nor in an inset that does not produce output, such as notes or inactive branches)
+ Paragraph const & para = it.paragraph();
+ active_ = !para.isDeleted(it.pos()) && para.inInset().producesOutput();
+ // If not, check whether we are in a deleted/non-outputting inset
+ if (active_) {
+ for (size_type sl = 0 ; sl < it.depth() ; ++sl) {
+ Paragraph const & outer_par = it[sl].paragraph();
+ if (outer_par.isDeleted(it[sl].pos())
+ || !outer_par.inInset().producesOutput()) {
+ active_ = false;
+ break;
+ }
+ }
+ }
+
// register this inset into the buffer reference cache.
buffer().addReference(ref, this, it);
screen_label_ = label;
broken_ = false;
+ setBroken(broken_);
}
void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
- UpdateType, TocBackend & backend) const
+ UpdateType, TocBackend & backend) const
{
+ active_ = output_active;
docstring const & label = getParam("reference");
if (buffer().insetLabel(label)) {
broken_ = !buffer().activeLabel(label);
+ setBroken(broken_);
+ if (broken_ && output_active) {
+ shared_ptr<Toc> toc2 = backend.toc("brokenrefs");
+ toc2->push_back(TocItem(cpit, 0, screenLabel(), output_active));
+ }
// This InsetRef has already been taken care of in InsetLabel::addToToc().
return;
}
// It seems that this reference does not point to any valid label.
-
broken_ = true;
+ setBroken(broken_);
shared_ptr<Toc> toc = backend.toc("label");
toc->push_back(TocItem(cpit, 0, screenLabel(), output_active));
+ shared_ptr<Toc> toc2 = backend.toc("brokenrefs");
+ toc2->push_back(TocItem(cpit, 0, screenLabel(), output_active));
}
features.require("nameref");
}
-bool InsetRef::forceLTR() const
+bool InsetRef::forceLTR(OutputParams const & rp) const
{
- // We force LTR for references. Namerefs are output in the scripts direction
- // at least with fontspec/bidi, though (see #11518).
+ // We force LTR for references. However,
+ // * Namerefs are output in the scripts direction
+ // at least with fontspec/bidi and luabidi, though (see #11518).
+ // * Parentheses are automatically swapped with XeTeX/bidi
+ // [not with LuaTeX/luabidi] (see #11626).
// FIXME: Re-Audit all other RTL cases.
+ if (rp.useBidiPackage())
+ return false;
return (getCmdName() != "nameref" || !buffer().masterParams().useNonTeXFonts);
}
docstring InsetRef::getTOCString() const
{
+ docstring const & label = getParam("reference");
+ if (buffer().insetLabel(label))
+ broken_ = !buffer().activeLabel(label) && active_;
+ else
+ broken_ = active_;
return tooltip_.empty() ? screenLabel() : tooltip_;
}