]> git.lyx.org Git - features.git/commitdiff
Rationalize the handling of makeTextClass().
authorRichard Heck <rgheck@comcast.net>
Sat, 5 Jan 2008 17:04:56 +0000 (17:04 +0000)
committerRichard Heck <rgheck@comcast.net>
Sat, 5 Jan 2008 17:04:56 +0000 (17:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22388 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/LyXFunc.cpp
src/frontends/qt4/GuiDocument.cpp

index 3777370501b536bf663bb992b0f134e603b4afde..44572501ea0b866aab72082101c52ef9bf0f5d39 100644 (file)
@@ -517,6 +517,8 @@ int Buffer::readHeader(Lexer & lex)
                errorList.push_back(ErrorItem(_("Document header error"),
                        s, -1, 0, 0));
        }
+       
+       params().makeTextClass();
 
        return unknown_tokens;
 }
@@ -542,14 +544,6 @@ bool Buffer::readDocument(Lexer & lex)
        BOOST_ASSERT(paragraphs().empty());
 
        readHeader(lex);
-       TextClass const & baseClass = textclasslist[params().getBaseClass()];
-       if (!baseClass.load(filePath())) {
-               string theclass = baseClass.name();
-               Alert::error(_("Can't load document class"), bformat(
-                       _("Using the default document class, because the "
-                                    "class %1$s could not be loaded."), from_utf8(theclass)));
-               params().setBaseClass(defaultTextclass());
-       }
 
        if (params().outputChanges) {
                bool dvipost    = LaTeXFeatures::isAvailable("dvipost");
index dc2823911dc75cc136a1c453ecf87a6a14f9b575..f84a9792854b99b826e4a2de46a066770c2cabe7 100644 (file)
@@ -314,6 +314,7 @@ BufferParams::BufferParams()
        : pimpl_(new Impl)
 {
        setBaseClass(defaultTextclass());
+       makeTextClass();
        paragraph_separation = PARSEP_INDENT;
        quotes_language = InsetQuotes::EnglishQ;
        fontsize = "default";
@@ -497,7 +498,6 @@ string const BufferParams::readToken(Lexer & lex, string const & token,
                readPreamble(lex);
        } else if (token == "\\begin_modules") {
                readModules(lex);
-               makeTextClass();
        } else if (token == "\\options") {
                lex.eatLine();
                options = lex.getString();
@@ -1363,24 +1363,16 @@ void BufferParams::setTextClass(TextClassPtr tc) {
 
 bool BufferParams::setBaseClass(textclass_type tc)
 {
-       bool retVal = true;
-       if (textclasslist[tc].load())
+       if (textclasslist[tc].load()) {
                baseClass_ = tc;
-       else {
-               docstring s = 
-                       bformat(_("The document class %1$s could not be loaded."),
-                from_utf8(textclasslist[tc].name()));
-               frontend::Alert::error(_("Could not load class"), s);
-               retVal = false;
+               return true;
        }
-       makeTextClass();
-       return retVal;
-}
-
-
-void BufferParams::setJustBaseClass(textclass_type tc)
-{ 
-       baseClass_ = tc; 
+       
+       docstring s = 
+               bformat(_("The document class %1$s could not be loaded."),
+               from_utf8(textclasslist[tc].name()));
+       frontend::Alert::error(_("Could not load class"), s);
+       return false;
 }
 
 
@@ -1393,6 +1385,7 @@ textclass_type BufferParams::getBaseClass() const
 void BufferParams::makeTextClass()
 {
        textClass_.reset(new TextClass(textclasslist[getBaseClass()]));
+       
        //FIXME It might be worth loading the children's modules here,
        //just as we load their bibliographies and such, instead of just 
        //doing a check in InsetInclude.
@@ -1432,7 +1425,7 @@ vector<string> const & BufferParams::getModules() const {
 
 
 
-bool BufferParams::addLayoutModule(string modName, bool makeClass) {
+bool BufferParams::addLayoutModule(string modName) {
        LayoutModuleList::const_iterator it = layoutModules_.begin();
        LayoutModuleList::const_iterator end = layoutModules_.end();
        for (; it != end; it++) {
@@ -1442,27 +1435,23 @@ bool BufferParams::addLayoutModule(string modName, bool makeClass) {
        if (it != layoutModules_.end())
                return false;
        layoutModules_.push_back(modName);
-       if (makeClass)
-               makeTextClass();
        return true;
 }
 
-
+/* This is not currently used but may prove useful
 bool BufferParams::addLayoutModules(vector<string>modNames)
 {
        bool retval = true;
        vector<string>::const_iterator it = modNames.begin();
        vector<string>::const_iterator end = modNames.end();
        for (; it != end; ++it)
-               retval &= addLayoutModule(*it, false);
-       makeTextClass();
+               retval &= addLayoutModule(*it);
        return retval;
 }
-
+*/
 
 void BufferParams::clearLayoutModules() {
        layoutModules_.clear();
-       makeTextClass();
 }
 
 
index 2e670f3eeb13544a2cd044a03962474379241b6a..862a07aed2eadf18f660b5d2e2e1f81f54fa6a7e 100644 (file)
@@ -108,24 +108,19 @@ public:
        std::string fontsize;
        ///Get the LyX TextClass (that is, the layout file) this document is using.
        textclass_type getBaseClass() const;
-       ///Set the LyX TextClass (that is, the layout file) this document is using.
-       ///NOTE This also calls makeTextClass(), to update the local
-       ///TextClass.
+       /// Set the LyX TextClass (that is, the layout file) this document is using.
+       /// NOTE: This does not call makeTextClass() to update the local TextClass.
+       /// That needs to be done manually.
        bool setBaseClass(textclass_type);
-       ///Returns the TextClass currently in use: the BaseClass as modified
-       ///by modules.
+       /// Adds the module information to the baseClass information to
+       /// create our local TextClass.
+       void makeTextClass();
+       /// Returns the TextClass currently in use: the BaseClass as modified
+       /// by modules.
        TextClass const & getTextClass() const;
-       ///Returns a pointer to the TextClass currently in use: the BaseClass 
-       ///as modified by modules. (See \file TextClassPtr.h for the typedef.)
+       /// Returns a pointer to the TextClass currently in use: the BaseClass 
+       /// as modified by modules. (See \file TextClassPtr.h for the typedef.)
        TextClassPtr getTextClassPtr() const;
-       ///Set the LyX TextClass---layout file---this document is using.
-       ///This does NOT call makeTextClass() and so should be used with
-       ///care. This is most likely not what you want if you are operating on 
-       ///BufferParams that are actually associatd with a Buffer. If, on the
-       ///other hand, you are using a temporary set of BufferParams---say, in
-       ///a controller, it may well be, since in that case the local TextClass
-       ///has nothing to do.
-       void setJustBaseClass(textclass_type);
        /// This bypasses the baseClass and sets the textClass directly.
        /// Should be called with care and would be better not being here,
        /// but it seems to be needed by CutAndPaste::putClipboard().
@@ -134,10 +129,15 @@ public:
        std::vector<std::string> const & getModules() const;
        /// Add a module to the list of modules in use.
        /// Returns true if module was successfully added.
-       bool addLayoutModule(std::string modName, bool makeClass = true);
-       /// Add a list of modules.
-       /// Returns true if all modules were successfully added.
-       bool addLayoutModules(std::vector<std::string>modNames);
+       /// The makeClass variable signals whether to call makeTextClass. This
+       /// need not be done if we know this isn't the final time through, or if
+       /// the BufferParams do not represent the parameters for an actual buffer
+       /// (as in GuiDocument).
+       bool addLayoutModule(std::string modName);
+       // Add a list of modules.
+       // Returns true if all modules were successfully added.
+       // Currently unused.
+       // bool addLayoutModules(std::vector<std::string>modNames);
        /// Clear the list
        void clearLayoutModules();
 
@@ -314,11 +314,7 @@ private:
        void readBulletsLaTeX(Lexer &);
        ///
        void readModules(Lexer &);
-       /// Adds the module information to the baseClass information to
-       /// create our local TextClass.
-       void makeTextClass();
 
-       
        /// for use with natbib
        biblio::CiteEngine cite_engine_;
        /// the base TextClass associated with the document
index 386545b0c91349607d9f30fd1951e6170e3afc18..7a499f1dd773d65bab9ccd80c4674087aa659794 100644 (file)
@@ -1659,6 +1659,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        TextClassPtr oldClass = buffer->params().getTextClassPtr();
                        view()->cursor().recordUndoFullDocument();
                        buffer->params().clearLayoutModules();
+                       buffer->params().makeTextClass();
                        updateLayout(oldClass, buffer);
                        updateFlags = Update::Force | Update::FitCursor;
                        break;
@@ -1670,6 +1671,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        TextClassPtr oldClass = buffer->params().getTextClassPtr();
                        view()->cursor().recordUndoFullDocument();
                        buffer->params().addLayoutModule(argument);
+                       buffer->params().makeTextClass();
                        updateLayout(oldClass, buffer);
                        updateFlags = Update::Force | Update::FitCursor;
                        break;
@@ -1698,6 +1700,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        TextClassPtr oldClass = buffer->params().getTextClassPtr();
                        view()->cursor().recordUndoFullDocument();
                        buffer->params().setBaseClass(new_class);
+                       buffer->params().makeTextClass();
                        updateLayout(oldClass, buffer);
                        updateFlags = Update::Force | Update::FitCursor;
                        break;
@@ -1710,6 +1713,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        textclass_type const tc = buffer->params().getBaseClass();
                        textclasslist.reset(tc);
                        buffer->params().setBaseClass(tc);
+                       buffer->params().makeTextClass();
                        updateLayout(oldClass, buffer);
                        updateFlags = Update::Force | Update::FitCursor;
                        break;
index 7063e9e0e2d2c228a6e356280e8d2dc1db4b54e4..19212fa525d37e1d83add8eb38153da2d0e9e9a4 100644 (file)
@@ -913,7 +913,7 @@ void GuiDocument::updatePagestyle(string const & items, string const & sel)
 void GuiDocument::classChanged()
 {
        textclass_type const tc = latexModule->classCO->currentIndex();
-       bp_.setJustBaseClass(tc);
+       bp_.setBaseClass(tc);
        if (lyxrc.auto_reset_options)
                bp_.useClassDefaults();
        updateContents();
@@ -1097,13 +1097,15 @@ void GuiDocument::apply(BufferParams & params)
        params.graphicsDriver =
                tex_graphics[latexModule->psdriverCO->currentIndex()];
        
+       // text layout
+       params.setBaseClass(latexModule->classCO->currentIndex());
+
        // Modules
        params.clearLayoutModules();
        QStringList const selMods = selectedModel()->stringList();
        for (int i = 0; i != selMods.size(); ++i)
                params.addLayoutModule(lyx::fromqstr(selMods[i]));
 
-
        if (mathsModule->amsautoCB->isChecked()) {
                params.use_amsmath = BufferParams::package_auto;
        } else {
@@ -1122,9 +1124,6 @@ void GuiDocument::apply(BufferParams & params)
                        params.use_esint = BufferParams::package_off;
        }
 
-       // text layout
-       params.setJustBaseClass(latexModule->classCO->currentIndex());
-
        if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
                params.pagestyle = "default";
        else {
@@ -1639,7 +1638,7 @@ void GuiDocument::updateContents()
 
 void GuiDocument::useClassDefaults()
 {
-       bp_.setJustBaseClass(latexModule->classCO->currentIndex());
+       bp_.setBaseClass(latexModule->classCO->currentIndex());
        bp_.useClassDefaults();
        updateContents();
 }
@@ -1742,8 +1741,6 @@ void GuiDocument::dispatchParams()
 
        // Apply the BufferParams. Note that this will set the base class
        // and then update the buffer's layout.
-       //FIXME Could this be done last? Then, I think, we'd get the automatic
-       //update mentioned in the next FIXME...
        dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
 
        // Generate the colours requested by each new branch.