On 08/15/2009 06:53 AM, Jean-Marc Lasgouttes wrote:
Le 12/08/2009 17:40, rgheck a écrit :
I've thought about this, too, but don't know how to implement it. I'm
not a GUI guy. But it would be nice to have some concept of
"category" with modules, and then they could be grouped together as
such.
If this is done for modules, I guess textclasses should follow...
Good idea. A patch is attached, for the backend.
JMarc, I'd appreciate your comments. I've chosen to do this the same way
as with modules, by adding a line like:
# Category: Letter
rather than by adding a second optional argument to the \Declare line.
The latter just seemed too complicated.
rh
Index: lib/chkconfig.ltx
===================================================================
--- lib/chkconfig.ltx (revision 31054)
+++ 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'}}
@@ -98,30 +98,30 @@
\newcommand{\TestPackage}[2][\default]{
\TestItem[#1]{#2}{package}{sty}{\AddPackage{#2}}{}}
-\newcommand{\TestDocClass}[2]{
+\newcommand{\TestDocClass}[3]{
\def\layoutname{#1} % remember the name of the layout file
\...@ifundefined{layout@#1}
- {#2 % execute the command
+ {#2{#3} % execute the command
\glob...@namedef{layout@#1}{}}
{} % we have already tried this one.
}
-\newcommand{\DeclareLaTeXClass}[2][\default]{
+\newcommand{\DeclareLaTeXClass}[3][\default]{
\TestItem[#1]{\layoutname}{document class}{cls}
- {\AddLayout[\firstelement]{\layoutname}{#2}{true}}
- {\AddLayout[\firstelement]{\layoutname}{#2}{false}}
+{\AddLayout[\firstelement]{\layoutname}{#2}{#3}{true}}
+{\AddLayout[\firstelement]{\layoutname}{#2}{#3}{false}}
}
% Only for compatibility. Will be removed later.
\let\DeclareSGMLClass=\DeclareDocBookClass
-\newcommand{\DeclareDocBookClass}[2][\default]{
+\newcommand{\DeclareDocBookClass}[3][\default]{
\message{^^J\prefix checking for docbook\space\space class \layoutname... }
\...@ifundefined{hasdocbook}
{\message{no^^J}
- \AddLayout[#1]{\layoutname}{#2}{false}}
+ \AddLayout[#1]{\layoutname}{#2}{#3}{false}}
{\message{yes^^J}
- \AddLayout[#1]{\layoutname}{#2}{true}}
+ \AddLayout[#1]{\layoutname}{#2}{#3}{true}}
}
% Stolen from article.cls
Index: lib/configure.py
===================================================================
--- lib/configure.py (revision 31054)
+++ lib/configure.py (working copy)
@@ -712,25 +712,44 @@
we expect output:
- "article" "article" "article" "false"
- "scrbook" "scrbook" "book (koma-script)" "false"
- "svjog" "svjour" "article (Springer - svjour/jog)" "false"
+ "article" "article" "article" "category" "false"
+ "scrbook" "scrbook" "book (koma-script)" "category" "false"
+ "svjog" "svjour" "article (Springer - svjour/jog)" "category" "false"
+
+ Of course, the category will depend upon the class.
'''
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*{(.*)}')
+ catgy = re.compile(r'^#\s*Category:\s*(.+)')
+ declare = re.compile(r'\Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}')
+
+ classtype = opt = desc = avai = cat = ""
for line in open(file).readlines():
- res = p.search(line)
+ # we're done if we find a non-comment line
+ if line[0] != '#':
+ break
+ # we're also done if we've found everything we need
+ if classtype != "" and catgy != "":
+ break
+
+ res = declare.search(line)
if res != None:
(classtype, optAll, opt, opt1, desc) = res.groups()
avai = {'LaTeX':'false', 'DocBook':bool_docbook}[classtype]
if opt == None:
opt = classname
- return '"%s" "%s" "%s" "%s"\n' % (classname, opt, desc, avai)
- logger.warning("Layout file " + file + " has no \DeclareXXClass line. ")
- return ""
+ continue
+ res = catgy.search(line)
+ if res != None:
+ cat = res.group(1)
+ if classtype == "":
+ logger.warning("Layout file " + file + " has no \DeclareXXClass line. ")
+ return ""
+ return '"%s" "%s" "%s" "%s" "%s"\n' % (classname, opt, desc, cat, avai)
+
+
def checkLatexConfig(check_config, bool_docbook):
''' Explore the LaTeX configuration
Return None (will be passed to sys.exit()) for success.
@@ -791,20 +810,33 @@
# build the list of available layout files and convert it to commands
# for chkconfig.ltx
p1 = re.compile(r'\Declare(LaTeX|DocBook)Class')
+ catre = re.compile(r'^#\s*Category:\s*(.+)')
testclasses = list()
for file in glob.glob( os.path.join('layouts', '*.layout') ) + \
glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) :
if not os.path.isfile(file):
continue
classname = file.split(os.sep)[-1].split('.')[0]
+ decline = catgy = ""
for line in open(file).readlines():
- if p1.search(line) == None:
+ # we're done if we find a non-comment line
+ if line[0] != '#':
+ break
+ # ... or if we've found everything we need
+ if decline != "" and catgy != "":
+ break
+ res = p1.search(line)
+ if res != None:
+ decline = line[1:].strip()
continue
- if line[0] != '#':
- logger.error("Wrong input layout file with line '" + line)
- sys.exit(3)
- testclasses.append("\\TestDocClass{%s}{%s}" % (classname, line[1:].strip()))
- break
+ res = catre.search(line)
+ if res != None:
+ catgy = res.group(1)
+ continue
+ if decline == "":
+ logger.error("Wrong input layout file with line '" + line)
+ sys.exit(3)
+ testclasses.append("\\TestDocClass{%s}{%s}{%s}" % (classname, decline, catgy))
testclasses.sort()
cl = open('chklayouts.tex', 'w')
for line in testclasses:
Index: src/LayoutFile.h
===================================================================
--- src/LayoutFile.h (revision 31054)
+++ src/LayoutFile.h (working copy)
@@ -74,17 +74,22 @@
///
LayoutModuleList const & excludedModules() const
{ return excluded_modules_; }
+ ///
+ std::string category() { return category_; }
private:
/// Construct a layout with default values. Actual values loaded later.
explicit LayoutFile(std::string const & filename,
std::string const & className = std::string(),
std::string const & description = std::string(),
+ std::string const & catgy = std::string(),
bool texClassAvail = false);
/// The only class that should create a LayoutFile is
/// LayoutFileList, which calls the private constructor.
friend class LayoutFileList;
/// can't create empty LayoutFile
LayoutFile() {};
+ /// Category of this document class
+ std::string category_;
};
Index: src/LayoutFile.cpp
===================================================================
--- src/LayoutFile.cpp (revision 31058)
+++ src/LayoutFile.cpp (working copy)
@@ -39,7 +39,8 @@
using boost::smatch;
LayoutFile::LayoutFile(string const & fn, string const & cln,
- string const & desc, bool texClassAvail )
+ string const & desc, string const & catgy, bool texClassAvail ) :
+ category_(catgy)
{
name_ = fn;
latexname_ = cln;
@@ -47,6 +48,7 @@
texClassAvail_ = texClassAvail;
}
+
LayoutFileList::~LayoutFileList()
{
ClassMap::const_iterator it = classmap_.begin();
@@ -146,11 +148,15 @@
LYXERR(Debug::TCLASS, "Desc: " << desc);
if (!lex.next())
break;
+ string const catgy = lex.getString();
+ LYXERR(Debug::TCLASS, "Cat: " << catgy);
+ if (!lex.next())
+ break;
bool avail = lex.getBool();
LYXERR(Debug::TCLASS, "Avail: " << avail);
// This code is run when we have
// fname, clname, desc, and avail
- LayoutFile * tmpl = new LayoutFile(fname, clname, desc, avail);
+ LayoutFile * tmpl = new LayoutFile(fname, clname, desc, catgy, avail);
if (lyxerr.debugging(Debug::TCLASS)) {
// only system layout files are loaded here so no
// buffer path is needed.
@@ -187,7 +193,7 @@
LayoutFile * tc = classmap_[classname];
LayoutFile * tmpl =
new LayoutFile(tc->name(), tc->latexname(), tc->description(),
- tc->isTeXClassAvailable());
+ tc->category(), tc->isTeXClassAvailable());
classmap_[classname] = tmpl;
delete tc;
}
@@ -225,7 +231,8 @@
// 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);
if (!tc->load(tempLayout.absFilename())) {
// The only way this happens is because the hardcoded layout file above
// is wrong.
@@ -267,7 +274,7 @@
// now, create a TextClass with description containing path information
string className(sub.str(2) == "" ? textclass : sub.str(2));
LayoutFile * tmpl =
- new LayoutFile(textclass, className, textclass, true);
+ new LayoutFile(textclass, className, textclass, "local", true);
// 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: lib/layouts/dinbrief.layout
===================================================================
--- lib/layouts/dinbrief.layout (revision 31054)
+++ lib/layouts/dinbrief.layout (working copy)
@@ -1,5 +1,6 @@
#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass{letter (DIN-Brief, German)}
+# Category: Letter
# German DIN-Brief textclass definition file.
# Author : Juergen Vigna <j...@sad.it>
# Modified by: Carsten Kaemmerer <kamme...@ips.cs.tu-bs.de>
@@ -73,14 +74,14 @@
EndFont
End
-# vor der Emfängeranschrift (Einschreiben, Luftpost)
+# vor der Emf�ngeranschrift (Einschreiben, Luftpost)
Style "Postal comment"
CopyStyle DinBrief
LabelString "Postvermerk:"
LatexName postremark
End
-# rechts neben der Emfängeranschrift (Eilt, Persönlich)
+# rechts neben der Emf�ngeranschrift (Eilt, Pers�nlich)
Style Handling
CopyStyle DinBrief
LabelString "Zusatz:"
Index: lib/layouts/europecv.layout
===================================================================
--- lib/layouts/europecv.layout (revision 31054)
+++ lib/layouts/europecv.layout (working copy)
@@ -1,5 +1,6 @@
#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass{curriculum vitae (Europe)}
+# Category: CV
# europe CV textclass definition file.
# Author : Uwe Stöhr (uwesto...@web.de)
Index: lib/layouts/letter.layout
===================================================================
--- lib/layouts/letter.layout (revision 31054)
+++ lib/layouts/letter.layout (working copy)
@@ -1,5 +1,6 @@
#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass{letter}
+# Category: Letter
# Letter textclass definition file.
# Author : Matthias Ettrich <ettr...@informatik.uni-tuebingen.de>
# Heavily modifed and enhanced by serveral developers.
Index: lib/layouts/moderncv.layout
===================================================================
--- lib/layouts/moderncv.layout (revision 31054)
+++ lib/layouts/moderncv.layout (working copy)
@@ -1,5 +1,6 @@
#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass{curriculum vitae (modern)}
+# Category: CV
# modern CV textclass definition file.
# Author : Uwe Stöhr (uwesto...@web.de)
Index: lib/layouts/scrlettr.layout
===================================================================
--- lib/layouts/scrlettr.layout (revision 31054)
+++ lib/layouts/scrlettr.layout (working copy)
@@ -1,5 +1,6 @@
#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass[scrlettr]{letter (KOMA-Script)}
+# Category: Letter
# KOMA scrlettr textclass definition file.
# Bernd Rellermeyer <100.41...@germanynet.de>, 1999/2/17.