mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +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>
|
2005-02-21 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* CREDITS: add some missing pretty printing info.
|
* CREDITS: add some missing pretty printing info.
|
||||||
|
@ -71,7 +71,7 @@ Style Caption
|
|||||||
Align Center
|
Align Center
|
||||||
AlignPossible Center
|
AlignPossible Center
|
||||||
LabelType Sensitive
|
LabelType Sensitive
|
||||||
LabelString Caption
|
LabelString "Senseless!"
|
||||||
OptionalArgs 1
|
OptionalArgs 1
|
||||||
LabelFont
|
LabelFont
|
||||||
Series Bold
|
Series Bold
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
#include "support/types.h"
|
#include "support/types.h"
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/current_function.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#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>
|
2005-02-24 Johnathan Burchill <jkerrb@users.sourceforge.net>
|
||||||
|
|
||||||
* paragraph_funcs.C: fix crash when pasting insets in change
|
* 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)
|
// need a valid cursor. (Lgb)
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
text->updateCounters();
|
updateCounters(cur.buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur.inMathed()) {
|
if (cur.inMathed()) {
|
||||||
@ -596,7 +596,7 @@ void pasteSelection(LCursor & cur, size_t sel_index)
|
|||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
text->setCursor(cur, ppp.first, ppp.second);
|
text->setCursor(cur, ppp.first, ppp.second);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
text->updateCounters();
|
updateCounters(cur.buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur.inMathed()) {
|
if (cur.inMathed()) {
|
||||||
|
@ -18,16 +18,25 @@
|
|||||||
#include "bufferlist.h"
|
#include "bufferlist.h"
|
||||||
#include "bufferparams.h"
|
#include "bufferparams.h"
|
||||||
#include "dociterator.h"
|
#include "dociterator.h"
|
||||||
|
#include "counters.h"
|
||||||
#include "errorlist.h"
|
#include "errorlist.h"
|
||||||
|
#include "Floating.h"
|
||||||
|
#include "FloatList.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "LaTeX.h"
|
#include "LaTeX.h"
|
||||||
|
#include "lyxtextclass.h"
|
||||||
#include "paragraph.h"
|
#include "paragraph.h"
|
||||||
|
#include "ParagraphList_fwd.h"
|
||||||
|
#include "ParagraphParameters.h"
|
||||||
|
#include "pariterator.h"
|
||||||
#include "lyxvc.h"
|
#include "lyxvc.h"
|
||||||
#include "texrow.h"
|
#include "texrow.h"
|
||||||
#include "vc-backend.h"
|
#include "vc-backend.h"
|
||||||
|
|
||||||
#include "frontends/Alert.h"
|
#include "frontends/Alert.h"
|
||||||
|
|
||||||
|
#include "insets/insetbibitem.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"
|
||||||
@ -35,6 +44,7 @@
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
#include <boost/filesystem/operations.hpp>
|
||||||
|
|
||||||
|
using lyx::pit_type;
|
||||||
using lyx::support::bformat;
|
using lyx::support::bformat;
|
||||||
using lyx::support::LibFileSearch;
|
using lyx::support::LibFileSearch;
|
||||||
using lyx::support::MakeDisplayPath;
|
using lyx::support::MakeDisplayPath;
|
||||||
@ -42,6 +52,7 @@ using lyx::support::OnlyFilename;
|
|||||||
using lyx::support::OnlyPath;
|
using lyx::support::OnlyPath;
|
||||||
using lyx::support::unlink;
|
using lyx::support::unlink;
|
||||||
|
|
||||||
|
using std::min;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
@ -252,3 +263,255 @@ int countWords(DocIterator const & from, DocIterator const & to)
|
|||||||
|
|
||||||
return count;
|
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
|
#ifndef BUFFER_FUNCS_H
|
||||||
#define BUFFER_FUNCS_H
|
#define BUFFER_FUNCS_H
|
||||||
|
|
||||||
|
#include "lyxlayout_ptr_fwd.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
class Buffer;
|
class Buffer;
|
||||||
class DocIterator;
|
class DocIterator;
|
||||||
class ErrorList;
|
class ErrorList;
|
||||||
|
class LyXTextClass;
|
||||||
class TeXErrors;
|
class TeXErrors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,5 +45,12 @@ void bufferErrors(Buffer const &, ErrorList const &);
|
|||||||
/// Count the number of words in the text between these two iterators
|
/// Count the number of words in the text between these two iterators
|
||||||
int countWords(DocIterator const & from, DocIterator const & to);
|
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
|
#endif // BUFFER_FUNCS_H
|
||||||
|
@ -123,8 +123,6 @@ namespace {
|
|||||||
{
|
{
|
||||||
BOOST_ASSERT(!cursor.empty());
|
BOOST_ASSERT(!cursor.empty());
|
||||||
CursorSlice bottom = cursor[0];
|
CursorSlice bottom = cursor[0];
|
||||||
LyXText * text = bottom.text();
|
|
||||||
BOOST_ASSERT(text);
|
|
||||||
|
|
||||||
DocIterator it = doc_iterator_begin(bottom.inset());
|
DocIterator it = doc_iterator_begin(bottom.inset());
|
||||||
DocIterator const et = doc_iterator_end(bottom.inset());
|
DocIterator const et = doc_iterator_end(bottom.inset());
|
||||||
|
@ -382,8 +382,27 @@ void DocIterator::forwardPosNoDescend()
|
|||||||
void DocIterator::forwardPar()
|
void DocIterator::forwardPar()
|
||||||
{
|
{
|
||||||
forwardPos();
|
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();
|
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
|
/// current text heigth
|
||||||
int height() const;
|
int height() const;
|
||||||
|
|
||||||
/// updates all counters
|
|
||||||
void updateCounters();
|
|
||||||
/// Returns an inset if inset was hit, or 0 if not.
|
/// Returns an inset if inset was hit, or 0 if not.
|
||||||
InsetBase * checkInsetHit(int x, int y) const;
|
InsetBase * checkInsetHit(int x, int y) const;
|
||||||
|
|
||||||
@ -374,8 +372,6 @@ private:
|
|||||||
/// delete double space or empty paragraphs around old cursor
|
/// delete double space or empty paragraphs around old cursor
|
||||||
bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
|
bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
|
||||||
|
|
||||||
///
|
|
||||||
void setCounter(Buffer const &, pit_type pit);
|
|
||||||
///
|
///
|
||||||
void deleteWordForward(LCursor & cur);
|
void deleteWordForward(LCursor & cur);
|
||||||
///
|
///
|
||||||
@ -402,9 +398,4 @@ private:
|
|||||||
/// return the default height of a row in pixels, considering font zoom
|
/// return the default height of a row in pixels, considering font zoom
|
||||||
int defaultRowHeight();
|
int defaultRowHeight();
|
||||||
|
|
||||||
///
|
|
||||||
std::string expandLabel(LyXTextClass const & textclass,
|
|
||||||
LyXLayout_ptr const & layout, bool appendix);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // LYXTEXT_H
|
#endif // LYXTEXT_H
|
||||||
|
@ -14,12 +14,13 @@
|
|||||||
#include "output_docbook.h"
|
#include "output_docbook.h"
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
#include "buffer_funcs.h"
|
||||||
#include "bufferparams.h"
|
#include "bufferparams.h"
|
||||||
#include "counters.h"
|
#include "counters.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "lyxtext.h"
|
|
||||||
#include "paragraph.h"
|
#include "paragraph.h"
|
||||||
#include "paragraph_funcs.h"
|
#include "paragraph_funcs.h"
|
||||||
|
#include "ParagraphList_fwd.h"
|
||||||
#include "ParagraphParameters.h"
|
#include "ParagraphParameters.h"
|
||||||
#include "sgml.h"
|
#include "sgml.h"
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "author.h"
|
#include "author.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
#include "buffer_funcs.h"
|
||||||
#include "bufferparams.h"
|
#include "bufferparams.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "cursor.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))
|
while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
|
||||||
pars_[next_par].erase(0);
|
pars_[next_par].erase(0);
|
||||||
|
|
||||||
updateCounters();
|
updateCounters(cur.buffer());
|
||||||
|
|
||||||
// This check is necessary. Otherwise the new empty paragraph will
|
// This check is necessary. Otherwise the new empty paragraph will
|
||||||
// be deleted automatically. And it is more friendly for the user!
|
// be deleted automatically. And it is more friendly for the user!
|
||||||
@ -1609,7 +1610,7 @@ void LyXText::backspace(LCursor & cur)
|
|||||||
--cur.pos();
|
--cur.pos();
|
||||||
|
|
||||||
// the counters may have changed
|
// the counters may have changed
|
||||||
updateCounters();
|
updateCounters(cur.buffer());
|
||||||
setCursor(cur, cur.pit(), cur.pos(), false);
|
setCursor(cur, cur.pit(), cur.pos(), false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
314
src/text2.C
314
src/text2.C
@ -26,15 +26,12 @@
|
|||||||
#include "bufferparams.h"
|
#include "bufferparams.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "Bullet.h"
|
#include "Bullet.h"
|
||||||
#include "counters.h"
|
|
||||||
#include "coordcache.h"
|
#include "coordcache.h"
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include "CutAndPaste.h"
|
#include "CutAndPaste.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "dispatchresult.h"
|
#include "dispatchresult.h"
|
||||||
#include "errorlist.h"
|
#include "errorlist.h"
|
||||||
#include "Floating.h"
|
|
||||||
#include "FloatList.h"
|
|
||||||
#include "funcrequest.h"
|
#include "funcrequest.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
@ -45,26 +42,21 @@
|
|||||||
#include "paragraph.h"
|
#include "paragraph.h"
|
||||||
#include "paragraph_funcs.h"
|
#include "paragraph_funcs.h"
|
||||||
#include "ParagraphParameters.h"
|
#include "ParagraphParameters.h"
|
||||||
|
#include "pariterator.h"
|
||||||
#include "undo.h"
|
#include "undo.h"
|
||||||
#include "vspace.h"
|
#include "vspace.h"
|
||||||
|
|
||||||
#include "frontends/font_metrics.h"
|
#include "frontends/font_metrics.h"
|
||||||
#include "frontends/LyXView.h"
|
#include "frontends/LyXView.h"
|
||||||
|
|
||||||
#include "insets/insetbibitem.h"
|
|
||||||
#include "insets/insetenv.h"
|
#include "insets/insetenv.h"
|
||||||
#include "insets/insetfloat.h"
|
|
||||||
#include "insets/insetwrap.h"
|
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
|
||||||
#include "support/textutils.h"
|
#include "support/textutils.h"
|
||||||
#include "support/convert.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using lyx::pit_type;
|
using lyx::pit_type;
|
||||||
using lyx::pos_type;
|
using lyx::pos_type;
|
||||||
using lyx::support::bformat;
|
|
||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::ostringstream;
|
using std::ostringstream;
|
||||||
@ -93,7 +85,7 @@ void LyXText::init(BufferView * bv)
|
|||||||
pars_[pit].rows().clear();
|
pars_[pit].rows().clear();
|
||||||
|
|
||||||
current_font = getFont(pars_[0], 0);
|
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 start = cur.selBegin().pit();
|
||||||
pit_type end = cur.selEnd().pit() + 1;
|
pit_type end = cur.selEnd().pit() + 1;
|
||||||
setLayout(start, end, layout);
|
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
|
// this handles the counter labels, and also fixes up
|
||||||
// depth values for follow-on (child) paragraphs
|
// 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.
|
// this really should just insert the inset and not move the cursor.
|
||||||
void LyXText::insertInset(LCursor & cur, InsetBase * inset)
|
void LyXText::insertInset(LCursor & cur, InsetBase * inset)
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "FloatList.h"
|
#include "FloatList.h"
|
||||||
#include "FuncStatus.h"
|
#include "FuncStatus.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
#include "buffer_funcs.h"
|
||||||
#include "bufferparams.h"
|
#include "bufferparams.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
@ -297,6 +298,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
|||||||
Paragraph & par = cur.paragraph();
|
Paragraph & par = cur.paragraph();
|
||||||
bool start = !par.params().startOfAppendix();
|
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
|
// ensure that we have only one start_of_appendix in this document
|
||||||
for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
|
for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
|
||||||
if (pars_[tmp].params().startOfAppendix()) {
|
if (pars_[tmp].params().startOfAppendix()) {
|
||||||
@ -310,7 +315,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
|||||||
par.params().startOfAppendix(start);
|
par.params().startOfAppendix(start);
|
||||||
|
|
||||||
// we can set the refreshing parameters now
|
// we can set the refreshing parameters now
|
||||||
updateCounters();
|
updateCounters(cur.buffer());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user