From: Abdelrazak Younes Date: Mon, 3 Mar 2008 17:58:26 +0000 (+0000) Subject: Sanitize a bit the way InsetRef and InsetCommand button are drawn. X-Git-Tag: 1.6.10~5923 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=017ba3c4c7b7711431779dba931f50735ce32b71;p=features.git Sanitize a bit the way InsetRef and InsetCommand button are drawn. * 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 --- diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 33a6ca0f06..875853bd01 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -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(); } } diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 949ede774e..3c188f1f32 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -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; } diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index 576cece165..95a138dbe8 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -208,7 +208,6 @@ void InsetBibitem::updateLabels(ParIterator const &) } else { autolabel_ = from_ascii("??"); } - refresh(); } diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index 7a51624adf..30c944abaa 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -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: { diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index 96e523a3ce..0228a0160c 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -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_; }; diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index 57ec16ad9f..0158361ab8 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -43,7 +43,7 @@ InsetLabel::InsetLabel(InsetCommandParams const & p) {} -void InsetLabel::validate() +void InsetLabel::initView() { update(getParam("name")); } diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h index ca86840045..a963448909 100644 --- a/src/insets/InsetLabel.h +++ b/src/insets/InsetLabel.h @@ -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; diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 88c76fa553..0b36a7f7c7 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -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_)); } diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index eab494474b..9ba7895d86 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -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