cell().insert(pos(), t);
++pos();
inset().setBuffer(bv_->buffer());
- inset().validate();
+ inset().initView();
}
else {
text()->insertInset(*this, inset0);
inset0->setBuffer(bv_->buffer());
- inset0->validate();
+ inset0->initView();
}
}
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; }
} else {
autolabel_ = from_ascii("??");
}
- refresh();
}
string const & mailer_name)
: p_(p),
mailer_name_(mailer_name),
- mouse_hover_(false),
- updateButtonLabel_(true)
+ mouse_hover_(false)
{}
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);
}
void InsetCommand::setParams(InsetCommandParams const & p)
{
p_ = p;
- updateButtonLabel_ = true;
+ initView();
}
{
switch (cmd.action) {
case LFUN_INSET_REFRESH:
- updateButtonLabel_ = true;
break;
case LFUN_INSET_MODIFY: {
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;
}
///
///
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
/// changes color when mouse enters/leaves this inset
bool mouse_hover_;
///
- mutable bool updateButtonLabel_;
- ///
mutable RenderButton button_;
};
{}
-void InsetLabel::validate()
+void InsetLabel::initView()
{
update(getParam("name"));
}
/// verify label and update references.
/**
- * Overloaded from Inset::validate.
+ * Overloaded from Inset::initView.
**/
- void validate();
+ void initView();
///
docstring screenLabel() const;
#include "InsetRef.h"
#include "Buffer.h"
+#include "buffer_funcs.h"
#include "Cursor.h"
#include "DispatchResult.h"
#include "FuncRequest.h"
{}
+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.
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_;
}
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");
+ }
}
// 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_));
}
InsetRef(InsetCommandParams const &, Buffer const &);
+ /// verify label and reference.
+ /**
+ * Overloaded from Inset::initView.
+ **/
+ void initView();
///
docstring screenLabel() const;
///
Inset * clone() const { return new InsetRef(*this); }
///
bool isLatex;
+ ///
+ mutable docstring screen_label_;
};
} // namespace lyx