]> git.lyx.org Git - features.git/commitdiff
Sanitize a bit the way InsetRef and InsetCommand button are drawn.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 3 Mar 2008 17:58:26 +0000 (17:58 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 3 Mar 2008 17:58:26 +0000 (17:58 +0000)
* Inset::validate(): renamed to initView()

* InsetCommand:
- get rid of unneeded refresh() and updateButtonLabel_
- setParams(): call initView()

* InsetRef:
- implement initView()
- screenLabel(): transfer code to updateLabels()
- addToToc(): prefix name with BROKEN if the reference is broken.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23417 a592a061-630c-0410-9148-cb99ea01b6c8

src/Cursor.cpp
src/insets/Inset.h
src/insets/InsetBibitem.cpp
src/insets/InsetCommand.cpp
src/insets/InsetCommand.h
src/insets/InsetLabel.cpp
src/insets/InsetLabel.h
src/insets/InsetRef.cpp
src/insets/InsetRef.h

index 33a6ca0f068c1b0eb2a84119221d8039ef86db6b..875853bd017dd6c6efdd219456e5dddb93452729 100644 (file)
@@ -987,7 +987,7 @@ void Cursor::plainInsert(MathAtom const & t)
        cell().insert(pos(), t);
        ++pos();
        inset().setBuffer(bv_->buffer());
-       inset().validate();
+       inset().initView();
 }
 
 
@@ -1029,7 +1029,7 @@ void Cursor::insert(Inset * inset0)
        else {
                text()->insertInset(*this, inset0);
                inset0->setBuffer(bv_->buffer());
-               inset0->validate();
+               inset0->initView();
        }
 }
 
index 949ede774e8a037e1887ef930d88f2ecfb18f7b9..3c188f1f325f6fb153f45501d025f377cba6636e 100644 (file)
@@ -97,13 +97,13 @@ public:
        virtual Buffer & buffer();
        virtual Buffer const & buffer() const;
 
-       /// validate inset.
+       /// initialize view for this inset.
        /**
          * This is typically used after this inset is created interactively.
          * Intented purpose is to sanitize internal state with regard to current
          * Buffer.
          **/
-       virtual void validate() {}
+       virtual void initView() {}
 
        /// identification as math inset
        virtual InsetMath * asInsetMath() { return 0; }
index 576cece165b49120c0dbef4c0374c4c5810f0a77..95a138dbe82d8cf0a07c02a87817c0080c2554a7 100644 (file)
@@ -208,7 +208,6 @@ void InsetBibitem::updateLabels(ParIterator const &)
        } else {
                autolabel_ = from_ascii("??");
        }
-       refresh();
 }
 
 
index 7a51624adfd937982eee78868318f2bea155985a..30c944abaad5d506f5a8476d70e3bc798d5277e0 100644 (file)
@@ -35,8 +35,7 @@ InsetCommand::InsetCommand(InsetCommandParams const & p,
                           string const & mailer_name)
        : p_(p),
          mailer_name_(mailer_name),
-         mouse_hover_(false),
-         updateButtonLabel_(true)
+         mouse_hover_(false)
 {}
 
 
@@ -49,10 +48,7 @@ InsetCommand::~InsetCommand()
 
 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       if (updateButtonLabel_) {
-               updateButtonLabel_ = false;
-               button_.update(screenLabel(), editable() != NOT_EDITABLE);
-       }
+       button_.update(screenLabel(), editable() != NOT_EDITABLE);
        button_.metrics(mi, dim);
 }
 
@@ -74,7 +70,7 @@ void InsetCommand::draw(PainterInfo & pi, int x, int y) const
 void InsetCommand::setParams(InsetCommandParams const & p)
 {
        p_ = p;
-       updateButtonLabel_ = true;
+       initView();
 }
 
 
@@ -104,7 +100,6 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_REFRESH:
-               updateButtonLabel_ = true;
                break;
 
        case LFUN_INSET_MODIFY: {
index 96e523a3ce4118e1f1521adf4b37e1d5839620f7..0228a0160cce3c70e8ff3f8230824441e444c3d5 100644 (file)
@@ -56,12 +56,9 @@ public:
        InsetCommandParams const & params() const { return p_; }
        /// FIXME Remove
        docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
-       /// Whether the button label should be recomputed.
-       void refresh() { updateButtonLabel_ = true; }
        ///
        void setParam(std::string const & name, docstring const & value)
        {
-               updateButtonLabel_ = true;
                p_[name] = value;
        }
        ///
@@ -98,11 +95,7 @@ protected:
        ///
        std::string const & getCmdName() const { return p_.getCmdName(); }
        ///
-       void setCmdName(std::string const & n)
-       {
-               updateButtonLabel_ = true;
-               p_.setCmdName(n);
-       }
+       void setCmdName(std::string const & n) { p_.setCmdName(n); }
        ///
        void setParams(InsetCommandParams const &);
        /// This should provide the text for the button
@@ -116,8 +109,6 @@ private:
        /// changes color when mouse enters/leaves this inset
        bool mouse_hover_;
        ///
-       mutable bool updateButtonLabel_;
-       ///
        mutable RenderButton button_;
 };
 
index 57ec16ad9f09102e95dd58cc5fc0b0331659f88d..0158361ab8b1774fc25fa5d5165456b91b601b7b 100644 (file)
@@ -43,7 +43,7 @@ InsetLabel::InsetLabel(InsetCommandParams const & p)
 {}
 
 
-void InsetLabel::validate()
+void InsetLabel::initView()
 {
        update(getParam("name"));
 }
index ca868400457dcb2d29cc116463951dcdc66f12fa..a96344890916bd7613c143d25777813f267f654f 100644 (file)
@@ -24,9 +24,9 @@ public:
 
        /// verify label and update references.
        /**
-         * Overloaded from Inset::validate.
+         * Overloaded from Inset::initView.
          **/
-       void validate();
+       void initView();
 
        ///
        docstring screenLabel() const;
index 88c76fa5530b5e8a2fe9f48216d884a2f4025a8e..0b36a7f7c71edc6bfd5c1ba1e0fad79f9412b620 100644 (file)
@@ -12,6 +12,7 @@
 #include "InsetRef.h"
 
 #include "Buffer.h"
+#include "buffer_funcs.h"
 #include "Cursor.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
@@ -42,6 +43,14 @@ InsetRef::InsetRef(InsetRef const & ir)
 {}
 
 
+void InsetRef::initView()
+{
+       // We need an update of the Buffer reference cache. This is achieved by
+       // updateLabel().
+       lyx::updateLabels(buffer());
+}
+
+
 bool InsetRef::isCompatibleCommand(string const & s) {
        //FIXME This is likely not the best way to handle this.
        //But this stuff is hardcoded elsewhere already.
@@ -85,20 +94,7 @@ void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
 
 docstring InsetRef::screenLabel() const
 {
-       docstring temp;
-       for (int i = 0; !types[i].latex_name.empty(); ++i) {
-               if (getCmdName() == types[i].latex_name) {
-                       temp = _(types[i].short_gui_name);
-                       break;
-               }
-       }
-       temp += getParam("reference");
-
-       if (!isLatex && !getParam("name").empty()) {
-               temp += "||";
-               temp += getParam("name");
-       }
-       return temp;
+       return screen_label_;
 }
 
 
@@ -155,7 +151,21 @@ void InsetRef::textString(odocstream & os) const
 void InsetRef::updateLabels(ParIterator const & it)
 {
        docstring const & label = getParam("reference");
+       // register this inset into the buffer reference cache.
        buffer().references(label).push_back(make_pair(this, it));
+
+       for (int i = 0; !types[i].latex_name.empty(); ++i) {
+               if (getCmdName() == types[i].latex_name) {
+                       screen_label_ = _(types[i].short_gui_name);
+                       break;
+               }
+       }
+       screen_label_ += getParam("reference");
+
+       if (!isLatex && !getParam("name").empty()) {
+               screen_label_ += "||";
+               screen_label_ += getParam("name");
+       }
 }
 
 
@@ -166,9 +176,10 @@ void InsetRef::addToToc(ParConstIterator const & cpit) const
                // This InsetRef has already been taken care of in InsetLabel::addToToc().
                return;
 
+       // It seems that this reference does not point to any valid label.
+       screen_label_ = _("BROKEN: ") + screen_label_;
        Toc & toc = buffer().tocBackend().toc("label");
-       docstring const reflabel = _("BROKEN: ") + screenLabel();
-       toc.push_back(TocItem(cpit, 0, reflabel));
+       toc.push_back(TocItem(cpit, 0, screen_label_));
 }
 
 
index eab494474b1950f26ca8fa9e41ae08e23a1d7818..9ba7895d86bb624aed5db59f2ee0e0a72e72da6d 100644 (file)
@@ -38,6 +38,11 @@ public:
 
        InsetRef(InsetCommandParams const &, Buffer const &);
 
+       /// verify label and reference.
+       /**
+         * Overloaded from Inset::initView.
+         **/
+       void initView();
        ///
        docstring screenLabel() const;
        ///
@@ -76,6 +81,8 @@ private:
        Inset * clone() const { return new InsetRef(*this); }
        ///
        bool isLatex;
+       ///
+       mutable docstring screen_label_;
 };
 
 } // namespace lyx