UndoGroupHelper ugh(&buffer());
if (cursor)
cursor->recordUndo();
- if (buffer().params().track_changes) {
+ if (buffer().masterParams().track_changes) {
// With change tracking, we insert a new label and
// delete the old one
InsetCommandParams p(LABEL_CODE, "label");
docstring const & new_label)
{
UndoGroupHelper ugh;
- for (auto const & p: buffer().references(old_label)) {
- ugh.resetBuffer(p.second.buffer());
- CursorData(p.second).recordUndo();
- if (p.first->lyxCode() == MATH_REF_CODE) {
- InsetMathRef * mi = p.first->asInsetMath()->asRefInset();
- mi->changeTarget(new_label);
- } else {
- InsetCommand * ref = p.first->asInsetCommand();
- ref->setParam("reference", new_label);
+ if (buffer().masterParams().track_changes) {
+ // With change tracking, we insert a new ref and
+ // delete the old one
+ lyx::dispatch(FuncRequest(LFUN_MASTER_BUFFER_FORALL,
+ "inset-forall Ref inset-modify ref changetarget "
+ + old_label + " " + new_label));
+ } else {
+ for (auto const & p: buffer().references(old_label)) {
+ ugh.resetBuffer(p.second.buffer());
+ CursorData(p.second).recordUndo();
+ if (p.first->lyxCode() == MATH_REF_CODE) {
+ InsetMathRef * mi = p.first->asInsetMath()->asRefInset();
+ mi->changeTarget(new_label);
+ } else {
+ InsetCommand * ref = p.first->asInsetCommand();
+ ref->setParam("reference", new_label);
+ }
}
}
}
}
+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")
///
InsetRef(Buffer * buffer, InsetCommandParams const &);
+ ///
+ void changeTarget(docstring const & new_label);
+
/// \name Public functions inherited from Inset class
//@{
///
+ docstring layoutName() const;
+ ///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const;
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
if (cmd.getArg(0) == "ref") {
+ if (cmd.getArg(1) == "changetarget") {
+ string const oldtarget = cmd.getArg(2);
+ string const newtarget = cmd.getArg(3);
+ if (!oldtarget.empty() && !newtarget.empty()
+ && asString(cell(0)) == from_utf8(oldtarget))
+ changeTarget(from_utf8(newtarget));
+ cur.forceBufferUpdate();
+ break;
+ }
MathData ar;
if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
cur.recordUndo();