[LyX/master] Refactoring
Juergen Spitzmueller
spitz at lyx.org
Fri Oct 2 06:03:07 UTC 2020
commit 8b155ce957cfe20908518ce844a9c61e713e4cd8
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Fri Oct 2 08:30:31 2020 +0200
Refactoring
---
src/tex2lyx/Preamble.cpp | 40 ++++++++++++++++++----------------------
src/tex2lyx/Preamble.h | 2 ++
2 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 10bf328..f28df64 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -469,6 +469,16 @@ void Preamble::add_package(string const & name, vector<string> & options)
}
}
+void Preamble::setTextClass(string const tclass, TeX2LyXDocClass & tc)
+{
+ h_textclass = tclass;
+ tc.setName(h_textclass);
+ if (!LayoutFileList::get().haveClass(h_textclass) || !tc.load()) {
+ cerr << "Error: Could not read layout file for textclass \"" << h_textclass << "\"." << endl;
+ exit(EXIT_FAILURE);
+ }
+}
+
namespace {
@@ -2164,12 +2174,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
// Force textclass if the user wanted it
if (!forceclass.empty()) {
- h_textclass = forceclass;
- tc.setName(h_textclass);
- if (!LayoutFileList::get().haveClass(h_textclass) || !tc.load()) {
- cerr << "Error: Could not read layout file for textclass \"" << h_textclass << "\"." << endl;
- exit(EXIT_FAILURE);
- }
+ setTextClass(forceclass, tc);
class_set = true;
}
@@ -2677,14 +2682,10 @@ void Preamble::parse(Parser & p, string const & forceclass,
// Only set text class if a class hasn't been forced
// (this was set above)
if (!class_set) {
- h_textclass = tclass;
- // textclass needs to be set at this place as we need to know
- // it for other parameters (such as class-dependent paper size)
- tc.setName(h_textclass);
- if (!LayoutFileList::get().haveClass(h_textclass) || !tc.load()) {
- cerr << "Error: Could not read layout file for textclass \"" << h_textclass << "\"." << endl;
- exit(EXIT_FAILURE);
- }
+ // textclass needs to be set at this place (if not already done)
+ // as we need to know it for other parameters
+ // (such as class-dependent paper size)
+ setTextClass(tclass, tc);
class_set = true;
}
@@ -3109,14 +3110,9 @@ void Preamble::parse(Parser & p, string const & forceclass,
}
// set textclass if not yet done (snippets without \documentclass and forced class)
- if (!class_set) {
- tc.setName(h_textclass);
- if (!LayoutFileList::get().haveClass(h_textclass) || !tc.load()) {
- cerr << "Error: Could not read layout file for textclass \"" << h_textclass << "\"." << endl;
- exit(EXIT_FAILURE);
- }
- }
-
+ if (!class_set)
+ setTextClass(h_textclass, tc);
+
// remove the whitespace
p.skip_spaces();
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index dccd780..92d3694 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -95,6 +95,8 @@ public:
void registerAuthor(std::string const & name, std::string const & initials);
/// Get author named \p name (must be registered first)
Author const & getAuthor(std::string const & name) const;
+ /// Set text class
+ void setTextClass(std::string const tclass, TeX2LyXDocClass & tc);
/// Get number of arguments of special table column type \c or -1
/// if no column type \p c exists
int getSpecialTableColumnArguments(char c) const;
More information about the lyx-cvs
mailing list