mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 10:18:50 +00:00
Backport various parts of the fix for #7655. This include r39211, r39250, and r39251.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39598 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
35f1ce3ebe
commit
8c529c99c2
@ -227,7 +227,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist,
|
||||
InsetIterator const i_end = inset_iterator_end(in);
|
||||
for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
|
||||
// Even though this will also be done later, it has to be done here
|
||||
// since, e.g., InsetLabel::updateCommand() is going to try to access
|
||||
// since some inset might going to try to access
|
||||
// the buffer() member.
|
||||
it->setBuffer(const_cast<Buffer &>(buffer));
|
||||
switch (it->lyxCode()) {
|
||||
@ -241,7 +241,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist,
|
||||
continue;
|
||||
InsetLabel * lab = labels[i];
|
||||
docstring const oldname = lab->getParam("name");
|
||||
lab->updateCommand(oldname, false);
|
||||
lab->updateLabel(oldname);
|
||||
// We need to update the buffer reference cache.
|
||||
cur.forceBufferUpdate();
|
||||
docstring const newname = lab->getParam("name");
|
||||
@ -272,7 +272,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist,
|
||||
// check for duplicates
|
||||
InsetLabel & lab = static_cast<InsetLabel &>(*it);
|
||||
docstring const oldname = lab.getParam("name");
|
||||
lab.updateCommand(oldname, false);
|
||||
lab.updateLabel(oldname);
|
||||
// We need to update the buffer reference cache.
|
||||
cur.forceBufferUpdate();
|
||||
docstring const newname = lab.getParam("name");
|
||||
|
@ -271,7 +271,7 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
}
|
||||
|
||||
if (new_label != old_label) {
|
||||
label_->updateCommand(new_label);
|
||||
label_->updateLabelAndRefs(new_label, &cur);
|
||||
// the label might have been adapted (duplicate)
|
||||
if (new_label != label_->getParam("name")) {
|
||||
new_params.addParam("label", "{" +
|
||||
@ -1096,7 +1096,7 @@ void InsetInclude::updateCommand()
|
||||
return;
|
||||
|
||||
docstring old_label = label_->getParam("name");
|
||||
label_->updateCommand(old_label, false);
|
||||
label_->updateLabel(old_label);
|
||||
// the label might have been adapted (duplicate)
|
||||
docstring new_label = label_->getParam("name");
|
||||
if (old_label == new_label)
|
||||
@ -1111,6 +1111,7 @@ void InsetInclude::updateCommand()
|
||||
setParams(p);
|
||||
}
|
||||
|
||||
|
||||
void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype)
|
||||
{
|
||||
Buffer const * const childbuffer = getChildBuffer();
|
||||
|
@ -55,46 +55,71 @@ InsetLabel::InsetLabel(Buffer * buf, InsetCommandParams const & p)
|
||||
|
||||
void InsetLabel::initView()
|
||||
{
|
||||
updateCommand(getParam("name"));
|
||||
// FIXME: This seems to be used only for inset creation so
|
||||
// we probably just need to call updateLabel() here.
|
||||
updateLabelAndRefs(getParam("name"));
|
||||
}
|
||||
|
||||
|
||||
void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
|
||||
void InsetLabel::uniqueLabel(docstring & label) const
|
||||
{
|
||||
docstring const old_label = getParam("name");
|
||||
docstring label = new_label;
|
||||
docstring const new_label = label;
|
||||
int i = 1;
|
||||
while (buffer().insetLabel(label)) {
|
||||
label = new_label + '-' + convert<docstring>(i);
|
||||
++i;
|
||||
}
|
||||
|
||||
if (label != new_label) {
|
||||
// Warn the user that the label has been changed to something else.
|
||||
frontend::Alert::warning(_("Label names must be unique!"),
|
||||
bformat(_("The label %1$s already exists,\n"
|
||||
"it will be changed to %2$s."), new_label, label));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsetLabel::updateLabel(docstring const & new_label)
|
||||
{
|
||||
docstring label = new_label;
|
||||
uniqueLabel(label);
|
||||
setParam("name", label);
|
||||
}
|
||||
|
||||
|
||||
void InsetLabel::updateLabelAndRefs(docstring const & new_label,
|
||||
Cursor * cursor)
|
||||
{
|
||||
docstring const old_label = getParam("name");
|
||||
docstring label = new_label;
|
||||
uniqueLabel(label);
|
||||
if (label == old_label)
|
||||
return;
|
||||
|
||||
buffer().undo().beginUndoGroup();
|
||||
if (cursor)
|
||||
cursor->recordUndo();
|
||||
setParam("name", label);
|
||||
updateReferences(old_label, label);
|
||||
buffer().undo().endUndoGroup();
|
||||
}
|
||||
|
||||
if (updaterefs) {
|
||||
Buffer::References & refs = buffer().references(old_label);
|
||||
Buffer::References::iterator it = refs.begin();
|
||||
Buffer::References::iterator end = refs.end();
|
||||
for (; it != end; ++it) {
|
||||
buffer().undo().recordUndo(it->second);
|
||||
if (it->first->lyxCode() == MATH_REF_CODE) {
|
||||
InsetMathHull * mi = it->first->asInsetMath()->asHullInset();
|
||||
mi->asRefInset()->changeTarget(label);
|
||||
} else {
|
||||
InsetCommand * ref = it->first->asInsetCommand();
|
||||
ref->setParam("reference", label);
|
||||
}
|
||||
|
||||
void InsetLabel::updateReferences(docstring const & old_label,
|
||||
docstring const & new_label)
|
||||
{
|
||||
Buffer::References & refs = buffer().references(old_label);
|
||||
Buffer::References::iterator it = refs.begin();
|
||||
Buffer::References::iterator end = refs.end();
|
||||
for (; it != end; ++it) {
|
||||
buffer().undo().recordUndo(it->second);
|
||||
if (it->first->lyxCode() == MATH_REF_CODE) {
|
||||
InsetMathHull * mi = it->first->asInsetMath()->asHullInset();
|
||||
mi->asRefInset()->changeTarget(new_label);
|
||||
} else {
|
||||
InsetCommand * ref = it->first->asInsetCommand();
|
||||
ref->setParam("reference", new_label);
|
||||
}
|
||||
}
|
||||
buffer().undo().endUndoGroup();
|
||||
}
|
||||
|
||||
|
||||
@ -197,8 +222,8 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
break;
|
||||
}
|
||||
if (p["name"] != params()["name"]) {
|
||||
// undo is handled in updateCommand
|
||||
updateCommand(p["name"]);
|
||||
// undo is handled in updateLabelAndRefs
|
||||
updateLabelAndRefs(p["name"], &cur);
|
||||
}
|
||||
cur.forceBufferUpdate();
|
||||
break;
|
||||
|
@ -31,8 +31,11 @@ public:
|
||||
docstring const & counterValue() const { return counter_value_; }
|
||||
///
|
||||
docstring const & prettyCounter() const { return pretty_counter_; }
|
||||
///
|
||||
void updateCommand(docstring const & new_label, bool updaterefs = true);
|
||||
/// Updates only the label string, doesn't handle undo nor references.
|
||||
void updateLabel(docstring const & new_label);
|
||||
/// Updates the label and the references to it.
|
||||
/// Will also handle undo/redo if \p cursor is passed.
|
||||
void updateLabelAndRefs(docstring const & new_label, Cursor * cursor = 0);
|
||||
|
||||
/// \name Public functions inherited from Inset class
|
||||
//@{
|
||||
@ -85,6 +88,11 @@ private:
|
||||
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||
//@}
|
||||
|
||||
///
|
||||
void uniqueLabel(docstring & label) const;
|
||||
///
|
||||
void updateReferences(docstring const & old_label,
|
||||
docstring const & new_label);
|
||||
///
|
||||
docstring screen_label_;
|
||||
///
|
||||
|
@ -663,7 +663,7 @@ void InsetMathHull::label(row_type row, docstring const & label)
|
||||
label_[row] = dummy_pointer;
|
||||
} else {
|
||||
if (buffer_)
|
||||
label_[row]->updateCommand(label);
|
||||
label_[row]->updateLabelAndRefs(label);
|
||||
else
|
||||
label_[row]->setParam("name", label);
|
||||
}
|
||||
|
@ -61,6 +61,9 @@ What's new
|
||||
|
||||
- Repair broken outliner display for broken references (bug 7708).
|
||||
|
||||
- Mark buffer dirty when a label is changed, so the file can be saved and
|
||||
the change can be reverted (bug 7655).
|
||||
|
||||
|
||||
* ADVANCED FIND AND REPLACE
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user