]> git.lyx.org Git - features.git/commitdiff
more environment infrastructure
authorAndré Pönitz <poenitz@gmx.net>
Fri, 14 Mar 2003 11:57:12 +0000 (11:57 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 14 Mar 2003 11:57:12 +0000 (11:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6501 a592a061-630c-0410-9148-cb99ea01b6c8

lib/layouts/stdlists.inc
src/lyxtextclass.C
src/lyxtextclass.h

index 1ec9ac8caf9ea681185900827b1ac6a71cbf17ac..c2a586ad649368c2f89be84d42e1ebf9ab152ad6 100644 (file)
@@ -1,3 +1,4 @@
+
 # Standard textclass definition file. Taken from initial LyX source code
 # Author : Matthias Ettrich <ettrich@informatik.uni-tuebingen.de>
 # Transposed by Pascal André <andre@via.ecp.fr>
@@ -112,3 +113,43 @@ Style Bibliography
   AlignPossible                Block, Left
   LabelType            Counter_EnumI
 End
+
+
+#
+# New environments (not active yet)
+#
+#Environment Itemize
+#      LaTeXHeader "\begin{itemize}"
+#      LaTeXFooter "\end{itemize}"
+#  LabelString         *
+#  Margin              Static
+#  LatexType           Item_Environment
+#  NextNoIndent                1
+#  LeftMargin          MMN
+#  LabelSep            xx
+#  ItemSep             0.2
+#  TopSep              0.7
+#  BottomSep           0.7
+#  ParSep              0.3
+#  Align                       Block
+#  AlignPossible               Block, Left
+#  LabelType           Static
+#End
+
+#Environment Enumerate
+#  Margin              Static
+#  LatexType           Item_Environment
+#  LatexName           enumerate
+#  NextNoIndent                1
+#  LeftMargin          MMN
+#  LabelSep            xx
+#  ParSkip             0.0
+#  ItemSep             0.2
+#  TopSep              0.7
+#  BottomSep           0.7
+#  ParSep              0.3
+#  Align                       Block
+#  AlignPossible               Block, Left
+#  LabelType           Counter_EnumI
+#End
+
index d44748b0e5cec4e526fcc78bc15a8bef6348f259..3e2365c60ad0486842a49aeeefaaf774517882ee 100644 (file)
@@ -32,13 +32,19 @@ using std::ostream;
 namespace { // anon
 
 struct compare_name {
+
        compare_name(string const & name)
-               : name_(name) {}
-       template <class C>
-       bool operator()(C & c) {
+               : name_(name)
+       {}
+
+       bool operator()(boost::shared_ptr<LyXLayout> const & c)
+       {
+               //lyxerr << "comparing '" << name_ << "' to '" << c->name() << "'\n";
                return c->name() == name_;
        }
+
        string name_;
+
 };
 
 } // anon
@@ -107,7 +113,8 @@ enum TextClassTags {
        TC_COUNTER,
        TC_NOFLOAT,
        TC_TITLELATEXNAME,
-       TC_TITLELATEXTYPE
+       TC_TITLELATEXTYPE,
+       TC_ENVIRONMENT
 };
 
 // Reads a textclass structure from file.
@@ -201,8 +208,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                                string const name = subst(lexrc.getString(),
                                                    '_', ' ');
                                if (hasLayout(name)) {
-                                       LyXLayout * lay =
-                                               operator[](name).get();
+                                       LyXLayout * lay = operator[](name).get();
                                        error = do_readStyle(lexrc, *lay);
                                } else {
                                        LyXLayout lay;
@@ -224,6 +230,29 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                        }
                        break;
 
+               case TC_ENVIRONMENT:
+                       if (lexrc.next()) {
+                               string const name = subst(lexrc.getString(),
+                                                   '_', ' ');
+                               if (hasLayout(name)) {
+                                       LyXLayout * lay = operator[](name).get();
+                                       error = do_readStyle(lexrc, *lay);
+                               } else {
+                                       LyXLayout lay;
+                                       lay.setName(name);
+                                       if (!(error = do_readStyle(lexrc, lay)))
+                                               envlist_.push_back
+                                                       (boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
+                                       else
+                                               lexrc.printError("Problems reading environment: `$$Token'.");
+                               }
+                       }
+                       else {
+                               lexrc.printError("No name given for style: `$$Token'.");
+                               error = true;
+                       }
+                       break;
+
                case TC_NOSTYLE:
                        if (lexrc.next()) {
                                string const style = subst(lexrc.getString(),
@@ -732,7 +761,7 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
        lyx::Assert(!n.empty());
 
        if (n.empty())
-               lyxerr << "Operator[] called with empty n" << endl;
+               lyxerr << "LyXTextClass::operator[] called with empty n" << endl;
 
        string const name = (n.empty() ? defaultLayoutName() : n);
 
@@ -763,6 +792,28 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
 }
 
 
+LyXLayout_ptr const & LyXTextClass::getEnv(string const & name) const
+{
+       lyx::Assert(!name.empty());
+
+       if (name.empty())
+               lyxerr << "LyXTextClass::getEnv() called with empty n" << endl;
+
+       LayoutList::const_iterator cit =
+               find_if(envlist_.begin(), envlist_.end(), compare_name(name));
+
+       if (cit == envlist_.end()) {
+               lyxerr << "We failed to find the environment '" << name
+                      << "' in the layout list. You MUST investigate!"
+                      << endl;
+               // we require the name to exist
+               lyx::Assert(false);
+       }
+
+       return *cit;
+}
+
+
 bool LyXTextClass::delete_layout(string const & name)
 {
        if (name == defaultLayoutName())
index 2b0a3a538a5d0ad308e7dbb0641431daa217b497..53ccef4c12568ca657942efb6f6e23d6edbc56f2 100644 (file)
@@ -61,6 +61,8 @@ public:
 
        ///
        LyXLayout_ptr const & operator[](string const & vname) const;
+       ///
+       LyXLayout_ptr const & getEnv(string const & vname) const;
 
        /// Sees to that the textclass structure has been loaded
        bool load() const;
@@ -149,6 +151,8 @@ private:
        ///
        bool delete_layout(string const &);
        ///
+       bool delete_env(string const &);
+       ///
        bool do_readStyle(LyXLex &, LyXLayout &);
        /// Layout file name
        string name_;
@@ -202,6 +206,9 @@ private:
        /// Paragraph styles used in this layout
        LayoutList layoutlist_;
 
+       /// Environment styles used in this layout
+       LayoutList envlist_;
+
        /// available types of float, eg. figure, algorithm.
        boost::shared_ptr<FloatList> floatlist_;