Fix bug #6930: no undo for inset type changing

THis is a consequence of the new AtPoint mechanism. In the old
world, recordUndoInset was called before INSET_MODIFY. I reintroduced
manual recordUndoInset calls in all places that matter. I suspect
that this issue should be revisited later.

Note that recordUndoInset can now take an optional parameter that tells
what inset is concerned. This is useful because the cursor can be
either just inside the inset or in front of it.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36580 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2010-11-29 09:47:46 +00:00
parent baaceb10c2
commit 574931dcdb
17 changed files with 42 additions and 15 deletions

View File

@ -2358,9 +2358,9 @@ void Cursor::recordUndo(UndoKind kind) const
}
void Cursor::recordUndoInset(UndoKind kind) const
void Cursor::recordUndoInset(UndoKind kind, Inset const * inset) const
{
buffer()->undo().recordUndoInset(*this, kind);
buffer()->undo().recordUndoInset(*this, kind, inset);
}

View File

@ -280,7 +280,8 @@ public:
void recordUndo(UndoKind kind = ATOMIC_UNDO) const;
/// Convenience: prepare undo for the inset containing the cursor
void recordUndoInset(UndoKind kind = ATOMIC_UNDO) const;
void recordUndoInset(UndoKind kind = ATOMIC_UNDO,
Inset const * inset = 0) const;
/// Convenience: prepare undo for the whole buffer
void recordUndoFullDocument() const;

View File

@ -503,11 +503,18 @@ void Undo::recordUndo(DocIterator const & cur, UndoKind kind)
}
void Undo::recordUndoInset(DocIterator const & cur, UndoKind kind)
void Undo::recordUndoInset(DocIterator const & cur, UndoKind kind,
Inset const * inset)
{
if (!inset || inset == &cur.inset()) {
DocIterator c = cur;
c.pop_back();
d->doRecordUndo(kind, c, c.pit(), c.pit(), cur, false, d->undostack_);
d->doRecordUndo(kind, c, c.pit(), c.pit(),
cur, false, d->undostack_);
} else if (inset == cur.nextInset())
recordUndo(cur, kind);
else
LYXERR0("Inset not found, no undo stack added.");
}

View File

@ -24,6 +24,7 @@ namespace lyx {
class Buffer;
class BufferParams;
class DocIterator;
class Inset;
class MathData;
class ParagraphList;
@ -102,7 +103,8 @@ public:
/// Convenience: record undo information for the inset
/// containing the cursor.
void recordUndoInset(DocIterator const & cur,
UndoKind kind = ATOMIC_UNDO);
UndoKind kind = ATOMIC_UNDO,
Inset const * inset = 0);
/// Convenience: prepare undo for the whole buffer
void recordUndoFullDocument(DocIterator const & cur);

View File

@ -192,9 +192,10 @@ void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
//lyxerr << "InsetBox::dispatch MODIFY" << endl;
if (cmd.getArg(0) == "changetype")
if (cmd.getArg(0) == "changetype") {
cur.recordUndoInset(ATOMIC_UNDO, this);
params_.type = cmd.getArg(1);
else
} else
string2params(to_utf8(cmd.argument()), params_);
setButtonLabel();
break;

View File

@ -146,6 +146,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action()) {
case LFUN_INSET_MODIFY: {
if (cmd.getArg(0) == "changetype") {
cur.recordUndo();
p_.setCmdName(cmd.getArg(1));
cur.forceBufferUpdate();
initView();

View File

@ -243,6 +243,7 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
// child_buffer_ = 0;
InsetCommandParams p(INCLUDE_CODE);
if (cmd.getArg(0) == "changetype") {
cur.recordUndo();
InsetCommand::doDispatch(cur, cmd);
p = params();
} else

View File

@ -207,6 +207,7 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
if (cmd.getArg(0) == "changetype") {
cur.recordUndoInset(ATOMIC_UNDO, this);
params_.index = from_utf8(cmd.getArg(1));
break;
}
@ -478,6 +479,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
cmd = subst(cmd, "printindex", "printsubindex");
else
cmd = subst(cmd, "printsubindex", "printindex");
cur.recordUndo();
setCmdName(cmd);
break;
} else if (cmd.argument() == from_ascii("check-printindex*")) {
@ -485,6 +487,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
if (suffixIs(cmd, '*'))
break;
cmd += '*';
cur.recordUndo();
setParam("type", docstring());
setCmdName(cmd);
break;

View File

@ -231,6 +231,7 @@ void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
cur.recordUndo();
setInfo(to_utf8(cmd.argument()));
break;

View File

@ -13,6 +13,7 @@
#include "InsetNewline.h"
#include "Cursor.h"
#include "Dimension.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
@ -94,6 +95,7 @@ void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetNewlineParams params;
cur.recordUndo();
string2params(to_utf8(cmd.argument()), params);
params_.kind = params.kind;
break;

View File

@ -13,6 +13,7 @@
#include "InsetNewpage.h"
#include "Cursor.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "Lexer.h"
@ -141,6 +142,7 @@ void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetNewpageParams params;
cur.recordUndo();
string2params(to_utf8(cmd.argument()), params);
params_.kind = params.kind;
break;

View File

@ -174,6 +174,7 @@ void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
cur.recordUndoInset(ATOMIC_UNDO, this);
string2params(to_utf8(cmd.argument()), params_);
setButtonLabel();
// what we really want here is a TOC update, but that means

View File

@ -259,6 +259,7 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
cur.recordUndoInset(ATOMIC_UNDO, this);
string2params(to_utf8(cmd.argument()), params_);
break;

View File

@ -214,6 +214,7 @@ void InsetScript::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
cur.recordUndoInset(ATOMIC_UNDO, this);
string2params(to_utf8(cmd.argument()), params_);
break;
default:

View File

@ -144,6 +144,7 @@ void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
cur.recordUndo();
string2params(to_utf8(cmd.argument()), params_);
break;

View File

@ -58,6 +58,7 @@ void InsetVSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action()) {
case LFUN_INSET_MODIFY: {
cur.recordUndo();
InsetVSpace::string2params(to_utf8(cmd.argument()), space_);
break;
}

View File

@ -300,6 +300,7 @@ void InsetMathSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
if (cmd.getArg(0) == "mathspace") {
MathData ar;
if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
cur.recordUndo();
*this = *ar[0].nucleus()->asSpaceInset();
break;
}