mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-07 02:28:35 +00:00
Honor change tracking when automatically renaming refs to labels
Fixes rest of #11556
This commit is contained in:
parent
69792bbaa5
commit
affc006bae
@ -105,7 +105,7 @@ void InsetLabel::updateLabelAndRefs(docstring const & new_label,
|
||||
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");
|
||||
@ -123,15 +123,23 @@ void InsetLabel::updateReferences(docstring const & old_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,28 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -91,6 +113,15 @@ void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
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())
|
||||
@ -111,6 +142,8 @@ bool InsetRef::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
|
||||
string const arg = cmd.getArg(1);
|
||||
string pstring;
|
||||
if (arg == "changetarget")
|
||||
return true;
|
||||
if (arg == "toggle-plural")
|
||||
pstring = "plural";
|
||||
else if (arg == "toggle-caps")
|
||||
|
@ -33,9 +33,14 @@ public:
|
||||
///
|
||||
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;
|
||||
|
@ -64,6 +64,15 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user