]> git.lyx.org Git - features.git/commitdiff
Fix bug 4346: http://bugzilla.lyx.org/show_bug.cgi?id=4346.
authorVincent van Ravesteijn <vfr@lyx.org>
Sat, 21 Feb 2009 16:27:00 +0000 (16:27 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Sat, 21 Feb 2009 16:27:00 +0000 (16:27 +0000)
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

src/insets/InsetBranch.cpp
src/insets/InsetBranch.h
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetERT.cpp
src/insets/InsetERT.h
src/insets/InsetFloat.cpp
src/insets/InsetFoot.cpp
src/insets/InsetListings.cpp
src/insets/InsetListings.h
src/insets/InsetWrap.cpp

index d28ba0deeaaff49fead0109cf1e56643268c75cd..4bc330b3ad59578d61783283dede1a1951e7c0d5 100644 (file)
@@ -81,7 +81,7 @@ docstring InsetBranch::toolTip(BufferView const &, int, int) const
 }
 
 
-void InsetBranch::setButtonLabel()
+void InsetBranch::setButtonLabel(BufferView const & bv)
 {
        docstring s = _("Branch: ") + params_.branch;
        if (!params_.branch.empty()) {
@@ -91,7 +91,7 @@ void InsetBranch::setButtonLabel()
                        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 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
                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 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
                        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 67fde95cf8f8856fa46bddaeb9be2a6a6b042103..71591a127a730809bb8d8922e747a5c91f61d83c 100644 (file)
@@ -62,7 +62,7 @@ private:
        ///
        void read(Lexer & lex);
        ///
-       void setButtonLabel();
+       void setButtonLabel(BufferView const & bv);
        ///
        ColorCode backgroundColor() const;
        ///
index 31e3daf33cd84b9251787dafe8b39d33e344e595..6c5a44bbefcc4d3ecd6e8bd5ed8a0da09da4f5af 100644 (file)
@@ -46,27 +46,27 @@ using namespace std;
 
 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::Geometry InsetCollapsable::geometry() const
 
 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 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
          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 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
 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 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        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 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
        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;
@@ -266,7 +267,7 @@ 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 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
        // 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 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
        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 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                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 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                        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::draw(PainterInfo & pi, 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)
                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 @@ void InsetCollapsable::cursorPos(BufferView const & bv,
 }
 
 
-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 @@ void InsetCollapsable::edit(Cursor & cur, bool front, EntryDirection entry_from)
 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 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
                                cur.noUpdate();
                                break;
                        }
-               } else if (geometry() != ButtonOnly)
+               } else if (geometry(cur.bv()) != ButtonOnly)
                        InsetText::doDispatch(cur, cmd);
                else
                        cur.undispatched();
@@ -504,7 +505,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
        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 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
        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 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
                // 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 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
                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 @@ docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
        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 8610516002b679a87bf2a7af46715565e97c8754..88055b4ba00f7e7cab46f241b8e6859b4a125946 100644 (file)
@@ -78,17 +78,18 @@ public:
        ///
        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 @@ public:
        /// 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 @@ private:
        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_;
 };
index bc4756a5d823ed0d22268a9f4b5ffcf0f9b3d3b7..de911557c72ad1c964353f9c7a9b790b44132b82 100644 (file)
@@ -162,10 +162,10 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-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::insetAllowed(InsetCode /* code */) const
 
 bool InsetERT::showInsetDialog(BufferView * bv) const
 {
-       bv->showDialog("ert", params2string(status()), 
+       bv->showDialog("ert", params2string(status(*bv)), 
                const_cast<InsetERT *>(this));
        return true;
 }
index 1a81775ac445e81e1734da92485658ccb2b84fb6..2df001b3e0972615b10418bb6f67fa2c78425ef3 100644 (file)
@@ -69,7 +69,7 @@ private:
        ///
        Inset * clone() const { return new InsetERT(*this); }
        ///
-       void setButtonLabel();
+       void setButtonLabel(BufferView const & bv);
        ///
        bool allowSpellCheck() const { return false; }
 };
index 0dfe34326bbaf41fde0267d214aa92cc3be60b2d..37a247af44341588628045ca3064656786b5583b 100644 (file)
@@ -135,7 +135,7 @@ docstring InsetFloat::name() 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());
index 615171d0e28343486f925bdf7143db4968fb00da..66654e6cb71ef445c1b0d7aa174287d698b35e78 100644 (file)
@@ -81,7 +81,7 @@ void InsetFoot::addToToc(DocIterator const & cpit)
 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 647d401386484503f54b7c3ae2663250fab2d275..035da731f22714c46c6ccdcab5d13c7295a7a29f 100644 (file)
@@ -397,11 +397,11 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-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 a1eeeda315958f6560dfd286b523db2d71e30e89..09d1ac73000f837939ede43789e6e2fc51c6f24d 100644 (file)
@@ -73,7 +73,7 @@ private:
        ///
        Inset * clone() const { return new InsetListings(*this); }
        ///
-       void setButtonLabel();
+       void setButtonLabel(BufferView const & bv);
        ///
        docstring getCaption(OutputParams const &) const;
 
index 566ba91d732b9426a8fc7d29775167c017dd9d52..c21d2225079eb191c05195c69e1600098e69443c 100644 (file)
@@ -71,7 +71,7 @@ docstring InsetWrap::toolTip(BufferView const & bv, int x, int y) const
        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;
 }