mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Catch another potential crash of the same kind as in the previous commit.
Also refactor.
This commit is contained in:
parent
aacc5147b6
commit
2e945584bf
@ -184,6 +184,26 @@ void InsetCommand::validate(LaTeXFeatures & features) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool InsetCommand::isChangedByCurrentAuthor() const
|
||||||
|
{
|
||||||
|
InsetIterator it = begin(buffer().inset());
|
||||||
|
InsetIterator const itend = end(buffer().inset());
|
||||||
|
for (; it != itend; ++it) {
|
||||||
|
if (&*it == this)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (it == itend) {
|
||||||
|
LYXERR0("Unable to find inset!");
|
||||||
|
// to be on the safe side.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Paragraph const & ourpara = it.paragraph();
|
||||||
|
pos_type const ourpos = it.pos();
|
||||||
|
Change const & change = ourpara.lookupChange(ourpos);
|
||||||
|
return change.currentAuthor();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetCommand::changeCmdName(string const & new_name)
|
void InsetCommand::changeCmdName(string const & new_name)
|
||||||
{
|
{
|
||||||
string const & old_name = getCmdName();
|
string const & old_name = getCmdName();
|
||||||
@ -196,21 +216,7 @@ void InsetCommand::changeCmdName(string const & new_name)
|
|||||||
// But we need to make sure that the inset isn't one
|
// But we need to make sure that the inset isn't one
|
||||||
// that the current author inserted. Otherwise, we might
|
// that the current author inserted. Otherwise, we might
|
||||||
// delete ourselves!
|
// delete ourselves!
|
||||||
InsetIterator it = begin(buffer().inset());
|
if (isChangedByCurrentAuthor()) {
|
||||||
InsetIterator const itend = end(buffer().inset());
|
|
||||||
for (; it != itend; ++it) {
|
|
||||||
if (&*it == this)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (it == itend) {
|
|
||||||
LYXERR0("Unable to find inset!");
|
|
||||||
p_.setCmdName(new_name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Paragraph const & ourpara = it.paragraph();
|
|
||||||
pos_type const ourpos = it.pos();
|
|
||||||
Change const & change = ourpara.lookupChange(ourpos);
|
|
||||||
if (change.currentAuthor()) {
|
|
||||||
p_.setCmdName(new_name);
|
p_.setCmdName(new_name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -247,7 +253,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
cur.noScreenUpdate();
|
cur.noScreenUpdate();
|
||||||
else {
|
else {
|
||||||
cur.recordUndo();
|
cur.recordUndo();
|
||||||
if (buffer().masterParams().track_changes) {
|
if (buffer().masterParams().track_changes && !isChangedByCurrentAuthor()) {
|
||||||
// With change tracking, we insert a new inset and
|
// With change tracking, we insert a new inset and
|
||||||
// delete the old one
|
// delete the old one
|
||||||
string const data = InsetCommand::params2string(p);
|
string const data = InsetCommand::params2string(p);
|
||||||
|
@ -124,6 +124,10 @@ protected:
|
|||||||
void setCmdName(std::string const & n) { p_.setCmdName(n); }
|
void setCmdName(std::string const & n) { p_.setCmdName(n); }
|
||||||
///
|
///
|
||||||
void changeCmdName(std::string const & new_name);
|
void changeCmdName(std::string const & new_name);
|
||||||
|
/// was this inset changed by the current author?
|
||||||
|
/// if we're unable to find out, we return true, because of
|
||||||
|
/// how this is used.
|
||||||
|
bool isChangedByCurrentAuthor() const;
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user