]> git.lyx.org Git - features.git/commitdiff
This is one of a series of patches that will merge the layout modules development...
authorRichard Heck <rgheck@comcast.net>
Thu, 23 Aug 2007 16:41:13 +0000 (16:41 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 23 Aug 2007 16:41:13 +0000 (16:41 +0000)
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.

This first patch does some reworking of the infrastructrue. We need to distinguish between the TextClass that a particular document is using and the layout of that document, since modules, in particular, can modify the layout. The solution adopted here is to add a TextClass pointer to BufferParams, which will hold the layout. The layout itself is then constructed from the TextClass the document is using. At present, this is completely trivial, but that will change when modules are added.

The pointer in question is a boost::shared_ptr. This is needed because CutAndPaste saves a copy of the layout with each cut or copied selection. We cannot assume the selection vanishes when the document is closed, so there are two options: (i) keep a list of all the layouts that have ever been used by any document; (ii) used some kind of smart pointer. The latter seems preferable, as the former would waste memory. More importantly, the use of a smart pointer allows modules to be modified on disk and then reloaded while LyX is running, and it will eventually allow the same for layout files.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19756 a592a061-630c-0410-9148-cb99ea01b6c8

19 files changed:
development/scons/scons_manifest.py
src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/BufferView.cpp
src/CutAndPaste.cpp
src/CutAndPaste.h
src/LyXFunc.cpp
src/Makefile.am
src/Text.cpp
src/TextClass_ptr.h [new file with mode: 0644]
src/buffer_funcs.cpp
src/buffer_funcs.h
src/frontends/LyXView.cpp
src/frontends/Toolbars.cpp
src/frontends/Toolbars.h
src/frontends/controllers/ControlDocument.cpp
src/frontends/qt4/QDocument.cpp
src/insets/InsetInclude.cpp

index 9a57bd6eb24f0f0ab4c5c8058d36ec4dcfd99ab8..56798aa82902c15ad29666974efbc1d30e02e929 100644 (file)
@@ -107,6 +107,7 @@ src_header_files = Split('''
     TexRow.h
     Text.h
     TextClass.h
+    TextClass_ptr.h
     TextClassList.h
     TextMetrics.h
     Thesaurus.h
index 5f73e27f6bec1f9ce4eb07510839b996138d3ad4..abcad36f9b164bad0b51b37bb8cec5ead2160aa4 100644 (file)
@@ -49,6 +49,7 @@
 #include "ParIterator.h"
 #include "sgml.h"
 #include "TexRow.h"
+#include "TextClassList.h"
 #include "TexStream.h"
 #include "TocBackend.h"
 #include "Undo.h"
@@ -439,6 +440,7 @@ int Buffer::readHeader(Lexer & lex)
        params().headsep.erase();
        params().footskip.erase();
        params().listings_params.clear();
+       
        for (int i = 0; i < 4; ++i) {
                params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
                params().temp_bullet(i) = ITEMIZE_DEFAULTS[i];
@@ -515,7 +517,7 @@ bool Buffer::readDocument(Lexer & lex)
                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().textclass = 0;
+               params().setBaseClass(defaultTextclass());
        }
 
        if (params().outputChanges) {
index 57932680f5bdb2e33fc016e6f287df4f9d463aef..bc18c35e7e146ad1d75b11ca37ad678b6c4b7000 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "Author.h"
 #include "BranchList.h"
+#include "buffer_funcs.h"
 #include "Bullet.h"
 #include "debug.h"
 #include "Encoding.h"
@@ -268,15 +269,6 @@ SpaceTranslator const & spacetranslator()
 }
 
 
-textclass_type defaultTextclass()
-{
-       // Initialize textclass to point to article. if `first' is
-       // true in the returned pair, then `second' is the textclass
-       // number; if it is false, second is 0. In both cases, second
-       // is what we want.
-       return textclasslist.numberOfClass("article").second;
-}
-
 } // anon namespace
 
 
@@ -322,8 +314,9 @@ void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
 
 
 BufferParams::BufferParams()
-       : textclass(defaultTextclass()), pimpl_(new Impl)
+       : pimpl_(new Impl)
 {
+       setBaseClass(defaultTextclass());
        paragraph_separation = PARSEP_INDENT;
        quotes_language = InsetQuotes::EnglishQ;
        fontsize = "default";
@@ -458,20 +451,17 @@ string const BufferParams::readToken(Lexer & lex, string const & token)
                pair<bool, lyx::textclass_type> pp =
                        textclasslist.numberOfClass(classname);
                if (pp.first) {
-                       textclass = pp.second;
+                       setBaseClass(pp.second);
                } else {
                        // if text class does not exist, try to load it from filepath
                        pp = textclasslist.addTextClass(classname, filepath);
                        if (pp.first) {
-                               textclass = pp.second;
+                               setBaseClass(pp.second);
                        } else {
-                               textclass = defaultTextclass();
+                               setBaseClass(defaultTextclass());
                                return classname;
                        }
                }
-               // FIXME: isTeXClassAvailable will try to load the layout file, but will
-               // fail because of the lack of path info. Warnings will be given although
-               // the layout file will be correctly loaded later.
                if (!getTextClass().isTeXClassAvailable()) {
                        docstring const msg =
                                bformat(_("The layout file requested by this document,\n"
@@ -648,7 +638,7 @@ void BufferParams::writeFile(ostream & os) const
        // Prints out the buffer info into the .lyx file given by file
 
        // the textclass
-       os << "\\textclass " << textclasslist[textclass].name() << '\n';
+       os << "\\textclass " << textclasslist[baseClass_].name() << '\n';
 
        // then the preamble
        if (!preamble.empty()) {
@@ -1172,7 +1162,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
 
 void BufferParams::useClassDefaults()
 {
-       TextClass const & tclass = textclasslist[textclass];
+       TextClass const & tclass = textclasslist[baseClass_];
 
        sides = tclass.sides();
        columns = tclass.columns();
@@ -1188,7 +1178,7 @@ void BufferParams::useClassDefaults()
 
 bool BufferParams::hasClassDefaults() const
 {
-       TextClass const & tclass = textclasslist[textclass];
+       TextClass const & tclass = textclasslist[baseClass_];
 
        return (sides == tclass.sides()
                && columns == tclass.columns()
@@ -1201,7 +1191,42 @@ bool BufferParams::hasClassDefaults() const
 
 TextClass const & BufferParams::getTextClass() const
 {
-       return textclasslist[textclass];
+       return *textClass_;
+}
+
+
+TextClass_ptr BufferParams::getTextClass_ptr() const {
+       return textClass_;
+}
+
+
+void BufferParams::setTextClass(TextClass_ptr tc) {
+       textClass_ = tc;
+}
+
+
+void BufferParams::setBaseClass(textclass_type tc)
+{
+       baseClass_ = tc;
+       makeTextClass();
+}
+
+
+void BufferParams::setJustBaseClass(textclass_type tc)
+{ 
+       baseClass_ = tc; 
+}
+
+
+textclass_type BufferParams::getBaseClass() const
+{
+       return baseClass_;
+}
+
+
+void BufferParams::makeTextClass()
+{
+       textClass_.reset(new TextClass(textclasslist[getBaseClass()]));
 }
 
 
index bf5926e823f8c2dd0711c3b8e5ebb87a0cc303b4..56fd7249038d13adcdad25bd92838844ac41368d 100644 (file)
 
 #include "BiblioInfo.h"
 #include "TextClass.h"
+#include "TextClass_ptr.h"
 #include "paper.h"
 
 #include "insets/InsetQuotes.h"
 
 #include "support/copied_ptr.h"
+#include "support/FileName.h"
 #include "support/types.h"
 
 #include "frontends/controllers/frontend_helpers.h"
 
 #include <vector>
 
-
 namespace lyx {
 
 class AuthorList;
@@ -42,9 +43,8 @@ class TexRow;
 class VSpace;
 class Language;
 
-
 /** Buffer parameters.
- *  This class contains all the parameters for this a buffer uses. Some
+ *  This class contains all the parameters for this buffer's use. Some
  *  work needs to be done on this class to make it nice. Now everything
  *  is in public.
  */
@@ -88,7 +88,7 @@ public:
        ///
        void setDefSkip(VSpace const & vs);
 
-       /** Wether paragraphs are separated by using a indent like in
+       /** Whether paragraphs are separated by using a indent like in
         *  articles or by using a little skip like in letters.
         */
        PARSEP paragraph_separation;
@@ -98,10 +98,30 @@ public:
        InsetQuotes::quote_times quotes_times;
        ///
        std::string fontsize;
-       ///
-       textclass_type textclass;
-       ///
+       ///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.
+       void setBaseClass(textclass_type);
+       ///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 TextClass_ptr.h for the typedef.)
+       TextClass_ptr getTextClass_ptr() 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().
+       void setTextClass(TextClass_ptr);
 
        /// returns the main font for the buffer (document)
        Font const getFont() const;
@@ -202,16 +222,6 @@ public:
        /// \param index should lie in the range 0 <= \c index <= 3.
        Bullet & user_defined_bullet(size_type index);
        Bullet const & user_defined_bullet(size_type index) const;
-       ///
-       void readPreamble(Lexer &);
-       ///
-       void readLanguage(Lexer &);
-       ///
-       void readGraphicsDriver(Lexer &);
-       ///
-       void readBullets(Lexer &);
-       ///
-       void readBulletsLaTeX(Lexer &);
 
        /// Whether to load a package such as amsmath or esint.
        /// The enum values must not be changed (file format!)
@@ -271,6 +281,27 @@ public:
        void setCiteEngine(biblio::CiteEngine const);
 
 private:
+       ///
+       void readPreamble(Lexer &);
+       ///
+       void readLanguage(Lexer &);
+       ///
+       void readGraphicsDriver(Lexer &);
+       ///
+       void readBullets(Lexer &);
+       ///
+       void readBulletsLaTeX(Lexer &);
+       /// create our local TextClass.
+       void makeTextClass();
+
+       
+       /// for use with natbib
+       biblio::CiteEngine cite_engine_;
+       /// the base TextClass associated with the document
+       textclass_type baseClass_;
+       /// the possibly modular TextClass actually in use
+       TextClass_ptr textClass_;
+
        /** Use the Pimpl idiom to hide those member variables that would otherwise
         *  drag in other header files.
         */
@@ -282,8 +313,6 @@ private:
        };
        support::copied_ptr<Impl, MemoryTraits> pimpl_;
 
-       ///
-       biblio::CiteEngine cite_engine_;
 };
 
 } // namespace lyx
index 3e5e01f9d39ad00ec534350e59f90d897ff794a9..abf55eb8ec0e86b4ea9733a13b525ab6cff9e286 100644 (file)
@@ -1516,7 +1516,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
                el = buf.errorList("Parse");
                recordUndo(cursor_);
                cap::pasteParagraphList(cursor_, buf.paragraphs(),
-                                            buf.params().textclass, el);
+                                            buf.params().getTextClass_ptr(), el);
                res = _("Document %1$s inserted.");
        } else
                res = _("Could not insert document %1$s");
index a6339581ec0f80d0cf2e48c0e89cfd707942e84b..485b581e37bb8d959bad3f1ddef498be38e9e3bd 100644 (file)
@@ -30,6 +30,7 @@
 #include "LyXFunc.h"
 #include "LyXRC.h"
 #include "Text.h"
+#include "TextClass_ptr.h"
 #include "TextClassList.h"
 #include "Paragraph.h"
 #include "paragraph_funcs.h"
@@ -71,7 +72,7 @@ namespace {
 
 typedef std::pair<pit_type, int> PitPosPair;
 
-typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
+typedef limited_stack<pair<ParagraphList, TextClass_ptr> > CutStack;
 
 CutStack theCuts(10);
 // persistent selection, cleared until the next selection
@@ -107,7 +108,7 @@ bool checkPastePossible(int index)
 
 pair<PitPosPair, pit_type>
 pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
-                    textclass_type textclass, ErrorList & errorlist)
+                    TextClass_ptr textclass, ErrorList & errorlist)
 {
        Buffer const & buffer = cur.buffer();
        pit_type pit = cur.pit();
@@ -121,7 +122,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
 
        // Make a copy of the CaP paragraphs.
        ParagraphList insertion = parlist;
-       textclass_type const tc = buffer.params().textclass;
+       TextClass_ptr const tc = buffer.params().getTextClass_ptr();
 
        // Now remove all out of the pars which is NOT allowed in the
        // new environment and set also another font if that is required.
@@ -335,7 +336,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params,
 }
 
 
-void putClipboard(ParagraphList const & paragraphs, textclass_type textclass,
+void putClipboard(ParagraphList const & paragraphs, TextClass_ptr textclass,
                  docstring const & plaintext)
 {
        // For some strange reason gcc 3.2 and 3.3 do not accept
@@ -343,7 +344,7 @@ void putClipboard(ParagraphList const & paragraphs, textclass_type textclass,
        Buffer buffer("", false);
        buffer.setUnnamed(true);
        buffer.paragraphs() = paragraphs;
-       buffer.params().textclass = textclass;
+       buffer.params().setTextClass(textclass);
        std::ostringstream lyx;
        if (buffer.write(lyx))
                theClipboard().put(lyx.str(), plaintext);
@@ -354,7 +355,7 @@ void putClipboard(ParagraphList const & paragraphs, textclass_type textclass,
 
 void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
        pit_type startpit, pit_type endpit,
-       int start, int end, textclass_type tc, CutStack & cutstack)
+       int start, int end, TextClass_ptr tc, CutStack & cutstack)
 {
        BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
        BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
@@ -411,17 +412,17 @@ docstring grabAndEraseSelection(Cursor & cur)
 }
 
 
-void switchBetweenClasses(textclass_type c1, textclass_type c2,
-       InsetText & in, ErrorList & errorlist)
+void switchBetweenClasses(TextClass_ptr const & c1, 
+       TextClass_ptr const & c2, InsetText & in, ErrorList & errorlist)
 {
        errorlist.clear();
 
        BOOST_ASSERT(!in.paragraphs().empty());
        if (c1 == c2)
                return;
-
-       TextClass const & tclass1 = textclasslist[c1];
-       TextClass const & tclass2 = textclasslist[c2];
+       
+       TextClass const & tclass1 = *c1;
+       TextClass const & tclass2 = *c2;
 
        // layouts
        ParIterator end = par_iterator_end(in);
@@ -542,7 +543,7 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut)
                                text->paragraphs(),
                                begpit, endpit,
                                cur.selBegin().pos(), endpos,
-                               bp.textclass, theCuts);
+                               bp.getTextClass_ptr(), theCuts);
                        // Stuff what we got on the clipboard.
                        // Even if there is no selection.
                        putClipboard(theCuts[0].first, theCuts[0].second,
@@ -626,7 +627,8 @@ void copySelectionToStack(Cursor & cur, CutStack & cutstack)
                        ++pos;
 
                copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
-                       pos, cur.selEnd().pos(), cur.buffer().params().textclass, cutstack);
+                       pos, cur.selEnd().pos(), 
+                       cur.buffer().params().getTextClass_ptr(), cutstack);
                dirtyTabularStack(false);
        }
 
@@ -638,7 +640,7 @@ void copySelectionToStack(Cursor & cur, CutStack & cutstack)
                par.layout(bp.getTextClass().defaultLayout());
                par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
                pars.push_back(par);
-               cutstack.push(make_pair(pars, bp.textclass));
+               cutstack.push(make_pair(pars, bp.getTextClass_ptr()));
        }
 }
 
@@ -665,7 +667,7 @@ void copySelection(Cursor & cur, docstring const & plaintext)
                par.layout(bp.getTextClass().defaultLayout());
                par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
                pars.push_back(par);
-               theCuts.push(make_pair(pars, bp.textclass));
+               theCuts.push(make_pair(pars, bp.getTextClass_ptr()));
        } else
                copySelectionToStack(cur, theCuts);
 
@@ -711,7 +713,7 @@ docstring getSelection(Buffer const & buf, size_t sel_index)
 
 
 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
-                       textclass_type textclass, ErrorList & errorList)
+                       TextClass_ptr textclass, ErrorList & errorList)
 {
        if (cur.inTexted()) {
                Text * text = cur.text();
@@ -765,7 +767,7 @@ void pasteClipboard(Cursor & cur, ErrorList & errorList, bool asParagraphs)
                        if (buffer.readString(lyx)) {
                                recordUndo(cur);
                                pasteParagraphList(cur, buffer.paragraphs(),
-                                       buffer.params().textclass, errorList);
+                                       buffer.params().getTextClass_ptr(), errorList);
                                cur.setSelection();
                                return;
                        }
index d1162cb16500b13b4f5625aae79cb5c434bc29d2..e3fccedb76bc7fef0a3037d09bc1e8de319f06aa 100644 (file)
@@ -15,6 +15,7 @@
 #define CUTANDPASTE_H
 
 #include "support/docstring.h"
+#include "TextClass_ptr.h"
 
 #include <vector>
 
@@ -89,15 +90,15 @@ void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
 /// Paste the paragraph list \p parlist at the position given by \p cur.
 /// Does not handle undo. Does only work in text, not mathed.
 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
-                       textclass_type textclass, ErrorList & errorList);
+                       TextClass_ptr textclass, ErrorList & errorList);
 
 
 /** Needed to switch between different classes. This works
  *  for a list of paragraphs beginning with the specified par.
  *  It changes layouts and character styles.
  */
-void switchBetweenClasses(textclass_type c1, textclass_type c2,
-                         InsetText & in, ErrorList &);
+void switchBetweenClasses(TextClass_ptr const & c1, 
+       TextClass_ptr const & c2, InsetText & in, ErrorList &);
 
 /// Get the current selection as a string. Does not change the selection.
 /// Does only work if the whole selection is in mathed.
index 45d391390942af1884c4e089046014b287e39060..28d9b4ad2c45891a564999a0c9a91f14debdb969 100644 (file)
@@ -816,10 +816,10 @@ void loadTextclass(string const & name)
        textclass_type const tc = tc_pair.second;
 
        if (!textclasslist[tc].load()) {
-               docstring s = bformat(_("The document could not be converted\n"
-                                                 "into the document class %1$s."),
+               docstring s = bformat(_("The document class %1$s."
+                                  "could not be loaded."),
                                   from_utf8(textclasslist[tc].name()));
-               Alert::error(_("Could not change class"), s);
+               Alert::error(_("Could not load class"), s);
        }
 }
 
@@ -1777,9 +1777,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        BOOST_ASSERT(lyx_view_);
                        Buffer * buffer = lyx_view_->buffer();
 
-                       textclass_type const old_class =
-                               buffer->params().textclass;
-
                        loadTextclass(argument);
 
                        std::pair<bool, textclass_type> const tc_pair =
@@ -1788,18 +1785,23 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (!tc_pair.first)
                                break;
 
+                       textclass_type const old_class = buffer->params().getBaseClass();
                        textclass_type const new_class = tc_pair.second;
+
                        if (old_class == new_class)
                                // nothing to do
                                break;
 
                        lyx_view_->message(_("Converting document to new document class..."));
                        recordUndoFullDocument(view());
-                       buffer->params().textclass = new_class;
+                       //Save the old, possibly modular, layout for use in conversion.
+                       TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+                       buffer->params().setBaseClass(new_class);
+                       
                        StableDocIterator backcur(view()->cursor());
                        ErrorList & el = buffer->errorList("Class Switch");
                        cap::switchBetweenClasses(
-                               old_class, new_class,
+                               oldClass, buffer->params().getTextClass_ptr(),
                                static_cast<InsetText &>(buffer->inset()), el);
 
                        view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
index d99921090bd80276fbc884f44f9aef1863d7d2a0..0be8085ccd6a49d307d4dc18ada0d30557a5ddab 100644 (file)
@@ -250,6 +250,7 @@ liblyxcore_la_SOURCES = \
        Text3.cpp \
        TextClass.cpp \
        TextClass.h \
+       TextClass_ptr.h \
        TextClassList.cpp \
        TextClassList.h \
        TextMetrics.cpp \
index 61467dc207a7a05a84927a0efafa8c14912c714e..ead9fdd187736342fd4bf48e8c03a81e8d36457a 100644 (file)
@@ -1342,7 +1342,7 @@ bool Text::dissolveInset(Cursor & cur) {
                                        b.getLanguage());
                }
 
-               pasteParagraphList(cur, plist, b.params().textclass,
+               pasteParagraphList(cur, plist, b.params().getTextClass_ptr(),
                                   b.errorList("Paste"));
                // restore position
                cur.pit() = std::min(cur.lastpit(), spit);
diff --git a/src/TextClass_ptr.h b/src/TextClass_ptr.h
new file mode 100644 (file)
index 0000000..aa78079
--- /dev/null
@@ -0,0 +1,28 @@
+// -*- C++ -*-
+/**
+ * \file TextClass_ptr.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef TEXTCLASS_PTR_H
+#define TEXTCLASS_PTR_H
+
+#include <boost/shared_ptr.hpp>
+
+namespace lyx {
+
+class TextClass;
+
+/** Shared pointer for possibly modular layout. Needed so that paste,
+        *  for example, will still be able to retain the pointer, even when
+        *  the buffer itself is closed.
+ */
+typedef boost::shared_ptr<TextClass> TextClass_ptr;
+
+}
+#endif
index 8db089a47cd18c34850b8628568ed7a4ece82bc9..87e97376c144834b096769aa899cfb0f1b91e035 100644 (file)
@@ -28,6 +28,7 @@
 #include "LaTeX.h"
 #include "LyX.h"
 #include "TextClass.h"
+#include "TextClassList.h"
 #include "Paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParagraphList.h"
@@ -632,6 +633,15 @@ void checkBufferStructure(Buffer & buffer, ParIterator const & par_it)
        }
 }
 
+textclass_type defaultTextclass()
+{
+       // We want to return the article class. if `first' is
+       // true in the returned pair, then `second' is the textclass
+       // number; if it is false, second is 0. In both cases, second
+       // is what we want.
+       return textclasslist.numberOfClass("article").second;
+}
+
 
 void loadChildDocuments(Buffer const & buf)
 {
@@ -652,5 +662,4 @@ void loadChildDocuments(Buffer const & buf)
        if (use_gui && buf.getMasterBuffer() == &buf)
                updateLabels(buf);
 }
-
 } // namespace lyx
index b2142f81185f9ae6590632c11e68ef916f27055d..044db3fc84ab5bcbe05644b607048760022b6182 100644 (file)
@@ -71,6 +71,9 @@ void updateLabels(Buffer const &, ParIterator &);
 ///
 void checkBufferStructure(Buffer &, ParIterator const &);
 
+///
+textclass_type defaultTextclass();
+
 ///
 void loadChildDocuments(Buffer const & buffer);
 
index 28a2133b1869cf95b9009dc7c71c053c1be01189..91cee4a1206759cb80e692bc6f0a5ddf9ddf65dc 100644 (file)
@@ -355,7 +355,7 @@ void LyXView::updateLayoutChoice()
        }
 
        // Update the layout display
-       if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
+       if (toolbars_->updateLayoutList(buffer()->params().getTextClass_ptr())) {
                current_layout = buffer()->params().getTextClass().defaultLayoutName();
        }
 
index fa8ba22fbf2a8d92484e68bdf1964498e4c0d7be..eae9f96ed3cfbd3e49c997b880feac0a41c10c08 100644 (file)
@@ -35,7 +35,7 @@ namespace frontend {
 Toolbars::Toolbars(LyXView & owner)
        : owner_(owner),
          layout_(0),
-         last_textclass_(-1)
+         last_textclass_(TextClass_ptr())
 {}
 
 #define TurnOnFlag(x)   flags |= ToolbarInfo::x
@@ -286,7 +286,7 @@ void Toolbars::setLayout(docstring const & layout)
 }
 
 
-bool Toolbars::updateLayoutList(int textclass)
+bool Toolbars::updateLayoutList(TextClass_ptr textclass)
 {
        // update the layout display
        if (last_textclass_ != textclass) {
@@ -308,7 +308,7 @@ void Toolbars::openLayoutList()
 
 void Toolbars::clearLayoutList()
 {
-       last_textclass_ = -1;
+       last_textclass_ = TextClass_ptr();
        if (layout_)
                layout_->clear();
 }
index 781292b529da13b272bb6aa8bcad992d85bbcc86..1828bcf6bb4f3a8c4d5f3e4d83851e74f94906b3 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef TOOLBARS_H
 #define TOOLBARS_H
 
+#include "TextClass_ptr.h"
 #include "ToolbarBackend.h"
 #include "Session.h"
 
@@ -115,7 +116,7 @@ public:
        /** Populate the layout combox - returns whether we did a full
         *  update or not
         */
-       bool updateLayoutList(int textclass);
+       bool updateLayoutList(TextClass_ptr textclass);
 
        /// Drop down the layout list.
        void openLayoutList();
@@ -150,7 +151,7 @@ private:
        ToolbarsMap toolbars_;
 
        /// The last textclass layout list in the layout choice selector
-       int last_textclass_;
+       TextClass_ptr last_textclass_;
 
        // load flags with saved values
        void initFlags(ToolbarInfo & tbinfo);
index 3eabeed4415159e127c70c044a361f765cfb2562..e7452ac2bee98e80625a877d301c415c7bd430a2 100644 (file)
@@ -87,7 +87,7 @@ BufferId ControlDocument::id() const
 
 TextClass const & ControlDocument::textClass() const
 {
-       return textclasslist[bp_->textclass];
+       return textclasslist[bp_->getBaseClass()];
 }
 
 
@@ -113,8 +113,8 @@ void ControlDocument::dispatchParams()
 
        // Set the document class.
        textclass_type const old_class =
-               kernel().buffer().params().textclass;
-       textclass_type const new_class = bp_->textclass;
+               kernel().buffer().params().getBaseClass();
+       textclass_type const new_class = bp_->getBaseClass();
        if (new_class != old_class) {
                string const name = textclasslist[new_class].name();
                kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
index baa3fad82eaf6dc6d7ef83239cf937c6c1172788..6087d6b46c13234af93e69762e4b96cc718c41ef 100644 (file)
@@ -834,12 +834,12 @@ void QDocumentDialog::classChanged()
        textclass_type const tc = latexModule->classCO->currentIndex();
 
        if (form_->controller().loadTextclass(tc)) {
-               params.textclass = tc;
+               params.setJustBaseClass(tc);
                if (lyxrc.auto_reset_options)
                        params.useClassDefaults();
                form_->update_contents();
        } else {
-               latexModule->classCO->setCurrentIndex(params.textclass);
+               latexModule->classCO->setCurrentIndex(params.getBaseClass());
        }
 }
 
@@ -969,8 +969,7 @@ void QDocumentDialog::apply(BufferParams & params)
        }
 
        // text layout
-       params.textclass =
-               latexModule->classCO->currentIndex();
+       params.setJustBaseClass(latexModule->classCO->currentIndex());
 
        if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
                params.pagestyle = "default";
@@ -1255,7 +1254,7 @@ void QDocumentDialog::updateParams(BufferParams const & params)
        }
 
        // text layout
-       latexModule->classCO->setCurrentIndex(params.textclass);
+       latexModule->classCO->setCurrentIndex(params.getBaseClass());
 
        updatePagestyle(form_->controller().textClass().opt_pagestyle(),
                                 params.pagestyle);
@@ -1454,8 +1453,7 @@ void QDocument::useClassDefaults()
 {
        BufferParams & params = controller().params();
 
-       ///\todo verify the use of below with lyx-devel:
-       params.textclass = dialog_->latexModule->classCO->currentIndex();
+       params.setJustBaseClass(dialog_->latexModule->classCO->currentIndex());
 
        params.useClassDefaults();
        update_contents();
index d2bd3652ef7ac4c7358b9bc10434ce1bae551efe..8ad44093aa7f13b8da28c8d7effee4d6588c58eb 100644 (file)
@@ -482,7 +482,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 
                Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
 
-               if (tmp->params().textclass != m_buffer->params().textclass) {
+               if (tmp->params().getBaseClass() != m_buffer->params().getBaseClass()) {
                        // FIXME UNICODE
                        docstring text = bformat(_("Included file `%1$s'\n"
                                                "has textclass `%2$s'\n"