2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2008-02-24 16:59:49 +00:00
|
|
|
|
* \file BaseClassList.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author John Levon
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-12-28 13:26:54 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2008-02-24 16:59:49 +00:00
|
|
|
|
#include "BaseClassList.h"
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
#include "Counters.h"
|
|
|
|
|
#include "Floating.h"
|
|
|
|
|
#include "FloatList.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
#include "TextClass.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/debug.h"
|
2007-12-17 16:04:46 +00:00
|
|
|
|
#include "support/FileName.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "support/filetools.h"
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
#include "support/gettext.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2004-11-06 16:14:22 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
2006-04-09 04:35:24 +00:00
|
|
|
|
#include <boost/regex.hpp>
|
2007-10-18 19:29:32 +00:00
|
|
|
|
|
2006-04-09 04:35:24 +00:00
|
|
|
|
#include <fstream>
|
2004-11-06 16:14:22 +00:00
|
|
|
|
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace lyx::support;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2004-11-06 16:14:22 +00:00
|
|
|
|
using boost::bind;
|
2006-04-09 04:35:24 +00:00
|
|
|
|
using boost::regex;
|
|
|
|
|
using boost::smatch;
|
2004-11-06 16:14:22 +00:00
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
LayoutFile::LayoutFile(string const & fn, string const & cln,
|
|
|
|
|
string const & desc, bool texClassAvail )
|
|
|
|
|
{
|
|
|
|
|
name_ = fn;
|
|
|
|
|
latexname_ = cln;
|
|
|
|
|
description_ = desc;
|
|
|
|
|
texClassAvail_ = texClassAvail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-28 14:49:01 +00:00
|
|
|
|
BaseClassList & BaseClassList::get()
|
|
|
|
|
{
|
|
|
|
|
static BaseClassList baseclasslist;
|
|
|
|
|
return baseclasslist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-28 21:04:55 +00:00
|
|
|
|
bool BaseClassList::haveClass(string const & classname) const
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2008-02-28 21:04:55 +00:00
|
|
|
|
ClassMap::const_iterator it = classmap_.begin();
|
|
|
|
|
ClassMap::const_iterator en = classmap_.end();
|
|
|
|
|
for (; it != en; ++it) {
|
|
|
|
|
if (it->first == classname)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
LayoutFile const & BaseClassList::operator[](string const & classname) const
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(haveClass(classname));
|
|
|
|
|
return classmap_[classname];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LayoutFile &
|
|
|
|
|
BaseClassList::operator[](string const & classname)
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2008-02-28 21:04:55 +00:00
|
|
|
|
BOOST_ASSERT(haveClass(classname));
|
|
|
|
|
return classmap_[classname];
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reads LyX textclass definitions according to textclass config file
|
2008-02-24 16:59:49 +00:00
|
|
|
|
bool BaseClassList::read()
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Lexer lex(0, 0);
|
2007-12-12 19:57:42 +00:00
|
|
|
|
FileName const real_file = libFileSearch("", "textclass.lst");
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "Reading textclasses from `" << real_file << '\'');
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
if (real_file.empty()) {
|
2008-02-24 16:59:49 +00:00
|
|
|
|
lyxerr << "BaseClassList::Read: unable to find "
|
2007-05-28 22:27:45 +00:00
|
|
|
|
"textclass file `"
|
2006-11-26 21:30:39 +00:00
|
|
|
|
<< to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
|
2001-12-28 13:26:54 +00:00
|
|
|
|
<< "'. Exiting." << endl;
|
|
|
|
|
return false;
|
|
|
|
|
// This causes LyX to end... Not a desirable behaviour. Lgb
|
|
|
|
|
// What do you propose? That the user gets a file dialog
|
|
|
|
|
// and is allowed to hunt for the file? (Asger)
|
|
|
|
|
// more that we have a layout for minimal.cls statically
|
|
|
|
|
// compiled in... (Lgb)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lex.setFile(real_file)) {
|
2008-02-24 16:59:49 +00:00
|
|
|
|
lyxerr << "BaseClassList::Read: "
|
2001-12-28 13:26:54 +00:00
|
|
|
|
"lyxlex was not able to set file: "
|
|
|
|
|
<< real_file << endl;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
if (!lex.isOK()) {
|
2008-02-24 16:59:49 +00:00
|
|
|
|
lyxerr << "BaseClassList::Read: unable to open "
|
2007-05-28 22:27:45 +00:00
|
|
|
|
"textclass file `"
|
2006-11-26 21:30:39 +00:00
|
|
|
|
<< to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
|
2001-12-28 13:26:54 +00:00
|
|
|
|
<< "'\nCheck your installation. LyX can't continue."
|
|
|
|
|
<< endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
return false;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool finished = false;
|
|
|
|
|
// Parse config-file
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "Starting parsing of textclass.lst");
|
2001-12-28 13:26:54 +00:00
|
|
|
|
while (lex.isOK() && !finished) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "\tline by line");
|
2001-12-28 13:26:54 +00:00
|
|
|
|
switch (lex.lex()) {
|
2007-04-26 11:30:54 +00:00
|
|
|
|
case Lexer::LEX_FEOF:
|
2001-12-28 13:26:54 +00:00
|
|
|
|
finished = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
string const fname = lex.getString();
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "Fname: " << fname);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
if (lex.next()) {
|
|
|
|
|
string const clname = lex.getString();
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "Clname: " << clname);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
if (lex.next()) {
|
2002-05-29 13:28:11 +00:00
|
|
|
|
string const desc = lex.getString();
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "Desc: " << desc);
|
2003-05-03 19:24:36 +00:00
|
|
|
|
if (lex.next()) {
|
|
|
|
|
bool avail = lex.getBool();
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "Avail: " << avail);
|
2003-05-03 19:24:36 +00:00
|
|
|
|
// This code is run when we have
|
|
|
|
|
// fname, clname, desc, and avail
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
LayoutFile tmpl(fname, clname, desc, avail);
|
2003-05-03 19:24:36 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::TCLASS)) {
|
2008-02-24 06:14:48 +00:00
|
|
|
|
// only system layout files are loaded here so no
|
|
|
|
|
// buffer path is needed.
|
2003-05-03 19:24:36 +00:00
|
|
|
|
tmpl.load();
|
|
|
|
|
}
|
2008-02-28 21:04:55 +00:00
|
|
|
|
classmap_[fname] = tmpl;
|
2002-05-29 13:28:11 +00:00
|
|
|
|
}
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "End of parsing of textclass.lst");
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2008-02-28 21:04:55 +00:00
|
|
|
|
// lyx will start with an empty classmap_, but only reconfigure is allowed
|
2007-09-26 19:36:09 +00:00
|
|
|
|
// in this case. This gives users a second chance to configure lyx if
|
|
|
|
|
// initial configuration fails. (c.f. bug 2829)
|
2008-02-28 21:04:55 +00:00
|
|
|
|
if (classmap_.empty())
|
2008-02-24 16:59:49 +00:00
|
|
|
|
lyxerr << "BaseClassList::Read: no textclasses found!"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
std::vector<LayoutFileIndex> BaseClassList::classList() const
|
2008-02-28 21:04:55 +00:00
|
|
|
|
{
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
std::vector<LayoutFileIndex> cl;
|
2008-02-28 21:04:55 +00:00
|
|
|
|
ClassMap::const_iterator it = classmap_.begin();
|
|
|
|
|
ClassMap::const_iterator en = classmap_.end();
|
|
|
|
|
for (; it != en; ++it)
|
|
|
|
|
cl.push_back(it->first);
|
|
|
|
|
return cl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
void BaseClassList::reset(LayoutFileIndex const & classname) {
|
2008-02-28 21:04:55 +00:00
|
|
|
|
BOOST_ASSERT(haveClass(classname));
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
LayoutFile const & tc = classmap_[classname];
|
|
|
|
|
LayoutFile tmpl(tc.name(), tc.latexname(), tc.description(),
|
2007-09-11 16:42:22 +00:00
|
|
|
|
tc.isTeXClassAvailable());
|
2008-02-28 21:04:55 +00:00
|
|
|
|
classmap_[classname] = tmpl;
|
2007-09-11 16:42:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-28 21:04:55 +00:00
|
|
|
|
string const BaseClassList::localPrefix = "LOCAL:";
|
|
|
|
|
|
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
LayoutFileIndex
|
|
|
|
|
BaseClassList::addLayoutFile(string const & textclass, string const & path)
|
2006-04-09 04:35:24 +00:00
|
|
|
|
{
|
2008-03-01 16:32:16 +00:00
|
|
|
|
// FIXME There is a bug here: 4593
|
2008-02-28 21:04:55 +00:00
|
|
|
|
//
|
2006-04-09 04:35:24 +00:00
|
|
|
|
// only check for textclass.layout file, .cls can be anywhere in $TEXINPUTS
|
2008-02-28 21:04:55 +00:00
|
|
|
|
// NOTE: latex class name is defined in textclass.layout, which can be
|
|
|
|
|
// different from textclass
|
|
|
|
|
string fullName = addName(path, textclass + ".layout");
|
2008-03-01 16:32:16 +00:00
|
|
|
|
string localIndex = localPrefix + fullName;
|
|
|
|
|
|
2008-02-28 21:04:55 +00:00
|
|
|
|
// if the local file has already been loaded, return it
|
|
|
|
|
if (haveClass(localIndex))
|
|
|
|
|
return localIndex;
|
|
|
|
|
|
|
|
|
|
FileName const layout_file(fullName);
|
2007-10-18 19:29:32 +00:00
|
|
|
|
if (layout_file.exists()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "Adding class " << textclass << " from directory " << path);
|
2006-04-09 04:35:24 +00:00
|
|
|
|
// Read .layout file and get description, real latex classname etc
|
|
|
|
|
//
|
|
|
|
|
// This is a C++ version of function processLayoutFile in configure.py,
|
|
|
|
|
// which uses the following regex
|
2006-08-23 12:55:23 +00:00
|
|
|
|
// \Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}
|
2006-11-29 21:47:37 +00:00
|
|
|
|
ifstream ifs(layout_file.toFilesystemEncoding().c_str());
|
2006-08-23 12:55:23 +00:00
|
|
|
|
static regex const reg("^#\\s*\\\\Declare(LaTeX|DocBook)Class\\s*"
|
2006-04-09 04:35:24 +00:00
|
|
|
|
"(?:\\[([^,]*)(?:,.*)*\\])*\\s*\\{(.*)\\}\\s*");
|
|
|
|
|
string line;
|
|
|
|
|
while (getline(ifs, line)) {
|
|
|
|
|
// look for the \DeclareXXXClass line
|
|
|
|
|
smatch sub;
|
|
|
|
|
if (regex_match(line, sub, reg)) {
|
2008-02-28 04:05:38 +00:00
|
|
|
|
// returns: whole string, classtype (not used here), class name, description
|
|
|
|
|
BOOST_ASSERT(sub.size() == 4);
|
2007-12-05 22:28:16 +00:00
|
|
|
|
// now, create a TextClass with description containing path information
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
LayoutFile tmpl(textclass, sub.str(2) == "" ? textclass : sub.str(2),
|
2006-04-09 04:35:24 +00:00
|
|
|
|
sub.str(3) + " <" + path + ">", true);
|
2008-02-28 21:04:55 +00:00
|
|
|
|
classmap_[localIndex] = tmpl;
|
2008-02-24 06:14:48 +00:00
|
|
|
|
// This textclass is added on request so it will definitely be
|
|
|
|
|
// used. Load it now because other load() calls may fail if they
|
|
|
|
|
// are called in a context without buffer path information.
|
2008-02-28 21:04:55 +00:00
|
|
|
|
classmap_[localIndex].load(path);
|
|
|
|
|
return localIndex;
|
2006-04-09 04:35:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-28 21:04:55 +00:00
|
|
|
|
// If .layout is not in local directory, or an invalid layout is found, return null
|
|
|
|
|
return string("");
|
2006-04-09 04:35:24 +00:00
|
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2006-04-09 04:35:24 +00:00
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
LayoutFileIndex defaultBaseclass()
|
2007-10-21 10:50:56 +00:00
|
|
|
|
{
|
2008-02-28 21:04:55 +00:00
|
|
|
|
if (BaseClassList::get().haveClass("article"))
|
|
|
|
|
return string("article");
|
|
|
|
|
else
|
|
|
|
|
return string("");
|
2007-10-21 10:50:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
// Reads the style files
|
2006-07-05 17:01:26 +00:00
|
|
|
|
bool LyXSetStyle()
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "LyXSetStyle: parsing configuration...");
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2008-02-28 14:49:01 +00:00
|
|
|
|
if (!BaseClassList::get().read()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "LyXSetStyle: an error occured "
|
|
|
|
|
"during parsing.\n Exiting.");
|
2006-07-05 17:01:26 +00:00
|
|
|
|
return false;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::TCLASS, "LyXSetStyle: configuration parsed.");
|
2006-07-05 17:01:26 +00:00
|
|
|
|
return true;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|