Synchronizing insets asserts with two views open
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.
Compare with the MathMacro::editing_ member.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28573
a592a061-630c-0410-9148-
cb99ea01b6c8
-void InsetBranch::setButtonLabel()
+void InsetBranch::setButtonLabel(BufferView const & bv)
{
docstring s = _("Branch: ") + params_.branch;
if (!params_.branch.empty()) {
{
docstring s = _("Branch: ") + params_.branch;
if (!params_.branch.empty()) {
s = _("Undef: ") + s;
}
if (decoration() == InsetLayout::CLASSIC)
s = _("Undef: ") + s;
}
if (decoration() == InsetLayout::CLASSIC)
- setLabel(isOpen() ? s : getNewLabel(s) );
+ setLabel(isOpen(bv) ? s : getNewLabel(s) );
else
setLabel(params_.branch + ": " + getNewLabel(s));
}
else
setLabel(params_.branch + ": " + getNewLabel(s));
}
if (cmd.argument() == "assign") {
// The branch inset uses "assign".
if (isBranchSelected()) {
if (cmd.argument() == "assign") {
// The branch inset uses "assign".
if (isBranchSelected()) {
+ if (status(cur.bv()) != Open)
setStatus(cur, Open);
else
cur.undispatched();
} else {
setStatus(cur, Open);
else
cur.undispatched();
} else {
- if (status() != Collapsed)
+ if (status(cur.bv()) != Collapsed)
setStatus(cur, Collapsed);
else
cur.undispatched();
setStatus(cur, Collapsed);
else
cur.undispatched();
flag.setEnabled(true);
else if (cmd.argument() == "assign" || cmd.argument().empty()) {
if (isBranchSelected())
flag.setEnabled(true);
else if (cmd.argument() == "assign" || cmd.argument().empty()) {
if (isBranchSelected())
- flag.setEnabled(status() != Open);
+ flag.setEnabled(status(cur.bv()) != Open);
- flag.setEnabled(status() != Collapsed);
+ flag.setEnabled(status(cur.bv()) != Collapsed);
} else
flag.setEnabled(true);
break;
} else
flag.setEnabled(true);
break;
///
void read(Lexer & lex);
///
///
void read(Lexer & lex);
///
+ void setButtonLabel(BufferView const & bv);
///
ColorCode backgroundColor() const;
///
///
ColorCode backgroundColor() const;
///
-InsetCollapsable::CollapseStatus InsetCollapsable::status() const
+InsetCollapsable::CollapseStatus InsetCollapsable::status(BufferView const & bv) const
{
if (decoration() == InsetLayout::CONGLOMERATE)
return status_;
{
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:
{
switch (decoration()) {
case InsetLayout::CLASSIC:
+ if (status(bv) == Open)
return openinlined_ ? LeftButton : TopButton;
return ButtonOnly;
case InsetLayout::MINIMALISTIC:
return openinlined_ ? LeftButton : TopButton;
return ButtonOnly;
case InsetLayout::MINIMALISTIC:
- return status() == Open ? NoButton : ButtonOnly ;
+ return status(bv) == Open ? NoButton : ButtonOnly ;
case InsetLayout::CONGLOMERATE:
case InsetLayout::CONGLOMERATE:
- return status() == Open ? SubLabel : Corners ;
+ return status(bv) == Open ? SubLabel : Corners ;
case InsetLayout::DEFAULT:
break; // this shouldn't happen
case InsetLayout::DEFAULT:
break; // this shouldn't happen
InsetCollapsable::InsetCollapsable(Buffer const & buf)
: InsetText(buf), status_(Inset::Open),
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);
{
DocumentClass const & dc = buf.params().documentClass();
setLayout(&dc);
labelstring_(rhs.labelstring_),
button_dim(rhs.button_dim),
openinlined_(rhs.openinlined_),
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)
{
// the sole purpose of this copy constructor
mouse_hover_(false)
{
docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
{
Dimension dim = dimensionCollapsed();
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());
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());
return docstring();
OutputParams rp(&buffer().params().encoding());
{
LASSERT(layout_, /**/);
{
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);
FontInfo tmpfont = mi.base.font;
mi.base.font = layout_->font();
mi.base.font.realize(tmpfont);
+ switch (geometry(*mi.base.bv)) {
case NoButton:
InsetText::metrics(mi, dim);
break;
case NoButton:
InsetText::metrics(mi, dim);
break;
case LeftButton:
case ButtonOnly:
dim = dimensionCollapsed();
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;
Dimension textdim;
InsetText::metrics(mi, textdim);
openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
{
LASSERT(layout_, /**/);
{
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();
FontInfo tmpfont = pi.base.font;
pi.base.font = layout_->font();
// Draw button first -- top, left or only
Dimension dimc = dimensionCollapsed();
// 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;
button_dim.x1 = x + 0;
button_dim.x2 = x + dimc.width();
button_dim.y1 = y - dimc.asc;
Dimension const textdim = InsetText::dimension(*pi.base.bv);
int const baseline = y;
int textx, texty;
Dimension const textdim = InsetText::dimension(*pi.base.bv);
int const baseline = y;
int textx, texty;
+ switch (geometry(*pi.base.bv)) {
case LeftButton:
textx = x + dimc.width();
texty = baseline;
case LeftButton:
textx = x + dimc.width();
texty = baseline;
const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
int desc = textdim.descent();
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;
desc -= 3;
const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
y + desc - 4, layout_->labelfont().color());
// the label below the text. Can be toggled.
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();
FontInfo font(layout_->labelfont());
font.realize(sane_font);
font.decSize();
void InsetCollapsable::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const
{
void InsetCollapsable::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const
{
- if (geometry() == ButtonOnly)
+ if (geometry(bv) == ButtonOnly)
- LASSERT(geometry() != ButtonOnly, /**/);
+ LASSERT(geometry(bv) != ButtonOnly, /**/);
InsetText::cursorPos(bv, sl, boundary, x, y);
Dimension const textdim = InsetText::dimension(bv);
InsetText::cursorPos(bv, sl, boundary, x, y);
Dimension const textdim = InsetText::dimension(bv);
+ switch (geometry(bv)) {
case LeftButton:
x += dimensionCollapsed().wid;
break;
case LeftButton:
x += dimensionCollapsed().wid;
break;
-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;
Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
{
//lyxerr << "InsetCollapsable: edit xy" << endl;
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)
|| (button_dim.contains(x, y)
- && geometry() != NoButton))
+ && geometry(cur.bv()) != NoButton))
return this;
cur.push(*this);
return InsetText::editXY(cur, x, y);
return this;
cur.push(*this);
return InsetText::editXY(cur, x, y);
- } else if (geometry() != ButtonOnly)
+ } else if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
else
cur.undispatched();
InsetText::doDispatch(cur, cmd);
else
cur.undispatched();
case LFUN_MOUSE_TRIPLE:
if (hitButton(cmd))
cur.noUpdate();
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();
InsetText::doDispatch(cur, cmd);
else
cur.undispatched();
case LFUN_MOUSE_RELEASE:
if (!hitButton(cmd)) {
// The mouse click has to be within the inset!
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();
InsetText::doDispatch(cur, cmd);
else
cur.undispatched();
// toggle the inset visual state.
cur.dispatched();
cur.updateFlags(Update::Force | Update::FitCursor);
// 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);
}
setStatus(cur, Open);
edit(cur, true);
}
else if (cmd.argument() == "toggle" || cmd.argument().empty())
if (status_ == Open) {
setStatus(cur, Collapsed);
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);
cur.top().forwardPos();
} else
setStatus(cur, Open);
if (decoration() == InsetLayout::CONGLOMERATE)
return from_ascii("context-conglomerate");
if (decoration() == InsetLayout::CONGLOMERATE)
return from_ascii("context-conglomerate");
- if (geometry() == NoButton)
+ if (geometry(bv) == NoButton)
return from_ascii("context-collapsable");
Dimension dim = dimensionCollapsed();
return from_ascii("context-collapsable");
Dimension dim = dimensionCollapsed();
///
docstring const getNewLabel(docstring const & l) const;
///
///
docstring const getNewLabel(docstring const & l) const;
///
- EDITABLE editable() const;
+ EDITABLE editable(BufferView const & bv) const;
/// can we go further down on mouse click?
/// 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() {}
///
///
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
/** Of the old CollapseStatus we only keep the values
* Open and Collapsed.
* We define a list of possible inset decoration
/// Returns the geometry based on CollapseStatus
/// (status_), autoOpen_ and openinlined_, and of
/// course decoration().
/// 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(); }
///
/// Allow spellchecking, except for insets with latex_language
bool allowSpellCheck() const { return !forceLTR(); }
///
mutable Box button_dim;
/// a substatus of the Open status, determined automatically in metrics
mutable bool openinlined_;
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_;
};
/// changes color when mouse enters/leaves this inset
bool mouse_hover_;
};
-void InsetERT::setButtonLabel()
+void InsetERT::setButtonLabel(BufferView const & bv)
{
if (decoration() == InsetLayout::CLASSIC)
{
if (decoration() == InsetLayout::CLASSIC)
- setLabel(isOpen() ? _("ERT") : getNewLabel(_("ERT")));
+ setLabel(isOpen(bv) ? _("ERT") : getNewLabel(_("ERT")));
else
setLabel(getNewLabel(_("ERT")));
}
else
setLabel(getNewLabel(_("ERT")));
}
bool InsetERT::showInsetDialog(BufferView * bv) const
{
bool InsetERT::showInsetDialog(BufferView * bv) const
{
- bv->showDialog("ert", params2string(status()),
+ bv->showDialog("ert", params2string(status(*bv)),
const_cast<InsetERT *>(this));
return true;
}
const_cast<InsetERT *>(this));
return true;
}
///
Inset * clone() const { return new InsetERT(*this); }
///
///
Inset * clone() const { return new InsetERT(*this); }
///
+ void setButtonLabel(BufferView const & bv);
///
bool allowSpellCheck() const { return false; }
};
///
bool allowSpellCheck() const { return false; }
};
docstring InsetFloat::toolTip(BufferView const & bv, int x, int y) const
{
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());
return docstring();
OutputParams rp(&buffer().params().encoding());
docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
{
docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
{
docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
return custom_label_ + ": " + default_tip;
return default_tip;
}
return custom_label_ + ": " + default_tip;
return default_tip;
}
-void InsetListings::setButtonLabel()
+void InsetListings::setButtonLabel(BufferView const & bv)
{
// FIXME UNICODE
if (decoration() == InsetLayout::CLASSIC)
{
// FIXME UNICODE
if (decoration() == InsetLayout::CLASSIC)
- setLabel(isOpen() ? _("Listing") : getNewLabel(_("Listing")));
+ setLabel(isOpen(bv) ? _("Listing") : getNewLabel(_("Listing")));
else
setLabel(getNewLabel(_("Listing")));
}
else
setLabel(getNewLabel(_("Listing")));
}
///
Inset * clone() const { return new InsetListings(*this); }
///
///
Inset * clone() const { return new InsetListings(*this); }
///
+ void setButtonLabel(BufferView const & bv);
///
docstring getCaption(OutputParams const &) const;
///
docstring getCaption(OutputParams const &) const;
OutputParams rp(&buffer().params().encoding());
docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
docstring caption_tip = getCaptionText(rp);
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;
}
return caption_tip + '\n' + default_tip;
return default_tip;
}