2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2008-03-07 03:53:21 +00:00
|
|
|
|
* \file LayoutFileList.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-03-07 03:53:21 +00:00
|
|
|
|
#include "LayoutFile.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-04-30 08:26:40 +00:00
|
|
|
|
#include "support/lassert.h"
|
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-04-16 19:43:06 +00:00
|
|
|
|
LayoutFileList::~LayoutFileList()
|
|
|
|
|
{
|
|
|
|
|
ClassMap::const_iterator it = classmap_.begin();
|
|
|
|
|
ClassMap::const_iterator en = classmap_.end();
|
|
|
|
|
for (; it != en; ++it) {
|
|
|
|
|
delete it->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
|
2008-03-07 03:53:21 +00:00
|
|
|
|
LayoutFileList & LayoutFileList::get()
|
2008-02-28 14:49:01 +00:00
|
|
|
|
{
|
2008-03-07 03:53:21 +00:00
|
|
|
|
static LayoutFileList baseclasslist;
|
2008-02-28 14:49:01 +00:00
|
|
|
|
return baseclasslist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-07 03:53:21 +00:00
|
|
|
|
bool LayoutFileList::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-07 03:53:21 +00:00
|
|
|
|
LayoutFile const & LayoutFileList::operator[](string const & classname) const
|
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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(haveClass(classname), /**/);
|
2008-03-06 23:31:40 +00:00
|
|
|
|
return *classmap_[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 &
|
2008-03-07 03:53:21 +00:00
|
|
|
|
LayoutFileList::operator[](string const & classname)
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(haveClass(classname), /**/);
|
2008-03-06 23:31:40 +00:00
|
|
|
|
return *classmap_[classname];
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reads LyX textclass definitions according to textclass config file
|
2008-03-07 03:53:21 +00:00
|
|
|
|
bool LayoutFileList::read()
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2008-04-02 23:06:22 +00:00
|
|
|
|
Lexer lex;
|
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-03-07 03:53:21 +00:00
|
|
|
|
lyxerr << "LayoutFileList::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-03-07 03:53:21 +00:00
|
|
|
|
lyxerr << "LayoutFileList::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-03-07 03:53:21 +00:00
|
|
|
|
lyxerr << "LayoutFileList::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
|
2008-03-06 23:31:40 +00:00
|
|
|
|
LayoutFile * tmpl = new LayoutFile(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.
|
2008-03-06 23:31:40 +00:00
|
|
|
|
tmpl->load();
|
2003-05-03 19:24:36 +00:00
|
|
|
|
}
|
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-03-07 03:53:21 +00:00
|
|
|
|
lyxerr << "LayoutFileList::Read: no textclasses found!"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-07 03:53:21 +00:00
|
|
|
|
std::vector<LayoutFileIndex> LayoutFileList::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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-07 03:53:21 +00:00
|
|
|
|
void LayoutFileList::reset(LayoutFileIndex const & classname) {
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(haveClass(classname), /**/);
|
2008-03-06 23:31:40 +00:00
|
|
|
|
LayoutFile * tc = classmap_[classname];
|
|
|
|
|
LayoutFile * tmpl =
|
|
|
|
|
new LayoutFile(tc->name(), tc->latexname(), tc->description(),
|
|
|
|
|
tc->isTeXClassAvailable());
|
2008-02-28 21:04:55 +00:00
|
|
|
|
classmap_[classname] = tmpl;
|
2008-03-06 23:31:40 +00:00
|
|
|
|
delete tc;
|
2007-09-11 16:42:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-07-11 03:41:56 +00:00
|
|
|
|
LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass)
|
2008-07-11 02:43:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (haveClass(textclass))
|
|
|
|
|
return textclass;
|
|
|
|
|
|
|
|
|
|
FileName const tempLayout = FileName::tempName();
|
|
|
|
|
ofstream ofs(tempLayout.toFilesystemEncoding().c_str());
|
|
|
|
|
ofs << "# This layout is automatically generated\n"
|
|
|
|
|
"# \\DeclareLaTeXClass{" << textclass << "}\n\n"
|
|
|
|
|
"Format 7\n"
|
|
|
|
|
"Input stdclass.inc\n\n"
|
|
|
|
|
"Columns 1\n"
|
|
|
|
|
"Sides 1\n"
|
|
|
|
|
"SecNumDepth 2\n"
|
|
|
|
|
"TocDepth 2\n"
|
|
|
|
|
"DefaultStyle Standard\n\n"
|
|
|
|
|
"Style Standard\n"
|
|
|
|
|
" Category MainText\n"
|
|
|
|
|
" Margin Static\n"
|
|
|
|
|
" LatexType Paragraph\n"
|
|
|
|
|
" LatexName dummy\n"
|
|
|
|
|
" ParIndent MM\n"
|
|
|
|
|
" ParSkip 0.4\n"
|
|
|
|
|
" Align Block\n"
|
|
|
|
|
" AlignPossible Block, Left, Right, Center\n"
|
|
|
|
|
" LabelType No_Label\n"
|
|
|
|
|
"End\n";
|
|
|
|
|
ofs.close();
|
|
|
|
|
|
|
|
|
|
// We do not know if a LaTeX class is available for this document, but setting
|
|
|
|
|
// the last parameter to true will suppress a warning message about missing
|
|
|
|
|
// tex class.
|
|
|
|
|
LayoutFile * tc = new LayoutFile(textclass, textclass, "Unknown text class " + textclass, true);
|
|
|
|
|
if (!tc->load(tempLayout.absFilename()))
|
|
|
|
|
// The only way this happens is because the hardcoded layout file above
|
|
|
|
|
// is wrong.
|
|
|
|
|
LASSERT(false, /**/);
|
|
|
|
|
classmap_[textclass] = tc;
|
|
|
|
|
return textclass;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
LayoutFileIndex
|
2008-07-11 02:43:02 +00:00
|
|
|
|
LayoutFileList::addLocalLayout(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-11 18:31:38 +00:00
|
|
|
|
|
2008-02-28 21:04:55 +00:00
|
|
|
|
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
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(sub.size() == 4, /**/);
|
2007-12-05 22:28:16 +00:00
|
|
|
|
// now, create a TextClass with description containing path information
|
2008-03-06 23:31:40 +00:00
|
|
|
|
string className(sub.str(2) == "" ? textclass : sub.str(2));
|
|
|
|
|
LayoutFile * tmpl =
|
2008-07-11 02:43:02 +00:00
|
|
|
|
new LayoutFile(textclass, className, textclass, true);
|
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-03-06 23:31:40 +00:00
|
|
|
|
tmpl->load(path);
|
2008-07-11 02:43:02 +00:00
|
|
|
|
// There will be only one textclass with this name, even if different
|
|
|
|
|
// layout files are loaded from different directories.
|
|
|
|
|
if (haveClass(textclass)) {
|
2008-10-25 00:01:36 +00:00
|
|
|
|
LYXERR0("Existing textclass " << textclass << " is redefined by " << fullName);
|
2008-07-11 02:43:02 +00:00
|
|
|
|
delete classmap_[textclass];
|
|
|
|
|
}
|
|
|
|
|
classmap_[textclass] = tmpl;
|
|
|
|
|
return textclass;
|
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
|
2008-03-06 19:59:05 +00:00
|
|
|
|
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-03-07 03:53:21 +00:00
|
|
|
|
if (LayoutFileList::get().haveClass("article"))
|
2008-02-28 21:04:55 +00:00
|
|
|
|
return string("article");
|
2008-03-07 03:53:21 +00:00
|
|
|
|
if (LayoutFileList::get().empty())
|
2008-03-06 19:59:05 +00:00
|
|
|
|
return string();
|
2008-03-07 03:53:21 +00:00
|
|
|
|
return LayoutFileList::get().classList().front();
|
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-03-07 03:53:21 +00:00
|
|
|
|
if (!LayoutFileList::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
|