On Mon, May 02, 2005 at 09:16:40AM +0200, Georg Baum wrote:
> Martin Vermeer wrote:
> 
> > On Sat, Apr 30, 2005 at 03:25:09PM +0200, Juergen Spitzmueller wrote:
> >> What does it do with the contents of such charstyles? Transform it to
> >> containing layout? Also, shouldn't the warning be the same as for missing
> >> layouts? (cf. the recent discussion on bug 1591).
> 
> IMO it should be transformed to standard layout with a warning (as it is for
> layouts right now). Of course, loss of charstyles is still better than a
> crash ;-)
> 
> > Ideally yes. Currently it produces an error (in the background xterm and
> > to a pop-up) and deletes the content. Yes it should be done better...
> > if only I knew how. Modify SwitchLayoutsBetweenClasses in Cut & Paste?
> > Rather not, having looked at it ;-/
> 
> But I think that would be the right place.
> 
> > I could of course convert the inset to a Note inset... easy to do I
> > think. Would that be an acceptable compromise for 1.4?
> 
> It is better than losing the data, but not understandable by the user IMHO.
> No chance to fix SwitchLayoutsBetweenClasses?

Not if I have to do it... and shouldn't it be called
SwitchCharStylesBetweenClasses then? (And would you call the adding of
more warts upon warts 'fixing'?)

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

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 08:52:55 -0000
@@ -417,7 +417,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 08:52:55 -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 08:52:55 -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;

Attachment: pgpE303gBz9V7.pgp
Description: PGP signature

Reply via email to