mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 21:55:29 +00:00
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:
parent
f847fb64f8
commit
017ba3c4c7
@ -987,7 +987,7 @@ void Cursor::plainInsert(MathAtom const & t)
|
|||||||
cell().insert(pos(), t);
|
cell().insert(pos(), t);
|
||||||
++pos();
|
++pos();
|
||||||
inset().setBuffer(bv_->buffer());
|
inset().setBuffer(bv_->buffer());
|
||||||
inset().validate();
|
inset().initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1029,7 +1029,7 @@ void Cursor::insert(Inset * inset0)
|
|||||||
else {
|
else {
|
||||||
text()->insertInset(*this, inset0);
|
text()->insertInset(*this, inset0);
|
||||||
inset0->setBuffer(bv_->buffer());
|
inset0->setBuffer(bv_->buffer());
|
||||||
inset0->validate();
|
inset0->initView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,13 +97,13 @@ public:
|
|||||||
virtual Buffer & buffer();
|
virtual Buffer & buffer();
|
||||||
virtual Buffer const & buffer() const;
|
virtual Buffer const & buffer() const;
|
||||||
|
|
||||||
/// validate inset.
|
/// initialize view for this inset.
|
||||||
/**
|
/**
|
||||||
* This is typically used after this inset is created interactively.
|
* This is typically used after this inset is created interactively.
|
||||||
* Intented purpose is to sanitize internal state with regard to current
|
* Intented purpose is to sanitize internal state with regard to current
|
||||||
* Buffer.
|
* Buffer.
|
||||||
**/
|
**/
|
||||||
virtual void validate() {}
|
virtual void initView() {}
|
||||||
|
|
||||||
/// identification as math inset
|
/// identification as math inset
|
||||||
virtual InsetMath * asInsetMath() { return 0; }
|
virtual InsetMath * asInsetMath() { return 0; }
|
||||||
|
@ -208,7 +208,6 @@ void InsetBibitem::updateLabels(ParIterator const &)
|
|||||||
} else {
|
} else {
|
||||||
autolabel_ = from_ascii("??");
|
autolabel_ = from_ascii("??");
|
||||||
}
|
}
|
||||||
refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,8 +35,7 @@ InsetCommand::InsetCommand(InsetCommandParams const & p,
|
|||||||
string const & mailer_name)
|
string const & mailer_name)
|
||||||
: p_(p),
|
: p_(p),
|
||||||
mailer_name_(mailer_name),
|
mailer_name_(mailer_name),
|
||||||
mouse_hover_(false),
|
mouse_hover_(false)
|
||||||
updateButtonLabel_(true)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -49,10 +48,7 @@ InsetCommand::~InsetCommand()
|
|||||||
|
|
||||||
void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
|
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);
|
button_.metrics(mi, dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +70,7 @@ void InsetCommand::draw(PainterInfo & pi, int x, int y) const
|
|||||||
void InsetCommand::setParams(InsetCommandParams const & p)
|
void InsetCommand::setParams(InsetCommandParams const & p)
|
||||||
{
|
{
|
||||||
p_ = p;
|
p_ = p;
|
||||||
updateButtonLabel_ = true;
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +100,6 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
{
|
{
|
||||||
switch (cmd.action) {
|
switch (cmd.action) {
|
||||||
case LFUN_INSET_REFRESH:
|
case LFUN_INSET_REFRESH:
|
||||||
updateButtonLabel_ = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_INSET_MODIFY: {
|
case LFUN_INSET_MODIFY: {
|
||||||
|
@ -56,12 +56,9 @@ public:
|
|||||||
InsetCommandParams const & params() const { return p_; }
|
InsetCommandParams const & params() const { return p_; }
|
||||||
/// FIXME Remove
|
/// FIXME Remove
|
||||||
docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
|
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)
|
void setParam(std::string const & name, docstring const & value)
|
||||||
{
|
{
|
||||||
updateButtonLabel_ = true;
|
|
||||||
p_[name] = value;
|
p_[name] = value;
|
||||||
}
|
}
|
||||||
///
|
///
|
||||||
@ -98,11 +95,7 @@ protected:
|
|||||||
///
|
///
|
||||||
std::string const & getCmdName() const { return p_.getCmdName(); }
|
std::string const & getCmdName() const { return p_.getCmdName(); }
|
||||||
///
|
///
|
||||||
void setCmdName(std::string const & n)
|
void setCmdName(std::string const & n) { p_.setCmdName(n); }
|
||||||
{
|
|
||||||
updateButtonLabel_ = true;
|
|
||||||
p_.setCmdName(n);
|
|
||||||
}
|
|
||||||
///
|
///
|
||||||
void setParams(InsetCommandParams const &);
|
void setParams(InsetCommandParams const &);
|
||||||
/// This should provide the text for the button
|
/// This should provide the text for the button
|
||||||
@ -116,8 +109,6 @@ private:
|
|||||||
/// changes color when mouse enters/leaves this inset
|
/// changes color when mouse enters/leaves this inset
|
||||||
bool mouse_hover_;
|
bool mouse_hover_;
|
||||||
///
|
///
|
||||||
mutable bool updateButtonLabel_;
|
|
||||||
///
|
|
||||||
mutable RenderButton button_;
|
mutable RenderButton button_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ InsetLabel::InsetLabel(InsetCommandParams const & p)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
void InsetLabel::validate()
|
void InsetLabel::initView()
|
||||||
{
|
{
|
||||||
update(getParam("name"));
|
update(getParam("name"));
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ public:
|
|||||||
|
|
||||||
/// verify label and update references.
|
/// verify label and update references.
|
||||||
/**
|
/**
|
||||||
* Overloaded from Inset::validate.
|
* Overloaded from Inset::initView.
|
||||||
**/
|
**/
|
||||||
void validate();
|
void initView();
|
||||||
|
|
||||||
///
|
///
|
||||||
docstring screenLabel() const;
|
docstring screenLabel() const;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "InsetRef.h"
|
#include "InsetRef.h"
|
||||||
|
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
#include "buffer_funcs.h"
|
||||||
#include "Cursor.h"
|
#include "Cursor.h"
|
||||||
#include "DispatchResult.h"
|
#include "DispatchResult.h"
|
||||||
#include "FuncRequest.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) {
|
bool InsetRef::isCompatibleCommand(string const & s) {
|
||||||
//FIXME This is likely not the best way to handle this.
|
//FIXME This is likely not the best way to handle this.
|
||||||
//But this stuff is hardcoded elsewhere already.
|
//But this stuff is hardcoded elsewhere already.
|
||||||
@ -85,20 +94,7 @@ void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
|
|
||||||
docstring InsetRef::screenLabel() const
|
docstring InsetRef::screenLabel() const
|
||||||
{
|
{
|
||||||
docstring temp;
|
return screen_label_;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -155,7 +151,21 @@ void InsetRef::textString(odocstream & os) const
|
|||||||
void InsetRef::updateLabels(ParIterator const & it)
|
void InsetRef::updateLabels(ParIterator const & it)
|
||||||
{
|
{
|
||||||
docstring const & label = getParam("reference");
|
docstring const & label = getParam("reference");
|
||||||
|
// register this inset into the buffer reference cache.
|
||||||
buffer().references(label).push_back(make_pair(this, it));
|
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().
|
// This InsetRef has already been taken care of in InsetLabel::addToToc().
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// It seems that this reference does not point to any valid label.
|
||||||
|
screen_label_ = _("BROKEN: ") + screen_label_;
|
||||||
Toc & toc = buffer().tocBackend().toc("label");
|
Toc & toc = buffer().tocBackend().toc("label");
|
||||||
docstring const reflabel = _("BROKEN: ") + screenLabel();
|
toc.push_back(TocItem(cpit, 0, screen_label_));
|
||||||
toc.push_back(TocItem(cpit, 0, reflabel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,11 @@ public:
|
|||||||
|
|
||||||
InsetRef(InsetCommandParams const &, Buffer const &);
|
InsetRef(InsetCommandParams const &, Buffer const &);
|
||||||
|
|
||||||
|
/// verify label and reference.
|
||||||
|
/**
|
||||||
|
* Overloaded from Inset::initView.
|
||||||
|
**/
|
||||||
|
void initView();
|
||||||
///
|
///
|
||||||
docstring screenLabel() const;
|
docstring screenLabel() const;
|
||||||
///
|
///
|
||||||
@ -76,6 +81,8 @@ private:
|
|||||||
Inset * clone() const { return new InsetRef(*this); }
|
Inset * clone() const { return new InsetRef(*this); }
|
||||||
///
|
///
|
||||||
bool isLatex;
|
bool isLatex;
|
||||||
|
///
|
||||||
|
mutable docstring screen_label_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
Loading…
Reference in New Issue
Block a user