The counters labelstring patch. Part 2: Use the new code.

* src/Paragraph.cpp (expandLabel): if the labelstring is empty,
	use \thecounter instead; when processing @layout@ tokens, pass the
	process_appendix boolean.

	* src/buffer_funcs.cpp (setLabel):
	* src/insets/InsetFoot.cpp (updateLabels): 
	* src/insets/InsetCaption.cpp (updateLabels): use
	Counters::theCounter.

	* src/insets/InsetBibitem.cpp: remove the ad-hoc numbering code
	and replace it with a proper updateLabels-based solution.

	* src/insets/InsetCommands.cpp (refresh): new method.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19603 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2007-08-16 11:12:56 +00:00
parent 88177a89cb
commit f756c02329
7 changed files with 41 additions and 35 deletions

View File

@ -1663,6 +1663,10 @@ docstring Paragraph::expandLabel(Layout_ptr const & layout,
else
fmt = translateIfPossible(layout->labelstring(), bparams);
if (fmt.empty() && layout->labeltype == LABEL_COUNTER
&& !layout->counter.empty())
fmt = "\\the" + layout->counter;
// handle 'inherited level parts' in 'fmt',
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
size_t const i = fmt.find('@', 0);
@ -1670,8 +1674,10 @@ docstring Paragraph::expandLabel(Layout_ptr const & layout,
size_t const j = fmt.find('@', i + 1);
if (j != docstring::npos) {
docstring parent(fmt, i + 1, j - i - 1);
docstring label = expandLabel(tclass[parent], bparams);
fmt = docstring(fmt, 0, i) + label + docstring(fmt, j + 1, docstring::npos);
docstring label = expandLabel(tclass[parent], bparams,
process_appendix);
fmt = docstring(fmt, 0, i) + label
+ docstring(fmt, j + 1, docstring::npos);
}
}

View File

@ -42,11 +42,8 @@
#include "frontends/alert.h"
#include "insets/InsetBibitem.h"
#include "insets/InsetCaption.h"
#include "insets/InsetInclude.h"
#include "insets/InsetTabular.h"
#include "support/convert.h"
#include "support/filetools.h"
#include "support/fs_extras.h"
#include "support/lyxlib.h"
@ -518,15 +515,6 @@ void setLabel(Buffer const & buf, ParIterator & it)
par.params().labelString(counters.counterLabel(
par.translateIfPossible(from_ascii(format), buf.params())));
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
counters.step(from_ascii("bibitem"));
int number = counters.value(from_ascii("bibitem"));
if (par.bibitem())
par.bibitem()->setCounter(number);
par.params().labelString(
par.translateIfPossible(layout->labelstring(), buf.params()));
// In biblio shouldn't be following counters but...
} else if (layout->labeltype == LABEL_SENSITIVE) {
string const & type = counters.current_float();
docstring full_label;
@ -538,7 +526,7 @@ void setLabel(Buffer const & buf, ParIterator & it)
counters.step(from_utf8(type));
full_label = bformat(from_ascii("%1$s %2$s:"),
name,
convert<docstring>(counters.value(from_utf8(type))));
counters.theCounter(from_utf8(type)));
} else
full_label = bformat(from_ascii("%1$s #:"), name);
}

View File

@ -12,9 +12,13 @@
#include "InsetBibitem.h"
#include "debug.h"
#include "Biblio.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Counters.h"
#include "DispatchResult.h"
#include "FuncRequest.h"
#include "Font.h"
@ -41,7 +45,7 @@ int InsetBibitem::key_counter = 0;
docstring const key_prefix = from_ascii("key-");
InsetBibitem::InsetBibitem(InsetCommandParams const & p)
: InsetCommand(p, "bibitem"), counter(1)
: InsetCommand(p, "bibitem")
{
if (getParam("key").empty())
setParam("key", key_prefix + convert<docstring>(++key_counter));
@ -51,7 +55,7 @@ InsetBibitem::InsetBibitem(InsetCommandParams const & p)
auto_ptr<Inset> InsetBibitem::doClone() const
{
auto_ptr<InsetBibitem> b(new InsetBibitem(params()));
b->setCounter(counter);
b->autolabel_ = autolabel_;
return auto_ptr<Inset>(b);
}
@ -80,12 +84,6 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
}
void InsetBibitem::setCounter(int c)
{
counter = c;
}
void InsetBibitem::read(Buffer const & buf, Lexer & lex)
{
InsetCommand::read(buf, lex);
@ -100,7 +98,7 @@ void InsetBibitem::read(Buffer const & buf, Lexer & lex)
docstring const InsetBibitem::getBibLabel() const
{
docstring const & label = getParam("label");
return label.empty() ? convert<docstring>(counter) : label;
return label.empty() ? autolabel_ : label;
}
@ -114,7 +112,7 @@ int InsetBibitem::plaintext(Buffer const &, odocstream & os,
OutputParams const &) const
{
odocstringstream oss;
oss << '[' << getCounter() << "] ";
oss << '[' << getBibLabel() << "] ";
docstring const str = oss.str();
os << str;
@ -199,4 +197,20 @@ void InsetBibitem::fillWithBibKeys(Buffer const & buf,
keys[key] = keyvalmap;
}
/// Update the counters of this inset and of its contents
void InsetBibitem::updateLabels(Buffer const &buf, ParIterator const & pit)
{
lyxerr << "update! " << to_utf8(getParam("key")) << std::endl;
Counters & counters = buf.params().getTextClass().counters();
docstring const bibitem = from_ascii("bibitem");
if (counters.hasCounter(bibitem) && getParam("label").empty()) {
counters.step(bibitem);
autolabel_ = counters.theCounter(bibitem);
} else
autolabel_ = from_ascii("??");
refresh();
}
} // namespace lyx

View File

@ -37,16 +37,14 @@ public:
///
Inset::Code lyxCode() const { return Inset::BIBITEM_CODE; }
///
void setCounter(int);
///
int getCounter() const { return counter; }
///
docstring const getBibLabel() const;
///
int plaintext(Buffer const &, odocstream &, OutputParams const &) const;
///
virtual void fillWithBibKeys(Buffer const &,
biblio::BibKeyList &, InsetIterator const &) const;
/// Update the counter of this inset
virtual void updateLabels(Buffer const &, ParIterator const &);
protected:
///
@ -54,8 +52,8 @@ protected:
private:
virtual std::auto_ptr<Inset> doClone() const;
///
int counter;
/// The label that is set by updateLabels
docstring autolabel_;
///
static int key_counter;
};

View File

@ -36,7 +36,6 @@
#include "frontends/Painter.h"
#include "support/lstrings.h"
#include "support/convert.h"
#include <sstream>
@ -306,7 +305,7 @@ void InsetCaption::updateLabels(Buffer const & buf, ParIterator const & it)
cnts.step(from_utf8(type));
full_label_ = bformat(from_ascii("%1$s %2$s:"),
name,
convert<docstring>(cnts.value(from_utf8(type))));
cnts.theCounter(from_utf8(type)));
} else
full_label_ = bformat(from_ascii("%1$s #:"), name);
}

View File

@ -68,6 +68,8 @@ protected:
p_.setContents(c);
}
public:
/// tell that the button label should be recomputed.
void refresh() { updateButtonLabel_ = true; }
///
void setParam(std::string const & name, docstring const & value)
{

View File

@ -23,7 +23,6 @@
#include "OutputParams.h"
#include "ParIterator.h"
#include "support/convert.h"
#include "support/std_ostream.h"
#include "support/lstrings.h"
@ -69,7 +68,7 @@ void InsetFoot::updateLabels(Buffer const & buf, ParIterator const & it)
//FIXME: the counter should format itself.
setLabel(support::bformat(from_ascii("%1$s %2$s"),
getLayout(buf.params()).labelstring,
convert<docstring>(cnts.value(foot))));
cnts.theCounter(foot)));
}
InsetCollapsable::updateLabels(buf, it);