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
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \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
|
|
|
|
2009-09-19 20:56:12 +00:00
|
|
|
#include "frontends/alert.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"
|
2009-09-19 20:56:12 +00:00
|
|
|
#include "support/lassert.h"
|
|
|
|
#include "support/lstrings.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2010-04-22 11:16:58 +00:00
|
|
|
#include "support/bind.h"
|
2010-06-29 17:09:40 +00:00
|
|
|
#include "support/regex.h"
|
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 {
|
|
|
|
|
2010-04-22 11:16:58 +00:00
|
|
|
|
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,
|
2010-03-22 12:25:16 +00:00
|
|
|
string const & desc, string const & prereq,
|
|
|
|
bool texclassavail)
|
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
|
|
|
{
|
|
|
|
name_ = fn;
|
|
|
|
latexname_ = cln;
|
|
|
|
description_ = desc;
|
2010-03-22 12:25:16 +00:00
|
|
|
prerequisites_ = prereq;
|
2010-03-23 14:16:02 +00:00
|
|
|
tex_class_avail_ = texclassavail;
|
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
|
|
|
}
|
|
|
|
|
2010-03-22 12:25:16 +00:00
|
|
|
|
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
|
|
|
|
2010-03-22 12:25:16 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-11 20:02:53 +00:00
|
|
|
LayoutFile & 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
|
|
|
{
|
2010-04-07 17:02:44 +00:00
|
|
|
bool success = false;
|
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");
|
2010-04-07 17:02:44 +00:00
|
|
|
LYXERR(Debug::TCLASS, "Reading textclasses from `" << real_file << "'.");
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
if (real_file.empty()) {
|
2010-07-17 21:12:48 +00:00
|
|
|
LYXERR0("LayoutFileList::Read: unable to find textclass file "
|
2010-07-17 21:22:32 +00:00
|
|
|
<< "`textclass.lst'.");
|
2010-04-07 17:02:44 +00:00
|
|
|
} else if (!lex.setFile(real_file)) {
|
|
|
|
LYXERR0("LayoutFileList::Read: lyxlex was not able to set file: "
|
|
|
|
<< real_file << '.');
|
|
|
|
} else if (!lex.isOK()) {
|
|
|
|
LYXERR0("LayoutFileList::Read: unable to open textclass file `"
|
2010-04-21 01:19:09 +00:00
|
|
|
<< makeDisplayPath(real_file.absFileName(), 1000)
|
2010-04-07 17:02:44 +00:00
|
|
|
<< "'\nCheck your installation.");
|
|
|
|
} else {
|
|
|
|
// we have a file we can read.
|
|
|
|
bool finished = false;
|
|
|
|
LYXERR(Debug::TCLASS, "Starting parsing of textclass.lst");
|
|
|
|
while (lex.isOK() && !finished) {
|
|
|
|
LYXERR(Debug::TCLASS, "\tline by line");
|
|
|
|
switch (lex.lex()) {
|
|
|
|
case Lexer::LEX_FEOF:
|
|
|
|
finished = true;
|
2009-08-15 16:50:44 +00:00
|
|
|
break;
|
2010-04-07 17:02:44 +00:00
|
|
|
default:
|
|
|
|
string const fname = lex.getString();
|
|
|
|
LYXERR(Debug::TCLASS, "Fname: " << fname);
|
|
|
|
if (!lex.next())
|
|
|
|
break;
|
|
|
|
string const clname = lex.getString();
|
|
|
|
LYXERR(Debug::TCLASS, "Clname: " << clname);
|
|
|
|
if (!lex.next())
|
|
|
|
break;
|
|
|
|
string const desc = lex.getString();
|
|
|
|
LYXERR(Debug::TCLASS, "Desc: " << desc);
|
|
|
|
if (!lex.next())
|
|
|
|
break;
|
|
|
|
bool avail = lex.getBool();
|
|
|
|
LYXERR(Debug::TCLASS, "Avail: " << avail);
|
|
|
|
if (!lex.next())
|
|
|
|
break;
|
|
|
|
string const prereq = lex.getString();
|
|
|
|
LYXERR(Debug::TCLASS, "Prereq: " << prereq);
|
|
|
|
// This code is run when we have
|
|
|
|
// fname, clname, desc, prereq, and avail
|
|
|
|
LayoutFile * tmpl = new LayoutFile(fname, clname, desc, prereq, avail);
|
|
|
|
if (lyxerr.debugging(Debug::TCLASS)) {
|
|
|
|
// only system layout files are loaded here so no
|
|
|
|
// buffer path is needed.
|
|
|
|
tmpl->load();
|
|
|
|
}
|
|
|
|
classmap_[fname] = tmpl;
|
|
|
|
} // end of switch
|
|
|
|
} // end of while loop
|
|
|
|
LYXERR(Debug::TCLASS, "End parsing of textclass.lst");
|
|
|
|
success = true;
|
|
|
|
} // end of else
|
|
|
|
|
|
|
|
// LyX will start with an empty classmap_. This is OK because
|
|
|
|
// (a) we will give the user a chance to reconfigure (see bug 2829) and
|
|
|
|
// (b) even if that fails, we can use addEmptyClass() to get some basic
|
|
|
|
// functionality.
|
2008-02-28 21:04:55 +00:00
|
|
|
if (classmap_.empty())
|
2010-04-07 17:02:44 +00:00
|
|
|
LYXERR0("LayoutFileList::Read: no textclasses found!");
|
|
|
|
return success;
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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(),
|
2010-03-22 12:25:16 +00:00
|
|
|
tc->prerequisites(), 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-07 16:15:26 +00:00
|
|
|
namespace {
|
2008-07-11 02:43:02 +00:00
|
|
|
|
2010-04-07 16:15:26 +00:00
|
|
|
string layoutpost =
|
|
|
|
"Columns 1\n"
|
|
|
|
"Sides 1\n"
|
|
|
|
"SecNumDepth 2\n"
|
|
|
|
"TocDepth 2\n"
|
2008-07-11 02:43:02 +00:00
|
|
|
"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";
|
2010-04-07 16:15:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass)
|
|
|
|
{
|
2012-05-03 09:55:54 +00:00
|
|
|
FileName const tempLayout = FileName::tempName("basic_layout");
|
2010-04-07 16:15:26 +00:00
|
|
|
ofstream ofs(tempLayout.toFilesystemEncoding().c_str());
|
|
|
|
// This writes a very basic class, but it also attempts to include
|
|
|
|
// stdclass.inc. That would give us something moderately usable.
|
|
|
|
ofs << "# This layout is automatically generated\n"
|
|
|
|
"# \\DeclareLaTeXClass{" << textclass << "}\n\n"
|
2010-07-18 11:58:38 +00:00
|
|
|
"Format " << LAYOUT_FORMAT << "\n"
|
2010-04-07 16:15:26 +00:00
|
|
|
"Input stdclass.inc\n\n"
|
|
|
|
<< layoutpost;
|
2008-07-11 02:43:02 +00:00
|
|
|
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.
|
2010-03-22 12:25:16 +00:00
|
|
|
LayoutFile * tc = new LayoutFile(textclass, textclass,
|
|
|
|
"Unknown text class " + textclass, textclass + ".cls", true);
|
2010-04-07 16:15:26 +00:00
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
if (!tc->load(tempLayout.absFileName())) {
|
2010-04-07 16:15:26 +00:00
|
|
|
// The only way this happens is because the hardcoded layout file
|
2010-07-18 11:52:12 +00:00
|
|
|
// above is wrong or stdclass.inc cannot be found. So try again
|
2010-04-07 16:15:26 +00:00
|
|
|
// without stdclass.inc.
|
|
|
|
ofstream ofs2(tempLayout.toFilesystemEncoding().c_str());
|
|
|
|
ofs2 << "# This layout is automatically generated\n"
|
|
|
|
"# \\DeclareLaTeXClass{" << textclass << "}\n\n"
|
2010-07-18 11:58:38 +00:00
|
|
|
"Format " << LAYOUT_FORMAT << "\n"
|
2010-04-07 16:15:26 +00:00
|
|
|
<< layoutpost;
|
|
|
|
ofs2.close();
|
2010-04-21 01:19:09 +00:00
|
|
|
if (!tc->load(tempLayout.absFileName())) {
|
2010-04-07 16:15:26 +00:00
|
|
|
// This can only happen if the hardcoded file above is wrong.
|
|
|
|
LASSERT(false, /* */);
|
|
|
|
}
|
2008-12-22 18:18:47 +00:00
|
|
|
}
|
2010-04-07 16:15:26 +00:00
|
|
|
|
2008-07-11 02:43:02 +00:00
|
|
|
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
|
2010-03-22 12:25:16 +00:00
|
|
|
string class_name(sub.str(2) == "" ? textclass : sub.str(2));
|
|
|
|
string class_prereq(class_name + ".cls");
|
2008-03-06 23:31:40 +00:00
|
|
|
LayoutFile * tmpl =
|
2010-03-22 12:25:16 +00:00
|
|
|
new LayoutFile(textclass, class_name, textclass, class_prereq, true);
|
|
|
|
//FIXME: The prerequisites are available from the layout file and
|
|
|
|
// can be extracted from the above regex, but for now this
|
|
|
|
// field is simply set to class_name + ".cls"
|
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
|
|
|
|
2009-09-19 20:56:12 +00:00
|
|
|
bool LayoutFileList::load(string const & name, string const & buf_path)
|
|
|
|
{
|
|
|
|
if (!haveClass(name)) {
|
|
|
|
LYXERR0("Document class \"" << name << "\" does not exist.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayoutFile * tc = classmap_[name];
|
2010-07-28 21:03:27 +00:00
|
|
|
return tc->load(buf_path);
|
2009-09-19 20:56:12 +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())
|
2010-04-07 17:02:44 +00:00
|
|
|
// we'll call it that, since this gives the user a chance to
|
|
|
|
// have a functioning document when things improve.
|
|
|
|
return string("article");
|
2008-03-07 03:53:21 +00:00
|
|
|
return LayoutFileList::get().classList().front();
|
2007-10-21 10:50:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|