This seems to be progressing very well. But I wonder if using the CS prefix is the right way to do this. How about something like "LyXType CharStyle", which is clearer and more easily extensible? I'd also like at some point to be able to use a separator like ":" to structure the charstyle menu. (This is part of the conversion from text settings into charstyles.) So, for example, we could have
InsetLayout Font:Italic
 LyXType CharStyle
 LatexType command
 LatexName \textit
 Etc.
End
and have it turn up as Insert>CharStyle>Font>Italic, or whatever.

Richard

Martin Vermeer wrote:
This makes the logic a bit simpler and the code shorter.

The syntax for the layout files (charstyle description)
changes, to (e.g.)
InsetLayout CS:Noun
LabelString  noun

from

CharStyle noun

Tested and works for me. Noun, Emph charstyle file included.
This will require layout2layout work (like also the earlier
InsetLayout patch)

- Martin

------------------------------------------------------------------------

Index: src/TextClass.cpp
===================================================================
--- src/TextClass.cpp   (revision 19542)
+++ src/TextClass.cpp   (working copy)
@@ -407,12 +407,6 @@
                        if (lexrc.next())
                                rightmargin_ = lexrc.getString();
                        break;
-               case TC_CHARSTYLE:
-                       if (lexrc.next()) {
-                               string const name = subst(lexrc.getString(), 
'_', ' ');
-                               readCharStyle(lexrc, name);
-                       }
-                       break;
                case TC_INSETLAYOUT:
                        if (lexrc.next()) {
                                docstring const name = 
subst(lexrc.getDocString(), '_', ' ');
@@ -626,84 +620,6 @@
 };
-
-void TextClass::readCharStyle(Lexer & lexrc, string const & name)
-{
-       keyword_item elementTags[] = {
-               { "end", CS_END },
-               { "font", CS_FONT },
-               { "labelfont", CS_LABELFONT },
-               { "latexname", CS_LATEXNAME },
-               { "latexparam", CS_LATEXPARAM },
-               { "latextype", CS_LATEXTYPE },
-               { "preamble", CS_PREAMBLE}
-       };
-
-       lexrc.pushTable(elementTags, CS_END);
-
-       string latextype;
-       string latexname;
-       string latexparam;
-       Font font(Font::ALL_INHERIT);
-       Font labelfont(Font::ALL_INHERIT);
-       string preamble;
-
-       bool getout = false;
-       while (!getout && lexrc.isOK()) {
-               int le = lexrc.lex();
-               switch (le) {
-               case Lexer::LEX_UNDEF:
-                       lexrc.printError("Unknown ClassOption tag `$$Token'");
-                       continue;
-               default: break;
-               }
-               switch (static_cast<CharStyleTags>(le)) {
-               case CS_LATEXTYPE:
-                       lexrc.next();
-                       latextype = lexrc.getString();
-                       break;
-               case CS_LATEXNAME:
-                       lexrc.next();
-                       latexname = lexrc.getString();
-                       break;
-               case CS_LATEXPARAM:
-                       lexrc.next();
-                       latexparam = subst(lexrc.getString(), "&quot;", "\"");
-                       break;
-               case CS_LABELFONT:
-                       labelfont.lyxRead(lexrc);
-                       break;
-               case CS_FONT:
-                       font.lyxRead(lexrc);
-                       labelfont = font;
-                       break;
-               case CS_PREAMBLE:
-                       preamble = lexrc.getLongString("EndPreamble");
-                       break;
-               case CS_END:
-                       getout = true;
-                       break;
-               }
-       }
-
-       //
-       // Here add element to list if getout == true
-       if (getout) {
-               CharStyle cs;
-               cs.name = name;
-               cs.latextype = latextype;
-               cs.latexname = latexname;
-               cs.latexparam = latexparam;
-               cs.font = font;
-               cs.labelfont = labelfont;
-               cs.preamble = from_utf8(preamble);
-               charstyles().push_back(cs);
-       }
-
-       lexrc.popTable();
-}
-
-
 void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
 {
        keyword_item elementTags[] = {
@@ -775,6 +691,7 @@
        // Here add element to list if getout == true
        if (getout) {
                InsetLayout il;
+               il.name = to_ascii(name);
                il.labelstring = labelstring;
                il.latextype = latextype;
                il.latexname = latexname;
@@ -783,6 +700,12 @@
                il.labelfont = labelfont;
                il.preamble = from_utf8(preamble);
                insetlayoutlist_[name] = il;
+
+               // test name for CS:
+               if (il.name.substr(0,3) == "CS:") {
+                       il.name = to_ascii(il.labelstring);
+                       charstyles().push_back(il);
+               }
        }
lexrc.popTable();
Index: src/TextClass.h
===================================================================
--- src/TextClass.h     (revision 19542)
+++ src/TextClass.h     (working copy)
@@ -29,20 +29,9 @@
///
-class CharStyle {
-public:
-       std::string name;
-       std::string latextype;
-       std::string latexname;
-       std::string latexparam;
-       Font font;
-       Font labelfont;
-       docstring preamble;
-};
-
-
 class InsetLayout {
 public:
+       std::string name;
        docstring labelstring;
        std::string latextype;
        std::string latexname;
@@ -54,7 +43,7 @@
/// List of semantically defined character style insets
-typedef std::vector<CharStyle> CharStyles;
+typedef std::vector<InsetLayout> CharStyles;
/// List of inset layouts
 typedef std::map<docstring, InsetLayout> InsetLayouts;
------------------------------------------------------------------------

# Textclass definition file for LaTeX.
# Author : Martin vermeer <[EMAIL PROTECTED]>
# Character Styles definition

Format 2
InsetLayout CS:Noun
        LabelString           noun
        LatexType             fontstyle
        LatexName             defined
        Font
          Shape               Smallcaps
        EndFont
End


InsetLayout CS:Emph
        LabelString           emph
        LatexType             fontstyle
        LatexName             defined
        Font
          Shape               Italic
        EndFont
End



--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Reply via email to