move floatlist to textclass

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5124 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2002-08-27 15:51:19 +00:00
parent 39d24aa20b
commit a0d71b53fe
18 changed files with 137 additions and 59 deletions

View File

@ -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

View File

@ -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;

View File

@ -1,3 +1,22 @@
2002-08-27 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* 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 <poenitz@gmx.net>

View File

@ -104,6 +104,3 @@ FloatList::const_iterator FloatList::operator[](string const & t) const
return list.find(t);
}
// The global floatlist
FloatList floatList;

View File

@ -49,7 +49,4 @@ private:
List list;
};
///
extern FloatList floatList;
#endif

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

@ -1,3 +1,7 @@
2002-08-27 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* ControlFloat.C (applyParamsToInset): wide() now has two arguments
2002-08-23 Rob Lahaye <lahaye@snu.ac.kr>
* ControlGraphics.C: make rotationOrigin's default ("leftBaseline") the

View File

@ -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);
}

View File

@ -1,3 +1,14 @@
2002-08-27 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* 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 <larsbj@birdstep.com>
* insetoptarg.h: add std:: qualifier.

View File

@ -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<InsetFloat *>(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...
// ...

View File

@ -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 += "*";

View File

@ -63,7 +63,7 @@ public:
///
string const & placement() const;
///
void wide(bool w);
void wide(bool w, BufferParams const &);
///
bool wide() const;
///

View File

@ -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();

View File

@ -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<LyXLayout>(new LyXLayout(lay)));
layoutlist_.push_back(boost::shared_ptr<LyXLayout>(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();
}

View File

@ -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;

View File

@ -1351,7 +1351,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
if (isOK) {
Floating const & fl
= floatList.getType(static_cast<InsetFloat*>(in)->type());
= textclass.floats().getType(static_cast<InsetFloat*>(in)->type());
buf->counters().step(fl.name());