Andre Poenitz wrote:
> On Sun, May 08, 2005 at 10:57:04AM +0200, Georg Baum wrote:
>> I did also call noUpdate() instead of undispatched() in insetcommand.C.
>> Is that correct?
>
> 'undispatched' means: I, the doDispatch() method of InsetFoo, hereby
> declare that I am not able to handle that request and trust my parent
> will do the Rigth Thing (even if my getStatus partner said that I can do
> it). It is sort of a kludge that should be used only rarely...
>
> noUpdate() means: I handled that request and I can reassure you that the
> screen does not need to be re-drawn and all entries in the coord cache
> stay valid (and there are no other thing to put in the coord cache).
> This is a fairly rare event as well and only some optimization. Not
> using noUpdate() should never be wrong.
And why is this information not in cursor.h? I added this now.
I am now sure that my undispatched -> noUpdate is correct: If
LFUN_INSET_MODIFY failed because of invalid parameters there is no chance
that a parent dispatcher can handle that better. After all, that
LFUN_INSET_MODIFY applies by definition to the inset holding the cursor,
and not to anything else. Invalid parameters should therefore be ignored,
trying to apply them to the parent would not work.
Attached is a third version of the patch that is going in now.
Georg
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2176
diff -u -p -r1.2176 ChangeLog
--- src/ChangeLog 8 May 2005 10:02:36 -0000 1.2176
+++ src/ChangeLog 9 May 2005 17:18:50 -0000
@@ -1,3 +1,7 @@
+2005-05-09 Georg Baum <[EMAIL PROTECTED]>
+
+ * cursor.h (undispatched, noUpdate): add comments from André
+
2005-05-07 Michael Schmitt <[EMAIL PROTECTED]>
* lfuns.h:
Index: src/cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.73
diff -u -p -r1.73 cursor.h
--- src/cursor.h 6 May 2005 20:00:30 -0000 1.73
+++ src/cursor.h 9 May 2005 17:18:50 -0000
@@ -146,13 +146,30 @@ public:
void reset(InsetBase &);
/// for spellchecking
void replaceWord(std::string const & replacestring);
- /// the event was not (yet) dispatched
+ /**
+ * the event was not (yet) dispatched.
+ *
+ * Should only be called by an inset's doDispatch() method. It means:
+ * I, the doDispatch() method of InsetFoo, hereby declare that I am
+ * not able to handle that request and trust my parent will do the
+ * Right Thing (even if my getStatus partner said that I can do it).
+ * It is sort of a kludge that should be used only rarely...
+ */
void undispatched();
/// the event was already dispatched
void dispatched();
/// call update() when done
void needsUpdate();
- /// don't call update() when done
+ /**
+ * don't call update() when done
+ *
+ * Should only be called by an inset's doDispatch() method. It means:
+ * I handled that request and I can reassure you that the screen does
+ * not need to be re-drawn and all entries in the coord cache stay
+ * valid (and there are no other things to put in the coord cache).
+ * This is a fairly rare event as well and only some optimization.
+ * Not using noUpdate() should never be wrong.
+ */
void noUpdate();
/// fix cursor in circumstances that should never happen
void fixIfBroken();
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1144
diff -u -p -r1.1144 ChangeLog
--- src/insets/ChangeLog 8 May 2005 10:02:38 -0000 1.1144
+++ src/insets/ChangeLog 9 May 2005 17:18:51 -0000
@@ -1,3 +1,11 @@
+2005-05-09 Georg Baum <[EMAIL PROTECTED]>
+
+ * insetbase.h (doDispatch): document a bit more
+ * insetcommand.C, insetfloat.C, insetgraphics.C, insetinclude.C,
+ insetnote.C, insetwrap.C, updatableinset.C (doDispatch): don't call
+ cur.bv().update(), because that leads to nested updates. Call
+ cur.noUpdate() instead where approriate.
+
2005-05-07 Michael Schmitt <[EMAIL PROTECTED]>
* insetbibtex.C: change screen label
Index: src/insets/insetbase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.h,v
retrieving revision 1.51
diff -u -p -r1.51 insetbase.h
--- src/insets/insetbase.h 22 Apr 2005 08:57:21 -0000 1.51
+++ src/insets/insetbase.h 9 May 2005 17:18:51 -0000
@@ -402,8 +406,17 @@ public:
protected:
InsetBase();
InsetBase(InsetBase const &);
- /// the real dispatcher.
- /// \sa getStatus
+ /** The real dispatcher.
+ * Gets normally called from LCursor::dispatch(). LCursor::dispatch()
+ * assumes the common case of 'LFUN handled, need update'.
+ * This has to be overriden by calling LCursor::undispatched() or
+ * LCursor::noUpdate() if appropriate.
+ * If you need to call the dispatch method of some inset directly
+ * you may have to explicitly request an update at that place. Don't
+ * do it in doDispatch(), since that causes nested updates when
+ * called from LCursor::dispatch(), and these can lead to crashes.
+ * \sa getStatus
+ */
virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
private:
virtual std::auto_ptr<InsetBase> doClone() const = 0;
Index: src/insets/insetcommand.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcommand.C,v
retrieving revision 1.117
diff -u -p -r1.117 insetcommand.C
--- src/insets/insetcommand.C 22 Apr 2005 08:57:22 -0000 1.117
+++ src/insets/insetcommand.C 9 May 2005 17:18:51 -0000
@@ -109,12 +109,10 @@ void InsetCommand::doDispatch(LCursor &
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetCommandMailer::string2params(mailer_name_, cmd.argument, p);
- if (p.getCmdName().empty()) {
- cur.undispatched();
- } else {
+ if (p.getCmdName().empty())
+ cur.noUpdate();
+ else
setParams(p);
- cur.bv().update();
- }
break;
}
Index: src/insets/insetfloat.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfloat.C,v
retrieving revision 1.139
diff -u -p -r1.139 insetfloat.C
--- src/insets/insetfloat.C 22 Apr 2005 09:16:28 -0000 1.139
+++ src/insets/insetfloat.C 9 May 2005 17:18:52 -0000
@@ -160,7 +160,6 @@ void InsetFloat::doDispatch(LCursor & cu
params_.sideways = params.sideways;
wide(params_.wide, cur.buffer().params());
sideways(params_.sideways, cur.buffer().params());
- cur.bv().update();
break;
}
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.277
diff -u -p -r1.277 insetgraphics.C
--- src/insets/insetgraphics.C 22 Apr 2005 08:57:22 -0000 1.277
+++ src/insets/insetgraphics.C 9 May 2005 17:18:52 -0000
@@ -197,10 +206,10 @@ void InsetGraphics::doDispatch(LCursor &
Buffer const & buffer = cur.buffer();
InsetGraphicsParams p;
InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
- if (!p.filename.empty()) {
+ if (!p.filename.empty())
setParams(p);
- cur.bv().update();
- }
+ else
+ cur.noUpdate();
break;
}
Index: src/insets/insetinclude.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.C,v
retrieving revision 1.205
diff -u -p -r1.205 insetinclude.C
--- src/insets/insetinclude.C 22 Apr 2005 08:57:22 -0000 1.205
+++ src/insets/insetinclude.C 9 May 2005 17:18:52 -0000
@@ -128,10 +153,10 @@ void InsetInclude::doDispatch(LCursor &
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetIncludeMailer::string2params(cmd.argument, p);
- if (!p.getCmdName().empty()) {
+ if (!p.getCmdName().empty())
set(p, cur.buffer());
- cur.bv().update();
- }
+ else
+ cur.noUpdate();
break;
}
Index: src/insets/insetnote.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetnote.C,v
retrieving revision 1.80
diff -u -p -r1.80 insetnote.C
--- src/insets/insetnote.C 22 Apr 2005 08:57:22 -0000 1.80
+++ src/insets/insetnote.C 9 May 2005 17:18:52 -0000
@@ -192,7 +192,6 @@ void InsetNote::doDispatch(LCursor & cur
case LFUN_INSET_MODIFY:
InsetNoteMailer::string2params(cmd.argument, params_);
setButtonLabel();
- cur.bv().update();
break;
case LFUN_INSET_DIALOG_UPDATE:
Index: src/insets/insetwrap.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetwrap.C,v
retrieving revision 1.75
diff -u -p -r1.75 insetwrap.C
--- src/insets/insetwrap.C 22 Apr 2005 08:57:22 -0000 1.75
+++ src/insets/insetwrap.C 9 May 2005 17:18:53 -0000
@@ -83,7 +83,6 @@ void InsetWrap::doDispatch(LCursor & cur
InsetWrapMailer::string2params(cmd.argument, params);
params_.placement = params.placement;
params_.width = params.width;
- cur.bv().update();
break;
}
Index: src/insets/render_preview.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/render_preview.h,v
retrieving revision 1.10
diff -u -p -r1.10 render_preview.h
--- src/insets/render_preview.h 23 Nov 2004 23:04:49 -0000 1.10
+++ src/insets/render_preview.h 9 May 2005 17:18:53 -0000
@@ -25,7 +25,6 @@
#include <boost/signals/connection.hpp>
class Buffer;
-class BufferView;
class LyXRC_PreviewStatus;
class MetricsInfo;
class PainterInfo;
Index: src/insets/updatableinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/updatableinset.C,v
retrieving revision 1.51
diff -u -p -r1.51 updatableinset.C
--- src/insets/updatableinset.C 31 Jan 2005 16:29:47 -0000 1.51
+++ src/insets/updatableinset.C 9 May 2005 17:18:53 -0000
@@ -99,8 +99,8 @@ void UpdatableInset::doDispatch(LCursor
scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
else
scroll(cur.bv(), convert<int>(cmd.argument));
- cur.bv().update();
- }
+ } else
+ cur.noUpdate();
break;
default: