mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 05:25:26 +00:00
fix counters updating mechanism
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9682 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3c851f1f79
commit
1e7112db43
@ -1,3 +1,7 @@
|
||||
2005-02-20 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* layouts/stdlayouts.inc: change labelstring to "Senseless!"
|
||||
|
||||
2005-02-21 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* CREDITS: add some missing pretty printing info.
|
||||
|
@ -71,7 +71,7 @@ Style Caption
|
||||
Align Center
|
||||
AlignPossible Center
|
||||
LabelType Sensitive
|
||||
LabelString Caption
|
||||
LabelString "Senseless!"
|
||||
OptionalArgs 1
|
||||
LabelFont
|
||||
Series Bold
|
||||
|
@ -74,6 +74,7 @@
|
||||
#include "support/types.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/current_function.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
@ -1,3 +1,29 @@
|
||||
2005-02-24 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* text2.C (updateCounters, setCounter, expandLabel): move to
|
||||
buffer_funcs.
|
||||
|
||||
* buffer_funcs.C (updateCounters): turn into a free standing
|
||||
function and add a buffer parameter. Remove dead code for tracking
|
||||
labelstring change.
|
||||
(setCounter): change into a free-standing function which gets a
|
||||
dociterator as argument. Use this iterator to fix captions in a
|
||||
simple way. When no float is found above the caption, use the
|
||||
labelstring of the caption layout as default.
|
||||
|
||||
* text.C (breakParagraph, backspace):
|
||||
* text2.C (init, setLayout, changeDepth):
|
||||
* text3.C (dispatch):
|
||||
* CutAndPaste.C (cutSelection, pasteSelection): pass a buffer to
|
||||
updateCounters.
|
||||
|
||||
* dociterator.C (forwardPar): make it much faster by calling
|
||||
forwardPos() only when really necessary.
|
||||
|
||||
* output_docbook.C (makeCommand): adapt to expandLabel move.
|
||||
|
||||
* cursor.C: remove unused variable
|
||||
|
||||
2005-02-24 Johnathan Burchill <jkerrb@users.sourceforge.net>
|
||||
|
||||
* paragraph_funcs.C: fix crash when pasting insets in change
|
||||
|
@ -503,7 +503,7 @@ void cutSelection(LCursor & cur, bool doclear, bool realcut)
|
||||
|
||||
// need a valid cursor. (Lgb)
|
||||
cur.clearSelection();
|
||||
text->updateCounters();
|
||||
updateCounters(cur.buffer());
|
||||
}
|
||||
|
||||
if (cur.inMathed()) {
|
||||
@ -596,7 +596,7 @@ void pasteSelection(LCursor & cur, size_t sel_index)
|
||||
cur.resetAnchor();
|
||||
text->setCursor(cur, ppp.first, ppp.second);
|
||||
cur.setSelection();
|
||||
text->updateCounters();
|
||||
updateCounters(cur.buffer());
|
||||
}
|
||||
|
||||
if (cur.inMathed()) {
|
||||
|
@ -18,16 +18,25 @@
|
||||
#include "bufferlist.h"
|
||||
#include "bufferparams.h"
|
||||
#include "dociterator.h"
|
||||
#include "counters.h"
|
||||
#include "errorlist.h"
|
||||
#include "Floating.h"
|
||||
#include "FloatList.h"
|
||||
#include "gettext.h"
|
||||
#include "LaTeX.h"
|
||||
#include "lyxtextclass.h"
|
||||
#include "paragraph.h"
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "pariterator.h"
|
||||
#include "lyxvc.h"
|
||||
#include "texrow.h"
|
||||
#include "vc-backend.h"
|
||||
|
||||
#include "frontends/Alert.h"
|
||||
|
||||
#include "insets/insetbibitem.h"
|
||||
|
||||
#include "support/filetools.h"
|
||||
#include "support/fs_extras.h"
|
||||
#include "support/lyxlib.h"
|
||||
@ -35,6 +44,7 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
using lyx::pit_type;
|
||||
using lyx::support::bformat;
|
||||
using lyx::support::LibFileSearch;
|
||||
using lyx::support::MakeDisplayPath;
|
||||
@ -42,6 +52,7 @@ using lyx::support::OnlyFilename;
|
||||
using lyx::support::OnlyPath;
|
||||
using lyx::support::unlink;
|
||||
|
||||
using std::min;
|
||||
using std::string;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
@ -252,3 +263,255 @@ int countWords(DocIterator const & from, DocIterator const & to)
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void incrementItemDepth(ParagraphList & pars, pit_type pit, pit_type first_pit)
|
||||
{
|
||||
int const cur_labeltype = pars[pit].layout()->labeltype;
|
||||
|
||||
if (cur_labeltype != LABEL_ENUMERATE && cur_labeltype != LABEL_ITEMIZE)
|
||||
return;
|
||||
|
||||
int const cur_depth = pars[pit].getDepth();
|
||||
|
||||
pit_type prev_pit = pit - 1;
|
||||
while (true) {
|
||||
int const prev_depth = pars[prev_pit].getDepth();
|
||||
int const prev_labeltype = pars[prev_pit].layout()->labeltype;
|
||||
if (prev_depth == 0 && cur_depth > 0) {
|
||||
if (prev_labeltype == cur_labeltype) {
|
||||
pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
|
||||
}
|
||||
break;
|
||||
} else if (prev_depth < cur_depth) {
|
||||
if (prev_labeltype == cur_labeltype) {
|
||||
pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
|
||||
break;
|
||||
}
|
||||
} else if (prev_depth == cur_depth) {
|
||||
if (prev_labeltype == cur_labeltype) {
|
||||
pars[pit].itemdepth = pars[prev_pit].itemdepth;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (prev_pit == first_pit)
|
||||
break;
|
||||
|
||||
--prev_pit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void resetEnumCounterIfNeeded(ParagraphList & pars, pit_type pit,
|
||||
pit_type firstpit, Counters & counters)
|
||||
{
|
||||
if (pit == firstpit)
|
||||
return;
|
||||
|
||||
int const cur_depth = pars[pit].getDepth();
|
||||
pit_type prev_pit = pit - 1;
|
||||
while (true) {
|
||||
int const prev_depth = pars[prev_pit].getDepth();
|
||||
int const prev_labeltype = pars[prev_pit].layout()->labeltype;
|
||||
if (prev_depth <= cur_depth) {
|
||||
if (prev_labeltype != LABEL_ENUMERATE) {
|
||||
switch (pars[pit].itemdepth) {
|
||||
case 0:
|
||||
counters.reset("enumi");
|
||||
case 1:
|
||||
counters.reset("enumii");
|
||||
case 2:
|
||||
counters.reset("enumiii");
|
||||
case 3:
|
||||
counters.reset("enumiv");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (prev_pit == firstpit)
|
||||
break;
|
||||
|
||||
--prev_pit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// set the counter of a paragraph. This includes the labels
|
||||
void setCounter(Buffer const & buf, ParIterator & it)
|
||||
{
|
||||
Paragraph & par = *it;
|
||||
BufferParams const & bufparams = buf.params();
|
||||
LyXTextClass const & textclass = bufparams.getLyXTextClass();
|
||||
LyXLayout_ptr const & layout = par.layout();
|
||||
Counters & counters = textclass.counters();
|
||||
|
||||
// Always reset
|
||||
par.itemdepth = 0;
|
||||
|
||||
if (it.pit() == 0) {
|
||||
par.params().appendix(par.params().startOfAppendix());
|
||||
} else {
|
||||
par.params().appendix(it.plist()[it.pit() - 1].params().appendix());
|
||||
if (!par.params().appendix() &&
|
||||
par.params().startOfAppendix()) {
|
||||
par.params().appendix(true);
|
||||
textclass.counters().reset();
|
||||
}
|
||||
|
||||
// Maybe we have to increment the item depth.
|
||||
incrementItemDepth(it.plist(), it.pit(), 0);
|
||||
}
|
||||
|
||||
// erase what was there before
|
||||
par.params().labelString(string());
|
||||
|
||||
if (layout->margintype == MARGIN_MANUAL) {
|
||||
if (par.params().labelWidthString().empty())
|
||||
par.setLabelWidthString(layout->labelstring());
|
||||
} else {
|
||||
par.setLabelWidthString(string());
|
||||
}
|
||||
|
||||
// is it a layout that has an automatic label?
|
||||
if (layout->labeltype == LABEL_COUNTER) {
|
||||
counters.step(layout->counter);
|
||||
string label = expandLabel(textclass, layout, par.params().appendix());
|
||||
par.params().labelString(label);
|
||||
} else if (layout->labeltype == LABEL_ITEMIZE) {
|
||||
// At some point of time we should do something more
|
||||
// clever here, like:
|
||||
// par.params().labelString(
|
||||
// bufparams.user_defined_bullet(par.itemdepth).getText());
|
||||
// for now, use a simple hardcoded label
|
||||
string itemlabel;
|
||||
switch (par.itemdepth) {
|
||||
case 0:
|
||||
itemlabel = "*";
|
||||
break;
|
||||
case 1:
|
||||
itemlabel = "-";
|
||||
break;
|
||||
case 2:
|
||||
itemlabel = "@";
|
||||
break;
|
||||
case 3:
|
||||
itemlabel = "·";
|
||||
break;
|
||||
}
|
||||
|
||||
par.params().labelString(itemlabel);
|
||||
} else if (layout->labeltype == LABEL_ENUMERATE) {
|
||||
// Maybe we have to reset the enumeration counter.
|
||||
resetEnumCounterIfNeeded(it.plist(), it.pit(), 0, counters);
|
||||
|
||||
// FIXME
|
||||
// Yes I know this is a really, really! bad solution
|
||||
// (Lgb)
|
||||
string enumcounter = "enum";
|
||||
|
||||
switch (par.itemdepth) {
|
||||
case 2:
|
||||
enumcounter += 'i';
|
||||
case 1:
|
||||
enumcounter += 'i';
|
||||
case 0:
|
||||
enumcounter += 'i';
|
||||
break;
|
||||
case 3:
|
||||
enumcounter += "iv";
|
||||
break;
|
||||
default:
|
||||
// not a valid enumdepth...
|
||||
break;
|
||||
}
|
||||
|
||||
counters.step(enumcounter);
|
||||
|
||||
par.params().labelString(counters.enumLabel(enumcounter));
|
||||
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
|
||||
counters.step("bibitem");
|
||||
int number = counters.value("bibitem");
|
||||
if (par.bibitem()) {
|
||||
par.bibitem()->setCounter(number);
|
||||
par.params().labelString(layout->labelstring());
|
||||
}
|
||||
// In biblio should't be following counters but...
|
||||
} else if (layout->labeltype == LABEL_SENSITIVE) {
|
||||
// Search for the first float or wrap inset in the iterator
|
||||
string type;
|
||||
size_t i = it.depth();
|
||||
while (i > 0) {
|
||||
--i;
|
||||
InsetBase * const in = &it[i].inset();
|
||||
if (in->lyxCode() == InsetBase::FLOAT_CODE
|
||||
|| in->lyxCode() == InsetBase::WRAP_CODE)
|
||||
type = in->getInsetName();
|
||||
break;
|
||||
}
|
||||
|
||||
string s;
|
||||
if (!type.empty()) {
|
||||
Floating const & fl = textclass.floats().getType(type);
|
||||
|
||||
counters.step(fl.type());
|
||||
|
||||
// Doesn't work... yet.
|
||||
s = bformat(_("%1$s #:"), buf.B_(fl.name()));
|
||||
} else {
|
||||
// par->SetLayout(0);
|
||||
s = buf.B_(layout->labelstring());
|
||||
}
|
||||
|
||||
par.params().labelString(s);
|
||||
} else
|
||||
par.params().labelString(buf.B_(layout->labelstring()));
|
||||
}
|
||||
|
||||
} // anon namespace
|
||||
|
||||
|
||||
void updateCounters(Buffer const & buf)
|
||||
{
|
||||
// start over
|
||||
buf.params().getLyXTextClass().counters().reset();
|
||||
|
||||
for (ParIterator it = par_iterator_begin(buf.inset()); it; ++it) {
|
||||
// reduce depth if necessary
|
||||
if (it.pit()) {
|
||||
Paragraph const & prevpar = it.plist()[it.pit() - 1];
|
||||
it->params().depth(min(it->params().depth(),
|
||||
prevpar.getMaxDepthAfter()));
|
||||
} else
|
||||
it->params().depth(0);
|
||||
|
||||
// set the counter for this paragraph
|
||||
setCounter(buf, it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string expandLabel(LyXTextClass const & textclass,
|
||||
LyXLayout_ptr const & layout, bool appendix)
|
||||
{
|
||||
string fmt = appendix ?
|
||||
layout->labelstring_appendix() : layout->labelstring();
|
||||
|
||||
// handle 'inherited level parts' in 'fmt',
|
||||
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
|
||||
size_t const i = fmt.find('@', 0);
|
||||
if (i != string::npos) {
|
||||
size_t const j = fmt.find('@', i + 1);
|
||||
if (j != string::npos) {
|
||||
string parent(fmt, i + 1, j - i - 1);
|
||||
string label = expandLabel(textclass, textclass[parent], appendix);
|
||||
fmt = string(fmt, 0, i) + label + string(fmt, j + 1, string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
return textclass.counters().counterLabel(fmt);
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,12 +12,15 @@
|
||||
#ifndef BUFFER_FUNCS_H
|
||||
#define BUFFER_FUNCS_H
|
||||
|
||||
#include "lyxlayout_ptr_fwd.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
class Buffer;
|
||||
class DocIterator;
|
||||
class ErrorList;
|
||||
class LyXTextClass;
|
||||
class TeXErrors;
|
||||
|
||||
/**
|
||||
@ -42,5 +45,12 @@ void bufferErrors(Buffer const &, ErrorList const &);
|
||||
/// Count the number of words in the text between these two iterators
|
||||
int countWords(DocIterator const & from, DocIterator const & to);
|
||||
|
||||
/// Expand the counters for the labelstring of \c layout
|
||||
std::string expandLabel(LyXTextClass const & textclass,
|
||||
LyXLayout_ptr const & layout, bool appendix);
|
||||
|
||||
/// updates all counters
|
||||
void updateCounters(Buffer const &);
|
||||
|
||||
|
||||
#endif // BUFFER_FUNCS_H
|
||||
|
@ -123,8 +123,6 @@ namespace {
|
||||
{
|
||||
BOOST_ASSERT(!cursor.empty());
|
||||
CursorSlice bottom = cursor[0];
|
||||
LyXText * text = bottom.text();
|
||||
BOOST_ASSERT(text);
|
||||
|
||||
DocIterator it = doc_iterator_begin(bottom.inset());
|
||||
DocIterator const et = doc_iterator_end(bottom.inset());
|
||||
|
@ -382,8 +382,27 @@ void DocIterator::forwardPosNoDescend()
|
||||
void DocIterator::forwardPar()
|
||||
{
|
||||
forwardPos();
|
||||
while (!empty() && (!inTexted() || pos() != 0))
|
||||
|
||||
#if 0
|
||||
DocIterator cmp(*this);
|
||||
#endif
|
||||
|
||||
while (!empty() && (!inTexted() || pos() != 0)) {
|
||||
if (inTexted()) {
|
||||
pos_type const lastp = lastpos();
|
||||
Paragraph const & par = paragraph();
|
||||
pos_type & pos = top().pos();
|
||||
while (pos < lastp && !par.isInset(pos))
|
||||
++pos;
|
||||
}
|
||||
forwardPos();
|
||||
}
|
||||
|
||||
#if 0
|
||||
while (!cmp.empty() && (!cmp.inTexted() || cmp.pos() != 0))
|
||||
cmp.forwardPos();
|
||||
BOOST_ASSERT(cmp == *this);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -261,8 +261,6 @@ public:
|
||||
/// current text heigth
|
||||
int height() const;
|
||||
|
||||
/// updates all counters
|
||||
void updateCounters();
|
||||
/// Returns an inset if inset was hit, or 0 if not.
|
||||
InsetBase * checkInsetHit(int x, int y) const;
|
||||
|
||||
@ -374,8 +372,6 @@ private:
|
||||
/// delete double space or empty paragraphs around old cursor
|
||||
bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
|
||||
|
||||
///
|
||||
void setCounter(Buffer const &, pit_type pit);
|
||||
///
|
||||
void deleteWordForward(LCursor & cur);
|
||||
///
|
||||
@ -402,9 +398,4 @@ private:
|
||||
/// return the default height of a row in pixels, considering font zoom
|
||||
int defaultRowHeight();
|
||||
|
||||
///
|
||||
std::string expandLabel(LyXTextClass const & textclass,
|
||||
LyXLayout_ptr const & layout, bool appendix);
|
||||
|
||||
|
||||
#endif // LYXTEXT_H
|
||||
|
@ -14,12 +14,13 @@
|
||||
#include "output_docbook.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "buffer_funcs.h"
|
||||
#include "bufferparams.h"
|
||||
#include "counters.h"
|
||||
#include "debug.h"
|
||||
#include "lyxtext.h"
|
||||
#include "paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "sgml.h"
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "author.h"
|
||||
#include "buffer.h"
|
||||
#include "buffer_funcs.h"
|
||||
#include "bufferparams.h"
|
||||
#include "BufferView.h"
|
||||
#include "cursor.h"
|
||||
@ -1074,7 +1075,7 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
|
||||
while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
|
||||
pars_[next_par].erase(0);
|
||||
|
||||
updateCounters();
|
||||
updateCounters(cur.buffer());
|
||||
|
||||
// This check is necessary. Otherwise the new empty paragraph will
|
||||
// be deleted automatically. And it is more friendly for the user!
|
||||
@ -1609,7 +1610,7 @@ void LyXText::backspace(LCursor & cur)
|
||||
--cur.pos();
|
||||
|
||||
// the counters may have changed
|
||||
updateCounters();
|
||||
updateCounters(cur.buffer());
|
||||
setCursor(cur, cur.pit(), cur.pos(), false);
|
||||
}
|
||||
} else {
|
||||
|
314
src/text2.C
314
src/text2.C
@ -26,15 +26,12 @@
|
||||
#include "bufferparams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Bullet.h"
|
||||
#include "counters.h"
|
||||
#include "coordcache.h"
|
||||
#include "cursor.h"
|
||||
#include "CutAndPaste.h"
|
||||
#include "debug.h"
|
||||
#include "dispatchresult.h"
|
||||
#include "errorlist.h"
|
||||
#include "Floating.h"
|
||||
#include "FloatList.h"
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
#include "language.h"
|
||||
@ -45,26 +42,21 @@
|
||||
#include "paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "pariterator.h"
|
||||
#include "undo.h"
|
||||
#include "vspace.h"
|
||||
|
||||
#include "frontends/font_metrics.h"
|
||||
#include "frontends/LyXView.h"
|
||||
|
||||
#include "insets/insetbibitem.h"
|
||||
#include "insets/insetenv.h"
|
||||
#include "insets/insetfloat.h"
|
||||
#include "insets/insetwrap.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/textutils.h"
|
||||
#include "support/convert.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using lyx::pit_type;
|
||||
using lyx::pos_type;
|
||||
using lyx::support::bformat;
|
||||
|
||||
using std::endl;
|
||||
using std::ostringstream;
|
||||
@ -93,7 +85,7 @@ void LyXText::init(BufferView * bv)
|
||||
pars_[pit].rows().clear();
|
||||
|
||||
current_font = getFont(pars_[0], 0);
|
||||
updateCounters();
|
||||
updateCounters(*bv->buffer());
|
||||
}
|
||||
|
||||
|
||||
@ -337,7 +329,7 @@ void LyXText::setLayout(LCursor & cur, string const & layout)
|
||||
pit_type start = cur.selBegin().pit();
|
||||
pit_type end = cur.selEnd().pit() + 1;
|
||||
setLayout(start, end, layout);
|
||||
updateCounters();
|
||||
updateCounters(cur.buffer());
|
||||
}
|
||||
|
||||
|
||||
@ -398,7 +390,7 @@ void LyXText::changeDepth(LCursor & cur, DEPTH_CHANGE type)
|
||||
}
|
||||
// this handles the counter labels, and also fixes up
|
||||
// depth values for follow-on (child) paragraphs
|
||||
updateCounters();
|
||||
updateCounters(cur.buffer());
|
||||
}
|
||||
|
||||
|
||||
@ -582,304 +574,6 @@ void LyXText::setParagraph(LCursor & cur,
|
||||
}
|
||||
|
||||
|
||||
string expandLabel(LyXTextClass const & textclass,
|
||||
LyXLayout_ptr const & layout, bool appendix)
|
||||
{
|
||||
string fmt = appendix ?
|
||||
layout->labelstring_appendix() : layout->labelstring();
|
||||
|
||||
// handle 'inherited level parts' in 'fmt',
|
||||
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
|
||||
size_t const i = fmt.find('@', 0);
|
||||
if (i != string::npos) {
|
||||
size_t const j = fmt.find('@', i + 1);
|
||||
if (j != string::npos) {
|
||||
string parent(fmt, i + 1, j - i - 1);
|
||||
string label = expandLabel(textclass, textclass[parent], appendix);
|
||||
fmt = string(fmt, 0, i) + label + string(fmt, j + 1, string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
return textclass.counters().counterLabel(fmt);
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void incrementItemDepth(ParagraphList & pars, pit_type pit, pit_type first_pit)
|
||||
{
|
||||
int const cur_labeltype = pars[pit].layout()->labeltype;
|
||||
|
||||
if (cur_labeltype != LABEL_ENUMERATE && cur_labeltype != LABEL_ITEMIZE)
|
||||
return;
|
||||
|
||||
int const cur_depth = pars[pit].getDepth();
|
||||
|
||||
pit_type prev_pit = pit - 1;
|
||||
while (true) {
|
||||
int const prev_depth = pars[prev_pit].getDepth();
|
||||
int const prev_labeltype = pars[prev_pit].layout()->labeltype;
|
||||
if (prev_depth == 0 && cur_depth > 0) {
|
||||
if (prev_labeltype == cur_labeltype) {
|
||||
pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
|
||||
}
|
||||
break;
|
||||
} else if (prev_depth < cur_depth) {
|
||||
if (prev_labeltype == cur_labeltype) {
|
||||
pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
|
||||
break;
|
||||
}
|
||||
} else if (prev_depth == cur_depth) {
|
||||
if (prev_labeltype == cur_labeltype) {
|
||||
pars[pit].itemdepth = pars[prev_pit].itemdepth;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (prev_pit == first_pit)
|
||||
break;
|
||||
|
||||
--prev_pit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void resetEnumCounterIfNeeded(ParagraphList & pars, pit_type pit,
|
||||
pit_type firstpit, Counters & counters)
|
||||
{
|
||||
if (pit == firstpit)
|
||||
return;
|
||||
|
||||
int const cur_depth = pars[pit].getDepth();
|
||||
pit_type prev_pit = pit - 1;
|
||||
while (true) {
|
||||
int const prev_depth = pars[prev_pit].getDepth();
|
||||
int const prev_labeltype = pars[prev_pit].layout()->labeltype;
|
||||
if (prev_depth <= cur_depth) {
|
||||
if (prev_labeltype != LABEL_ENUMERATE) {
|
||||
switch (pars[pit].itemdepth) {
|
||||
case 0:
|
||||
counters.reset("enumi");
|
||||
case 1:
|
||||
counters.reset("enumii");
|
||||
case 2:
|
||||
counters.reset("enumiii");
|
||||
case 3:
|
||||
counters.reset("enumiv");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (prev_pit == firstpit)
|
||||
break;
|
||||
|
||||
--prev_pit;
|
||||
}
|
||||
}
|
||||
|
||||
} // anon namespace
|
||||
|
||||
|
||||
// set the counter of a paragraph. This includes the labels
|
||||
void LyXText::setCounter(Buffer const & buf, pit_type pit)
|
||||
{
|
||||
Paragraph & par = pars_[pit];
|
||||
BufferParams const & bufparams = buf.params();
|
||||
LyXTextClass const & textclass = bufparams.getLyXTextClass();
|
||||
LyXLayout_ptr const & layout = par.layout();
|
||||
Counters & counters = textclass.counters();
|
||||
|
||||
// Always reset
|
||||
par.itemdepth = 0;
|
||||
|
||||
if (pit == 0) {
|
||||
par.params().appendix(par.params().startOfAppendix());
|
||||
} else {
|
||||
par.params().appendix(pars_[pit - 1].params().appendix());
|
||||
if (!par.params().appendix() &&
|
||||
par.params().startOfAppendix()) {
|
||||
par.params().appendix(true);
|
||||
textclass.counters().reset();
|
||||
}
|
||||
|
||||
// Maybe we have to increment the item depth.
|
||||
incrementItemDepth(pars_, pit, 0);
|
||||
}
|
||||
|
||||
// erase what was there before
|
||||
par.params().labelString(string());
|
||||
|
||||
if (layout->margintype == MARGIN_MANUAL) {
|
||||
if (par.params().labelWidthString().empty())
|
||||
par.setLabelWidthString(layout->labelstring());
|
||||
} else {
|
||||
par.setLabelWidthString(string());
|
||||
}
|
||||
|
||||
// is it a layout that has an automatic label?
|
||||
if (layout->labeltype == LABEL_COUNTER) {
|
||||
BufferParams const & bufparams = buf.params();
|
||||
LyXTextClass const & textclass = bufparams.getLyXTextClass();
|
||||
counters.step(layout->counter);
|
||||
string label = expandLabel(textclass, layout, par.params().appendix());
|
||||
par.params().labelString(label);
|
||||
} else if (layout->labeltype == LABEL_ITEMIZE) {
|
||||
// At some point of time we should do something more
|
||||
// clever here, like:
|
||||
// par.params().labelString(
|
||||
// bufparams.user_defined_bullet(par.itemdepth).getText());
|
||||
// for now, use a simple hardcoded label
|
||||
string itemlabel;
|
||||
switch (par.itemdepth) {
|
||||
case 0:
|
||||
itemlabel = "*";
|
||||
break;
|
||||
case 1:
|
||||
itemlabel = "-";
|
||||
break;
|
||||
case 2:
|
||||
itemlabel = "@";
|
||||
break;
|
||||
case 3:
|
||||
itemlabel = "·";
|
||||
break;
|
||||
}
|
||||
|
||||
par.params().labelString(itemlabel);
|
||||
} else if (layout->labeltype == LABEL_ENUMERATE) {
|
||||
// Maybe we have to reset the enumeration counter.
|
||||
resetEnumCounterIfNeeded(pars_, pit, 0, counters);
|
||||
|
||||
// FIXME
|
||||
// Yes I know this is a really, really! bad solution
|
||||
// (Lgb)
|
||||
string enumcounter = "enum";
|
||||
|
||||
switch (par.itemdepth) {
|
||||
case 2:
|
||||
enumcounter += 'i';
|
||||
case 1:
|
||||
enumcounter += 'i';
|
||||
case 0:
|
||||
enumcounter += 'i';
|
||||
break;
|
||||
case 3:
|
||||
enumcounter += "iv";
|
||||
break;
|
||||
default:
|
||||
// not a valid enumdepth...
|
||||
break;
|
||||
}
|
||||
|
||||
counters.step(enumcounter);
|
||||
|
||||
par.params().labelString(counters.enumLabel(enumcounter));
|
||||
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
|
||||
counters.step("bibitem");
|
||||
int number = counters.value("bibitem");
|
||||
if (par.bibitem()) {
|
||||
par.bibitem()->setCounter(number);
|
||||
par.params().labelString(layout->labelstring());
|
||||
}
|
||||
// In biblio should't be following counters but...
|
||||
} else {
|
||||
string s = buf.B_(layout->labelstring());
|
||||
|
||||
// the caption hack:
|
||||
if (layout->labeltype == LABEL_SENSITIVE) {
|
||||
pit_type end = paragraphs().size();
|
||||
pit_type tmppit = pit;
|
||||
InsetBase * in = 0;
|
||||
bool isOK = false;
|
||||
while (tmppit != end) {
|
||||
in = pars_[tmppit].inInset();
|
||||
// FIXME: in should be always valid.
|
||||
if (in &&
|
||||
(in->lyxCode() == InsetBase::FLOAT_CODE ||
|
||||
in->lyxCode() == InsetBase::WRAP_CODE)) {
|
||||
isOK = true;
|
||||
break;
|
||||
}
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning replace this code by something that works
|
||||
// This code does not work because we have currently no way to move up
|
||||
// in the hierarchy of insets (JMarc 16/08/2004)
|
||||
#endif
|
||||
#if 0
|
||||
/* I think this code is supposed to be useful when one has a caption
|
||||
* in a minipage in a figure inset. We need to go up to be able to see
|
||||
* that the caption should use "Figure" as label
|
||||
*/
|
||||
else {
|
||||
Paragraph const * owner = &ownerPar(buf, in);
|
||||
tmppit = 0;
|
||||
for ( ; tmppit != end; ++tmppit)
|
||||
if (&pars_[tmppit] == owner)
|
||||
break;
|
||||
}
|
||||
#else
|
||||
++tmppit;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (isOK) {
|
||||
string type;
|
||||
|
||||
if (in->lyxCode() == InsetBase::FLOAT_CODE)
|
||||
type = static_cast<InsetFloat*>(in)->params().type;
|
||||
else if (in->lyxCode() == InsetBase::WRAP_CODE)
|
||||
type = static_cast<InsetWrap*>(in)->params().type;
|
||||
else
|
||||
BOOST_ASSERT(false);
|
||||
|
||||
Floating const & fl = textclass.floats().getType(type);
|
||||
|
||||
counters.step(fl.type());
|
||||
|
||||
// Doesn't work... yet.
|
||||
s = bformat(_("%1$s #:"), buf.B_(fl.name()));
|
||||
} else {
|
||||
// par->SetLayout(0);
|
||||
// s = layout->labelstring;
|
||||
s = _("Senseless: ");
|
||||
}
|
||||
}
|
||||
par.params().labelString(s);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Updates all counters.
|
||||
void LyXText::updateCounters()
|
||||
{
|
||||
// start over
|
||||
bv()->buffer()->params().getLyXTextClass().counters().reset();
|
||||
|
||||
bool update_pos = false;
|
||||
|
||||
pit_type end = paragraphs().size();
|
||||
for (pit_type pit = 0; pit != end; ++pit) {
|
||||
string const oldLabel = pars_[pit].params().labelString();
|
||||
size_t maxdepth = 0;
|
||||
if (pit != 0)
|
||||
maxdepth = pars_[pit - 1].getMaxDepthAfter();
|
||||
|
||||
if (pars_[pit].params().depth() > maxdepth)
|
||||
pars_[pit].params().depth(maxdepth);
|
||||
|
||||
// setCounter can potentially change the labelString.
|
||||
setCounter(*bv()->buffer(), pit);
|
||||
string const & newLabel = pars_[pit].params().labelString();
|
||||
if (oldLabel != newLabel) {
|
||||
//lyxerr[Debug::DEBUG] << "changing labels: old: " << oldLabel << " new: "
|
||||
// << newLabel << endl;
|
||||
update_pos = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// this really should just insert the inset and not move the cursor.
|
||||
void LyXText::insertInset(LCursor & cur, InsetBase * inset)
|
||||
{
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "FloatList.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "buffer.h"
|
||||
#include "buffer_funcs.h"
|
||||
#include "bufferparams.h"
|
||||
#include "BufferView.h"
|
||||
#include "cursor.h"
|
||||
@ -297,6 +298,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
Paragraph & par = cur.paragraph();
|
||||
bool start = !par.params().startOfAppendix();
|
||||
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning The code below only makes sense a top level.
|
||||
// Should LFUN_APPENDIX be restricted to top-level paragraphs?
|
||||
#endif
|
||||
// ensure that we have only one start_of_appendix in this document
|
||||
for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
|
||||
if (pars_[tmp].params().startOfAppendix()) {
|
||||
@ -310,7 +315,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
par.params().startOfAppendix(start);
|
||||
|
||||
// we can set the refreshing parameters now
|
||||
updateCounters();
|
||||
updateCounters(cur.buffer());
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user