The idea is in the attached patch. A lot of unnecessary stuff can disappear.
- Martin PS What about the name for "meta-charstyles"? Soft Insets? That's the next project. Perhaps after Richard's big commit.
Index: src/CutAndPaste.cpp =================================================================== --- src/CutAndPaste.cpp (revision 19769) +++ src/CutAndPaste.cpp (working copy) @@ -455,11 +455,11 @@ 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 " @@ -470,11 +470,7 @@ 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); - } + } } } } Index: src/TextClass.cpp =================================================================== --- src/TextClass.cpp (revision 19769) +++ src/TextClass.cpp (working copy) @@ -698,7 +698,9 @@ insetlayoutlist_[name] = il; // test name for CS: - if (il.lyxtype == "charstyle" || il.lyxtype == "custom") { + if (il.lyxtype == "charstyle" + || il.lyxtype == "custom" + || il.lyxtype == "end") { charstyles().push_back(il); } } @@ -1011,6 +1013,14 @@ 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; @@ -1022,23 +1032,12 @@ 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) Index: src/TextClass.h =================================================================== --- src/TextClass.h (revision 19769) +++ src/TextClass.h (working copy) @@ -110,8 +110,6 @@ CharStyles & charstyles() const { return charstylelist_; }; /// Inset layouts of this doc class InsetLayout const & insetlayout(docstring const & name) const; - /// Retrieve element of name s: - CharStyles::iterator charstyle(std::string const & s) const; /// docstring const & defaultLayoutName() const; /// Index: src/insets/InsetCharStyle.cpp =================================================================== --- src/insets/InsetCharStyle.cpp (revision 19771) +++ src/insets/InsetCharStyle.cpp (working copy) @@ -48,34 +48,26 @@ 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 @@ -86,27 +78,16 @@ bool InsetCharStyle::undefined() const { - return layout_.latexname.empty(); + return layout_.labelstring == from_utf8("UNDEFINED"); } -void InsetCharStyle::setUndefined() +void InsetCharStyle::setLayout(InsetLayout il) { - 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); + layout_ = il; } -void InsetCharStyle::setDefined(CharStyles::iterator cs) -{ - layout_ = *cs; -} - - docstring const InsetCharStyle::editMessage() const { return _("Opened CharStyle Inset"); @@ -135,16 +116,6 @@ 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; } @@ -159,18 +130,6 @@ //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; - } } Index: src/insets/InsetCollapsable.cpp =================================================================== --- src/insets/InsetCollapsable.cpp (revision 19769) +++ src/insets/InsetCollapsable.cpp (working copy) @@ -246,6 +246,8 @@ 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 @@ -497,7 +499,6 @@ case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3) { if (decoration() == Conglomerate) { - if (internalStatus() == Open) setStatus(cur, Collapsed); else Index: src/insets/InsetCharStyle.h =================================================================== --- src/insets/InsetCharStyle.h (revision 19769) +++ src/insets/InsetCharStyle.h (working copy) @@ -39,16 +39,14 @@ /// 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; /// @@ -94,8 +92,6 @@ virtual std::auto_ptr<Inset> doClone() const; - /// used by the constructors - void init(); /// InsetCharStyleParams params_; }; Index: lib/layouts/stdcharstyles.inc =================================================================== --- lib/layouts/stdcharstyles.inc (revision 19732) +++ lib/layouts/stdcharstyles.inc (working copy) @@ -27,3 +27,14 @@ EndFont End + +# Error fallback: +InsetLayout CharStyle + LyxType end + LabelString "UNDEFINED" + LatexName "" + Font + Color error + EndFont +End +