mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
updateCounters fix + changeDepth simplification
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8138 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
af37f0d23e
commit
2a6106ff5f
@ -1,3 +1,12 @@
|
||||
2003-11-26 Alfredo Braunstein <abraunst@lyx.org>
|
||||
|
||||
* bufferview_funcs.[Ch]: split changeDepthAllowed from changeDepth
|
||||
* lyxtext.h: ditto
|
||||
* text2.C: same thing + updateCounters fix + redoCursor also adjusts
|
||||
selection cursors
|
||||
* lyxfunc.C: adjust
|
||||
* text3.C: adjust + re-allow multi par depth changes
|
||||
* textcursor.C: simplify a bit
|
||||
|
||||
2003-11-25 Martin Vermeer <martin.vermeer@hut.fi>
|
||||
|
||||
|
@ -149,17 +149,20 @@ bool string2font(string const & data, LyXFont & font, bool & toggle)
|
||||
}
|
||||
|
||||
|
||||
bool changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type, bool test_only)
|
||||
bool changeDepthAllowed(BufferView * bv, LyXText * text, DEPTH_CHANGE type)
|
||||
{
|
||||
if (!bv->available() || !text)
|
||||
return false;
|
||||
|
||||
if (test_only)
|
||||
return text->changeDepth(type, true);
|
||||
return text->changeDepthAllowed(type);
|
||||
}
|
||||
|
||||
bool const changed = text->changeDepth(type, false);
|
||||
bv->update();
|
||||
return changed;
|
||||
|
||||
void changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type)
|
||||
{
|
||||
if (!bv->available() || !text)
|
||||
return;
|
||||
text->changeDepth(type);
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,12 +48,11 @@ enum DEPTH_CHANGE {
|
||||
DEC_DEPTH
|
||||
};
|
||||
|
||||
/**
|
||||
* Increase or decrease the nesting depth of the selected paragraph(s)
|
||||
* if test_only, don't change any depths. Returns whether something
|
||||
* (would have) changed
|
||||
*/
|
||||
bool changeDepth(BufferView *, LyXText *, DEPTH_CHANGE, bool test_only);
|
||||
/// Increase or decrease the nesting depth of the selected paragraph(s)
|
||||
void changeDepth(BufferView *, LyXText *, DEPTH_CHANGE);
|
||||
|
||||
/// Returns whether something would be changed by changeDepth
|
||||
bool changeDepthAllowed(BufferView *, LyXText *, DEPTH_CHANGE);
|
||||
|
||||
/// Returns the current font and depth as a message.
|
||||
std::string const currentState(BufferView *);
|
||||
|
@ -349,11 +349,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
|
||||
break;
|
||||
|
||||
case LFUN_DEPTH_MIN:
|
||||
disable = !changeDepth(view(), view()->getLyXText(), DEC_DEPTH, true);
|
||||
disable = !changeDepthAllowed(view(), view()->getLyXText(), DEC_DEPTH);
|
||||
break;
|
||||
|
||||
case LFUN_DEPTH_PLUS:
|
||||
disable = !changeDepth(view(), view()->getLyXText(), INC_DEPTH, true);
|
||||
disable = !changeDepthAllowed(view(), view()->getLyXText(), INC_DEPTH);
|
||||
break;
|
||||
|
||||
case LFUN_LAYOUT:
|
||||
|
@ -87,12 +87,11 @@ public:
|
||||
///
|
||||
void setLayout(std::string const & layout);
|
||||
|
||||
/**
|
||||
* Increase or decrease the nesting depth of the selected paragraph(s)
|
||||
* if test_only, don't change any depths. Returns whether something
|
||||
* (would have) changed
|
||||
*/
|
||||
bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
|
||||
/// Increase or decrease the nesting depth of the selected paragraph(s)
|
||||
void changeDepth(bv_funcs::DEPTH_CHANGE type);
|
||||
|
||||
/// Returns whether something would be changed by changeDepth
|
||||
bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type);
|
||||
|
||||
/// get the depth at current cursor position
|
||||
int getDepth() const;
|
||||
|
153
src/text2.C
153
src/text2.C
@ -393,79 +393,83 @@ void LyXText::setLayout(string const & layout)
|
||||
}
|
||||
|
||||
|
||||
bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
|
||||
namespace {
|
||||
|
||||
|
||||
void getSelectionSpan(LyXText & text,
|
||||
ParagraphList::iterator & beg,
|
||||
ParagraphList::iterator & end)
|
||||
{
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
ParagraphList::iterator end = pit;
|
||||
ParagraphList::iterator start = pit;
|
||||
|
||||
if (selection.set()) {
|
||||
pit = getPar(selection.start);
|
||||
end = getPar(selection.end);
|
||||
start = pit;
|
||||
if (!text.selection.set()) {
|
||||
beg = text.cursorPar();
|
||||
end = boost::next(beg);
|
||||
} else {
|
||||
beg = text.getPar(text.selection.start);
|
||||
end = boost::next(text.getPar(text.selection.end));
|
||||
}
|
||||
}
|
||||
|
||||
if (!test_only)
|
||||
recUndo(parOffset(start), parOffset(end));
|
||||
|
||||
bool changed = false;
|
||||
bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type,
|
||||
Paragraph const & par,
|
||||
int max_depth)
|
||||
{
|
||||
if (par.layout()->labeltype == LABEL_BIBLIO)
|
||||
return false;
|
||||
int const depth = par.params().depth();
|
||||
if (type == bv_funcs::INC_DEPTH && depth < max_depth)
|
||||
return true;
|
||||
if (type == bv_funcs::DEC_DEPTH && depth > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int prev_after_depth = 0;
|
||||
#warning parlist ... could be nicer ?
|
||||
if (start != ownerParagraphs().begin()) {
|
||||
prev_after_depth = boost::prior(start)->getMaxDepthAfter();
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool LyXText::changeDepthAllowed(bv_funcs::DEPTH_CHANGE type)
|
||||
{
|
||||
ParagraphList::iterator beg, end;
|
||||
getSelectionSpan(*this, beg, end);
|
||||
int max_depth = 0;
|
||||
if (beg != ownerParagraphs().begin())
|
||||
max_depth = boost::prior(beg)->getMaxDepthAfter();
|
||||
|
||||
for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
|
||||
if (::changeDepthAllowed(type, *pit, max_depth))
|
||||
return true;
|
||||
max_depth = pit->getMaxDepthAfter();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
int const depth = pit->params().depth();
|
||||
if (type == bv_funcs::INC_DEPTH) {
|
||||
if (depth < prev_after_depth
|
||||
&& pit->layout()->labeltype != LABEL_BIBLIO) {
|
||||
changed = true;
|
||||
if (!test_only)
|
||||
pit->params().depth(depth + 1);
|
||||
}
|
||||
} else if (depth) {
|
||||
changed = true;
|
||||
if (!test_only)
|
||||
|
||||
void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
|
||||
{
|
||||
ParagraphList::iterator beg, end;
|
||||
getSelectionSpan(*this, beg, end);
|
||||
|
||||
recUndo(parOffset(beg), parOffset(end) - 1);
|
||||
|
||||
int max_depth = 0;
|
||||
if (beg != ownerParagraphs().begin())
|
||||
max_depth = boost::prior(beg)->getMaxDepthAfter();
|
||||
|
||||
for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
|
||||
if (::changeDepthAllowed(type, *pit, max_depth)) {
|
||||
int const depth = pit->params().depth();
|
||||
if (type == bv_funcs::INC_DEPTH)
|
||||
pit->params().depth(depth + 1);
|
||||
else
|
||||
pit->params().depth(depth - 1);
|
||||
}
|
||||
|
||||
prev_after_depth = pit->getMaxDepthAfter();
|
||||
|
||||
#warning SERIOUS: Uahh... does this mean we access end->getMaxDepthAfter?
|
||||
if (pit == end) {
|
||||
break;
|
||||
}
|
||||
|
||||
++pit;
|
||||
max_depth = pit->getMaxDepthAfter();
|
||||
}
|
||||
|
||||
if (test_only)
|
||||
return changed;
|
||||
|
||||
redoParagraphs(start, boost::next(end));
|
||||
|
||||
// We need to actually move the text->cursor. I don't
|
||||
// understand why ...
|
||||
LyXCursor tmpcursor = cursor;
|
||||
|
||||
// we have to reset the visual selection because the
|
||||
// geometry could have changed
|
||||
if (selection.set()) {
|
||||
setCursor(selection.start.par(), selection.start.pos());
|
||||
selection.cursor = cursor;
|
||||
setCursor(selection.end.par(), selection.end.pos());
|
||||
}
|
||||
|
||||
// this handles the counter labels, and also fixes up
|
||||
// depth values for follow-on (child) paragraphs
|
||||
updateCounters();
|
||||
|
||||
setSelection();
|
||||
setCursor(tmpcursor.par(), tmpcursor.pos());
|
||||
|
||||
return changed;
|
||||
redoCursor();
|
||||
}
|
||||
|
||||
|
||||
@ -654,8 +658,7 @@ string LyXText::getStringToIndex()
|
||||
// they do not duplicate themself and you cannot play dirty tricks with
|
||||
// them!
|
||||
|
||||
void LyXText::setParagraph(
|
||||
VSpace const & space_top,
|
||||
void LyXText::setParagraph(VSpace const & space_top,
|
||||
VSpace const & space_bottom,
|
||||
Spacing const & spacing,
|
||||
LyXAlignment align,
|
||||
@ -720,7 +723,6 @@ void LyXText::setParagraph(
|
||||
setCursor(selection.end.par(), selection.end.pos());
|
||||
setSelection();
|
||||
setCursor(tmpcursor.par(), tmpcursor.pos());
|
||||
bv()->update();
|
||||
}
|
||||
|
||||
|
||||
@ -980,17 +982,18 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
|
||||
}
|
||||
|
||||
|
||||
// Updates all counters. Paragraphs with changed label string will be
|
||||
// not be rebroken as this is too expensive. The next round will get it
|
||||
// right anyway...
|
||||
// Updates all counters.
|
||||
void LyXText::updateCounters()
|
||||
{
|
||||
// start over
|
||||
bv()->buffer()->params().getLyXTextClass().counters().reset();
|
||||
|
||||
bool update_pos = false;
|
||||
|
||||
ParagraphList::iterator beg = ownerParagraphs().begin();
|
||||
ParagraphList::iterator end = ownerParagraphs().end();
|
||||
for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
|
||||
string const oldLabel = pit->params().labelString();
|
||||
size_t maxdepth = 0;
|
||||
if (pit != beg)
|
||||
maxdepth = boost::prior(pit)->getMaxDepthAfter();
|
||||
@ -1000,7 +1003,15 @@ void LyXText::updateCounters()
|
||||
|
||||
// setCounter can potentially change the labelString.
|
||||
setCounter(*bv()->buffer(), pit);
|
||||
string const & newLabel = pit->params().labelString();
|
||||
if (oldLabel != newLabel) {
|
||||
redoParagraphInternal(pit);
|
||||
update_pos = true;
|
||||
}
|
||||
|
||||
}
|
||||
if (update_pos)
|
||||
updateParPositions();
|
||||
}
|
||||
|
||||
|
||||
@ -1268,8 +1279,16 @@ bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont, bool bou
|
||||
|
||||
void LyXText::redoCursor()
|
||||
{
|
||||
#warning maybe the same for selections?
|
||||
setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
|
||||
|
||||
if (!selection.set())
|
||||
return;
|
||||
|
||||
LyXCursor tmpcursor = cursor;
|
||||
setCursor(selection.cursor.par(), selection.cursor.pos());
|
||||
selection.cursor = cursor;
|
||||
setCursor(tmpcursor.par(), tmpcursor.pos());
|
||||
setSelection();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1436,14 +1436,12 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_DEPTH_MIN:
|
||||
clearSelection();
|
||||
bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
|
||||
bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
|
||||
bv->update();
|
||||
break;
|
||||
|
||||
case LFUN_DEPTH_PLUS:
|
||||
clearSelection();
|
||||
bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
|
||||
bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
|
||||
bv->update();
|
||||
break;
|
||||
|
||||
|
@ -22,14 +22,8 @@ using std::string;
|
||||
|
||||
void TextCursor::setSelection()
|
||||
{
|
||||
if (!selection.set()) {
|
||||
selection.start = selection.cursor;
|
||||
selection.end = selection.cursor;
|
||||
}
|
||||
|
||||
selection.set(true);
|
||||
|
||||
// and now the whole selection
|
||||
if (selection.cursor.par() == cursor.par())
|
||||
if (selection.cursor.pos() < cursor.pos()) {
|
||||
selection.end = cursor;
|
||||
@ -43,8 +37,7 @@ void TextCursor::setSelection()
|
||||
&& selection.cursor.pos() < cursor.pos())) {
|
||||
selection.end = cursor;
|
||||
selection.start = selection.cursor;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
selection.end = selection.cursor;
|
||||
selection.start = cursor;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user