bug 809 from Michael, and some small changes to it

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6932 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-05-03 19:24:36 +00:00
parent f48e8300e1
commit fc7c77587f
12 changed files with 108 additions and 36 deletions

View File

@ -59,9 +59,9 @@
% the variable chk_<name>.
%%%
\newcommand{\prefix}{+} % the character used by grep to filter 'good' output
\newcommand{\AddLayout}[3][\default]{
\newcommand{\AddLayout}[4][\default]{
\def\default{#2}
\immediate\write\layouts{"#2" "#1" "#3"}}
\immediate\write\layouts{"#2" "#1" "#3" "#4"}}
\newcommand{\AddVariable}[2]{
\immediate\write\sed{s!@chk_#1@!#2!g}
\immediate\write\vars{chk_#1='#2'}}
@ -107,15 +107,17 @@
}
\newcommand{\DeclareLaTeXClass}[2][\default]{
\TestItem[#1]{\layoutname}{document class}{cls}
{\AddLayout[\firstelement]{\layoutname}{#2}}{}
{\AddLayout[\firstelement]{\layoutname}{#2}{true}}
{\AddLayout[\firstelement]{\layoutname}{#2}{false}}
\expandafter\endinput
}
\newcommand{\DeclareLinuxDocClass}[2][\default]{
\message{^^J\prefix checking for linuxdoc class \layoutname... }
\@ifundefined{haslinuxdoc}
{\message{no^^J}}
{\message{no^^J}
\AddLayout[#1]{\layoutname}{#2}{false}}
{\message{yes^^J}
\AddLayout[#1]{\layoutname}{#2}}
\AddLayout[#1]{\layoutname}{#2}{true}}
\expandafter\endinput
}
% Only for compatibility. Will be removed later.
@ -124,9 +126,10 @@
\newcommand{\DeclareDocBookClass}[2][\default]{
\message{^^J\prefix checking for docbook\space\space class \layoutname... }
\@ifundefined{hasdocbook}
{\message{no^^J}}
{\message{no^^J}
\AddLayout[#1]{\layoutname}{#2}{false}}
{\message{yes^^J}
\AddLayout[#1]{\layoutname}{#2}}
\AddLayout[#1]{\layoutname}{#2}{true}}
\expandafter\endinput
}

View File

@ -1,3 +1,13 @@
2003-05-02 Michael Schmitt <michael.schmitt@teststep.org>
* bufferparams.C: Output warning if a document with missing
TeX document class is loaded
* exporter.C: Disable TeX exports if the document class is missing
* lyxtextclass.C:
* lyxtextclass.h:
* lyxtextclasslist.C: Handle new textclass.lst format; new method
isTeXClassAvailable()
2003-05-03 John Levon <levon@movementarian.org>
* BufferView.h:

View File

@ -22,11 +22,15 @@
#include "lyxlex.h"
#include "Lsstream.h"
#include "author.h"
#include "gettext.h"
#include "support/lyxalgo.h" // for lyx::count
#include "support/lyxlib.h"
#include "support/lstrings.h"
#include "support/types.h"
#include "support/BoostFormat.h"
#include "frontends/Alert.h"
#include <cstdlib>
#include <algorithm>
@ -92,6 +96,16 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
textclass = 0;
return classname;
}
if (!getLyXTextClass().isTeXClassAvailable()) {
string msg =
#if USE_BOOST_FORMAT
boost::io::str(boost::format(_("The document uses a missing TeX class \"%1$s\".\n")) % classname);
#else
_("The document uses a missing TeX class ") + classname + ".\n";
#endif
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 == "\\options") {

View File

@ -176,7 +176,8 @@ string const Exporter::BufferFormat(Buffer const * buffer)
vector<string> const Exporter::Backends(Buffer const * buffer)
{
vector<string> v;
v.push_back(BufferFormat(buffer));
if (buffer->params.getLyXTextClass().isTeXClassAvailable())
v.push_back(BufferFormat(buffer));
v.push_back("text");
return v;
}

View File

@ -1,3 +1,9 @@
2003-05-02 Michael Schmitt <michael.schmitt@teststep.org>
* QDocument.C:
* QDocumentDialog.C: Handle document classes with missing TeX class
(-> class name prefix: "Unavailable: ")
2003-05-03 John Levon <levon@movementarian.org>
* qscreen.h:

View File

@ -26,6 +26,7 @@
#include "tex-strings.h" // tex_graphics
#include "support/lstrings.h" // tostr()
#include "support/filetools.h" // LibFileSearch()
#include "support/BoostFormat.h"
#include "lyxtextclasslist.h"
#include "vspace.h"
#include "bufferparams.h"
@ -122,7 +123,17 @@ void QDocument::build_dialog()
// layout
for (LyXTextClassList::const_iterator cit = textclasslist.begin();
cit != textclasslist.end(); ++cit) {
dialog_->latexModule->classCO->insertItem(toqstr(cit->description()));
if (cit->isTeXClassAvailable()) {
dialog_->latexModule->classCO->insertItem(toqstr(cit->description()));
} else {
string item =
#if USE_BOOST_FORMAT
boost::io::str(boost::format(_("Unavailable: %1$s")) % cit->description());
#else
_("Unavailable: ") + cit->description();
#endif
dialog_->latexModule->classCO->insertItem(toqstr(item));
}
}
for (int n = 0; tex_fonts[n][0]; ++n) {
@ -499,13 +510,7 @@ void QDocument::update_contents()
// layout
for (int n = 0; n<dialog_->latexModule->classCO->count(); ++n) {
if (dialog_->latexModule->classCO->text(n) ==
toqstr(controller().textClass().description())) {
dialog_->latexModule->classCO->setCurrentItem(n);
break;
}
}
dialog_->latexModule->classCO->setCurrentItem(params.textclass);
dialog_->updateFontsize(controller().textClass().opt_fontsize(),
params.fontsize);

View File

@ -358,13 +358,7 @@ void QDocumentDialog::classChanged()
params.pagestyle);
}
} else {
for (int n = 0; n<latexModule->classCO->count(); ++n) {
if (latexModule->classCO->text(n) ==
toqstr(cntrl.textClass().description())) {
latexModule->classCO->setCurrentItem(n);
break;
}
}
latexModule->classCO->setCurrentItem(params.textclass);
}
}

View File

@ -1,3 +1,8 @@
2003-05-02 Michael Schmitt <michael.schmitt@teststep.org>
* FormDocument.C: Handle document classes with missing TeX class
(-> class name prefix: "Unavailable: ")
2003-05-03 John Levon <levon@movementarian.org>
* xscreen.h:

View File

@ -35,6 +35,7 @@
#include "support/lstrings.h" // contains_functor, getStringFromVector
#include "support/filetools.h" // LibFileSearch
#include "support/BoostFormat.h"
#include XPM_H_LOCATION
#include FORMS_H_LOCATION
@ -135,7 +136,17 @@ void FormDocument::build()
LyXTextClassList::const_iterator tit = textclasslist.begin();
LyXTextClassList::const_iterator tend = textclasslist.end();
for (; tit != tend; ++tit) {
fl_addto_combox(obj, tit->description().c_str());
if (tit->isTeXClassAvailable()) {
fl_addto_combox(obj, tit->description().c_str());
} else {
string item =
#if USE_BOOST_FORMAT
boost::io::str(boost::format(_("Unavailable: %1$s")) % tit->description());
#else
_("Unavailable: ") + tit->description();
#endif
fl_addto_combox(obj, item.c_str());
}
}
fl_set_combox_browser_height(obj, 400);

View File

@ -50,9 +50,9 @@ struct compare_name {
LyXTextClass::LyXTextClass(string const & fn, string const & cln,
string const & desc)
string const & desc, bool texClassAvail )
: name_(fn), latexname_(cln), description_(desc),
floatlist_(new FloatList), ctrs_(new Counters)
floatlist_(new FloatList), ctrs_(new Counters), texClassAvail_(texClassAvail)
{
outputType_ = LATEX;
columns_ = 1;
@ -71,6 +71,12 @@ LyXTextClass::LyXTextClass(string const & fn, string const & cln,
}
bool LyXTextClass::isTeXClassAvailable() const
{
return texClassAvail_;
}
bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
{
lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;

View File

@ -35,7 +35,11 @@ public:
explicit
LyXTextClass(string const & = string(),
string const & = string(),
string const & = string());
string const & = string(),
bool = false);
/// check whether the TeX class is available
bool isTeXClassAvailable() const;
/// paragraph styles begin iterator.
const_iterator begin() const { return layoutlist_.begin(); }
@ -217,6 +221,9 @@ private:
/// Has this layout file been loaded yet?
mutable bool loaded;
/// Is the TeX class available?
bool texClassAvail_;
};

View File

@ -62,10 +62,16 @@ LyXTextClassList::operator[](textclass_type textclass) const
// used when sorting the textclass list.
class less_textclass_desc {
class less_textclass_avail_desc {
public:
int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
return tc1.description() < tc2.description();
// Ordering criteria:
// 1. Availability of text class
// 2. Description (lexicographic)
return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
(tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
tc1.description() < tc2.description());
}
};
@ -122,13 +128,17 @@ bool LyXTextClassList::Read()
if (lex.next()) {
string const desc = lex.getString();
lyxerr[Debug::TCLASS] << "Desc: " << desc << endl;
// This code is run when we have
// fname, clname and desc
LyXTextClass tmpl(fname, clname, desc);
if (lyxerr.debugging(Debug::TCLASS)) {
tmpl.load();
if (lex.next()) {
bool avail = lex.getBool();
lyxerr[Debug::TCLASS] << "Avail: " << avail << endl;
// This code is run when we have
// fname, clname, desc, and avail
LyXTextClass tmpl(fname, clname, desc, avail);
if (lyxerr.debugging(Debug::TCLASS)) {
tmpl.load();
}
classlist_.push_back(tmpl);
}
classlist_.push_back(tmpl);
}
}
}
@ -141,7 +151,7 @@ bool LyXTextClassList::Read()
return false;
}
// Ok everything loaded ok, now sort the list.
sort(classlist_.begin(), classlist_.end(), less_textclass_desc());
sort(classlist_.begin(), classlist_.end(), less_textclass_avail_desc());
return true;
}