#include "lyxtext.h"
#include "BufferView.h"
#include "buffer.h"
-#include "insets/inset.h"
+#include "insets/updatableinset.h"
+#include "insets/insettext.h"
#include "debug.h"
#include "support/LAssert.h"
if (result)
return result;
}
- return bv->text->ownerParagraph();
+ return &*bv->text->ownerParagraphs().begin();
}
freezeUndo();
bv->unlockInset(bv->theLockingInset());
finishUndo();
- bv->text->status(bv, LyXText::NEED_MORE_REFRESH);
+ bv->text->postPaint(0);
unFreezeUndo();
}
{
Buffer * b = bv->buffer();
- Paragraph * before =
- b->getParFromID(undo.number_of_before_par);
- Paragraph * behind =
- b->getParFromID(undo.number_of_behind_par);
- Paragraph * tmppar;
- Paragraph * tmppar2;
+ Paragraph * const before = &*b->getParFromID(undo.number_of_before_par);
+ Paragraph * const behind = &*b->getParFromID(undo.number_of_behind_par);
// if there's no before take the beginning
// of the document for redoing
num = -1;
}
}
- t->setCursorIntern(bv, firstUndoParagraph(bv, num), 0);
+ t->setCursorIntern(firstUndoParagraph(bv, num), 0);
}
// replace the paragraphs with the undo informations
Paragraph * undopar = undo.par;
undo.par = 0; /* otherwise the undo destructor would
- delete the paragraph */
+ delete the paragraph */
// get last undo par and set the right(new) inset-owner of the
// paragraph if there is any. This is not needed if we don't have
vector<Paragraph *> deletelist;
- Paragraph * deletepar;
-
// now add old paragraphs to be deleted
if (before != behind || (!behind && !before)) {
+ Paragraph * deletepar;
if (before)
deletepar = before->next();
else
deletepar = firstUndoParagraph(bv, undo.number_of_inset_id);
- tmppar2 = undopar;
+ Paragraph * tmppar2 = undopar;
while (deletepar && deletepar != behind) {
deletelist.push_back(deletepar);
- tmppar = deletepar;
+ Paragraph * tmppar = deletepar;
deletepar = deletepar->next();
// a memory optimization for edit:
// is stored in the undo. So restore
// the text informations.
if (undo.kind == Undo::EDIT) {
- tmppar2->setContentsFromPar(tmppar);
+ tmppar2->setContentsFromPar(*tmppar);
tmppar2 = tmppar2->next();
}
}
undopar->previous(before);
if (before)
before->next(undopar);
- else
- bv->text->ownerParagraph(firstUndoParagraph(bv, undo.number_of_inset_id)->id(),
- undopar);
-
+ else {
+ int id = firstUndoParagraph(bv, undo.number_of_inset_id)->id();
+ Paragraph * op = &*bv->buffer()->getParFromID(id);
+ if (op && op->inInset()) {
+ static_cast<InsetText*>(op->inInset())->paragraph(undopar);
+ } else {
+ bv->buffer()->paragraphs.set(undopar);
+ }
+ }
} else {
// We enter here on DELETE undo operations where we have to
// substitue the second paragraph with the first if the removed
// one is the first!
if (!before && behind) {
- bv->text->ownerParagraph(firstUndoParagraph(bv, undo.number_of_inset_id)->id(),
- behind);
+ int id = firstUndoParagraph(bv, undo.number_of_inset_id)->id();
+ Paragraph * op = &*bv->buffer()->getParFromID(id);
+ if (op && op->inInset()) {
+ static_cast<InsetText*>(op->inInset())->paragraph(behind);
+ } else {
+ bv->buffer()->paragraphs.set(behind);
+ }
+
undopar = behind;
}
}
if (before) { // if we have a par before the undopar
Inset * it = before->inInset();
if (it)
- it->getLyXText(bv)->setCursorIntern(bv, before, 0);
+ it->getLyXText(bv)->setCursorIntern(before, 0);
else
- bv->text->setCursorIntern(bv, before, 0);
+ bv->text->setCursorIntern(before, 0);
}
// we are not ready for this we cannot set the cursor for a paragraph
// which is not already in a row of LyXText!!!
if (behind)
endpar = behind->next();
- tmppar = bv->buffer()->getParFromID(undo.number_of_cursor_par);
- UpdatableInset* it = 0;
+ UpdatableInset * it = 0;
if (undopar)
it = static_cast<UpdatableInset*>(undopar->inInset());
if (it) {
- it->getLyXText(bv)->redoParagraphs(bv,
+ it->getLyXText(bv)->redoParagraphs(
it->getLyXText(bv)->cursor,
endpar);
+ Paragraph * tmppar =
+ &*bv->buffer()->getParFromID(undo.number_of_cursor_par);
if (tmppar) {
it = static_cast<UpdatableInset*>(tmppar->inInset());
LyXText * t;
} else {
t = bv->text;
}
- t->setCursorIntern(bv, tmppar, undo.cursor_pos);
+ t->setCursorIntern(tmppar, undo.cursor_pos);
// clear any selection and set the selection cursor
// for an evt. new selection.
t->clearSelection();
t->selection.cursor = t->cursor;
- t->updateCounters(bv);
+ t->updateCounters();
bv->fitCursor();
}
- bv->updateInset(it, false);
- bv->text->setCursorIntern(bv, bv->text->cursor.par(),
+ bv->updateInset(it);
+ bv->text->setCursorIntern(bv->text->cursor.par(),
bv->text->cursor.pos());
} else {
- bv->text->redoParagraphs(bv, bv->text->cursor, endpar);
+ bv->text->redoParagraphs(bv->text->cursor, endpar);
+ Paragraph * tmppar =
+ &*bv->buffer()->getParFromID(undo.number_of_cursor_par);
if (tmppar) {
LyXText * t;
Inset * it = tmppar->inInset();
} else {
t = bv->text;
}
- t->setCursorIntern(bv, tmppar, undo.cursor_pos);
+ t->setCursorIntern(tmppar, undo.cursor_pos);
// clear any selection and set the selection cursor
// for an evt. new selection.
t->clearSelection();
t->selection.cursor = t->cursor;
- t->updateCounters(bv);
+ t->updateCounters();
}
}
}
finishUndo();
- bv->text->status(bv, LyXText::NEED_MORE_REFRESH);
+ bv->text->postPaint(0);
return true;
}
bool createUndo(BufferView * bv, Undo::undo_kind kind,
- Paragraph const * first, Paragraph const * behind, shared_ptr<Undo> & u)
+ ParagraphList::iterator itfirst, ParagraphList::iterator itbehind,
+ shared_ptr<Undo> & u)
{
+ Paragraph * first = &*itfirst;
+ Paragraph * behind = &*itbehind;
lyx::Assert(first);
int before_number = -1;
}
// create a new Undo
- Paragraph * undopar;
+ Paragraph * undopar = 0; // nothing to replace (undo of delete maybe)
- Paragraph * start = const_cast<Paragraph *>(first);
+ Paragraph * start = first;
Paragraph * end = 0;
if (behind)
tmppar2 = tmppar2->next();
}
tmppar2->next(0);
- } else
- undopar = 0; // nothing to replace (undo of delete maybe)
+ }
int cursor_par = undoCursor(bv).par()->id();
- int cursor_pos = undoCursor(bv).pos();
+ int cursor_pos = undoCursor(bv).pos();
u.reset(new Undo(kind, inset_id,
before_number, behind_number,
return true;
}
-} // namespace anon
-
-void finishUndo()
-{
- // makes sure the next operation will be stored
- undo_finished = true;
-}
-
-
-void freezeUndo()
-{
- // this is dangerous and for internal use only
- undo_frozen = true;
-}
-
-
-void unFreezeUndo()
-{
- // this is dangerous and for internal use only
- undo_frozen = false;
-}
-
// returns false if no undo possible
-bool textUndo(BufferView * bv)
+bool textUndoOrRedo(BufferView * bv,
+ limited_stack<boost::shared_ptr<Undo> > & stack,
+ limited_stack<boost::shared_ptr<Undo> > & otherstack)
{
Buffer * b = bv->buffer();
- if (b->undostack.empty()) {
+ if (stack.empty()) {
finishNoUndo(bv);
return false;
}
- shared_ptr<Undo> undo = b->undostack.top();
- b->undostack.pop();
+ shared_ptr<Undo> undo = stack.top();
+ stack.pop();
finishUndo();
if (!undo_frozen) {
- Paragraph * first = b->getParFromID(undo->number_of_before_par);
+ Paragraph * first = &*b->getParFromID(undo->number_of_before_par);
if (first && first->next())
first = first->next();
else if (!first)
if (first) {
shared_ptr<Undo> u;
if (createUndo(bv, undo->kind, first,
- b->getParFromID(undo->number_of_behind_par), u))
- b->redostack.push(u);
+ b->getParFromID(undo->number_of_behind_par), u))
+ otherstack.push(u);
}
}
return ret;
}
+} // namespace anon
-// returns false if no redo possible
-bool textRedo(BufferView * bv)
+void finishUndo()
{
- Buffer * b = bv->buffer();
+ // makes sure the next operation will be stored
+ undo_finished = true;
+}
- if (b->redostack.empty()) {
- finishNoUndo(bv);
- return false;
- }
- shared_ptr<Undo> undo = b->redostack.top();
- b->redostack.pop();
- finishUndo();
+void freezeUndo()
+{
+ // this is dangerous and for internal use only
+ undo_frozen = true;
+}
- if (!undo_frozen) {
- Paragraph * first = bv->buffer()->getParFromID(undo->number_of_before_par);
- if (first && first->next())
- first = first->next();
- else if (!first)
- first = firstUndoParagraph(bv, undo->number_of_inset_id);
- if (first) {
- shared_ptr<Undo> u;
- if (createUndo(bv, undo->kind, first,
- bv->buffer()->getParFromID(undo->number_of_behind_par), u))
- bv->buffer()->undostack.push(u);
- }
- }
- // now we can unlock the inset for saftey because the inset pointer could
- // be changed during the undo-function. Anyway if needed we have to lock
- // the right inset/position if this is requested.
- freezeUndo();
- bv->unlockInset(bv->theLockingInset());
- bool ret = textHandleUndo(bv, *undo.get());
- unFreezeUndo();
- return ret;
+void unFreezeUndo()
+{
+ // this is dangerous and for internal use only
+ undo_frozen = false;
+}
+
+
+bool textUndo(BufferView * bv)
+{
+ return textUndoOrRedo(bv, bv->buffer()->undostack, bv->buffer()->redostack);
+}
+
+
+bool textRedo(BufferView * bv)
+{
+ return textUndoOrRedo(bv, bv->buffer()->redostack, bv->buffer()->undostack);
}
void setUndo(BufferView * bv, Undo::undo_kind kind,
- Paragraph const * first, Paragraph const * behind)
+ ParagraphList::iterator first, ParagraphList::iterator behind)
{
if (!undo_frozen) {
shared_ptr<Undo> u;
void setRedo(BufferView * bv, Undo::undo_kind kind,
- Paragraph const * first, Paragraph const * behind)
+ ParagraphList::iterator first, ParagraphList::iterator behind)
{
shared_ptr<Undo> u;
if (createUndo(bv, kind, first, behind, u))
void setCursorParUndo(BufferView * bv)
{
setUndo(bv, Undo::FINISH, bv->text->cursor.par(),
- bv->text->cursor.par()->next());
+ boost::next(bv->text->cursor.par()));
}