From a0d71b53fea6dfb12489f937de0eb7218b0d20ea Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 27 Aug 2002 15:51:19 +0000 Subject: [PATCH] move floatlist to textclass git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5124 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/POTFILES.in | 1 + src/BufferView_pimpl.C | 2 +- src/ChangeLog | 19 +++++++++++++ src/FloatList.C | 3 -- src/FloatList.h | 3 -- src/LaTeXFeatures.C | 6 ++-- src/MenuBackend.C | 34 ++++++++++++++++------ src/factory.C | 10 +++---- src/frontends/controllers/ChangeLog | 4 +++ src/frontends/controllers/ControlFloat.C | 3 +- src/insets/ChangeLog | 11 ++++++++ src/insets/insetcaption.C | 5 +++- src/insets/insetfloat.C | 20 +++++++------ src/insets/insetfloat.h | 2 +- src/insets/insetfloatlist.C | 20 +++++++------ src/lyxtextclass.C | 36 ++++++++++++++++-------- src/lyxtextclass.h | 15 ++++++++-- src/text2.C | 2 +- 18 files changed, 137 insertions(+), 59 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 0736ed59c6..ca6ca71010 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -8,6 +8,7 @@ src/converter.C src/CutAndPaste.C src/debug.C src/exporter.C +src/ext_l10n.h src/FloatList.C src/frontends/controllers/biblio.C src/frontends/controllers/ButtonController.h diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 0579df09eb..737d6aaea2 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1725,7 +1725,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) break; case LFUN_FLOAT_LIST: - if (floatList.typeExist(ev.argument)) { + if (tclass.floats().typeExist(ev.argument)) { Inset * inset = new InsetFloatList(ev.argument); if (!insertInset(inset, tclass.defaultLayoutName())) delete inset; diff --git a/src/ChangeLog b/src/ChangeLog index 0d6883f369..415aad0a8d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2002-08-27 Jean-Marc Lasgouttes + + * factory.C (createInset): use LyXTextClass::floats + + * MenuBackend.C (expandFloatListInsert): + (expandFloatInsert): + (expandToc): + + * text2.C (setCounter): + + * LaTeXFeatures.C (useFloat): + (getFloatDefinitions): + + * BufferView_pimpl.C (dispatch): use LyXTextClass::floats() + + * lyxtextclass.[Ch]: rename layoutlist to layoutlist_; add + floatlist_, with accessor floats(). + + * FloatList.h: remove global FloatList 2002-08-26 André Pönitz diff --git a/src/FloatList.C b/src/FloatList.C index fd724fdb18..932eda5e86 100644 --- a/src/FloatList.C +++ b/src/FloatList.C @@ -104,6 +104,3 @@ FloatList::const_iterator FloatList::operator[](string const & t) const return list.find(t); } - -// The global floatlist -FloatList floatList; diff --git a/src/FloatList.h b/src/FloatList.h index 42aca7bc29..150399dc37 100644 --- a/src/FloatList.h +++ b/src/FloatList.h @@ -49,7 +49,4 @@ private: List list; }; -/// -extern FloatList floatList; - #endif diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index 143bbdfa38..7174eb91c8 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -110,7 +110,7 @@ void LaTeXFeatures::useFloat(string const & name) // We only need float.sty if we use non builtin floats, or if we // use the "H" modifier. This includes modified table and // figure floats. (Lgb) - Floating const & fl = floatList.getType(name); + Floating const & fl = params.getLyXTextClass().floats().getType(name); if (!fl.type().empty() && !fl.builtin()) { require("float"); } @@ -425,6 +425,8 @@ BufferParams const & LaTeXFeatures::bufferParams() const void LaTeXFeatures::getFloatDefinitions(ostream & os) const { + FloatList const & floats = params.getLyXTextClass().floats(); + // Here we will output the code to create the needed float styles. // We will try to do this as minimal as possible. // \floatstyle{ruled} @@ -434,7 +436,7 @@ void LaTeXFeatures::getFloatDefinitions(ostream & os) const UsedFloats::const_iterator end = usedFloats.end(); // ostringstream floats; for (; cit != end; ++cit) { - Floating const & fl = floatList.getType((*cit)); + Floating const & fl = floats.getType((*cit)); // For builtin floats we do nothing. if (fl.builtin()) continue; diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 30eadba0b2..055924da53 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -24,6 +24,7 @@ #include "lastfiles.h" #include "lyx_main.h" // for lastfiles #include "bufferlist.h" +#include "buffer.h" #include "converter.h" #include "exporter.h" #include "importer.h" @@ -386,10 +387,17 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf) } -void expandFloatListInsert(Menu & tomenu) +void expandFloatListInsert(Menu & tomenu, Buffer const * buf) { - FloatList::const_iterator cit = floatList.begin(); - FloatList::const_iterator end = floatList.end(); + if (!buf) { + tomenu.add(MenuItem(MenuItem::Command, + _("No Documents Open!"), LFUN_NOACTION)); + return; + } + + FloatList const & floats = buf->params.getLyXTextClass().floats(); + FloatList::const_iterator cit = floats.begin(); + FloatList::const_iterator end = floats.end(); for (; cit != end; ++cit) { int const action = lyxaction .getPseudoAction(LFUN_FLOAT_LIST, cit->second.type()); @@ -400,10 +408,17 @@ void expandFloatListInsert(Menu & tomenu) } -void expandFloatInsert(Menu & tomenu) +void expandFloatInsert(Menu & tomenu, Buffer const * buf) { - FloatList::const_iterator cit = floatList.begin(); - FloatList::const_iterator end = floatList.end(); + if (!buf) { + tomenu.add(MenuItem(MenuItem::Command, + _("No Documents Open!"), LFUN_NOACTION)); + return; + } + + FloatList const & floats = buf->params.getLyXTextClass().floats(); + FloatList::const_iterator cit = floats.begin(); + FloatList::const_iterator end = floats.end(); for (; cit != end; ++cit) { // normal float int const action = @@ -465,6 +480,7 @@ void expandToc2(Menu & tomenu, toc::Toc const & toc_list, void expandToc(Menu & tomenu, Buffer const * buf) { + FloatList const & floats = buf->params.getLyXTextClass().floats(); toc::TocList toc_list = toc::getTocList(buf); toc::TocList::const_iterator cit = toc_list.begin(); toc::TocList::const_iterator end = toc_list.end(); @@ -482,7 +498,7 @@ void expandToc(Menu & tomenu, Buffer const * buf) label, ccit->action())); } MenuItem item(MenuItem::Submenu, - floatList[cit->first]->second.name()); + floats[cit->first]->second.name()); item.submenu(menu); tomenu.add(item); } @@ -523,11 +539,11 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu, break; case MenuItem::FloatListInsert: - expandFloatListInsert(tomenu); + expandFloatListInsert(tomenu, buf); break; case MenuItem::FloatInsert: - expandFloatInsert(tomenu); + expandFloatInsert(tomenu, buf); break; case MenuItem::Toc: diff --git a/src/factory.C b/src/factory.C index 6decdacca2..54d08fa2ea 100644 --- a/src/factory.C +++ b/src/factory.C @@ -46,17 +46,17 @@ Inset * createInset(FuncRequest const & cmd) return new InsetOptArg(params); case LFUN_INSET_FLOAT: - // check if the float type exist - if (floatList.typeExist(cmd.argument)) + // check if the float type exists + if (params.getLyXTextClass().floats().typeExist(cmd.argument)) return new InsetFloat(params, cmd.argument); lyxerr << "Non-existent float type: " << cmd.argument << endl; return 0; case LFUN_INSET_WIDE_FLOAT: - // check if the float type exist - if (floatList.typeExist(cmd.argument)) { + // check if the float type exists + if (params.getLyXTextClass().floats().typeExist(cmd.argument)) { InsetFloat * p = new InsetFloat(params, cmd.argument); - p->wide(true); + p->wide(true, params); } lyxerr << "Non-existent float type: " << cmd.argument << endl; return 0; diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 3bfff59d44..c08dc43e83 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2002-08-27 Jean-Marc Lasgouttes + + * ControlFloat.C (applyParamsToInset): wide() now has two arguments + 2002-08-23 Rob Lahaye * ControlGraphics.C: make rotationOrigin's default ("leftBaseline") the diff --git a/src/frontends/controllers/ControlFloat.C b/src/frontends/controllers/ControlFloat.C index 2eb6cc47d5..40d34b295c 100644 --- a/src/frontends/controllers/ControlFloat.C +++ b/src/frontends/controllers/ControlFloat.C @@ -17,6 +17,7 @@ #include "ControlFloat.h" #include "BufferView.h" +#include "buffer.h" ControlFloat::ControlFloat(LyXView & lv, Dialogs & d) @@ -27,7 +28,7 @@ ControlFloat::ControlFloat(LyXView & lv, Dialogs & d) void ControlFloat::applyParamsToInset() { inset()->placement(params().placement); - inset()->wide(params().wide); + inset()->wide(params().wide, bufferview()->buffer()->params); bufferview()->updateInset(inset(), true); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 7d6c7c7043..e32525a51e 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,14 @@ +2002-08-27 Jean-Marc Lasgouttes + + * insetfloat.C (wide): add BufferParams parameter + + * insetfloatlist.C (read): + (latex): + (getScreenLabel): + * insetfloat.C (latex): + (floatname): + * insetcaption.C (draw): use LyXTextClass::floats() + 2002-08-26 Lars Gullik Bjønnes * insetoptarg.h: add std:: qualifier. diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index 494d69bd01..78a883bce5 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -18,6 +18,7 @@ #include "frontends/Painter.h" #include "frontends/font_metrics.h" #include "BufferView.h" +#include "buffer.h" #include "FloatList.h" #include "insets/insetfloat.h" #include "debug.h" @@ -79,7 +80,9 @@ void InsetCaption::draw(BufferView * bv, LyXFont const & f, Inset * i1 = owner(); Inset * i2 = i1 ? i1->owner() : 0; string const type = static_cast(i2)->type(); - string const fl = i2 ? floatList.getType(type).name() : N_("Float"); + FloatList const & floats = + bv->buffer()->params.getLyXTextClass().floats(); + string const fl = i2 ? floats.getType(type).name() : N_("Float"); // Discover the number... // ... diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 2bfb0aa927..328e356679 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -106,10 +106,11 @@ namespace { // of the float (JMarc) string const caplayout("Caption"); -string floatname(string const & type) +string floatname(string const & type, BufferParams const & bp) { - FloatList::const_iterator it = floatList[type]; - if (it == floatList.end()) + FloatList const & floats = bp.getLyXTextClass().floats(); + FloatList::const_iterator it = floats[type]; + if (it == floats.end()) return type; return _(it->second.name()); @@ -122,7 +123,7 @@ InsetFloat::InsetFloat(BufferParams const & bp, string const & type) : InsetCollapsable(bp), wide_(false) { string lab(_("float: ")); - lab += floatname(type); + lab += floatname(type, bp); setLabel(lab); LyXFont font(LyXFont::ALL_SANE); font.decSize(); @@ -185,9 +186,9 @@ void InsetFloat::read(Buffer const * buf, LyXLex & lex) lex.next(); string const tmptoken = lex.getString(); if (tmptoken == "true") - wide(true); + wide(true, buf->params); else - wide(false); + wide(false, buf->params); } else { lyxerr << "InsetFloat::Read:: Missing wide!" << endl; @@ -225,6 +226,7 @@ string const InsetFloat::editMessage() const int InsetFloat::latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const { + FloatList const & floats = buf->params.getLyXTextClass().floats(); string const tmptype = (wide_ ? floatType_ + "*" : floatType_); // Figure out the float placement to use. // From lowest to highest: @@ -233,7 +235,7 @@ int InsetFloat::latex(Buffer const * buf, // - specific float placement string placement; string const buf_placement = buf->params.float_placement; - string const def_placement = floatList.defaultPlacement(floatType_); + string const def_placement = floats.defaultPlacement(floatType_); if (!floatPlacement_.empty() && floatPlacement_ != def_placement) { placement = floatPlacement_; @@ -313,12 +315,12 @@ string const & InsetFloat::placement() const } -void InsetFloat::wide(bool w) +void InsetFloat::wide(bool w, BufferParams const & bp) { wide_ = w; string lab(_("float:")); - lab += floatname(floatType_); + lab += floatname(floatType_, bp); if (wide_) lab += "*"; diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index 2dcc45f9ef..792d9f7872 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -63,7 +63,7 @@ public: /// string const & placement() const; /// - void wide(bool w); + void wide(bool w, BufferParams const &); /// bool wide() const; /// diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index 33251b1350..6562e74bd2 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -11,6 +11,7 @@ #include "frontends/Dialogs.h" #include "frontends/LyXView.h" #include "BufferView.h" +#include "buffer.h" #include "toc.h" #include "gettext.h" #include "debug.h" @@ -33,10 +34,11 @@ InsetFloatList::InsetFloatList(string const & type) } -string const InsetFloatList::getScreenLabel(Buffer const *) const +string const InsetFloatList::getScreenLabel(Buffer const * buf) const { - FloatList::const_iterator it = floatList[getCmdName()]; - if (it != floatList.end()) + FloatList const & floats = buf->params.getLyXTextClass().floats(); + FloatList::const_iterator it = floats[getCmdName()]; + if (it != floats.end()) return _(it->second.listName()); else return _("ERROR: Nonexistent float type!"); @@ -55,14 +57,15 @@ void InsetFloatList::write(Buffer const *, ostream & os) const } -void InsetFloatList::read(Buffer const *, LyXLex & lex) +void InsetFloatList::read(Buffer const * buf, LyXLex & lex) { + FloatList const & floats = buf->params.getLyXTextClass().floats(); string token; if (lex.eatLine()) { setCmdName(lex.getString()); lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl; - if (!floatList.typeExist(getCmdName())) + if (!floats.typeExist(getCmdName())) lex.printError("InsetFloatList: Unknown float type: `$$Token'"); } else lex.printError("InsetFloatList: Parse error: `$$Token'"); @@ -91,11 +94,12 @@ void InsetFloatList::edit(BufferView * bv, bool) } -int InsetFloatList::latex(Buffer const *, ostream & os, bool, bool) const +int InsetFloatList::latex(Buffer const * buf, ostream & os, bool, bool) const { - FloatList::const_iterator cit = floatList[getCmdName()]; + FloatList const & floats = buf->params.getLyXTextClass().floats(); + FloatList::const_iterator cit = floats[getCmdName()]; - if (cit != floatList.end()) { + if (cit != floats.end()) { if (cit->second.builtin()) { // Only two different types allowed here: string const type = cit->second.type(); diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index a86ef7e28d..63c6f92bb8 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -204,7 +204,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) LyXLayout lay; lay.setName(name); if (!(error = do_readStyle(lexrc, lay))) - layoutlist.push_back(boost::shared_ptr(new LyXLayout(lay))); + layoutlist_.push_back(boost::shared_ptr(new LyXLayout(lay))); if (defaultlayout_.empty()) { // We do not have a default // layout yet, so we choose @@ -517,9 +517,9 @@ bool LyXTextClass::hasLayout(string const & n) const { string const name = (n.empty() ? defaultLayoutName() : n); - return find_if(layoutlist.begin(), layoutlist.end(), + return find_if(layoutlist_.begin(), layoutlist_.end(), compare_name(name)) - != layoutlist.end(); + != layoutlist_.end(); } @@ -536,14 +536,14 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const static LayoutList::difference_type lastLayoutIndex; if (name == lastLayoutName) - return layoutlist[lastLayoutIndex]; + return layoutlist_[lastLayoutIndex]; LayoutList::const_iterator cit = - find_if(layoutlist.begin(), - layoutlist.end(), + find_if(layoutlist_.begin(), + layoutlist_.end(), compare_name(name)); - if (cit == layoutlist.end()) { + if (cit == layoutlist_.end()) { lyxerr << "We failed to find the layout '" << name << "' in the layout list. You MUST investigate!" << endl; @@ -553,7 +553,7 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const } lastLayoutName = name; - lastLayoutIndex = std::distance(layoutlist.begin(), cit); + lastLayoutIndex = std::distance(layoutlist_.begin(), cit); return (*cit); } @@ -565,12 +565,12 @@ bool LyXTextClass::delete_layout(string const & name) return false; LayoutList::iterator it = - remove_if(layoutlist.begin(), layoutlist.end(), + remove_if(layoutlist_.begin(), layoutlist_.end(), compare_name(name)); - LayoutList::iterator end = layoutlist.end(); + LayoutList::iterator end = layoutlist_.end(); bool const ret = (it != end); - layoutlist.erase(it, end); + layoutlist_.erase(it, end); return ret; } @@ -597,6 +597,18 @@ bool LyXTextClass::load() const } +FloatList & LyXTextClass::floats() +{ + return floatlist_; +} + + +FloatList const & LyXTextClass::floats() const +{ + return floatlist_; +} + + string const LyXTextClass::defaultLayoutName() const { // This really should come from the actual layout... (Lgb) @@ -703,7 +715,7 @@ int LyXTextClass::maxcounter() const int LyXTextClass::size() const { - return layoutlist.size(); + return layoutlist_.size(); } diff --git a/src/lyxtextclass.h b/src/lyxtextclass.h index 1a8a6e8633..2d1021f792 100644 --- a/src/lyxtextclass.h +++ b/src/lyxtextclass.h @@ -19,6 +19,7 @@ #include "lyxlayout.h" #include "LString.h" #include "lyxlayout_ptr_fwd.h" +#include "FloatList.h" #include "support/types.h" @@ -40,9 +41,9 @@ public: string const & = string()); /// - const_iterator begin() const { return layoutlist.begin(); } + const_iterator begin() const { return layoutlist_.begin(); } /// - const_iterator end() const { return layoutlist.end(); } + const_iterator end() const { return layoutlist_.end(); } /// bool Read(string const & filename, bool merge = false); @@ -61,6 +62,11 @@ public: /// Sees to that the textclass structure has been loaded bool load() const; + /// the list of floats defined in the class + FloatList & floats(); + /// the list of floats defined in the class + FloatList const & floats() const; + /// string const defaultLayoutName() const; /// @@ -179,7 +185,10 @@ private: int maxcounter_; // add approp. signedness /// - LayoutList layoutlist; + LayoutList layoutlist_; + + /// + FloatList floatlist_; /// Has this layout file been loaded yet? mutable bool loaded; diff --git a/src/text2.C b/src/text2.C index 91097ed278..228a5039c6 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1351,7 +1351,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const if (isOK) { Floating const & fl - = floatList.getType(static_cast(in)->type()); + = textclass.floats().getType(static_cast(in)->type()); buf->counters().step(fl.name()); -- 2.39.2