On Mon, May 02, 2005 at 12:00:34PM +0300, Martin Vermeer wrote: ... > Here is a solution that is nearly as good. What it does is that upon > re-load, it turns it into an "Undef:" type charstyle inset, red for > attention. Yes, the lack of warning at the time of conversion is > unpleasant, but then this is something people should expect to happen. > And there's no data loss. > > A more permanent solution would include the possibility to define user > charstyles which are saved with the document, as John L proposed already > many times. Then we can create a user charstyle when a class charstyle > doesn't exist. But that's not for 1.4. Let's not invest a lot of time > now in a solution that is to be obsoleted anyway. > > Please test. > > - Martin
Ehh, the _proper_ patch is this... - Martin
Index: factory.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/factory.C,v retrieving revision 1.95 diff -u -p -r1.95 factory.C --- factory.C 14 Aug 2004 15:55:17 -0000 1.95 +++ factory.C 2 May 2005 11:51:25 -0000 @@ -88,8 +88,12 @@ InsetBase * createInset(BufferView * bv, case LFUN_INSERT_CHARSTYLE: { string s = cmd.getArg(0); - CharStyles::iterator found_cs = params.getLyXTextClass().charstyle(s); - return new InsetCharStyle(params, found_cs); + LyXTextClass tclass = params.getLyXTextClass(); + 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); } case LFUN_INSERT_NOTE: { @@ -417,7 +421,12 @@ InsetBase * readInset(LyXLex & lex, Buff lex.next(); string s = lex.getString(); CharStyles::iterator found_cs = tclass.charstyle(s); - inset.reset(new InsetCharStyle(buf.params(), found_cs)); + if (found_cs != tclass.charstyles().end()) + inset.reset(new InsetCharStyle(buf.params(), found_cs)); + else { + // "Undefined" inset + inset.reset(new InsetCharStyle(buf.params(), s)); + } } else if (tmptok == "Branch") { inset.reset(new InsetBranch(buf.params(), InsetBranchParams())); Index: insets/insetcharstyle.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcharstyle.C,v retrieving revision 1.33 diff -u -p -r1.33 insetcharstyle.C --- insets/insetcharstyle.C 26 Apr 2005 11:12:19 -0000 1.33 +++ insets/insetcharstyle.C 2 May 2005 11:51:25 -0000 @@ -51,6 +51,20 @@ void InsetCharStyle::init() } +InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s) + : InsetCollapsable(bp) +{ + params_.type = "Undef: " + s; + params_.latextype = string(); + params_.latexname = string(); + params_.latexparam = string(); + params_.font = LyXFont(LyXFont::ALL_INHERIT); + params_.labelfont = LyXFont(LyXFont::ALL_INHERIT); + params_.labelfont.setColor(LColor::red); + init(); +} + + InsetCharStyle::InsetCharStyle(BufferParams const & bp, CharStyles::iterator cs) : InsetCollapsable(bp) @@ -210,12 +224,15 @@ bool InsetCharStyle::getStatus(LCursor & int InsetCharStyle::latex(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - os << "\\" << params_.latexname; - if (!params_.latexparam.empty()) - os << params_.latexparam; - os << "{"; + if (!params_.latexname.empty()) { + os << "\\" << params_.latexname; + if (!params_.latexparam.empty()) + os << params_.latexparam; + os << "{"; + } int i = InsetText::latex(buf, os, runparams); - os << "}"; + if (!params_.latexname.empty()) + os << "}"; return i; } @@ -223,9 +240,11 @@ int InsetCharStyle::latex(Buffer const & int InsetCharStyle::linuxdoc(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - sgml::openTag(os, params_.latexname, params_.latexparam); + if (!params_.latexname.empty()) + sgml::openTag(os, params_.latexname, params_.latexparam); int i = InsetText::linuxdoc(buf, os, runparams); - sgml::closeTag(os, params_.latexname); + if (!params_.latexname.empty()) + sgml::closeTag(os, params_.latexname); return i; } @@ -236,15 +255,19 @@ int InsetCharStyle::docbook(Buffer const ParagraphList::const_iterator par = paragraphs().begin(); ParagraphList::const_iterator end = paragraphs().end(); - sgml::openTag(os, params_.latexname, par->getID(buf, runparams) + params_.latexparam); + if (!params_.latexname.empty()) + sgml::openTag(os, params_.latexname, + par->getID(buf, runparams) + params_.latexparam); for (; par != end; ++par) { par->simpleDocBookOnePar(buf, os, runparams, - outerFont(par - paragraphs().begin(), + outerFont(par - paragraphs().begin(), paragraphs())); } - sgml::closeTag(os, params_.latexname); + if (!params_.latexname.empty()) + sgml::closeTag(os, params_.latexname); + return 0; } @@ -258,6 +281,7 @@ int InsetCharStyle::plaintext(Buffer con void InsetCharStyle::validate(LaTeXFeatures & features) const { + // Force inclusion of preamble snippet in layout file features.require(params_.type); InsetText::validate(features); } Index: insets/insetcharstyle.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcharstyle.h,v retrieving revision 1.13 diff -u -p -r1.13 insetcharstyle.h --- insets/insetcharstyle.h 19 Jan 2005 15:03:30 -0000 1.13 +++ insets/insetcharstyle.h 2 May 2005 11:51:25 -0000 @@ -44,6 +44,8 @@ public: class InsetCharStyle : public InsetCollapsable { public: /// + InsetCharStyle::InsetCharStyle(BufferParams const &, std::string const); + /// InsetCharStyle(BufferParams const &, CharStyles::iterator); /// std::string const editMessage() const;
pgpguDRPUivH1.pgp
Description: PGP signature