move counters to the layout files

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5218 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2002-09-06 14:48:01 +00:00
parent 1c090286fe
commit 2b834e310b
12 changed files with 236 additions and 95 deletions

View File

@ -1,3 +1,9 @@
2002-09-06 Lars Gullik Bjønnes <larsbj@gullik.net>
* layouts/stdcounters.inc: new file
* layouts/stdclass.inc: include standard counters
2002-09-05 Angus Leeming <leeming@lyx.org>
* scripts/lyxpreview2bitmap.sh: augment the preliminary blurb, as

View File

@ -43,4 +43,5 @@ Input stdstruct.inc
Input lyxmacros.inc
Input stdlayouts.inc
Input stdfloats.inc
Input stdcounters.inc
Input obsolete.inc

View File

@ -0,0 +1,73 @@
# Author : Lars Gullik Bjønnes <larsbj@lyx.org>
# This include file contains all the counters that are defined as standard
# in most LyX layouts.
Counter
Name part
End
Counter
Name chapter
End
Counter
Name section
Within chapter
End
Counter
Name subsection
Within section
End
Counter
Name subsubsection
Within subsection
End
Counter
Name paragraph
Within subsubsection
End
Counter
Name subparagraph
Within paragraph
End
Counter
Name enumi
End
Counter
Name enumii
Within enumi
End
Counter
Name enumiii
Within enumii
End
Counter
Name enumiv
Within enumiii
End
Counter
Name bibitem
End
Counter
Name figure
End
Counter
Name table
End
Counter
Name algorithm
End

View File

@ -1,23 +1,50 @@
2002-09-06 Lars Gullik Bjønnes <larsbj@gullik.net>
* text2.C (init): update counters after init
(insertParagraph): no need to set counter on idividual paragraphs.
(setCounter): access the counters object in the textclass object
on in the buffer object.
(updateCounters): ditto
* lyxtextclass.C: include counters.h, add variable ctrs_ as
shared_ptr<Counters> to avoid loading counters.h in all
compilation units.
(LyXTextClass): initialize ctrs_
(TextClassTags): add TC_COUNTER, and ...
(Read): use it here.
(CounterTags): new tags
(readCounter): new function
(counters): new funtion
(defaultLayoutName): return a const reference
* counters.C (Counters): remove contructor
(newCounter): remove a couple of unneeded statements.
(newCounter): simplify a bit.
(numberLabel): some small formatting changes.
* buffer.[Ch]: remove all traces of counters, move the Counters
object to the LyXTextClass.
2002-09-06 Alain Castera <castera@in2p3.fr>
* tabular.C: uses \tabularnewline; uses >{...} construct from array
* tabular.C: uses \tabularnewline; uses >{...} construct from array
package to set the horizontal alignment on fixed width columns.
* lyx_sty.C:
* lyx_sty.C:
* lyx_sty.h: added tabularnewline macro def.
* LaTeXFeatures.C: added NeedTabularnewline macro feature
* LaTeXFeatures.C: added NeedTabularnewline macro feature
2002-09-06 John Levon <levon@movementarian.org>
* LyXAction.C: tooltips for sub/superscript
* MenuBackend.C: a bit more verbose
* lyxfunc.C: tiny clean
* undo_funcs.C: document undo_frozen
* undo_funcs.C: document undo_frozen
2002-09-05 Lars Gullik Bjønnes <larsbj@gullik.net>
* counters.C (Counters): add missing algorithm counter.
@ -37,7 +64,7 @@
2002-09-04 Lars Gullik Bjønnes <larsbj@gullik.net>
* lyxtextclass.C (TextClassTags): add TC_FLOAT
* lyxtextclass.C (TextClassTags): add TC_FLOAT
(Read): add float->TC_FLOAT to textclassTags
(Read): and handle it in the switch
(readFloat): new function

View File

@ -20,7 +20,6 @@
#include "buffer.h"
#include "bufferlist.h"
#include "counters.h"
#include "LyXAction.h"
#include "lyxrc.h"
#include "lyxlex.h"
@ -154,7 +153,7 @@ const int LYX_FORMAT = 221;
Buffer::Buffer(string const & file, bool ronly)
: niceFile(true), lyx_clean(true), bak_clean(true),
unnamed(false), dep_clean(0), read_only(ronly),
filename_(file), users(0), ctrs(new Counters)
filename_(file), users(0)
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
filepath_ = OnlyPath(file);
@ -1171,7 +1170,7 @@ bool Buffer::readFile(LyXLex & lex, Paragraph * par)
"Use LyX 0.10.x to read this!"));
return false;
} else {
string command =
string command =
LibFileSearch("lyx2lyx", "lyx2lyx");
if (command.empty()) {
Alert::alert(_("ERROR!"),
@ -3221,7 +3220,7 @@ vector<pair<string, string> > const Buffer::getBibkeyList() const
if (!keys.empty())
return keys;
// Might be either using bibtex or a child has bibliography
for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it) {
@ -3340,12 +3339,6 @@ bool Buffer::isMultiLingual()
}
Counters & Buffer::counters() const
{
return *ctrs.get();
}
void Buffer::inset_iterator::setParagraph()
{
while (pit != pend) {

View File

@ -27,11 +27,9 @@
#include "ParagraphList.h"
#include "paragraph.h"
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
class BufferView;
class Counters;
class LyXRC;
class TeXErrors;
class LaTeXFeatures;
@ -311,9 +309,6 @@ public:
/// Used when typesetting to place errorboxes.
TexRow texrow;
/// Buffer-wide counter array
Counters & counters() const;
private:
/// is save needed
mutable bool lyx_clean;
@ -346,10 +341,6 @@ private:
of the buffers in the list of users to do a #updateLayoutChoice#.
*/
BufferView * users;
/// The pointer is const although its contents may not be
boost::scoped_ptr<Counters> const ctrs;
public:
///
class inset_iterator {

View File

@ -17,6 +17,7 @@
#include "counters.h"
#include "debug.h"
#include "support/lstrings.h"
#include "support/LAssert.h"
@ -59,45 +60,19 @@ void Counter::reset()
value_ = 0;
}
string Counter::master() const
{
return master_;
}
void Counter::setMaster(string const & m)
{
master_ = m;
}
Counters::Counters()
{
// Ehh, should this take a textclass arg?
// Sectioning counters:
newCounter("part");
newCounter("chapter");
newCounter("section", "chapter");
newCounter("subsection", "section");
newCounter("subsubsection", "subsection");
newCounter("paragraph", "subsubsection");
newCounter("subparagraph", "paragraph");
// Enumeration counters:
newCounter("enumi");
newCounter("enumii", "enumi");
newCounter("enumiii", "enumii");
newCounter("enumiv", "enumiii");
// Biblio:
newCounter("bibitem");
// Float counters:
newCounter("figure");
newCounter("table");
newCounter("algorithm");
}
void Counters::newCounter(string const & newc)
{
@ -109,8 +84,6 @@ void Counters::newCounter(string const & newc)
return;
}
counterList[newc];
cit = counterList.find(newc);
cit->second.setMaster("");
}
@ -131,9 +104,7 @@ void Counters::newCounter(string const & newc, string const & masterc)
return;
}
counterList[newc];
cit = counterList.find(newc);
cit->second.setMaster(masterc);
counterList[newc].setMaster(masterc);
}
@ -343,9 +314,11 @@ string Counters::numberLabel(string const & ctr,
}
} else if (numbertype == "enumeration") {
ostringstream ei, eii, eiii, eiv;
//string ei, eiii, eiv;
//char eii;
ostringstream ei;
ostringstream eii;
ostringstream eiii;
ostringstream eiv;
if (langtype == "hebrew") {
ei << '.' << value("enumi");
eii << '(' << hebrewCounter(value("enumii")) << ')';

View File

@ -55,10 +55,6 @@ private:
/// Every instantiation is an array of counters of type Counter.
class Counters {
public:
///
Counters();
///
//~Counters();
/// Add a new counter to array.
void newCounter(string const & newc);
/// Add new counter having oldc as its master.

View File

@ -18,6 +18,7 @@
#include "lyxtextclass.h"
#include "debug.h"
#include "lyxlex.h"
#include "counters.h"
#include "support/lstrings.h"
#include "support/LAssert.h"
@ -48,7 +49,7 @@ struct compare_name {
LyXTextClass::LyXTextClass(string const & fn, string const & cln,
string const & desc)
: name_(fn), latexname_(cln), description_(desc)
: name_(fn), latexname_(cln), description_(desc), ctrs_(new Counters)
{
outputType_ = LATEX;
columns_ = 1;
@ -108,7 +109,8 @@ enum TextClassTags {
TC_PROVIDESURL,
TC_LEFTMARGIN,
TC_RIGHTMARGIN,
TC_FLOAT
TC_FLOAT,
TC_COUNTER
};
@ -118,6 +120,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
keyword_item textClassTags[] = {
{ "classoptions", TC_CLASSOPTIONS },
{ "columns", TC_COLUMNS },
{ "counter", TC_COUNTER },
{ "defaultfont", TC_DEFAULTFONT },
{ "defaultstyle", TC_DEFAULTSTYLE },
{ "float", TC_FLOAT },
@ -148,7 +151,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
<< MakeDisplayPath(filename)
<< endl;
LyXLex lexrc(textClassTags, TC_FLOAT);
LyXLex lexrc(textClassTags, TC_COUNTER);
bool error = false;
lexrc.setFile(filename);
@ -327,6 +330,9 @@ bool LyXTextClass::Read(string const & filename, bool merge)
case TC_FLOAT:
readFloat(lexrc);
break;
case TC_COUNTER:
readCounter(lexrc);
break;
}
}
@ -600,6 +606,64 @@ void LyXTextClass::readFloat(LyXLex & lexrc)
}
enum CounterTags {
CT_NAME = 1,
CT_WITHIN,
CT_END
};
void LyXTextClass::readCounter(LyXLex & lexrc)
{
keyword_item counterTags[] = {
{ "end", CT_END },
{ "name", CT_NAME },
{ "within", CT_WITHIN }
};
lexrc.pushTable(counterTags, CT_END);
string name;
string within;
bool getout = false;
while (!getout && lexrc.isOK()) {
int le = lexrc.lex();
switch (le) {
case LyXLex::LEX_UNDEF:
lexrc.printError("Unknown ClassOption tag `$$Token'");
continue;
default: break;
}
switch (static_cast<CounterTags>(le)) {
case CT_NAME:
lexrc.next();
name = lexrc.getString();
break;
case CT_WITHIN:
lexrc.next();
within = lexrc.getString();
if (within == "none")
within.erase();
break;
case CT_END:
getout = true;
break;
}
}
// Here if have a full float if getout == true
if (getout) {
if (within.empty()) {
ctrs_->newCounter(name);
} else {
ctrs_->newCounter(name, within);
}
}
lexrc.popTable();
}
LyXFont const & LyXTextClass::defaultfont() const
{
return defaultfont_;
@ -714,7 +778,13 @@ FloatList const & LyXTextClass::floats() const
}
string const LyXTextClass::defaultLayoutName() const
Counters & LyXTextClass::counters() const
{
return *ctrs_.get();
}
string const & LyXTextClass::defaultLayoutName() const
{
// This really should come from the actual layout... (Lgb)
return defaultlayout_;

View File

@ -23,9 +23,12 @@
#include "support/types.h"
#include <boost/shared_ptr.hpp>
#include <vector>
class LyXLex;
class Counters;
///
class LyXTextClass {
@ -36,9 +39,9 @@ public:
typedef LayoutList::const_iterator const_iterator;
///
explicit
LyXTextClass (string const & = string(),
string const & = string(),
string const & = string());
LyXTextClass(string const & = string(),
string const & = string(),
string const & = string());
///
const_iterator begin() const { return layoutlist_.begin(); }
@ -56,6 +59,8 @@ public:
///
void readFloat(LyXLex &);
///
void readCounter(LyXLex &);
///
bool hasLayout(string const & name) const;
///
@ -68,9 +73,10 @@ public:
FloatList & floats();
/// the list of floats defined in the class
FloatList const & floats() const;
/// The Counters present in this textclass.
Counters & counters() const;
///
string const defaultLayoutName() const;
string const & defaultLayoutName() const;
///
LyXLayout_ptr const & defaultLayout() const;
///
@ -192,6 +198,9 @@ private:
///
FloatList floatlist_;
///
boost::shared_ptr<Counters> ctrs_;
/// Has this layout file been loaded yet?
mutable bool loaded;
};

View File

@ -20,7 +20,6 @@
#include "debug.h"
#include "lyxlex.h"
#include "gettext.h"
#include "frontends/Alert.h"
#include "support/lyxfunctional.h"

View File

@ -98,6 +98,8 @@ void LyXText::init(BufferView * bview, bool reinit)
}
setCursorIntern(bview, firstrow->par(), 0);
selection.cursor = cursor;
updateCounters(bview);
}
@ -383,9 +385,6 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
// insert a new row, starting at position 0
insertRow(row, par, 0);
// set the counters
setCounter(bview->buffer(), par);
// and now append the whole paragraph behind the new row
if (!row) {
firstrow->height(0);
@ -1218,7 +1217,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
par->params().appendix(par->previous()->params().appendix());
if (!par->params().appendix() && par->params().startOfAppendix()) {
par->params().appendix(true);
buf->counters().reset();
textclass.counters().reset();
}
par->enumdepth = par->previous()->enumdepth;
par->itemdepth = par->previous()->itemdepth;
@ -1272,7 +1271,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
if (i >= 0 && i <= buf->params.secnumdepth) {
buf->counters().step(layout->latexname());
textclass.counters().step(layout->latexname());
// Is there a label? Useful for Chapter layout
if (!par->params().appendix()) {
@ -1299,7 +1298,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
langtype = "latin";
}
s << buf->counters()
s << textclass.counters()
.numberLabel(layout->latexname(),
numbertype, langtype, head);
@ -1308,9 +1307,9 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
// possible...
// reset enum counters
buf->counters().reset("enum");
textclass.counters().reset("enum");
} else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
buf->counters().reset("enum");
textclass.counters().reset("enum");
} else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
// FIXME
// Yes I know this is a really, really! bad solution
@ -1333,16 +1332,16 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
break;
}
buf->counters().step(enumcounter);
textclass.counters().step(enumcounter);
s << buf->counters()
s << textclass.counters()
.numberLabel(enumcounter,
"enumeration", langtype);
par->params().labelString(s.str().c_str());
}
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
buf->counters().step("bibitem");
int number = buf->counters().value("bibitem");
textclass.counters().step("bibitem");
int number = textclass.counters().value("bibitem");
if (!par->bibkey) {
InsetCommandParams p("bibitem");
par->bibkey = new InsetBibKey(p);
@ -1374,7 +1373,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
Floating const & fl
= textclass.floats().getType(static_cast<InsetFloat*>(in)->type());
buf->counters().step(fl.type());
textclass.counters().step(fl.type());
// Doesn't work... yet.
ostringstream o;
@ -1390,17 +1389,19 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
}
par->params().labelString(s);
// reset the enumeration counter. They are always resetted
// reset the enumeration counter. They are always reset
// when there is any other layout between
// Just fall-through between the cases so that all
// enum counters deeper than enumdepth is also reset.
switch (par->enumdepth) {
case 0:
buf->counters().reset("enumi");
textclass.counters().reset("enumi");
case 1:
buf->counters().reset("enumii");
textclass.counters().reset("enumii");
case 2:
buf->counters().reset("enumiii");
textclass.counters().reset("enumiii");
case 3:
buf->counters().reset("enumiv");
textclass.counters().reset("enumiv");
}
}
}
@ -1415,7 +1416,9 @@ void LyXText::updateCounters(BufferView * bview) const
Row * row = firstrow;
par = row->par();
bview->buffer()->counters().reset();
// CHECK if this is really needed. (Lgb)
bview->buffer()->params.getLyXTextClass().counters().reset();
while (par) {
while (row->par() != par)
row = row->next();