Le 14/11/2010 01:38, Pavel Sanda a écrit :
JMarc, these two seems to have somthing in comon with you ;) : 6768 (at point
machinery), 6930 (undo broken)
Concerning 6930, the introduction of AtPoint lead to removing a
recordUndo call for INSET_MODIFY. Since the code is common to all
AtPoint entries (and toggle had no recordUndo entry), this has to be
reintroduced somehow.
The first (easy) try was to call recordUndo whenever the lfun is not
marked readonly. However I do not like lfun relying on such behaviour
from the dispatcher.
Therefore I decided to add the recordUndo in every place they were
needed (aka reached through stdcontext.inc).
However, there are other places where INSET_MODIFY is used without any
undo call. Presumably this is handled somewhere in Gui, but I do not
know where.
Should I apply the patch right like it is, or is it better to add a
recordUndo statement in each and every INSET_MODIFY function? (or to
revert to the trivial first solution?)
BTW, why is the following lfuns AtPoint? This is only useful if the
cursor can be inside the inset (it may be that we should rename this
flag if it is not clear)
{ LFUN_GRAPHICS_RELOAD, "graphics-reload", ReadOnly | AtPoint, Edit },
{ LFUN_LABEL_COPY_AS_REF, "copy-label-as-reference", ReadOnly | NoUpdate
| AtPoint, Edit },
JMarc
Index: src/Cursor.h
===================================================================
--- src/Cursor.h (révision 36354)
+++ src/Cursor.h (copie de travail)
@@ -280,7 +280,8 @@
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;
Index: src/insets/InsetSpace.cpp
===================================================================
--- src/insets/InsetSpace.cpp (révision 36354)
+++ src/insets/InsetSpace.cpp (copie de travail)
@@ -144,6 +144,7 @@
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
+ cur.recordUndo();
string2params(to_utf8(cmd.argument()), params_);
break;
Index: src/insets/InsetNewline.cpp
===================================================================
--- src/insets/InsetNewline.cpp (révision 36354)
+++ src/insets/InsetNewline.cpp (copie de travail)
@@ -13,6 +13,7 @@
#include "InsetNewline.h"
+#include "Cursor.h"
#include "Dimension.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
@@ -94,6 +95,7 @@
case LFUN_INSET_MODIFY: {
InsetNewlineParams params;
+ cur.recordUndo();
string2params(to_utf8(cmd.argument()), params);
params_.kind = params.kind;
break;
Index: src/insets/InsetNote.cpp
===================================================================
--- src/insets/InsetNote.cpp (révision 36354)
+++ src/insets/InsetNote.cpp (copie de travail)
@@ -174,6 +174,7 @@
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
Index: src/insets/InsetPhantom.cpp
===================================================================
--- src/insets/InsetPhantom.cpp (révision 36354)
+++ src/insets/InsetPhantom.cpp (copie de travail)
@@ -259,6 +259,7 @@
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
+ cur.recordUndoInset(ATOMIC_UNDO, this);
string2params(to_utf8(cmd.argument()), params_);
break;
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp (révision 36354)
+++ src/insets/InsetInclude.cpp (copie de travail)
@@ -242,6 +242,7 @@
// child_buffer_ = 0;
InsetCommandParams p(INCLUDE_CODE);
if (cmd.getArg(0) == "changetype") {
+ cur.recordUndo();
InsetCommand::doDispatch(cur, cmd);
p = params();
} else
Index: src/insets/InsetNewpage.cpp
===================================================================
--- src/insets/InsetNewpage.cpp (révision 36354)
+++ src/insets/InsetNewpage.cpp (copie de travail)
@@ -13,6 +13,7 @@
#include "InsetNewpage.h"
+#include "Cursor.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "Lexer.h"
@@ -141,6 +142,7 @@
case LFUN_INSET_MODIFY: {
InsetNewpageParams params;
+ cur.recordUndo();
string2params(to_utf8(cmd.argument()), params);
params_.kind = params.kind;
break;
Index: src/insets/InsetBox.cpp
===================================================================
--- src/insets/InsetBox.cpp (révision 36354)
+++ src/insets/InsetBox.cpp (copie de travail)
@@ -192,9 +192,10 @@
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;
Index: src/insets/InsetInfo.cpp
===================================================================
--- src/insets/InsetInfo.cpp (révision 36354)
+++ src/insets/InsetInfo.cpp (copie de travail)
@@ -208,19 +208,19 @@
switch (cmd.action()) {
case LFUN_INSET_SETTINGS:
return InsetCollapsable::getStatus(cur, cmd, flag);
-
+
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_COPY_AS:
flag.setEnabled(true);
return true;
-
+
case LFUN_INSET_MODIFY:
if (validateModifyArgument(cmd.argument())) {
flag.setEnabled(true);
return true;
}
//fall through
-
+
default:
return false;
}
@@ -231,6 +231,7 @@
{
switch (cmd.action()) {
case LFUN_INSET_MODIFY:
+ cur.recordUndo();
setInfo(to_utf8(cmd.argument()));
break;
Index: src/insets/InsetIndex.cpp
===================================================================
--- src/insets/InsetIndex.cpp (révision 36354)
+++ src/insets/InsetIndex.cpp (copie de travail)
@@ -207,6 +207,7 @@
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 @@
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 @@
if (suffixIs(cmd, '*'))
break;
cmd += '*';
+ cur.recordUndo();
setParam("type", docstring());
setCmdName(cmd);
break;
Index: src/insets/InsetCommand.cpp
===================================================================
--- src/insets/InsetCommand.cpp (révision 36354)
+++ src/insets/InsetCommand.cpp (copie de travail)
@@ -146,6 +146,7 @@
switch (cmd.action()) {
case LFUN_INSET_MODIFY: {
if (cmd.getArg(0) == "changetype") {
+ cur.recordUndo();
p_.setCmdName(cmd.getArg(1));
cur.forceBufferUpdate();
initView();
Index: src/insets/InsetVSpace.cpp
===================================================================
--- src/insets/InsetVSpace.cpp (révision 36354)
+++ src/insets/InsetVSpace.cpp (copie de travail)
@@ -58,6 +58,7 @@
switch (cmd.action()) {
case LFUN_INSET_MODIFY: {
+ cur.recordUndo();
InsetVSpace::string2params(to_utf8(cmd.argument()), space_);
break;
}
Index: src/mathed/InsetMathSpace.cpp
===================================================================
--- src/mathed/InsetMathSpace.cpp (révision 36354)
+++ src/mathed/InsetMathSpace.cpp (copie de travail)
@@ -300,6 +300,7 @@
if (cmd.getArg(0) == "mathspace") {
MathData ar;
if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
+ cur.recordUndo();
*this = *ar[0].nucleus()->asSpaceInset();
break;
}
Index: src/Undo.h
===================================================================
--- src/Undo.h (révision 36354)
+++ src/Undo.h (copie de travail)
@@ -24,6 +24,7 @@
class Buffer;
class BufferParams;
class DocIterator;
+class Inset;
class MathData;
class ParagraphList;
@@ -101,8 +102,9 @@
/// Convenience: record undo information for the inset
/// containing the cursor.
- void recordUndoInset(DocIterator const & cur,
- UndoKind kind = ATOMIC_UNDO);
+ void recordUndoInset(DocIterator const & cur,
+ UndoKind kind = ATOMIC_UNDO,
+ Inset const * inset = 0);
/// Convenience: prepare undo for the whole buffer
void recordUndoFullDocument(DocIterator const & cur);
Index: src/Cursor.cpp
===================================================================
--- src/Cursor.cpp (révision 36354)
+++ src/Cursor.cpp (copie de travail)
@@ -336,7 +336,7 @@
disp_ = DispatchResult();
buffer()->undo().beginUndoGroup();
-
+
// Is this a function that acts on inset at point?
if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint)
&& nextInset()) {
@@ -2358,9 +2358,9 @@
}
-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);
}
Index: src/Undo.cpp
===================================================================
--- src/Undo.cpp (révision 36354)
+++ src/Undo.cpp (copie de travail)
@@ -503,11 +503,18 @@
}
-void Undo::recordUndoInset(DocIterator const & cur, UndoKind kind)
+void Undo::recordUndoInset(DocIterator const & cur, UndoKind kind,
+ Inset const * inset)
{
- DocIterator c = cur;
- c.pop_back();
- d->doRecordUndo(kind, c, c.pit(), c.pit(), cur, false, d->undostack_);
+ if (!inset || inset == &cur.inset()) {
+ DocIterator c = cur;
+ c.pop_back();
+ 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.");
}