EndFont
End
+
+# Error fallback:
+InsetLayout CharStyle
+ LyxType end
+ LabelString "UNDEFINED"
+ Font
+ Color error
+ EndFont
+End
+
InsetCharStyle & inset =
static_cast<InsetCharStyle &>(*it);
string const name = inset.params().name;
- CharStyles::iterator const found_cs =
- tclass2.charstyle(name);
- if (found_cs == tclass2.charstyles().end()) {
+ InsetLayout const il =
+ tclass2.insetlayout(from_utf8(name));
+ inset.setLayout(il);
+ if (il.labelstring == from_utf8("UNDEFINED")) {
// The character style is undefined in tclass2
- inset.setUndefined();
docstring const s = bformat(_(
"Character style %1$s is "
"undefined because of class "
errorlist.push_back(ErrorItem(
_("Undefined character style"),
s, it.paragraph().id(), it.pos(), it.pos() + 1));
- } else if (inset.undefined()) {
- // The character style is undefined in
- // tclass1 and is defined in tclass2
- inset.setDefined(found_cs);
- }
+ }
}
}
}
return *counters_.get();
}
+
+// Return the layout object of an inset given by name. If the name
+// is not found as such, the part after the ':' is stripped off, and
+// searched again. In this way, an error fallback can be provided:
+// An erroneous 'CharStyle:badname' (e.g., after a documentclass switch)
+// will invoke the layout object defined by name = 'CharStyle'.
+// If that doesn't work either, an empty object returns (shouldn't
+// happen). -- Idea JMarc, comment MV
InsetLayout const & TextClass::insetlayout(docstring const & name) const
{
docstring n = name;
break;
n = n.substr(0,i);
}
- static const InsetLayout empty;
+ static InsetLayout empty;
+ empty.labelstring = from_utf8("UNDEFINED");
return empty;
}
-CharStyles::iterator TextClass::charstyle(string const & s) const
-{
- CharStyles::iterator cs = charstyles().begin();
- CharStyles::iterator csend = charstyles().end();
- for (; cs != csend; ++cs) {
- if (cs->name == s)
- return cs;
- }
- return csend;
-}
-
-
docstring const & TextClass::defaultLayoutName() const
{
// This really should come from the actual layout... (Lgb)
InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
///
InsetLayout const & insetlayout(docstring const & name) const;
- /// Retrieve element of name s:
- CharStyles::iterator charstyle(std::string const & s) const;
///
docstring const & defaultLayoutName() const;
///
case LFUN_CHARSTYLE_INSERT: {
string s = cmd.getArg(0);
TextClass tclass = params.getTextClass();
- CharStyles::iterator found_cs = tclass.charstyle(s);
- if (found_cs != tclass.charstyles().end())
- return new InsetCharStyle(params, found_cs);
- else
- return new InsetCharStyle(params, s);
+ InsetLayout il = tclass.insetlayout(from_utf8(s));
+ return new InsetCharStyle(params, il);
}
case LFUN_NOTE_INSERT: {
} else if (tmptok == "CharStyle") {
lex.next();
string s = lex.getString();
- CharStyles::iterator found_cs = tclass.charstyle(s);
- if (found_cs != tclass.charstyles().end())
- inset.reset(new InsetCharStyle(buf.params(), found_cs));
- else {
- // "Undefined" inset
- inset.reset(new InsetCharStyle(buf.params(), s));
- }
+ InsetLayout il = tclass.insetlayout(from_utf8(s));
+ inset.reset(new InsetCharStyle(buf.params(), il));
} else if (tmptok == "Branch") {
inset.reset(new InsetBranch(buf.params(),
InsetBranchParams()));
using std::ostringstream;
-void InsetCharStyle::init()
-{}
-
InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
: InsetCollapsable(bp, Collapsed)
{
params_.name = s;
- setUndefined();
- init();
}
InsetCharStyle::InsetCharStyle(BufferParams const & bp,
- CharStyles::iterator cs)
+ InsetLayout il)
: InsetCollapsable(bp, Collapsed)
{
- params_.name = cs->name;
- setDefined(cs);
- init();
+ params_.name = il.name;
+ setLayout(il);
}
InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
: InsetCollapsable(in), params_(in.params_)
-{
- init();
-}
+{}
auto_ptr<Inset> InsetCharStyle::doClone() const
bool InsetCharStyle::undefined() const
{
- return layout_.latexname.empty();
-}
-
-
-void InsetCharStyle::setUndefined()
-{
- layout_.latextype.clear();
- layout_.latexname.clear();
- layout_.latexparam.clear();
- layout_.font = Font(Font::ALL_INHERIT);
- layout_.labelfont = Font(Font::ALL_INHERIT);
- layout_.labelfont.setColor(Color::error);
+ return layout_.labelstring == from_utf8("UNDEFINED");
}
-void InsetCharStyle::setDefined(CharStyles::iterator cs)
+void InsetCharStyle::setLayout(InsetLayout il)
{
- layout_ = *cs;
+ layout_ = il;
}
mi.base.font.realize(tmpfont);
bool changed = InsetCollapsable::metrics(mi, dim);
mi.base.font = tmpfont;
- if (status() == Open) {
- // FIXME UNICODE
- docstring s(from_utf8(params_.name));
- // Chop off prefix:
- if (s.find(':') != string::npos)
- s = s.substr(s.find(':'));
- if (undefined())
- s = _("Undef: ") + s;
- layout_.labelstring = s;
- }
return changed;
}
//needed, or even wanted, here. It just works. -- MV 10.04.2005
InsetCollapsable::draw(pi, x, y);
pi.base.font = tmpfont;
-
- // the name of the charstyle. Can be toggled.
- if (status() == Open) {
- // FIXME UNICODE
- docstring s(from_utf8(params_.name));
- // Chop off prefix:
- if (s.find(':') != string::npos)
- s = s.substr(s.find(':'));
- if (undefined())
- s = _("Undef: ") + s;
- layout_.labelstring = s;
- }
}
/// Construct an undefined character style
InsetCharStyle(BufferParams const &, std::string const);
///
- InsetCharStyle(BufferParams const &, CharStyles::iterator);
+ InsetCharStyle(BufferParams const &, InsetLayout);
///
docstring name() const { return from_ascii("CharStyle"); }
/// Is this character style defined in the document's textclass?
/// May be wrong after textclass change or paste from another document
bool undefined() const;
- /// Set the character style to "undefined"
- void setUndefined();
- /// (Re-)set the character style parameters from \p cs
- void setDefined(CharStyles::iterator cs);
+ /// (Re-)set the character style parameters from \p il
+ void setLayout(InsetLayout il);
///
virtual docstring const editMessage() const;
///
virtual std::auto_ptr<Inset> doClone() const;
- /// used by the constructors
- void init();
///
InsetCharStyleParams params_;
};
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
{
+ autoOpen_ = pi.base.bv->cursor().isInside(this);
+
const int xx = x + TEXT_TO_INSET_OFFSET;
// Draw button first -- top, left or only
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3) {
if (decoration() == Conglomerate) {
-
if (internalStatus() == Open)
setStatus(cur, Collapsed);
else