On Tue, Aug 14, 2007 at 11:20:59AM -0400, Richard Heck wrote: > > 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
Like the attached? Appears to work even. Yes I see the sense in this. We could also have a LyXType = Custom for your Endnote inset, or why not a NoSpellCheck inset -- in a layout file module :-) Does anybody else spot a problem with this? I'll wait for the Bromarv Cowboys to appear on the list again before committing. - Martin
Index: TextClass.cpp =================================================================== --- TextClass.cpp (revision 19567) +++ TextClass.cpp (working copy) @@ -149,7 +149,6 @@ TC_INPUT, TC_STYLE, TC_DEFAULTSTYLE, - TC_CHARSTYLE, TC_INSETLAYOUT, TC_ENVIRONMENT, TC_NOSTYLE, @@ -183,7 +182,6 @@ } keyword_item textClassTags[] = { - { "charstyle", TC_CHARSTYLE }, { "classoptions", TC_CLASSOPTIONS }, { "columns", TC_COLUMNS }, { "counter", TC_COUNTER }, @@ -407,12 +405,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(), '_', ' '); @@ -603,19 +595,10 @@ lexrc.popTable(); } -enum CharStyleTags { - CS_FONT = 1, - CS_LABELFONT, - CS_LATEXTYPE, - CS_LATEXNAME, - CS_LATEXPARAM, - CS_PREAMBLE, - CS_END -}; - enum InsetLayoutTags { IL_FONT = 1, + IL_LYXTYPE, IL_LABELFONT, IL_LABELSTRING, IL_LATEXTYPE, @@ -626,84 +609,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(), """, "\""); - 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[] = { @@ -714,11 +619,13 @@ { "latexname", IL_LATEXNAME }, { "latexparam", IL_LATEXPARAM }, { "latextype", IL_LATEXTYPE }, + { "lyxtype", IL_LYXTYPE }, { "preamble", IL_PREAMBLE} }; lexrc.pushTable(elementTags, IL_END); + string lyxtype; docstring labelstring; string latextype; string latexname; @@ -737,6 +644,10 @@ default: break; } switch (static_cast<InsetLayoutTags>(le)) { + case IL_LYXTYPE: + lexrc.next(); + lyxtype = lexrc.getString(); + break; case IL_LATEXTYPE: lexrc.next(); latextype = lexrc.getString(); @@ -775,6 +686,8 @@ // Here add element to list if getout == true if (getout) { InsetLayout il; + il.name = to_ascii(name); + il.lyxtype = lyxtype; il.labelstring = labelstring; il.latextype = latextype; il.latexname = latexname; @@ -783,6 +696,11 @@ il.labelfont = labelfont; il.preamble = from_utf8(preamble); insetlayoutlist_[name] = il; + + // test name for CS: + if (il.lyxtype == "charstyle") { + charstyles().push_back(il); + } } lexrc.popTable(); Index: TextClass.h =================================================================== --- TextClass.h (revision 19567) +++ TextClass.h (working copy) @@ -29,20 +29,10 @@ /// -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; + std::string lyxtype; docstring labelstring; std::string latextype; std::string latexname; @@ -54,7 +44,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 noun LyxType charstyle LabelString noun LatexType fontstyle LatexName defined Font Shape Smallcaps EndFont End InsetLayout emph LyxType charstyle LabelString emph LatexType fontstyle LatexName defined Font Shape Italic EndFont End