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"
|
2014-06-09 11:05:50 +00:00
|
|
|
#include "support/TempFile.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,
|
2012-10-09 05:17:36 +00:00
|
|
|
string const & desc, string const & prereq,
|
|
|
|
string const & category, 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;
|
2012-10-09 05:17:36 +00:00
|
|
|
category_ = category;
|
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
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(haveClass(classname));
|
|
|
|
// safe to continue, since we will make an empty LayoutFile
|
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
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(haveClass(classname));
|
|
|
|
// safe to continue, since we will make an empty LayoutFile
|
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);
|
2012-10-09 05:17:36 +00:00
|
|
|
if (!lex.next())
|
|
|
|
break;
|
|
|
|
string const category = lex.getString();
|
|
|
|
LYXERR(Debug::TCLASS, "Category: " << category);
|
2010-04-07 17:02:44 +00:00
|
|
|
// This code is run when we have
|
|
|
|
// fname, clname, desc, prereq, and avail
|
2012-10-09 05:17:36 +00:00
|
|
|
LayoutFile * tmpl = new LayoutFile(fname, clname, desc, prereq, category, avail);
|
2010-04-07 17:02:44 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
void LayoutFileList::reset(LayoutFileIndex const & classname)
|
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(haveClass(classname));
|
|
|
|
// safe to continue, since we will make an empty LayoutFile
|
2008-03-06 23:31:40 +00:00
|
|
|
LayoutFile * tc = classmap_[classname];
|
|
|
|
LayoutFile * tmpl =
|
|
|
|
new LayoutFile(tc->name(), tc->latexname(), tc->description(),
|
2012-10-09 05:17:36 +00:00
|
|
|
tc->prerequisites(), tc->category(),
|
|
|
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
|
2010-04-07 16:15:26 +00:00
|
|
|
LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass)
|
|
|
|
{
|
2013-04-06 22:07:07 +00:00
|
|
|
// FIXME This could be simplified a bit to call TextClass::read(string, ReadType).
|
2014-06-09 11:05:50 +00:00
|
|
|
|
|
|
|
TempFile tempfile("basicXXXXXX.layout");
|
|
|
|
FileName const tempLayout = tempfile.name();
|
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,
|
2012-10-09 05:17:36 +00:00
|
|
|
"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
|
2012-05-03 10:02:34 +00:00
|
|
|
// without stdclass.inc and without stdinsets.inc.
|
2010-04-07 16:15:26 +00:00
|
|
|
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"
|
2012-05-03 10:02:34 +00:00
|
|
|
"Provides stdinsets 1\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())) {
|
2013-04-06 22:07:07 +00:00
|
|
|
// This can only happen if the hardcoded file above is wrong
|
|
|
|
// or there is some weird filesystem error.
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(false); // We will get an empty layout or something.
|
2010-04-07 16:15:26 +00:00
|
|
|
}
|
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
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
LayoutFileIndex LayoutFileList::addLocalLayout(
|
Fix bug #4812 (Layout in local directory lost on Save As, Copying)
The "save-as" part of the bug is fixed by extending the \textclass tag
such that, if a local layout file is used, its path relative to the
document directory is now stored together with the name. If a relative
path cannot be used, an absolute one is used but, in this case, the
document is not usable on a different platform.
The "copy" part is fixed by introducing a new \origin tag, which is
written when the file is saved. This tag stores the absolute path of
the document directory. If the document is manually copied to a
different location, the local layout file is retrivied by using
\origin (which is only updated on save).
This new tag may prove useful also for locating other files when the
document is manually moved to a different directory.
As in the original implementation the files needed for the layout
(for example, a latex class) had to be in the same directory as the
layout file, this directory has also to be added to TEXINPUTS.
2015-05-13 19:40:51 +00:00
|
|
|
string const & textclass, string const & path, string const & oldpath)
|
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
|
|
|
|
Fix bug #4812 (Layout in local directory lost on Save As, Copying)
The "save-as" part of the bug is fixed by extending the \textclass tag
such that, if a local layout file is used, its path relative to the
document directory is now stored together with the name. If a relative
path cannot be used, an absolute one is used but, in this case, the
document is not usable on a different platform.
The "copy" part is fixed by introducing a new \origin tag, which is
written when the file is saved. This tag stores the absolute path of
the document directory. If the document is manually copied to a
different location, the local layout file is retrivied by using
\origin (which is only updated on save).
This new tag may prove useful also for locating other files when the
document is manually moved to a different directory.
As in the original implementation the files needed for the layout
(for example, a latex class) had to be in the same directory as the
layout file, this directory has also to be added to TEXINPUTS.
2015-05-13 19:40:51 +00:00
|
|
|
FileName layout_file(fullName);
|
|
|
|
bool moved = false;
|
|
|
|
|
|
|
|
if (!layout_file.exists()) {
|
|
|
|
if (oldpath.empty())
|
|
|
|
return string();
|
|
|
|
// The document has been moved to a different directory.
|
|
|
|
// However, oldpath always points to the right spot, unless
|
|
|
|
// the user also moved the layout file.
|
|
|
|
fullName = addName(oldpath, textclass + ".layout");
|
|
|
|
layout_file.set(fullName);
|
|
|
|
layout_file.refresh();
|
|
|
|
if (!layout_file.exists())
|
|
|
|
return string();
|
|
|
|
moved = true;
|
|
|
|
}
|
2013-04-12 01:41:52 +00:00
|
|
|
|
|
|
|
LYXERR(Debug::TCLASS, "Adding class " << textclass << " from directory " << path);
|
|
|
|
// 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
|
|
|
|
// \Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}
|
|
|
|
ifstream ifs(layout_file.toFilesystemEncoding().c_str());
|
|
|
|
static regex const reg("^#\\s*\\\\Declare(LaTeX|DocBook)Class\\s*"
|
|
|
|
"(?:\\[([^,]*)(?:,.*)*\\])*\\s*\\{(.*)\\}\\s*");
|
|
|
|
static regex const catreg("^#\\s*\\\\DeclareCategory\\{(.*)\\}");
|
|
|
|
string line;
|
|
|
|
string class_name;
|
|
|
|
string class_prereq;
|
|
|
|
string category;
|
|
|
|
bool have_declaration = false;
|
|
|
|
while (getline(ifs, line)) {
|
|
|
|
// look for the \DeclareXXXClass line
|
|
|
|
smatch sub;
|
|
|
|
if (regex_match(line, sub, reg)) {
|
|
|
|
// returns: whole string, classtype (not used here), class name, description
|
2013-04-25 21:27:10 +00:00
|
|
|
// LASSERT: Why would this fail?
|
2013-04-12 01:41:52 +00:00
|
|
|
LASSERT(sub.size() == 4, /**/);
|
|
|
|
// now, create a TextClass with description containing path information
|
|
|
|
class_name = (sub.str(2) == "" ? textclass : sub.str(2));
|
|
|
|
class_prereq = class_name + ".cls";
|
|
|
|
have_declaration = true;
|
2012-10-09 05:17:36 +00:00
|
|
|
}
|
2013-04-12 01:41:52 +00:00
|
|
|
else if (regex_match(line, sub, catreg)) {
|
|
|
|
category = sub.str(1);
|
2006-04-09 04:35:24 +00:00
|
|
|
}
|
2013-04-12 01:41:52 +00:00
|
|
|
if (have_declaration && !category.empty())
|
|
|
|
break;
|
2006-04-09 04:35:24 +00:00
|
|
|
}
|
2013-04-12 01:41:52 +00:00
|
|
|
|
|
|
|
if (!have_declaration)
|
|
|
|
return string();
|
|
|
|
|
|
|
|
LayoutFile * tmpl =
|
|
|
|
new LayoutFile(textclass, class_name, textclass, class_prereq, category, 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"
|
|
|
|
// 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.
|
Fix bug #4812 (Layout in local directory lost on Save As, Copying)
The "save-as" part of the bug is fixed by extending the \textclass tag
such that, if a local layout file is used, its path relative to the
document directory is now stored together with the name. If a relative
path cannot be used, an absolute one is used but, in this case, the
document is not usable on a different platform.
The "copy" part is fixed by introducing a new \origin tag, which is
written when the file is saved. This tag stores the absolute path of
the document directory. If the document is manually copied to a
different location, the local layout file is retrivied by using
\origin (which is only updated on save).
This new tag may prove useful also for locating other files when the
document is manually moved to a different directory.
As in the original implementation the files needed for the layout
(for example, a latex class) had to be in the same directory as the
layout file, this directory has also to be added to TEXINPUTS.
2015-05-13 19:40:51 +00:00
|
|
|
tmpl->load(moved ? oldpath : path);
|
2013-04-12 01:41:52 +00:00
|
|
|
// There will be only one textclass with this name, even if different
|
|
|
|
// layout files are loaded from different directories.
|
|
|
|
if (haveClass(textclass)) {
|
Fix bug #4812 (Layout in local directory lost on Save As, Copying)
The "save-as" part of the bug is fixed by extending the \textclass tag
such that, if a local layout file is used, its path relative to the
document directory is now stored together with the name. If a relative
path cannot be used, an absolute one is used but, in this case, the
document is not usable on a different platform.
The "copy" part is fixed by introducing a new \origin tag, which is
written when the file is saved. This tag stores the absolute path of
the document directory. If the document is manually copied to a
different location, the local layout file is retrivied by using
\origin (which is only updated on save).
This new tag may prove useful also for locating other files when the
document is manually moved to a different directory.
As in the original implementation the files needed for the layout
(for example, a latex class) had to be in the same directory as the
layout file, this directory has also to be added to TEXINPUTS.
2015-05-13 19:40:51 +00:00
|
|
|
// Unconditionally issuing the warning may be confusing when
|
|
|
|
// saving the document with a different name, as it is exactly
|
|
|
|
// the same textclass that is being re-established.
|
|
|
|
LYXERR(Debug::TCLASS, "Existing textclass " << textclass << " is redefined by " << fullName);
|
2013-04-12 01:41:52 +00:00
|
|
|
delete classmap_[textclass];
|
|
|
|
}
|
|
|
|
classmap_[textclass] = tmpl;
|
Fix bug #4812 (Layout in local directory lost on Save As, Copying)
The "save-as" part of the bug is fixed by extending the \textclass tag
such that, if a local layout file is used, its path relative to the
document directory is now stored together with the name. If a relative
path cannot be used, an absolute one is used but, in this case, the
document is not usable on a different platform.
The "copy" part is fixed by introducing a new \origin tag, which is
written when the file is saved. This tag stores the absolute path of
the document directory. If the document is manually copied to a
different location, the local layout file is retrivied by using
\origin (which is only updated on save).
This new tag may prove useful also for locating other files when the
document is manually moved to a different directory.
As in the original implementation the files needed for the layout
(for example, a latex class) had to be in the same directory as the
layout file, this directory has also to be added to TEXINPUTS.
2015-05-13 19:40:51 +00:00
|
|
|
return removeExtension(fullName);
|
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
|