On 05/03/2010 2:38 PM, rgheck wrote:
> On 03/05/2010 11:43 AM, Julien Rioux wrote:
> Missing requirements would obviously be better, since then the user
> knows what to do.
>
Thanks Richard.
Here's a patch for review. Missing packages that prevent a layout from
being available are listed in textclass.lst; they can be displayed to
the user when he/she attempts to use such a class.
Note that I am no C++ hacker, so please check that I am not doing
anything crazy here.
Julien
Index: src/Layout.h
===================================================================
--- src/Layout.h (revision 33664)
+++ src/Layout.h (working copy)
@@ -85,6 +85,8 @@
///
void setLatexName(std::string const & n) { latexname_ = n; }
///
+ // std::string const & prerequisites() const { return prerequisites_; }
+ ///
docstring const & labelstring(bool in_appendix) const
{ return in_appendix ? labelstring_appendix_ : labelstring_; }
///
Index: src/LayoutFile.cpp
===================================================================
--- src/LayoutFile.cpp (revision 33664)
+++ src/LayoutFile.cpp (working copy)
@@ -42,12 +42,14 @@
using boost::smatch;
LayoutFile::LayoutFile(string const & fn, string const & cln,
- string const & desc, bool texClassAvail )
+ string const & desc, bool texClassAvail,
+ string const & prereq )
{
name_ = fn;
latexname_ = cln;
description_ = desc;
texClassAvail_ = texClassAvail;
+ prerequisites_ = prereq;
}
LayoutFileList::~LayoutFileList()
@@ -151,9 +153,13 @@
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, and avail
- LayoutFile * tmpl = new LayoutFile(fname, clname, desc,
avail);
+ // fname, clname, desc, avail, and prereq
+ LayoutFile * tmpl = new LayoutFile(fname, clname, desc,
avail, prereq);
if (lyxerr.debugging(Debug::TCLASS)) {
// only system layout files are loaded here so
no
// buffer path is needed.
@@ -190,7 +196,7 @@
LayoutFile * tc = classmap_[classname];
LayoutFile * tmpl =
new LayoutFile(tc->name(), tc->latexname(), tc->description(),
- tc->isTeXClassAvailable());
+ tc->isTeXClassAvailable(), tc->prerequisites());
classmap_[classname] = tmpl;
delete tc;
}
@@ -228,7 +234,7 @@
// 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);
+ LayoutFile * tc = new LayoutFile(textclass, textclass, "Unknown text
class " + textclass, true, textclass + ".cls");
if (!tc->load(tempLayout.absFilename())) {
// The only way this happens is because the hardcoded layout
file above
// is wrong.
@@ -269,8 +275,12 @@
LASSERT(sub.size() == 4, /**/);
// now, create a TextClass with description
containing path information
string className(sub.str(2) == "" ? textclass :
sub.str(2));
+ string classPrereq(className + ".cls");
LayoutFile * tmpl =
- new LayoutFile(textclass, className,
textclass, true);
+ new LayoutFile(textclass, className,
textclass, true, classPrereq);
+ //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 className +
".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.
Index: src/TextClass.h
===================================================================
--- src/TextClass.h (revision 33664)
+++ src/TextClass.h (working copy)
@@ -189,6 +189,8 @@
std::string const & description() const { return description_; }
///
std::string const & latexname() const { return latexname_; }
+ ///
+ std::string const & prerequisites() const { return prerequisites_; }
/// Can be LaTeX, DocBook, etc.
OutputType outputType() const { return outputType_; }
/// Can be latex, docbook ... (the name of a format)
@@ -238,6 +240,8 @@
mutable bool loaded_;
/// Is the TeX class available?
bool texClassAvail_;
+ /// document class prerequisites
+ std::string prerequisites_;
///
std::string opt_fontsize_;
///
Index: src/LayoutFile.h
===================================================================
--- src/LayoutFile.h (revision 33664)
+++ src/LayoutFile.h (working copy)
@@ -79,7 +79,8 @@
explicit LayoutFile(std::string const & filename,
std::string const & className = std::string(),
std::string const & description = std::string(),
- bool texClassAvail = false);
+ bool texClassAvail = false,
+ std::string const & prerequisites = std::string());
/// The only class that should create a LayoutFile is
/// LayoutFileList, which calls the private constructor.
friend class LayoutFileList;
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp (revision 33664)
+++ src/BufferParams.cpp (working copy)
@@ -522,13 +522,12 @@
docstring const msg =
bformat(_("The layout file requested by this
document,\n"
"%1$s.layout,\n"
- "is not usable. This is
probably because a LaTeX\n"
- "class or style file required
by it is not\n"
- "available. See the
Customization documentation\n"
- "for more information.\n"),
from_utf8(classname));
+ "is not usable. The following
prerequisites\n"
+ "are missing:\n%2$s\n"),
+ from_utf8(classname),
from_utf8(baseClass()->prerequisites()));
frontend::Alert::warning(_("Document class not
available"),
msg + _("LyX will not be able to produce
output."));
- }
+ }
} else if (token == "\\begin_preamble") {
readPreamble(lex);
} else if (token == "\\begin_local_layout") {
Index: lib/chkconfig.ltx
===================================================================
--- lib/chkconfig.ltx (revision 33664)
+++ lib/chkconfig.ltx (working copy)
@@ -57,9 +57,9 @@
\newcommand{\prefix}{+} % the character used by grep to filter 'good' output
-\newcommand{\AddLayout}[4][\default]{
+\newcommand{\AddLayout}[5][\default]{
\def\default{#2}
- \immediate\write\layouts{"#2" "#1" "#3" "#4"}}
+ \immediate\write\layouts{"#2" "#1" "#3" "#4" "#5"}}
\newcommand{\AddVariable}[2]{
\immediate\write\vars{chk_#1='#2'}}
@@ -76,14 +76,28 @@
\def\files{#1}
\message{^^J\prefix checking for #3 #2 [#1]...}
\let\firstelement\relax
+ \let\missingelements\empty
\existstrue
\...@for\file:=\files\do{
\ifx\firstelement\relax
\edef\firstelement{\file}
\fi
- \IfFileExists{\file}
+ \...@expandtwoargs\in@{.}{\file}
+ \ifin@
+ \def\myfile{\file}
+ \else
+ \def\myfile{\file.#4}
+ \fi
+ \IfFileExists{\myfile}
{}
- {\IfFileExists{\file.#4}{}{\existsfalse}}
+ {
+ \existsfalse
+ \ifx\missingelements\empty
+ \edef\missingelements{\myfile}
+ \else
+ \edef\missingelements{\missingelements, \myfile}
+ \fi
+ }
}
\ifexists
\message{yes^^J}
@@ -108,8 +122,8 @@
\newcommand{\DeclareLaTeXClass}[2][\default]{
\TestItem[#1]{\layoutname}{document class}{cls}
- {\AddLayout[\firstelement]{\layoutname}{#2}{true}}
- {\AddLayout[\firstelement]{\layoutname}{#2}{false}}
+ {\AddLayout[\firstelement]{\layoutname}{#2}{true}{\missingelements}}
+
{\AddLayout[\firstelement]{\layoutname}{#2}{false}{\missingelements}}
}
% Only for compatibility. Will be removed later.
@@ -119,9 +133,9 @@
\message{^^J\prefix checking for docbook\space\space class \layoutname... }
\...@ifundefined{hasdocbook}
{\message{no^^J}
- \AddLayout[#1]{\layoutname}{#2}{false}}
+ \AddLayout[#1]{\layoutname}{#2}{false}{docbook}}
{\message{yes^^J}
- \AddLayout[#1]{\layoutname}{#2}{true}}
+ \AddLayout[#1]{\layoutname}{#2}{true}{}}
}
% Stolen from article.cls
Index: lib/configure.py
===================================================================
--- lib/configure.py (revision 33664)
+++ lib/configure.py (working copy)
@@ -890,10 +890,17 @@
we expect output:
- "article" "article" "article" "false"
- "scrbook" "scrbook" "book (koma-script)" "false"
- "svjog" "svjour" "article (Springer - svjour/jog)" "false"
+ "article" "article" "article" "false" "article.cls"
+ "scrbook" "scrbook" "book (koma-script)" "false" "scrbook.cls"
+ "svjog" "svjour" "article (Springer - svjour/jog)" "false"
"svjour.cls, svjog.clo"
'''
+ def checkForClassExtension(x):
+ '''if the extension for a latex class is not
+ provided, add .cls to the classname'''
+ if not '.' in x:
+ return x.strip() + '.cls'
+ else:
+ return x.strip()
classname = file.split(os.sep)[-1].split('.')[0]
# return ('LaTeX', '[a,b]', 'a', ',b,c', 'article') for
\DeclareLaTeXClass[a,b,c]{article}
p =
re.compile(r'\Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}')
@@ -904,7 +911,14 @@
avai = {'LaTeX':'false', 'DocBook':bool_docbook}[classtype]
if opt == None:
opt = classname
- return '"%s" "%s" "%s" "%s"\n' % (classname, opt, desc, avai)
+ prereq_latex = checkForClassExtension(classname)
+ else:
+ prereq_list = optAll[1:-1].split(',')
+ prereq_list = map(checkForClassExtension, prereq_list)
+ prereq_latex = ', '.join(prereq_list)
+ prereq_docbook = {'true':'', 'false':'docbook'}[bool_docbook]
+ prereq = {'LaTeX':prereq_latex,
'DocBook':prereq_docbook}[classtype]
+ return '"%s" "%s" "%s" "%s" "%s"\n' % (classname, opt, desc, avai,
prereq)
logger.warning("Layout file " + file + " has no \DeclareXXClass line. ")
return ""