]> git.lyx.org Git - lyx.git/blobdiff - src/TextClass.cpp
Natbib authoryear uses (Ref1; Ref2) by default.
[lyx.git] / src / TextClass.cpp
index d0a9f0d61b24c1b24ec97065ff5e00203796da41..b55e8a2f0a4863acad97e02bd82e38059dcf4dab 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "support/lassert.h"
 #include "support/debug.h"
+#include "support/ExceptionMessage.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
@@ -60,7 +61,7 @@ namespace lyx {
 // development/tools/updatelayouts.sh script, to update the format of
 // all of our layout files.
 //
-int const LAYOUT_FORMAT = 41; // spitz: new InsetArgument syntax
+int const LAYOUT_FORMAT = 45; // rgh: New Tag "NoInsetLayout"
 
 namespace {
 
@@ -182,6 +183,7 @@ enum TextClassTags {
        TC_IFSTYLE,
        TC_DEFAULTSTYLE,
        TC_INSETLAYOUT,
+       TC_NOINSETLAYOUT,
        TC_NOSTYLE,
        TC_COLUMNS,
        TC_SIDES,
@@ -250,6 +252,7 @@ LexerKeyword textClassTags[] = {
        { "leftmargin",        TC_LEFTMARGIN },
        { "nocounter",         TC_NOCOUNTER },
        { "nofloat",           TC_NOFLOAT },
+       { "noinsetlayout",     TC_NOINSETLAYOUT },
        { "nostyle",           TC_NOSTYLE },
        { "outputformat",      TC_OUTPUTFORMAT },
        { "outputtype",        TC_OUTPUTTYPE },
@@ -525,6 +528,16 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                        }
                        break;
 
+               case TC_NOINSETLAYOUT:
+                       if (lexrc.next()) {
+                               docstring const style = from_utf8(subst(lexrc.getString(),
+                                                                '_', ' '));
+                               if (!deleteInsetLayout(style))
+                                       LYXERR0("Style `" << style << "' cannot be removed\n"
+                                               "because it was not found!");
+                       }
+                       break;
+
                case TC_COLUMNS:
                        if (lexrc.next())
                                columns_ = lexrc.getInteger();
@@ -1252,31 +1265,27 @@ bool TextClass::hasInsetLayout(docstring const & n) const
 {
        if (n.empty())
                return false;
-       InsetLayouts::const_iterator it = insetlayoutlist_.begin();
-       InsetLayouts::const_iterator en = insetlayoutlist_.end();
-       for (; it != en; ++it)
-               if (n == it->first)
-                       return true;
-       return false;
+       InsetLayouts::const_iterator it = insetlayoutlist_.find(n);
+       return it != insetlayoutlist_.end();
 }
 
 
 Layout const & TextClass::operator[](docstring const & name) const
 {
-       LASSERT(!name.empty(), /**/);
+       LATTEST(!name.empty());
 
        const_iterator it =
                find_if(begin(), end(), LayoutNamesEqual(name));
 
        if (it == end()) {
-               lyxerr << "We failed to find the layout '" << to_utf8(name)
-                      << "' in the layout list. You MUST investigate!"
-                      << endl;
+               LYXERR0("We failed to find the layout '" << name
+                      << "' in the layout list. You MUST investigate!");
                for (const_iterator cit = begin(); cit != end(); ++cit)
                        lyxerr  << " " << to_utf8(cit->name()) << endl;
 
-               // we require the name to exist
-               LASSERT(false, /**/);
+               // We require the name to exist
+               static const Layout dummy;
+               LASSERT(false, return dummy);
        }
 
        return *it;
@@ -1285,7 +1294,8 @@ Layout const & TextClass::operator[](docstring const & name) const
 
 Layout & TextClass::operator[](docstring const & name)
 {
-       LASSERT(!name.empty(), /**/);
+       LATTEST(!name.empty());
+       // Safe to continue, given what we do below.
 
        iterator it = find_if(begin(), end(), LayoutNamesEqual(name));
 
@@ -1296,7 +1306,10 @@ Layout & TextClass::operator[](docstring const & name)
                        LYXERR0(" " << to_utf8(cit->name()));
 
                // we require the name to exist
-               LASSERT(false, /**/);
+               LATTEST(false);
+               // we are here only in release mode
+               layoutlist_.push_back(createBasicLayout(name, true));
+               it = find_if(begin(), end(), LayoutNamesEqual(name));
        }
 
        return *it;
@@ -1319,6 +1332,12 @@ bool TextClass::deleteLayout(docstring const & name)
 }
 
 
+bool TextClass::deleteInsetLayout(docstring const & name)
+{
+       return insetlayoutlist_.erase(name);
+}
+
+
 // Load textclass info if not loaded yet
 bool TextClass::load(string const & path) const
 {
@@ -1426,7 +1445,7 @@ Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
        if (!readStyle(lex, *defaultLayout)) {
                // The only way this happens is because the hardcoded layout above
                // is wrong.
-               LASSERT(false, /**/);
+               LATTEST(false);
        };
        return *defaultLayout;
 }
@@ -1517,8 +1536,9 @@ Layout const & DocumentClass::getTOCLayout() const
        Layout const * lay = NULL;
        for (; lit != len; ++lit) {
                int const level = lit->toclevel;
-               // we don't want Part
-               if (level == Layout::NOT_IN_TOC || level < 0 || level >= minlevel)
+               // we don't want Part or unnumbered sections
+               if (level == Layout::NOT_IN_TOC || level < 0 
+                   || level >= minlevel || lit->counter.empty())
                        continue;
                lay = &*lit;
                minlevel = level;