mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 11:08:41 +00:00
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:
parent
88177a89cb
commit
f756c02329
@ -1663,6 +1663,10 @@ docstring Paragraph::expandLabel(Layout_ptr const & layout,
|
|||||||
else
|
else
|
||||||
fmt = translateIfPossible(layout->labelstring(), bparams);
|
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',
|
// handle 'inherited level parts' in 'fmt',
|
||||||
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
|
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
|
||||||
size_t const i = fmt.find('@', 0);
|
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);
|
size_t const j = fmt.find('@', i + 1);
|
||||||
if (j != docstring::npos) {
|
if (j != docstring::npos) {
|
||||||
docstring parent(fmt, i + 1, j - i - 1);
|
docstring parent(fmt, i + 1, j - i - 1);
|
||||||
docstring label = expandLabel(tclass[parent], bparams);
|
docstring label = expandLabel(tclass[parent], bparams,
|
||||||
fmt = docstring(fmt, 0, i) + label + docstring(fmt, j + 1, docstring::npos);
|
process_appendix);
|
||||||
|
fmt = docstring(fmt, 0, i) + label
|
||||||
|
+ docstring(fmt, j + 1, docstring::npos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,11 +42,8 @@
|
|||||||
#include "frontends/alert.h"
|
#include "frontends/alert.h"
|
||||||
|
|
||||||
#include "insets/InsetBibitem.h"
|
#include "insets/InsetBibitem.h"
|
||||||
#include "insets/InsetCaption.h"
|
|
||||||
#include "insets/InsetInclude.h"
|
#include "insets/InsetInclude.h"
|
||||||
#include "insets/InsetTabular.h"
|
|
||||||
|
|
||||||
#include "support/convert.h"
|
|
||||||
#include "support/filetools.h"
|
#include "support/filetools.h"
|
||||||
#include "support/fs_extras.h"
|
#include "support/fs_extras.h"
|
||||||
#include "support/lyxlib.h"
|
#include "support/lyxlib.h"
|
||||||
@ -518,15 +515,6 @@ void setLabel(Buffer const & buf, ParIterator & it)
|
|||||||
par.params().labelString(counters.counterLabel(
|
par.params().labelString(counters.counterLabel(
|
||||||
par.translateIfPossible(from_ascii(format), buf.params())));
|
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) {
|
} else if (layout->labeltype == LABEL_SENSITIVE) {
|
||||||
string const & type = counters.current_float();
|
string const & type = counters.current_float();
|
||||||
docstring full_label;
|
docstring full_label;
|
||||||
@ -538,7 +526,7 @@ void setLabel(Buffer const & buf, ParIterator & it)
|
|||||||
counters.step(from_utf8(type));
|
counters.step(from_utf8(type));
|
||||||
full_label = bformat(from_ascii("%1$s %2$s:"),
|
full_label = bformat(from_ascii("%1$s %2$s:"),
|
||||||
name,
|
name,
|
||||||
convert<docstring>(counters.value(from_utf8(type))));
|
counters.theCounter(from_utf8(type)));
|
||||||
} else
|
} else
|
||||||
full_label = bformat(from_ascii("%1$s #:"), name);
|
full_label = bformat(from_ascii("%1$s #:"), name);
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,13 @@
|
|||||||
|
|
||||||
#include "InsetBibitem.h"
|
#include "InsetBibitem.h"
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
#include "Biblio.h"
|
#include "Biblio.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
#include "BufferParams.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
|
#include "Counters.h"
|
||||||
#include "DispatchResult.h"
|
#include "DispatchResult.h"
|
||||||
#include "FuncRequest.h"
|
#include "FuncRequest.h"
|
||||||
#include "Font.h"
|
#include "Font.h"
|
||||||
@ -41,7 +45,7 @@ int InsetBibitem::key_counter = 0;
|
|||||||
docstring const key_prefix = from_ascii("key-");
|
docstring const key_prefix = from_ascii("key-");
|
||||||
|
|
||||||
InsetBibitem::InsetBibitem(InsetCommandParams const & p)
|
InsetBibitem::InsetBibitem(InsetCommandParams const & p)
|
||||||
: InsetCommand(p, "bibitem"), counter(1)
|
: InsetCommand(p, "bibitem")
|
||||||
{
|
{
|
||||||
if (getParam("key").empty())
|
if (getParam("key").empty())
|
||||||
setParam("key", key_prefix + convert<docstring>(++key_counter));
|
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<Inset> InsetBibitem::doClone() const
|
||||||
{
|
{
|
||||||
auto_ptr<InsetBibitem> b(new InsetBibitem(params()));
|
auto_ptr<InsetBibitem> b(new InsetBibitem(params()));
|
||||||
b->setCounter(counter);
|
b->autolabel_ = autolabel_;
|
||||||
return auto_ptr<Inset>(b);
|
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)
|
void InsetBibitem::read(Buffer const & buf, Lexer & lex)
|
||||||
{
|
{
|
||||||
InsetCommand::read(buf, lex);
|
InsetCommand::read(buf, lex);
|
||||||
@ -100,7 +98,7 @@ void InsetBibitem::read(Buffer const & buf, Lexer & lex)
|
|||||||
docstring const InsetBibitem::getBibLabel() const
|
docstring const InsetBibitem::getBibLabel() const
|
||||||
{
|
{
|
||||||
docstring const & label = getParam("label");
|
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
|
OutputParams const &) const
|
||||||
{
|
{
|
||||||
odocstringstream oss;
|
odocstringstream oss;
|
||||||
oss << '[' << getCounter() << "] ";
|
oss << '[' << getBibLabel() << "] ";
|
||||||
|
|
||||||
docstring const str = oss.str();
|
docstring const str = oss.str();
|
||||||
os << str;
|
os << str;
|
||||||
@ -199,4 +197,20 @@ void InsetBibitem::fillWithBibKeys(Buffer const & buf,
|
|||||||
keys[key] = keyvalmap;
|
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
|
} // namespace lyx
|
||||||
|
@ -37,16 +37,14 @@ public:
|
|||||||
///
|
///
|
||||||
Inset::Code lyxCode() const { return Inset::BIBITEM_CODE; }
|
Inset::Code lyxCode() const { return Inset::BIBITEM_CODE; }
|
||||||
///
|
///
|
||||||
void setCounter(int);
|
|
||||||
///
|
|
||||||
int getCounter() const { return counter; }
|
|
||||||
///
|
|
||||||
docstring const getBibLabel() const;
|
docstring const getBibLabel() const;
|
||||||
///
|
///
|
||||||
int plaintext(Buffer const &, odocstream &, OutputParams const &) const;
|
int plaintext(Buffer const &, odocstream &, OutputParams const &) const;
|
||||||
///
|
///
|
||||||
virtual void fillWithBibKeys(Buffer const &,
|
virtual void fillWithBibKeys(Buffer const &,
|
||||||
biblio::BibKeyList &, InsetIterator const &) const;
|
biblio::BibKeyList &, InsetIterator const &) const;
|
||||||
|
/// Update the counter of this inset
|
||||||
|
virtual void updateLabels(Buffer const &, ParIterator const &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
@ -54,8 +52,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
virtual std::auto_ptr<Inset> doClone() const;
|
virtual std::auto_ptr<Inset> doClone() const;
|
||||||
|
|
||||||
///
|
/// The label that is set by updateLabels
|
||||||
int counter;
|
docstring autolabel_;
|
||||||
///
|
///
|
||||||
static int key_counter;
|
static int key_counter;
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "frontends/Painter.h"
|
#include "frontends/Painter.h"
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
#include "support/convert.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -306,7 +305,7 @@ void InsetCaption::updateLabels(Buffer const & buf, ParIterator const & it)
|
|||||||
cnts.step(from_utf8(type));
|
cnts.step(from_utf8(type));
|
||||||
full_label_ = bformat(from_ascii("%1$s %2$s:"),
|
full_label_ = bformat(from_ascii("%1$s %2$s:"),
|
||||||
name,
|
name,
|
||||||
convert<docstring>(cnts.value(from_utf8(type))));
|
cnts.theCounter(from_utf8(type)));
|
||||||
} else
|
} else
|
||||||
full_label_ = bformat(from_ascii("%1$s #:"), name);
|
full_label_ = bformat(from_ascii("%1$s #:"), name);
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,8 @@ protected:
|
|||||||
p_.setContents(c);
|
p_.setContents(c);
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
/// tell that the button label should be recomputed.
|
||||||
|
void refresh() { updateButtonLabel_ = true; }
|
||||||
///
|
///
|
||||||
void setParam(std::string const & name, docstring const & value)
|
void setParam(std::string const & name, docstring const & value)
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include "OutputParams.h"
|
#include "OutputParams.h"
|
||||||
#include "ParIterator.h"
|
#include "ParIterator.h"
|
||||||
|
|
||||||
#include "support/convert.h"
|
|
||||||
#include "support/std_ostream.h"
|
#include "support/std_ostream.h"
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ void InsetFoot::updateLabels(Buffer const & buf, ParIterator const & it)
|
|||||||
//FIXME: the counter should format itself.
|
//FIXME: the counter should format itself.
|
||||||
setLabel(support::bformat(from_ascii("%1$s %2$s"),
|
setLabel(support::bformat(from_ascii("%1$s %2$s"),
|
||||||
getLayout(buf.params()).labelstring,
|
getLayout(buf.params()).labelstring,
|
||||||
convert<docstring>(cnts.value(foot))));
|
cnts.theCounter(foot)));
|
||||||
|
|
||||||
}
|
}
|
||||||
InsetCollapsable::updateLabels(buf, it);
|
InsetCollapsable::updateLabels(buf, it);
|
||||||
|
Loading…
Reference in New Issue
Block a user