From 6bc54517df228d0d5e8350ea0f2dd8b69462ffb7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 14 Mar 2003 11:57:12 +0000 Subject: [PATCH] more environment infrastructure git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6501 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/stdlists.inc | 41 +++++++++++++++++++++++++ src/lyxtextclass.C | 65 +++++++++++++++++++++++++++++++++++----- src/lyxtextclass.h | 7 +++++ 3 files changed, 106 insertions(+), 7 deletions(-) diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc index 1ec9ac8caf..c2a586ad64 100644 --- a/lib/layouts/stdlists.inc +++ b/lib/layouts/stdlists.inc @@ -1,3 +1,4 @@ + # Standard textclass definition file. Taken from initial LyX source code # Author : Matthias Ettrich # Transposed by Pascal André @@ -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 + diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index d44748b0e5..3e2365c60a 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -32,13 +32,19 @@ using std::ostream; namespace { // anon struct compare_name { + compare_name(string const & name) - : name_(name) {} - template - bool operator()(C & c) { + : name_(name) + {} + + bool operator()(boost::shared_ptr 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(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()) diff --git a/src/lyxtextclass.h b/src/lyxtextclass.h index 2b0a3a538a..53ccef4c12 100644 --- a/src/lyxtextclass.h +++ b/src/lyxtextclass.h @@ -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_; -- 2.39.2