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
This commit is contained in:
Abdelrazak Younes 2008-03-03 17:58:26 +00:00
parent f847fb64f8
commit 017ba3c4c7
9 changed files with 45 additions and 42 deletions

View 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();
}
}

View 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; }

View File

@ -208,7 +208,6 @@ void InsetBibitem::updateLabels(ParIterator const &)
} else {
autolabel_ = from_ascii("??");
}
refresh();
}

View 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: {

View 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_;
};

View File

@ -43,7 +43,7 @@ InsetLabel::InsetLabel(InsetCommandParams const & p)
{}
void InsetLabel::validate()
void InsetLabel::initView()
{
update(getParam("name"));
}

View 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;

View 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_));
}

View 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