From 556f26e8eb8d3e8068b0bb800f88f383f738465f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 13 Nov 2003 15:51:44 +0000 Subject: [PATCH] allow to open documents when the textclass is unavailable (backport from 1.4.0cvs) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_3_X@8081 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 8 ++++++++ lib/chkconfig.ltx | 17 ++++++++++------- lib/configure.m4 | 6 +----- lib/layouts/cv.layout | 2 +- src/buffer.C | 13 +++++++++++++ src/exporter.C | 3 ++- src/frontends/qt2/QDocument.C | 15 +++++++-------- src/frontends/xforms/FormDocument.C | 8 ++++++-- src/lyxtextclass.C | 9 +++++++-- src/lyxtextclass.h | 8 +++++++- src/lyxtextclasslist.C | 20 +++++++++++++------- status.13x | 7 +++++++ 12 files changed, 82 insertions(+), 34 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 40d45bba30..f21ce4b551 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,11 @@ +2003-11-12 Jean-Marc Lasgouttes + + * configure.m4: when latex configuration detection is disabled, + fix the default textclass.lst to the new format. Also simplify it + to contain only "article". + + * layouts/cv.layout: change description to lowercase + 2003-11-05 Jean-Marc Lasgouttes * Makefile.am (install-xfonts): fix error when PSres.upr does not diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index 3e83096080..70d0fa3640 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/lib/configure.m4 b/lib/configure.m4 index 7176f0b13b..c38938a3ec 100644 --- a/lib/configure.m4 +++ b/lib/configure.m4 @@ -408,11 +408,7 @@ PROVIDE_DEFAULT_FILE(textclass.lst,dnl # It contains only default values, since chkconfig.ltx could not be run # for some reason. Run ./configure if you need to update it after a # configuration change. -article article article -report report report -book book book -linuxdoc linuxdoc linuxdoc -letter letter letter]) +article article article false]) PROVIDE_DEFAULT_FILE(chkconfig.sed,[s/@.*@/???/g]) diff --git a/lib/layouts/cv.layout b/lib/layouts/cv.layout index f6da5c3296..75e4192a91 100644 --- a/lib/layouts/cv.layout +++ b/lib/layouts/cv.layout @@ -1,5 +1,5 @@ #% Do not delete the line below; configure depends on this -# \DeclareLaTeXClass{Curriculum Vitae} +# \DeclareLaTeXClass{curriculum vitae} # CV textclass definition file. # Author : Jean-Marc Lasgouttes (Jean-Marc.Lasgouttes@inria.fr) diff --git a/src/buffer.C b/src/buffer.C index 2c02f55133..0ea31739a4 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -650,6 +650,19 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, #endif params.textclass = 0; } + if (!params.getLyXTextClass().isTeXClassAvailable()) { +#if USE_BOOST_FORMAT + Alert::alert(_("Textclass error"), + boost::io::str(boost::format(_("The document uses a missing TeX class \"%1$s\".")) % lex.getString()), + _("LyX will not be able to produce output.")); +#else + Alert::alert( + _("Textclass error"), + _("The document uses a missing TeX class ") + + lex.getString(), + _("LyX will not be able to produce output.")); +#endif + } } else if (token == "\\options") { lex.eatLine(); params.options = lex.getString(); diff --git a/src/exporter.C b/src/exporter.C index 08a857ff68..7eb7207411 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -169,7 +169,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/QDocument.C b/src/frontends/qt2/QDocument.C index dd37537997..da0cdb3c7b 100644 --- a/src/frontends/qt2/QDocument.C +++ b/src/frontends/qt2/QDocument.C @@ -115,7 +115,12 @@ void QDocument::build_dialog() // layout for (LyXTextClassList::const_iterator cit = textclasslist.begin(); cit != textclasslist.end(); ++cit) { - dialog_->layoutModule->classCO->insertItem(toqstr(cit->description())); + if (cit->isTeXClassAvailable()) { + dialog_->layoutModule->classCO->insertItem(toqstr(cit->description())); + } else { + dialog_->layoutModule->classCO->insertItem(toqstr("Unavailable: " + + cit->description())); + } } for (int n = 0; tex_fonts[n][0]; ++n) { @@ -467,13 +472,7 @@ void QDocument::update_contents() // layout - for (int n = 0; nlayoutModule->classCO->count(); ++n) { - if (dialog_->layoutModule->classCO->text(n) == - toqstr(controller().textClass().description())) { - dialog_->layoutModule->classCO->setCurrentItem(n); - break; - } - } + dialog_->layoutModule->classCO->setCurrentItem(params.textclass); dialog_->updateFontsize(controller().textClass().opt_fontsize(), params.fontsize); diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index c72e8d5f9d..210994411f 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -145,7 +145,11 @@ void FormDocument::build() fl_end_form(); for (LyXTextClassList::const_iterator cit = textclasslist.begin(); cit != textclasslist.end(); ++cit) { - combo_doc_class->addto(cit->description()); + if (cit->isTeXClassAvailable()) { + combo_doc_class->addto(cit->description()); + } else { + combo_doc_class->addto("Unavailable: " + cit->description()); + } } fl_addto_choice(class_->choice_doc_spacing, @@ -852,7 +856,7 @@ void FormDocument::UpdateClassParams(BufferParams const & params) LyXTextClass const & tclass = textclasslist[params.textclass]; - combo_doc_class->select(tclass.description()); + combo_doc_class->select(params.textclass + 1); fl_clear_choice(class_->choice_doc_fontsize); fl_addto_choice(class_->choice_doc_fontsize, "default"); fl_addto_choice(class_->choice_doc_fontsize, diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index e18000f194..bc2e4fd347 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -49,9 +49,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; @@ -70,6 +70,11 @@ 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 df3c111a60..d2aae4fa01 100644 --- a/src/lyxtextclass.h +++ b/src/lyxtextclass.h @@ -39,7 +39,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(); } @@ -150,6 +154,8 @@ public: /// int size() const; private: + /// Is the TeX class available? + bool texClassAvail_; /// bool delete_layout(string const &); /// diff --git a/src/lyxtextclasslist.C b/src/lyxtextclasslist.C index 861b33e261..bf68c4f8aa 100644 --- a/src/lyxtextclasslist.C +++ b/src/lyxtextclasslist.C @@ -69,7 +69,9 @@ LyXTextClassList::operator[](textclass_type textclass) const class less_textclass_desc { public: int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) { - return tc1.description() < tc2.description(); + return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) || + (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && + tc1.description() < tc2.description()); } }; @@ -130,13 +132,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); } } } diff --git a/status.13x b/status.13x index 71d9abe800..f1e7789954 100644 --- a/status.13x +++ b/status.13x @@ -22,6 +22,13 @@ What's new ** Updates +- it is now possible to open documents which use a textclasse for + which no LaTeX support is installed. The documents can be normally + edited, but they can of course not be previewed or printed. Note + that the format of the file .lyx/textclasses.lst has changed as a + consequence and it is therefore not possible to use LyX 1.3.4 and an + earlier version with the same .lyx/ directory. + - add support for \boldsymbol in math editor - update danish, italian, romanian and slovenian interface localizations