From fc7c77587f85368b5ef86d75fe4c202c1f58a158 Mon Sep 17 00:00:00 2001 From: John Levon Date: Sat, 3 May 2003 19:24:36 +0000 Subject: [PATCH] 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 --- lib/chkconfig.ltx | 17 ++++++++++------- src/ChangeLog | 10 ++++++++++ src/bufferparams.C | 14 ++++++++++++++ src/exporter.C | 3 ++- src/frontends/qt2/ChangeLog | 6 ++++++ src/frontends/qt2/QDocument.C | 21 +++++++++++++-------- src/frontends/qt2/QDocumentDialog.C | 8 +------- src/frontends/xforms/ChangeLog | 5 +++++ src/frontends/xforms/FormDocument.C | 13 ++++++++++++- src/lyxtextclass.C | 10 ++++++++-- src/lyxtextclass.h | 9 ++++++++- src/lyxtextclasslist.C | 28 +++++++++++++++++++--------- 12 files changed, 108 insertions(+), 36 deletions(-) diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index 3604fdc386..19dff8bb67 100644 --- a/lib/chkconfig.ltx +++ b/lib/chkconfig.ltx @@ -59,9 +59,9 @@ % the variable chk_. %%% \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 } diff --git a/src/ChangeLog b/src/ChangeLog index 1083c2906a..585dd409ee 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2003-05-02 Michael Schmitt + + * 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 * BufferView.h: diff --git a/src/bufferparams.C b/src/bufferparams.C index fd2a8eae06..a58a8fdc07 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -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 #include @@ -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") { diff --git a/src/exporter.C b/src/exporter.C index c0b89ab18c..1882a89fe2 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -176,7 +176,8 @@ string const Exporter::BufferFormat(Buffer const * buffer) vector const Exporter::Backends(Buffer const * buffer) { vector v; - v.push_back(BufferFormat(buffer)); + if (buffer->params.getLyXTextClass().isTeXClassAvailable()) + v.push_back(BufferFormat(buffer)); v.push_back("text"); return v; } diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index d9bf35f2ea..69136f8474 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,9 @@ +2003-05-02 Michael Schmitt + + * QDocument.C: + * QDocumentDialog.C: Handle document classes with missing TeX class + (-> class name prefix: "Unavailable: ") + 2003-05-03 John Levon * qscreen.h: diff --git a/src/frontends/qt2/QDocument.C b/src/frontends/qt2/QDocument.C index 4b937368cf..aeacd6dee0 100644 --- a/src/frontends/qt2/QDocument.C +++ b/src/frontends/qt2/QDocument.C @@ -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; nlatexModule->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); diff --git a/src/frontends/qt2/QDocumentDialog.C b/src/frontends/qt2/QDocumentDialog.C index 3ed90e3f68..15c7b4f6e5 100644 --- a/src/frontends/qt2/QDocumentDialog.C +++ b/src/frontends/qt2/QDocumentDialog.C @@ -358,13 +358,7 @@ void QDocumentDialog::classChanged() params.pagestyle); } } else { - for (int n = 0; nclassCO->count(); ++n) { - if (latexModule->classCO->text(n) == - toqstr(cntrl.textClass().description())) { - latexModule->classCO->setCurrentItem(n); - break; - } - } + latexModule->classCO->setCurrentItem(params.textclass); } } diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 34ac8d45e5..cfee1b3fb0 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2003-05-02 Michael Schmitt + + * FormDocument.C: Handle document classes with missing TeX class + (-> class name prefix: "Unavailable: ") + 2003-05-03 John Levon * xscreen.h: diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index 593857bbda..d55286f6f8 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -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); diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index 61b2b1f44c..462e9ed74c 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -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; diff --git a/src/lyxtextclass.h b/src/lyxtextclass.h index 53ccef4c12..bc93f8d6fe 100644 --- a/src/lyxtextclass.h +++ b/src/lyxtextclass.h @@ -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_; }; diff --git a/src/lyxtextclasslist.C b/src/lyxtextclasslist.C index d764c5c043..71e7d1b23e 100644 --- a/src/lyxtextclasslist.C +++ b/src/lyxtextclasslist.C @@ -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; } -- 2.39.2