Juergen Spitzmueller wrote: > I have adapted the patch to current cvs (see attached).
After some more testing, I came up with the attached, slightly improved version, which does also respect inlined (as well opened) insets (i.e. does not force inlined ERTs to opened ones when the cursor enters, which btw also s&r currently does, due to André's change below). The only difference to the prior patch is the change in status(). > The autoopen > feature is not yet used by the spellchecker, though (which would be a > oneliner, I guess, but could certainly also wait). The reason why they are not closed is this recent change by André in cursor.C, which ought to fix this very problem (but doesn't), if I'm not mistaken. http://www.lyx.org/cgi-bin/viewcvs.cgi/lyx-devel/src/cursor.C.diff?r1=1.126&r2=1.127 I think this change can (and should be) reverted now (see second patch). I have done this here and haven't found any regression. André, are you listening? Jürgen
Index: cursor.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v retrieving revision 1.133 diff -p -u -r1.133 cursor.C --- cursor.C 18 Jul 2005 17:12:22 -0000 1.133 +++ cursor.C 17 Sep 2005 14:10:49 -0000 @@ -467,9 +467,6 @@ void LCursor::setSelection(DocIterator c selection() = true; anchor_ = where; pos() += n; - // Open all collapsed insets - for (int i = depth() - 1; i >= 0; --i) - operator[](i).inset().setStatus(*this, InsetBase::Open); }
Index: insetcollapsable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v retrieving revision 1.278 diff -p -u -r1.278 insetcollapsable.C --- insetcollapsable.C 15 Jul 2005 22:10:21 -0000 1.278 +++ insetcollapsable.C 17 Sep 2005 14:10:23 -0000 @@ -40,9 +40,16 @@ using std::min; using std::ostream; +InsetCollapsable::CollapseStatus InsetCollapsable::status() const +{ + return (autoOpen_ && status_ != Inlined) ? Open : status_; +} + + InsetCollapsable::InsetCollapsable (BufferParams const & bp, CollapseStatus status) - : InsetText(bp), label("Label"), status_(status), openinlined_(false) + : InsetText(bp), label("Label"), status_(status), + openinlined_(false), autoOpen_(false) { setAutoBreakRows(true); setDrawFrame(true); @@ -122,12 +129,14 @@ Dimension InsetCollapsable::dimensionCol void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const { + autoOpen_ = mi.base.bv->cursor().isInside(this); mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET; - if (status_ == Inlined) { + + if (status() == Inlined) { InsetText::metrics(mi, dim); } else { dim = dimensionCollapsed(); - if (status_ == Open) { + if (status() == Open) { InsetText::metrics(mi, textdim_); openinlined_ = (textdim_.wid + dim.wid <= mi.base.textwidth); if (openinlined_) { @@ -151,7 +160,7 @@ void InsetCollapsable::metrics(MetricsIn void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const { const int xx = x + TEXT_TO_INSET_OFFSET; - if (status_ == Inlined) { + if (status() == Inlined) { InsetText::draw(pi, xx, y); } else { Dimension dimc = dimensionCollapsed(); @@ -162,7 +171,7 @@ void InsetCollapsable::draw(PainterInfo button_dim.y2 = top + dimc.height(); pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_); - if (status_ == Open) { + if (status() == Open) { int textx, texty; if (openinlined_) { textx = xx + dimc.width(); @@ -181,13 +190,13 @@ void InsetCollapsable::draw(PainterInfo void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const { x += TEXT_TO_INSET_OFFSET; - if (status_ == Open) { + if (status() == Open) { if (openinlined_) x += dimensionCollapsed().wid; else y += dimensionCollapsed().des + textdim_.asc; } - if (status_ != Collapsed) + if (status() != Collapsed) InsetText::drawSelection(pi, x, y); } @@ -195,32 +204,30 @@ void InsetCollapsable::drawSelection(Pai void InsetCollapsable::cursorPos (CursorSlice const & sl, bool boundary, int & x, int & y) const { - if (status_ == Collapsed) { - x = xo(); - y = yo(); - } else { - InsetText::cursorPos(sl, boundary, x, y); - if (status_ == Open) { - if (openinlined_) - x += dimensionCollapsed().wid; - else - y += dimensionCollapsed().height() - ascent() - + TEXT_TO_INSET_OFFSET + textdim_.asc; - } - x += TEXT_TO_INSET_OFFSET; + BOOST_ASSERT(status() != Collapsed); + + InsetText::cursorPos(sl, boundary, x, y); + + if (status() == Open) { + if (openinlined_) + x += dimensionCollapsed().wid; + else + y += dimensionCollapsed().height() - ascent() + + TEXT_TO_INSET_OFFSET + textdim_.asc; } + x += TEXT_TO_INSET_OFFSET; } InsetBase::EDITABLE InsetCollapsable::editable() const { - return status_ != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE; + return status() != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE; } bool InsetCollapsable::descendable() const { - return status_ != Collapsed; + return status() != Collapsed; } @@ -262,7 +269,7 @@ void InsetCollapsable::edit(LCursor & cu InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) { //lyxerr << "InsetCollapsable: edit xy" << endl; - if (status_ == Collapsed) + if (status() == Collapsed) return this; cur.push(*this); return InsetText::editXY(cur, x, y); @@ -276,9 +283,9 @@ void InsetCollapsable::doDispatch(LCurso switch (cmd.action) { case LFUN_MOUSE_PRESS: - if (status_ == Inlined) + if (status() == Inlined) InsetText::doDispatch(cur, cmd); - else if (status_ == Open && !hitButton(cmd)) + else if (status() == Open && !hitButton(cmd)) InsetText::doDispatch(cur, cmd); else cur.noUpdate(); @@ -289,7 +296,7 @@ void InsetCollapsable::doDispatch(LCurso case LFUN_MOUSE_TRIPLE: if (status_ == Inlined) InsetText::doDispatch(cur, cmd); - else if (status_ == Open && !hitButton(cmd)) + else if (status() && !hitButton(cmd)) InsetText::doDispatch(cur, cmd); else cur.undispatched(); @@ -301,7 +308,7 @@ void InsetCollapsable::doDispatch(LCurso break; } - switch (status_) { + switch (status()) { case Collapsed: //lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl; Index: insetcollapsable.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v retrieving revision 1.187 diff -p -u -r1.187 insetcollapsable.h --- insetcollapsable.h 15 Jul 2005 22:10:22 -0000 1.187 +++ insetcollapsable.h 17 Sep 2005 14:10:24 -0000 @@ -69,7 +69,7 @@ public: /// bool inlined() const { return status_ == Inlined; } /// - CollapseStatus status() const { return status_; } + CollapseStatus status() const; /// bool allowSpellCheck() const { return true; } /// @@ -107,6 +107,8 @@ private: mutable CollapseStatus status_; /// a substatus of the Open status, determined automatically in metrics mutable bool openinlined_; + /// the inset will automatically open when the cursor is inside + mutable bool autoOpen_; /// mutable Dimension textdim_; };