[LyX/master] Fix problem with validation when using InsetLayout.
Richard Kimberly Heck
rikiheck at lyx.org
Thu Feb 27 03:02:59 UTC 2020
commit 2e444dd6570804d33c1fd44713dc3b3f15ec9c5c
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Wed Feb 26 22:18:58 2020 -0500
Fix problem with validation when using InsetLayout.
---
src/TextClass.cpp | 11 +++++++----
src/insets/InsetLayout.cpp | 26 +++++++++++++++++++++++---
src/insets/InsetLayout.h | 3 ++-
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 9f22d6d..4ac03ab 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -745,6 +745,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
break;
}
docstring const name = subst(lexrc.getDocString(), '_', ' ');
+ bool const validating = (rt == VALIDATION);
if (name.empty()) {
string s = "Could not read name for InsetLayout: `$$Token' "
+ lexrc.getString() + " is probably not valid UTF-8!";
@@ -753,15 +754,17 @@ 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.
il.read(lexrc, *this);
- // Let's try to continue rather than abort.
- // error = true;
+ // Let's try to continue rather than abort, unless we're validating
+ // in which case we want to report the error
+ if (validating)
+ error = true;
} else if (hasInsetLayout(name)) {
InsetLayout & il = insetlayoutlist_[name];
- error = !il.read(lexrc, *this);
+ error = !il.read(lexrc, *this, validating);
} else {
InsetLayout il;
il.setName(name);
- error = !il.read(lexrc, *this);
+ error = !il.read(lexrc, *this, validating);
if (!error)
insetlayoutlist_[name] = il;
}
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index b523457..dbe2909 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -78,7 +78,8 @@ InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
} // namespace
-bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
+bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
+ bool validating)
{
enum {
IL_ADDTOTOC,
@@ -216,6 +217,8 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
switch (le) {
case Lexer::LEX_UNDEF:
lex.printError("Unknown InsetLayout tag");
+ if (validating)
+ return false;
continue;
default:
break;
@@ -232,13 +235,20 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
LYXERR0("Flex insets must have names of the form `Flex:<name>'.\n"
"This one has the name `" << to_utf8(name_) << "'\n"
"Ignoring LyXType declaration.");
+ // this is not really a reason to abort
+ if (validating)
+ return false;
break;
}
string lt;
lex >> lt;
lyxtype_ = translateLyXType(lt);
- if (lyxtype_ == NOLYXTYPE)
+ if (lyxtype_ == NOLYXTYPE) {
LYXERR0("Unknown LyXType `" << lt << "'.");
+ // this is not really a reason to abort
+ if (validating)
+ return false;
+ }
if (lyxtype_ == CHARSTYLE) {
// by default, charstyles force the plain layout
multipar_ = false;
@@ -250,8 +260,12 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
string lt;
lex >> lt;
latextype_ = translateLaTeXType(lt);
- if (latextype_ == ILT_ERROR)
+ if (latextype_ == ILT_ERROR) {
LYXERR0("Unknown LaTeXType `" << lt << "'.");
+ // this is not really a reason to abort
+ if (validating)
+ return false;
+ }
break;
}
case IL_LABELSTRING:
@@ -378,6 +392,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
tclass.insetLayouts().end();
for (; lit != len; ++lit)
lyxerr << lit->second.name() << "\n";
+ // this is not really a reason to abort
+ if (validating)
+ return false;
}
break;
}
@@ -408,6 +425,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
tclass.insetLayouts().end();
for (; lit != len; ++lit)
lyxerr << lit->second.name() << "\n";
+ // this is not really a reason to abort
+ if (validating)
+ return false;
}
break;
}
diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h
index bed2136..3db9ad1 100644
--- a/src/insets/InsetLayout.h
+++ b/src/insets/InsetLayout.h
@@ -56,7 +56,8 @@ public:
ILT_ERROR
};
///
- bool read(Lexer & lexrc, TextClass const & tclass);
+ bool read(Lexer & lexrc, TextClass const & tclass,
+ bool validating = false);
///
docstring name() const { return name_; }
///
More information about the lyx-cvs
mailing list