Hi all,
This patch solves bug 4346. It changes the autoOpen_ member of
InsetCollapsable into a map, such that an autoOpen value can be
specified for each bufferView. Now, the assertion is avoided and
insetCollapsable can be open in one bufferview and be closed in the
other in very special cases that the cursor end up in a closed inset.
The basic change is the one below, the rather large patch is just
administration.
Index: src/insets/InsetCollapsable.h
===================================================================
@@ -190,8 +191,9 @@
- /// the inset will automatically open when the cursor is inside
- mutable bool autoOpen_;
+ /// the inset will automatically open when the cursor is inside.
This is
+ /// dependent on the bufferview, compare with MathMacro::editing_.
+ mutable std::map<BufferView const *, bool> auto_open_;
Objections (for branch too) ?
Vincent
Index: src/insets/InsetERT.h
===================================================================
--- src/insets/InsetERT.h (revision 28468)
+++ src/insets/InsetERT.h (working copy)
@@ -69,7 +69,7 @@
///
Inset * clone() const { return new InsetERT(*this); }
///
- void setButtonLabel();
+ void setButtonLabel(BufferView const & bv);
///
bool allowSpellCheck() const { return false; }
};
Index: src/insets/InsetFoot.cpp
===================================================================
--- src/insets/InsetFoot.cpp (revision 28468)
+++ src/insets/InsetFoot.cpp (working copy)
@@ -81,7 +81,7 @@
docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
{
docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
- if (!isOpen())
+ if (!isOpen(bv))
return custom_label_ + ": " + default_tip;
return default_tip;
}
Index: src/insets/InsetERT.cpp
===================================================================
--- src/insets/InsetERT.cpp (revision 28468)
+++ src/insets/InsetERT.cpp (working copy)
@@ -162,10 +162,10 @@
}
-void InsetERT::setButtonLabel()
+void InsetERT::setButtonLabel(BufferView const & bv)
{
if (decoration() == InsetLayout::CLASSIC)
- setLabel(isOpen() ? _("ERT") : getNewLabel(_("ERT")));
+ setLabel(isOpen(bv) ? _("ERT") : getNewLabel(_("ERT")));
else
setLabel(getNewLabel(_("ERT")));
}
@@ -179,7 +179,7 @@
bool InsetERT::showInsetDialog(BufferView * bv) const
{
- bv->showDialog("ert", params2string(status()),
+ bv->showDialog("ert", params2string(status(*bv)),
const_cast<InsetERT *>(this));
return true;
}
Index: src/insets/InsetBranch.cpp
===================================================================
--- src/insets/InsetBranch.cpp (revision 28468)
+++ src/insets/InsetBranch.cpp (working copy)
@@ -81,7 +81,7 @@
}
-void InsetBranch::setButtonLabel()
+void InsetBranch::setButtonLabel(BufferView const & bv)
{
docstring s = _("Branch: ") + params_.branch;
if (!params_.branch.empty()) {
@@ -91,7 +91,7 @@
s = _("Undef: ") + s;
}
if (decoration() == InsetLayout::CLASSIC)
- setLabel(isOpen() ? s : getNewLabel(s) );
+ setLabel(isOpen(bv) ? s : getNewLabel(s) );
else
setLabel(params_.branch + ": " + getNewLabel(s));
}
@@ -143,12 +143,12 @@
if (cmd.argument() == "assign") {
// The branch inset uses "assign".
if (isBranchSelected()) {
- if (status() != Open)
+ if (status(cur.bv()) != Open)
setStatus(cur, Open);
else
cur.undispatched();
} else {
- if (status() != Collapsed)
+ if (status(cur.bv()) != Collapsed)
setStatus(cur, Collapsed);
else
cur.undispatched();
@@ -180,9 +180,9 @@
flag.setEnabled(true);
else if (cmd.argument() == "assign" || cmd.argument().empty()) {
if (isBranchSelected())
- flag.setEnabled(status() != Open);
+ flag.setEnabled(status(cur.bv()) != Open);
else
- flag.setEnabled(status() != Collapsed);
+ flag.setEnabled(status(cur.bv()) != Collapsed);
} else
flag.setEnabled(true);
break;
Index: src/insets/InsetListings.h
===================================================================
--- src/insets/InsetListings.h (revision 28468)
+++ src/insets/InsetListings.h (working copy)
@@ -73,7 +73,7 @@
///
Inset * clone() const { return new InsetListings(*this); }
///
- void setButtonLabel();
+ void setButtonLabel(BufferView const & bv);
///
docstring getCaption(OutputParams const &) const;
Index: src/insets/InsetListings.cpp
===================================================================
--- src/insets/InsetListings.cpp (revision 28468)
+++ src/insets/InsetListings.cpp (working copy)
@@ -397,11 +397,11 @@
}
-void InsetListings::setButtonLabel()
+void InsetListings::setButtonLabel(BufferView const & bv)
{
// FIXME UNICODE
if (decoration() == InsetLayout::CLASSIC)
- setLabel(isOpen() ? _("Listing") : getNewLabel(_("Listing")));
+ setLabel(isOpen(bv) ? _("Listing") :
getNewLabel(_("Listing")));
else
setLabel(getNewLabel(_("Listing")));
}
Index: src/insets/InsetBranch.h
===================================================================
--- src/insets/InsetBranch.h (revision 28468)
+++ src/insets/InsetBranch.h (working copy)
@@ -62,7 +62,7 @@
///
void read(Lexer & lex);
///
- void setButtonLabel();
+ void setButtonLabel(BufferView const & bv);
///
ColorCode backgroundColor() const;
///
Index: src/insets/InsetFloat.cpp
===================================================================
--- src/insets/InsetFloat.cpp (revision 28468)
+++ src/insets/InsetFloat.cpp (working copy)
@@ -135,7 +135,7 @@
docstring InsetFloat::toolTip(BufferView const & bv, int x, int y) const
{
- if (InsetCollapsable::toolTip(bv, x, y).empty() || isOpen())
+ if (InsetCollapsable::toolTip(bv, x, y).empty() || isOpen(bv))
return docstring();
OutputParams rp(&buffer().params().encoding());
Index: src/insets/InsetCollapsable.cpp
===================================================================
--- src/insets/InsetCollapsable.cpp (revision 28468)
+++ src/insets/InsetCollapsable.cpp (working copy)
@@ -46,27 +46,27 @@
namespace lyx {
-InsetCollapsable::CollapseStatus InsetCollapsable::status() const
+InsetCollapsable::CollapseStatus InsetCollapsable::status(BufferView const &
bv) const
{
if (decoration() == InsetLayout::CONGLOMERATE)
return status_;
- return autoOpen_ ? Open : status_;
+ return auto_open_[&bv] ? Open : status_;
}
-InsetCollapsable::Geometry InsetCollapsable::geometry() const
+InsetCollapsable::Geometry InsetCollapsable::geometry(BufferView const & bv)
const
{
switch (decoration()) {
case InsetLayout::CLASSIC:
- if (status() == Open)
+ if (status(bv) == Open)
return openinlined_ ? LeftButton : TopButton;
return ButtonOnly;
case InsetLayout::MINIMALISTIC:
- return status() == Open ? NoButton : ButtonOnly ;
+ return status(bv) == Open ? NoButton : ButtonOnly ;
case InsetLayout::CONGLOMERATE:
- return status() == Open ? SubLabel : Corners ;
+ return status(bv) == Open ? SubLabel : Corners ;
case InsetLayout::DEFAULT:
break; // this shouldn't happen
@@ -80,7 +80,7 @@
InsetCollapsable::InsetCollapsable(Buffer const & buf)
: InsetText(buf), status_(Inset::Open),
- openinlined_(false), autoOpen_(false), mouse_hover_(false)
+ openinlined_(false), mouse_hover_(false)
{
DocumentClass const & dc = buf.params().documentClass();
setLayout(&dc);
@@ -98,7 +98,7 @@
labelstring_(rhs.labelstring_),
button_dim(rhs.button_dim),
openinlined_(rhs.openinlined_),
- autoOpen_(rhs.autoOpen_),
+ auto_open_(rhs.auto_open_),
// the sole purpose of this copy constructor
mouse_hover_(false)
{
@@ -108,9 +108,9 @@
docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
{
Dimension dim = dimensionCollapsed();
- if (geometry() == NoButton)
+ if (geometry(bv) == NoButton)
return translateIfPossible(layout_->labelstring());
- if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen())
+ if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv))
return docstring();
OutputParams rp(&buffer().params().encoding());
@@ -201,13 +201,13 @@
{
LASSERT(layout_, /**/);
- autoOpen_ = mi.base.bv->cursor().isInside(this);
+ auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
FontInfo tmpfont = mi.base.font;
mi.base.font = layout_->font();
mi.base.font.realize(tmpfont);
- switch (geometry()) {
+ switch (geometry(*mi.base.bv)) {
case NoButton:
InsetText::metrics(mi, dim);
break;
@@ -234,7 +234,8 @@
case LeftButton:
case ButtonOnly:
dim = dimensionCollapsed();
- if (geometry() == TopButton || geometry() == LeftButton) {
+ if (geometry(*mi.base.bv) == TopButton
+ || geometry(*mi.base.bv) == LeftButton) {
Dimension textdim;
InsetText::metrics(mi, textdim);
openinlined_ = (textdim.wid + dim.wid) <
mi.base.textwidth;
@@ -265,8 +266,8 @@
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
{
LASSERT(layout_, /**/);
- autoOpen_ = pi.base.bv->cursor().isInside(this);
+ auto_open_[pi.base.bv] = pi.base.bv->cursor().isInside(this);
FontInfo tmpfont = pi.base.font;
pi.base.font = layout_->font();
@@ -275,9 +276,9 @@
// Draw button first -- top, left or only
Dimension dimc = dimensionCollapsed();
- if (geometry() == TopButton ||
- geometry() == LeftButton ||
- geometry() == ButtonOnly) {
+ if (geometry(*pi.base.bv) == TopButton ||
+ geometry(*pi.base.bv) == LeftButton ||
+ geometry(*pi.base.bv) == ButtonOnly) {
button_dim.x1 = x + 0;
button_dim.x2 = x + dimc.width();
button_dim.y1 = y - dimc.asc;
@@ -295,7 +296,7 @@
Dimension const textdim = InsetText::dimension(*pi.base.bv);
int const baseline = y;
int textx, texty;
- switch (geometry()) {
+ switch (geometry(*pi.base.bv)) {
case LeftButton:
textx = x + dimc.width();
texty = baseline;
@@ -322,7 +323,7 @@
const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
int desc = textdim.descent();
- if (geometry() == Corners)
+ if (geometry(*pi.base.bv) == Corners)
desc -= 3;
const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
@@ -347,7 +348,7 @@
y + desc - 4, layout_->labelfont().color());
// the label below the text. Can be toggled.
- if (geometry() == SubLabel) {
+ if (geometry(*pi.base.bv) == SubLabel) {
FontInfo font(layout_->labelfont());
font.realize(sane_font);
font.decSize();
@@ -384,14 +385,14 @@
void InsetCollapsable::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const
{
- if (geometry() == ButtonOnly)
+ if (geometry(bv) == ButtonOnly)
status_ = Open;
- LASSERT(geometry() != ButtonOnly, /**/);
+ LASSERT(geometry(bv) != ButtonOnly, /**/);
InsetText::cursorPos(bv, sl, boundary, x, y);
Dimension const textdim = InsetText::dimension(bv);
- switch (geometry()) {
+ switch (geometry(bv)) {
case LeftButton:
x += dimensionCollapsed().wid;
break;
@@ -411,15 +412,15 @@
}
-Inset::EDITABLE InsetCollapsable::editable() const
+Inset::EDITABLE InsetCollapsable::editable(BufferView const & bv) const
{
- return geometry() != ButtonOnly ? HIGHLY_EDITABLE : IS_EDITABLE;
+ return geometry(bv) != ButtonOnly ? HIGHLY_EDITABLE : IS_EDITABLE;
}
-bool InsetCollapsable::descendable() const
+bool InsetCollapsable::descendable(BufferView const & bv) const
{
- return geometry() != ButtonOnly;
+ return geometry(bv) != ButtonOnly;
}
@@ -461,9 +462,9 @@
Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
{
//lyxerr << "InsetCollapsable: edit xy" << endl;
- if (geometry() == ButtonOnly
+ if (geometry(cur.bv()) == ButtonOnly
|| (button_dim.contains(x, y)
- && geometry() != NoButton))
+ && geometry(cur.bv()) != NoButton))
return this;
cur.push(*this);
return InsetText::editXY(cur, x, y);
@@ -493,7 +494,7 @@
cur.noUpdate();
break;
}
- } else if (geometry() != ButtonOnly)
+ } else if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
else
cur.undispatched();
@@ -504,7 +505,7 @@
case LFUN_MOUSE_TRIPLE:
if (hitButton(cmd))
cur.noUpdate();
- else if (geometry() != ButtonOnly)
+ else if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
else
cur.undispatched();
@@ -513,7 +514,7 @@
case LFUN_MOUSE_RELEASE:
if (!hitButton(cmd)) {
// The mouse click has to be within the inset!
- if (geometry() != ButtonOnly)
+ if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
else
cur.undispatched();
@@ -532,7 +533,7 @@
// toggle the inset visual state.
cur.dispatched();
cur.updateFlags(Update::Force | Update::FitCursor);
- if (geometry() == ButtonOnly) {
+ if (geometry(cur.bv()) == ButtonOnly) {
setStatus(cur, Open);
edit(cur, true);
}
@@ -549,7 +550,7 @@
else if (cmd.argument() == "toggle" || cmd.argument().empty())
if (status_ == Open) {
setStatus(cur, Collapsed);
- if (geometry() == ButtonOnly)
+ if (geometry(cur.bv()) == ButtonOnly)
cur.top().forwardPos();
} else
setStatus(cur, Open);
@@ -867,7 +868,7 @@
if (decoration() == InsetLayout::CONGLOMERATE)
return from_ascii("context-conglomerate");
- if (geometry() == NoButton)
+ if (geometry(bv) == NoButton)
return from_ascii("context-collapsable");
Dimension dim = dimensionCollapsed();
Index: src/insets/InsetWrap.cpp
===================================================================
--- src/insets/InsetWrap.cpp (revision 28468)
+++ src/insets/InsetWrap.cpp (working copy)
@@ -71,7 +71,7 @@
OutputParams rp(&buffer().params().encoding());
docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
docstring caption_tip = getCaptionText(rp);
- if (!isOpen() && !caption_tip.empty())
+ if (!isOpen(bv) && !caption_tip.empty())
return caption_tip + '\n' + default_tip;
return default_tip;
}
Index: src/insets/InsetCollapsable.h
===================================================================
--- src/insets/InsetCollapsable.h (revision 28468)
+++ src/insets/InsetCollapsable.h (working copy)
@@ -78,17 +78,18 @@
///
docstring const getNewLabel(docstring const & l) const;
///
- EDITABLE editable() const;
+ EDITABLE editable(BufferView const & bv) const;
/// can we go further down on mouse click?
- bool descendable() const;
+ bool descendable(BufferView const & bv) const;
///
void setLabel(docstring const & l);
///
virtual void setButtonLabel() {}
///
- bool isOpen() const { return geometry() != ButtonOnly; }
+ bool isOpen(BufferView const & bv) const
+ { return geometry(bv) != ButtonOnly; }
///
- CollapseStatus status() const;
+ CollapseStatus status(BufferView const & bv) const;
/** Of the old CollapseStatus we only keep the values
* Open and Collapsed.
* We define a list of possible inset decoration
@@ -122,7 +123,7 @@
/// Returns the geometry based on CollapseStatus
/// (status_), autoOpen_ and openinlined_, and of
/// course decoration().
- Geometry geometry() const;
+ Geometry geometry(BufferView const & bv) const;
/// Allow spellchecking, except for insets with latex_language
bool allowSpellCheck() const { return !forceLTR(); }
///
@@ -190,8 +191,9 @@
mutable Box button_dim;
/// 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_;
+ /// the inset will automatically open when the cursor is inside. This is
+ /// dependent on the bufferview, compare with MathMacro::editing_.
+ mutable std::map<BufferView const *, bool> auto_open_;
/// changes color when mouse enters/leaves this inset
bool mouse_hover_;
};