X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FTextClass.cpp;h=b282ba380261a5277d97448ce9eb2d08212a2c3e;hb=0c7bd9a57f2a308bb9659200eda3b7e45f8d5d3c;hp=a729fb58ae0e114e8b5d542213c256e1dc4d3c0e;hpb=e5cae37853ca71de16258dccf26ca9c18399eb56;p=lyx.git diff --git a/src/TextClass.cpp b/src/TextClass.cpp index a729fb58ae..b282ba3802 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -61,7 +61,7 @@ namespace lyx { // You should also run the development/tools/updatelayouts.py script, // to update the format of all of our layout files. // -int const LAYOUT_FORMAT = 57; //spitz: New Layout tag ParagraphGroup +int const LAYOUT_FORMAT = 60; //lasgouttes LongTableNoNumber => Unnumbered namespace { @@ -129,9 +129,6 @@ string translateReadType(TextClass::ReadType rt) docstring const TextClass::plain_layout_ = from_ascii(N_("Plain Layout")); -InsetLayout DocumentClass::plain_insetlayout_; - - ///////////////////////////////////////////////////////////////////////// // // TextClass @@ -139,22 +136,16 @@ InsetLayout DocumentClass::plain_insetlayout_; ///////////////////////////////////////////////////////////////////////// TextClass::TextClass() + : loaded_(false), tex_class_avail_(false), + opt_enginetype_("authoryear|numerical"), opt_fontsize_("10|11|12"), + opt_pagestyle_("empty|plain|headings|fancy"), pagestyle_("default"), + columns_(1), sides_(OneSide), secnumdepth_(3), tocdepth_(3), + outputType_(LATEX), outputFormat_("latex"), + defaultfont_(sane_font), + titletype_(TITLE_COMMAND_AFTER), titlename_("maketitle"), + min_toclevel_(0), max_toclevel_(0), + cite_full_author_list_(true) { - outputType_ = LATEX; - outputFormat_ = "latex"; - columns_ = 1; - sides_ = OneSide; - secnumdepth_ = 3; - tocdepth_ = 3; - pagestyle_ = "default"; - defaultfont_ = sane_font; - opt_enginetype_ = "authoryear|numerical"; - opt_fontsize_ = "10|11|12"; - opt_pagestyle_ = "empty|plain|headings|fancy"; - cite_full_author_list_ = true; - titletype_ = TITLE_COMMAND_AFTER; - titlename_ = "maketitle"; - loaded_ = false; } @@ -179,7 +170,8 @@ enum TextClassTags { TC_OUTPUTFORMAT, TC_INPUT, TC_STYLE, - TC_IFSTYLE, + TC_MODIFYSTYLE, + TC_PROVIDESTYLE, TC_DEFAULTSTYLE, TC_INSETLAYOUT, TC_NOINSETLAYOUT, @@ -218,7 +210,8 @@ enum TextClassTags { TC_CITEENGINETYPE, TC_CITEFORMAT, TC_DEFAULTBIBLIO, - TC_FULLAUTHORLIST + TC_FULLAUTHORLIST, + TC_OUTLINERNAME }; @@ -246,14 +239,15 @@ LexerKeyword textClassTags[] = { { "htmlstyles", TC_HTMLSTYLES }, { "htmltocsection", TC_HTMLTOCSECTION }, { "ifcounter", TC_IFCOUNTER }, - { "ifstyle", TC_IFSTYLE }, { "input", TC_INPUT }, { "insetlayout", TC_INSETLAYOUT }, { "leftmargin", TC_LEFTMARGIN }, + { "modifystyle", TC_MODIFYSTYLE }, { "nocounter", TC_NOCOUNTER }, { "nofloat", TC_NOFLOAT }, { "noinsetlayout", TC_NOINSETLAYOUT }, { "nostyle", TC_NOSTYLE }, + { "outlinername", TC_OUTLINERNAME }, { "outputformat", TC_OUTPUTFORMAT }, { "outputtype", TC_OUTPUTTYPE }, { "packageoptions", TC_PKGOPTS }, @@ -261,6 +255,7 @@ LexerKeyword textClassTags[] = { { "preamble", TC_PREAMBLE }, { "provides", TC_PROVIDES }, { "providesmodule", TC_PROVIDESMODULE }, + { "providestyle", TC_PROVIDESTYLE }, { "requires", TC_REQUIRES }, { "rightmargin", TC_RIGHTMARGIN }, { "secnumdepth", TC_SECNUMDEPTH }, @@ -419,8 +414,9 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) } // used below to track whether we are in an IfStyle or IfCounter tag. - bool ifstyle = false; - bool ifcounter = false; + bool modifystyle = false; + bool providestyle = false; + bool ifcounter = false; switch (static_cast(le)) { @@ -473,9 +469,15 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) } break; - case TC_IFSTYLE: - ifstyle = true; - // fall through + case TC_MODIFYSTYLE: + modifystyle = true; + // fall through + case TC_PROVIDESTYLE: + // if modifystyle is true, then we got here by falling through + // so we are not in an ProvideStyle block + if (!modifystyle) + providestyle = true; + // fall through case TC_STYLE: { if (!lexrc.next()) { lexrc.printError("No name given for style: `$$Token'."); @@ -492,10 +494,21 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) // Since we couldn't read the name, we just scan the rest // of the style and discard it. error = !readStyle(lexrc, lay); - } else if (hasLayout(name)) { + break; + } + + bool const have_layout = hasLayout(name); + + // If the layout already exists, then we want to add it to + // the existing layout, as long as we are not in an ProvideStyle + // block. + if (have_layout && !providestyle) { Layout & lay = operator[](name); error = !readStyle(lexrc, lay); - } else if (!ifstyle) { + } + // If the layout does not exist, then we want to create a new + // one, but not if we are in a ModifyStyle block. + else if (!have_layout && !modifystyle) { Layout layout; layout.setName(name); error = !readStyle(lexrc, layout); @@ -508,15 +521,17 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) defaultlayout_ = name; } } + // There are two ways to get here: + // (i) The layout exists but we are in an ProvideStyle block + // (ii) The layout doesn't exist, but we are in an ModifyStyle + // block. + // Either way, we just scan the rest and discard it else { - // this was an ifstyle where we didn't have the style - // scan the rest and discard it Layout lay; + // false positive from coverity + // coverity[CHECKED_RETURN] readStyle(lexrc, lay); } - - // reset flag - ifstyle = false; break; } @@ -751,6 +766,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) case TC_IFCOUNTER: ifcounter = true; + // fall through case TC_COUNTER: if (lexrc.next()) { docstring const name = lexrc.getDocString(); @@ -769,8 +785,6 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) lexrc.printError("No name given for style: `$$Token'."); error = true; } - // reset flag - ifcounter = false; break; case TC_TITLELATEXTYPE: @@ -788,6 +802,10 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) floatlist_.erase(nofloat); } break; + + case TC_OUTLINERNAME: + error = !readOutlinerName(lexrc); + break; } // end of switch // Note that this is triggered the first time through the loop unless @@ -1282,6 +1300,39 @@ bool TextClass::readFloat(Lexer & lexrc) } +bool TextClass::readOutlinerName(Lexer & lexrc) +{ + std::string type; + docstring name; + if (lexrc.next()) + type = lexrc.getString(); + else { + lexrc.printError("No type given for OutlinerName: `$$Token'."); + return false; + } + if (lexrc.next()) + name = lexrc.getDocString(); + else { + lexrc.printError("No name given for OutlinerName: `$$Token'."); + return false; + } + outliner_names_[type] = name; + return true; +} + + +docstring TextClass::outlinerName(std::string const & type) const +{ + std::map::const_iterator const it + = outliner_names_.find(type); + if (it == outliner_names_.end()) { + LYXERR0("Missing OutlinerName for " << type << "!"); + return from_utf8(type); + } else + return it->second; +} + + string const & TextClass::prerequisites(string const & sep) const { if (contains(prerequisites_, ',')) { @@ -1457,6 +1508,12 @@ InsetLayout const & DocumentClass::insetLayout(docstring const & name) const n = n.substr(0, i); } // Layout "name" not found. + return plainInsetLayout(); +} + + +InsetLayout const & DocumentClass::plainInsetLayout() { + static const InsetLayout plain_insetlayout_; return plain_insetlayout_; }