2001-07-06 15:57:54 +00:00
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
2001-07-06 15:57:54 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2001-07-06 15:57:54 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "undo_funcs.h"
|
|
|
|
#include "lyxtext.h"
|
2003-05-16 07:44:00 +00:00
|
|
|
#include "funcrequest.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "buffer.h"
|
2003-02-20 17:39:48 +00:00
|
|
|
#include "insets/updatableinset.h"
|
2003-04-16 00:02:38 +00:00
|
|
|
#include "insets/insettext.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "debug.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
#include "support/LAssert.h"
|
2001-12-19 08:59:15 +00:00
|
|
|
#include "iterators.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::vector;
|
2002-05-26 19:40:17 +00:00
|
|
|
using boost::shared_ptr;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
/// The flag used by FinishUndo().
|
2001-07-06 15:57:54 +00:00
|
|
|
bool undo_finished;
|
2003-05-01 23:24:30 +00:00
|
|
|
/// Whether actions are not added to the undo stacks.
|
2001-07-06 15:57:54 +00:00
|
|
|
bool undo_frozen;
|
|
|
|
|
2002-05-26 19:40:17 +00:00
|
|
|
namespace {
|
2001-12-13 17:19:53 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
/// Utility to return the cursor.
|
2002-05-26 19:40:17 +00:00
|
|
|
LyXCursor const & undoCursor(BufferView * bv)
|
2001-07-06 15:57:54 +00:00
|
|
|
{
|
2002-05-26 19:40:17 +00:00
|
|
|
if (bv->theLockingInset())
|
|
|
|
return bv->theLockingInset()->cursor(bv);
|
|
|
|
return bv->text->cursor;
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
|
2002-05-26 19:40:17 +00:00
|
|
|
/**
|
2003-05-01 23:24:30 +00:00
|
|
|
* Returns a pointer to the very first Paragraph depending of where
|
|
|
|
* we are so it will return the first paragraph of the buffer or the
|
|
|
|
* first paragraph of the textinset we're in.
|
2002-05-26 19:40:17 +00:00
|
|
|
*/
|
2003-05-23 10:33:40 +00:00
|
|
|
ParagraphList * undoParagraphs(BufferView * bv, int inset_id)
|
2002-05-26 19:40:17 +00:00
|
|
|
{
|
|
|
|
Inset * inset = bv->buffer()->getInsetFromID(inset_id);
|
|
|
|
if (inset) {
|
2003-05-05 15:39:48 +00:00
|
|
|
ParagraphList * result = inset->getParagraphs(0);
|
|
|
|
if (result && !result->empty())
|
2003-05-23 10:33:40 +00:00
|
|
|
return result;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
2003-05-23 10:33:40 +00:00
|
|
|
return &bv->text->ownerParagraphs();
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-26 19:40:17 +00:00
|
|
|
/**
|
|
|
|
* Finish the undo operation in the case there was no entry
|
|
|
|
* on the stack to perform.
|
|
|
|
*/
|
|
|
|
void finishNoUndo(BufferView * bv)
|
2001-07-06 15:57:54 +00:00
|
|
|
{
|
2001-12-14 11:55:58 +00:00
|
|
|
freezeUndo();
|
|
|
|
bv->unlockInset(bv->theLockingInset());
|
2002-05-26 19:40:17 +00:00
|
|
|
finishUndo();
|
2003-03-17 16:25:00 +00:00
|
|
|
bv->text->postPaint(0);
|
2001-12-14 11:55:58 +00:00
|
|
|
unFreezeUndo();
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// Returns false if no undo possible.
|
2002-05-26 19:40:17 +00:00
|
|
|
bool textHandleUndo(BufferView * bv, Undo & undo)
|
2001-07-06 15:57:54 +00:00
|
|
|
{
|
2002-05-26 19:40:17 +00:00
|
|
|
Buffer * b = bv->buffer();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
ParIterator const before = b->getParFromID(undo.number_of_before_par);
|
|
|
|
ParIterator const behind = b->getParFromID(undo.number_of_behind_par);
|
|
|
|
ParIterator const end = b->par_iterator_end();
|
2002-05-26 19:40:17 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// If there's no before take the beginning
|
|
|
|
// of the document for redoing.
|
2003-05-22 08:01:41 +00:00
|
|
|
if (before == end) {
|
2002-05-26 19:40:17 +00:00
|
|
|
LyXText * t = bv->text;
|
|
|
|
int num = undo.number_of_inset_id;
|
|
|
|
if (undo.number_of_inset_id >= 0) {
|
|
|
|
Inset * in = bv->buffer()->getInsetFromID(num);
|
|
|
|
if (in) {
|
|
|
|
t = in->getLyXText(bv);
|
|
|
|
} else {
|
|
|
|
num = -1;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-23 10:33:40 +00:00
|
|
|
t->setCursorIntern(undoParagraphs(bv, num)->begin(), 0);
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2003-05-22 16:10:34 +00:00
|
|
|
// Set the right(new) inset-owner of the paragraph if there is any.
|
2003-05-02 14:44:50 +00:00
|
|
|
if (!undo.pars.empty()) {
|
2002-05-26 19:40:17 +00:00
|
|
|
Inset * in = 0;
|
2003-05-22 08:01:41 +00:00
|
|
|
if (before != end)
|
2002-05-26 19:40:17 +00:00
|
|
|
in = before->inInset();
|
|
|
|
else if (undo.number_of_inset_id >= 0)
|
|
|
|
in = bv->buffer()->getInsetFromID(undo.number_of_inset_id);
|
2003-05-02 14:44:50 +00:00
|
|
|
for (size_t i = 0, n = undo.pars.size(); i < n; ++i)
|
|
|
|
undo.pars[i]->setInsetOwner(in);
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-05-02 14:54:08 +00:00
|
|
|
// Replace the paragraphs with the undo informations.
|
2002-05-26 19:40:17 +00:00
|
|
|
vector<Paragraph *> deletelist;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// Now add old paragraphs to be deleted.
|
2003-05-22 08:01:41 +00:00
|
|
|
if (before != behind || (behind == end && before == end)) {
|
|
|
|
ParagraphList::iterator deletepar;
|
|
|
|
if (before != end) {
|
|
|
|
deletepar = *before;
|
|
|
|
++deletepar;
|
|
|
|
} else {
|
2003-05-23 10:33:40 +00:00
|
|
|
deletepar = undoParagraphs(bv, undo.number_of_inset_id)->begin();
|
2003-05-22 08:01:41 +00:00
|
|
|
}
|
2003-05-02 15:21:45 +00:00
|
|
|
// this surprisingly fills the undo! (Andre')
|
|
|
|
size_t par = 0;
|
2003-05-22 16:10:34 +00:00
|
|
|
//while (deletepar && deletepar != *behind)
|
2003-05-22 08:01:41 +00:00
|
|
|
while (deletepar != *behind) {
|
|
|
|
deletelist.push_back(&*deletepar);
|
|
|
|
++deletepar;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// A memory optimization for edit:
|
2002-05-26 19:40:17 +00:00
|
|
|
// Only layout information
|
|
|
|
// is stored in the undo. So restore
|
|
|
|
// the text informations.
|
|
|
|
if (undo.kind == Undo::EDIT) {
|
2003-05-02 15:21:45 +00:00
|
|
|
undo.pars[par]->setContentsFromPar(*deletelist.back());
|
|
|
|
++par;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-10-14 14:59:50 +00:00
|
|
|
// The order here is VERY IMPORTANT. We have to set the right
|
|
|
|
// next/prev pointer in the paragraphs so that a rebuild of
|
|
|
|
// the LyXText works!!!
|
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// Thread the end of the undo onto the par in front if any.
|
2003-05-02 14:54:08 +00:00
|
|
|
if (!undo.pars.empty()) {
|
2003-05-23 07:44:09 +00:00
|
|
|
#warning FIXME
|
|
|
|
//undo.pars.back()->next(&**behind);
|
|
|
|
//if (behind != end)
|
|
|
|
//(&**behind)->previous(undo.pars.back());
|
2002-10-14 14:59:50 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// Put the new stuff in the list if there is one.
|
2003-05-02 15:21:45 +00:00
|
|
|
Paragraph * undopar = undo.pars.empty() ? 0 : undo.pars.front();
|
|
|
|
if (!undo.pars.empty()) {
|
2003-05-23 07:44:09 +00:00
|
|
|
#warning FIXME
|
|
|
|
//undo.pars.front()->previous(&**before);
|
|
|
|
if (before != end) {
|
|
|
|
#warning FIXME
|
|
|
|
//(&**before)->next(undopar);
|
|
|
|
} else {
|
2003-05-23 10:33:40 +00:00
|
|
|
int id = undoParagraphs(bv, undo.number_of_inset_id)->begin()->id();
|
2003-05-22 08:01:41 +00:00
|
|
|
ParIterator op = bv->buffer()->getParFromID(id);
|
|
|
|
if (op != end && op->inInset()) {
|
2003-05-22 16:10:34 +00:00
|
|
|
#warning FIXME reimplementaion needed here
|
|
|
|
//static_cast<InsetText*>(op->inInset())->paragraph(undopar);
|
2003-04-16 00:02:38 +00:00
|
|
|
} else {
|
2003-05-22 16:10:34 +00:00
|
|
|
#warning FIXME reimplementation needed here
|
|
|
|
//bv->buffer()->paragraphs.set(undopar);
|
2003-04-16 00:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
2002-05-26 19:40:17 +00:00
|
|
|
} else {
|
2003-05-01 23:24:30 +00:00
|
|
|
// 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.
|
2003-05-22 08:01:41 +00:00
|
|
|
if (before == end && behind != end) {
|
2003-05-23 10:33:40 +00:00
|
|
|
int id = undoParagraphs(bv, undo.number_of_inset_id)->begin()->id();
|
2003-05-22 08:01:41 +00:00
|
|
|
ParIterator op = bv->buffer()->getParFromID(id);
|
|
|
|
if (op != end && op->inInset()) {
|
2003-05-22 16:10:34 +00:00
|
|
|
#warning FIXME reimplementation needed here
|
|
|
|
//static_cast<InsetText*>(op->inInset())->paragraph(&**behind);
|
2003-04-16 00:02:38 +00:00
|
|
|
} else {
|
2003-05-22 16:10:34 +00:00
|
|
|
#warning FIXME reimplementation needed here
|
|
|
|
//bv->buffer()->paragraphs.set(&**behind);
|
2003-04-16 00:02:38 +00:00
|
|
|
}
|
2003-05-22 08:01:41 +00:00
|
|
|
undopar = &**behind;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// Set the cursor for redoing.
|
|
|
|
// If we have a par before the undopar.
|
2003-05-22 08:01:41 +00:00
|
|
|
if (before != end) {
|
2002-05-26 19:40:17 +00:00
|
|
|
Inset * it = before->inInset();
|
|
|
|
if (it)
|
2003-05-22 08:01:41 +00:00
|
|
|
it->getLyXText(bv)->setCursorIntern(*before, 0);
|
2002-05-26 19:40:17 +00:00
|
|
|
else
|
2003-05-22 08:01:41 +00:00
|
|
|
bv->text->setCursorIntern(*before, 0);
|
2002-11-08 14:51:03 +00:00
|
|
|
}
|
2003-05-01 23:24:30 +00:00
|
|
|
|
2002-11-08 14:51:03 +00:00
|
|
|
// we are not ready for this we cannot set the cursor for a paragraph
|
|
|
|
// which is not already in a row of LyXText!!!
|
|
|
|
#if 0
|
|
|
|
else { // otherwise this is the first one and we start here
|
2002-10-14 14:59:50 +00:00
|
|
|
Inset * it = undopar->inInset();
|
|
|
|
if (it)
|
|
|
|
it->getLyXText(bv)->setCursorIntern(bv, undopar, 0);
|
|
|
|
else
|
|
|
|
bv->text->setCursorIntern(bv, undopar, 0);
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
2002-11-08 14:51:03 +00:00
|
|
|
#endif
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2003-04-29 15:24:37 +00:00
|
|
|
UpdatableInset * it = 0;
|
2002-08-24 22:02:30 +00:00
|
|
|
if (undopar)
|
|
|
|
it = static_cast<UpdatableInset*>(undopar->inInset());
|
2003-05-22 08:01:41 +00:00
|
|
|
|
|
|
|
LyXText * text = it ? it->getLyXText(bv) : bv->text;
|
|
|
|
|
|
|
|
ParagraphList::iterator endpar = text->ownerParagraphs().end();
|
|
|
|
|
|
|
|
// Calculate the endpar for redoing the paragraphs.
|
|
|
|
if (behind != end) {
|
|
|
|
endpar = *behind;
|
|
|
|
++endpar;
|
|
|
|
}
|
|
|
|
|
|
|
|
text->redoParagraphs(text->cursor, endpar);
|
|
|
|
ParIterator tmppar =
|
|
|
|
bv->buffer()->getParFromID(undo.number_of_cursor_par);
|
|
|
|
|
2003-05-22 15:16:58 +00:00
|
|
|
if (tmppar != end) {
|
|
|
|
LyXText * t;
|
|
|
|
Inset * it = tmppar->inInset();
|
|
|
|
if (it) {
|
|
|
|
FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
|
|
|
|
it->localDispatch(cmd);
|
|
|
|
t = it->getLyXText(bv);
|
|
|
|
} else {
|
|
|
|
t = bv->text;
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
2003-05-22 15:16:58 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it) {
|
|
|
|
bv->fitCursor();
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->updateInset(it);
|
2003-03-17 16:25:00 +00:00
|
|
|
bv->text->setCursorIntern(bv->text->cursor.par(),
|
2002-05-26 19:40:17 +00:00
|
|
|
bv->text->cursor.pos());
|
|
|
|
}
|
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// And here it's safe enough to delete all removed paragraphs.
|
2002-05-26 19:40:17 +00:00
|
|
|
vector<Paragraph *>::iterator pit = deletelist.begin();
|
2003-05-01 23:24:30 +00:00
|
|
|
for(; pit != deletelist.end(); ++pit) {
|
2003-05-23 07:44:09 +00:00
|
|
|
#warning FIXME
|
|
|
|
//(*pit)->previous(0);
|
|
|
|
//(*pit)->next(0);
|
2003-05-01 23:24:30 +00:00
|
|
|
delete (*pit);
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-05-02 14:54:08 +00:00
|
|
|
// Otherwise the undo destructor would delete the paragraphs
|
|
|
|
undo.pars.resize(0);
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2003-03-17 16:25:00 +00:00
|
|
|
bv->text->postPaint(0);
|
2002-05-26 19:40:17 +00:00
|
|
|
return true;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2002-05-26 19:40:17 +00:00
|
|
|
bool createUndo(BufferView * bv, Undo::undo_kind kind,
|
2003-05-23 10:33:40 +00:00
|
|
|
ParagraphList::iterator itfirst, ParagraphList::iterator itlast,
|
2003-04-29 14:05:54 +00:00
|
|
|
shared_ptr<Undo> & u)
|
2001-07-06 15:57:54 +00:00
|
|
|
{
|
2003-05-23 10:33:40 +00:00
|
|
|
Buffer * b = bv->buffer();
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2003-05-23 10:33:40 +00:00
|
|
|
ParIterator it = b->par_iterator_begin();
|
|
|
|
ParIterator null = b->par_iterator_end();
|
|
|
|
ParIterator prev = null;
|
|
|
|
ParIterator before = null;
|
|
|
|
ParIterator first = null;
|
|
|
|
ParIterator last = null;
|
|
|
|
ParIterator behind = null;
|
|
|
|
|
|
|
|
for (; it != null; ++it) {
|
|
|
|
if ((*it)->id() == itfirst->id()) {
|
|
|
|
first = it;
|
|
|
|
before = prev;
|
|
|
|
} else if ((*it)->id() == itlast->id()) {
|
|
|
|
last = it;
|
|
|
|
behind = last;
|
|
|
|
++behind;
|
|
|
|
}
|
|
|
|
prev = it;
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2003-05-23 10:33:40 +00:00
|
|
|
if (last == null)
|
|
|
|
last = first;
|
|
|
|
|
|
|
|
int const before_id = (before == null) ? -1 : (*before)->id();
|
|
|
|
int const first_id = (first == null) ? -1 : (*first)->id();
|
|
|
|
int const last_id = (last == null) ? -1 : (*last)->id();
|
|
|
|
int const behind_id = (behind == null) ? -1 : (*behind)->id();
|
|
|
|
int inset_id = (first->inInset()) ? first->inInset()->id() : -1;
|
|
|
|
|
|
|
|
lyxerr << "\nbefore_id: " << before_id << "\n";
|
|
|
|
lyxerr << "first_id: " << first_id << "\n";
|
|
|
|
lyxerr << "last_id: " << last_id << "\n";
|
|
|
|
lyxerr << "behind_id: " << behind_id << "\n";
|
|
|
|
lyxerr << "inset_id: " << inset_id << "\n";
|
|
|
|
|
|
|
|
ParagraphList * plist = 0;
|
|
|
|
if (first != null)
|
|
|
|
plist = &first.plist();
|
|
|
|
else if (behind != null)
|
|
|
|
plist = &behind.plist();
|
|
|
|
else if (!plist) {
|
|
|
|
lyxerr << "plist from buffer (should this happen?)\n";
|
|
|
|
plist = &b->paragraphs;
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-05-23 10:33:40 +00:00
|
|
|
// Undo::EDIT and Undo::FINISH are
|
2001-07-06 15:57:54 +00:00
|
|
|
// always finished. (no overlapping there)
|
2002-03-21 17:27:08 +00:00
|
|
|
// overlapping only with insert and delete inside one paragraph:
|
2001-07-06 15:57:54 +00:00
|
|
|
// Nobody wants all removed character
|
2002-03-21 17:27:08 +00:00
|
|
|
// appear one by one when undoing.
|
2001-07-06 15:57:54 +00:00
|
|
|
// EDIT is special since only layout information, not the
|
|
|
|
// contents of a paragaph are stored.
|
2002-02-16 15:59:55 +00:00
|
|
|
if (!undo_finished && (kind != Undo::EDIT) && (kind != Undo::FINISH)) {
|
2003-05-01 23:24:30 +00:00
|
|
|
// Check whether storing is needed.
|
2002-05-26 19:40:17 +00:00
|
|
|
if (!b->undostack.empty() &&
|
|
|
|
b->undostack.top()->kind == kind &&
|
2003-05-23 10:33:40 +00:00
|
|
|
b->undostack.top()->number_of_before_par == before_id &&
|
|
|
|
b->undostack.top()->number_of_behind_par == behind_id) {
|
2003-05-01 23:24:30 +00:00
|
|
|
// No undo needed.
|
2002-05-26 19:40:17 +00:00
|
|
|
return false;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// Create a new Undo.
|
2003-05-02 13:11:39 +00:00
|
|
|
std::vector<Paragraph *> undo_pars;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2003-05-23 10:33:40 +00:00
|
|
|
for (ParagraphList::iterator it = *first; it != *last; ++it)
|
|
|
|
undo_pars.push_back(new Paragraph(*it, true));
|
|
|
|
undo_pars.push_back(new Paragraph(**last, true));
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2003-05-02 13:38:53 +00:00
|
|
|
// A memory optimization: Just store the layout
|
|
|
|
// information when only edit.
|
2003-05-23 10:33:40 +00:00
|
|
|
if (kind == Undo::EDIT)
|
2003-05-02 13:38:53 +00:00
|
|
|
for (size_t i = 0, n = undo_pars.size(); i < n; ++i)
|
|
|
|
undo_pars[i]->clearContents();
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
int cursor_par = undoCursor(bv).par()->id();
|
2003-04-29 14:31:53 +00:00
|
|
|
int cursor_pos = undoCursor(bv).pos();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-05-23 10:33:40 +00:00
|
|
|
lyxerr << "createUndo: inset_id: " << inset_id << " before_id: "
|
|
|
|
<< before_id << " behind_id: " << behind_id << "\n";
|
2002-05-26 19:40:17 +00:00
|
|
|
u.reset(new Undo(kind, inset_id,
|
2003-05-23 10:33:40 +00:00
|
|
|
before_id, behind_id, cursor_par, cursor_pos, undo_pars));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
undo_finished = false;
|
2002-05-26 19:40:17 +00:00
|
|
|
return true;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 19:40:17 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// Returns false if no undo possible.
|
2003-04-29 14:50:11 +00:00
|
|
|
bool textUndoOrRedo(BufferView * bv,
|
|
|
|
limited_stack<boost::shared_ptr<Undo> > & stack,
|
2003-05-23 07:44:09 +00:00
|
|
|
limited_stack<boost::shared_ptr<Undo> > & /*otherstack*/)
|
2002-05-26 19:40:17 +00:00
|
|
|
{
|
2003-05-23 07:44:09 +00:00
|
|
|
//Buffer * b = bv->buffer();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-04-29 14:50:11 +00:00
|
|
|
if (stack.empty()) {
|
2002-05-26 19:40:17 +00:00
|
|
|
finishNoUndo(bv);
|
|
|
|
return false;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-04-29 14:50:11 +00:00
|
|
|
shared_ptr<Undo> undo = stack.top();
|
|
|
|
stack.pop();
|
2002-05-26 19:40:17 +00:00
|
|
|
finishUndo();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2002-05-26 19:40:17 +00:00
|
|
|
if (!undo_frozen) {
|
2003-05-22 08:01:41 +00:00
|
|
|
/*
|
|
|
|
ParIterator p = b->getParFromID(undo->number_of_before_par);
|
|
|
|
bool ok = false;
|
|
|
|
ParagraphList::iterator first;
|
|
|
|
// default constructed?
|
|
|
|
ParIterator const end = b->par_iterator_end();
|
|
|
|
if (p != end) {
|
|
|
|
first = p.par();
|
|
|
|
if (first->next())
|
|
|
|
first = first->next();
|
|
|
|
} else
|
2003-05-23 10:33:40 +00:00
|
|
|
first = undoParagraphs(bv, undo->number_of_inset_id)->begin();
|
2002-05-26 19:40:17 +00:00
|
|
|
if (first) {
|
|
|
|
shared_ptr<Undo> u;
|
2003-05-22 08:01:41 +00:00
|
|
|
ParIterator behind = b->getParFromID(undo->number_of_behind_par);
|
|
|
|
if (createUndo(bv, undo->kind, first, behind.par(), u))
|
2003-04-29 14:50:11 +00:00
|
|
|
otherstack.push(u);
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
2003-05-22 08:01:41 +00:00
|
|
|
*/
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
// 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.
|
2002-05-26 19:40:17 +00:00
|
|
|
freezeUndo();
|
|
|
|
bv->unlockInset(bv->theLockingInset());
|
|
|
|
bool const ret = textHandleUndo(bv, *undo.get());
|
|
|
|
unFreezeUndo();
|
|
|
|
return ret;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2003-04-29 14:50:11 +00:00
|
|
|
} // namespace anon
|
2001-12-13 17:19:53 +00:00
|
|
|
|
2003-05-01 23:24:30 +00:00
|
|
|
|
2003-04-29 14:50:11 +00:00
|
|
|
void finishUndo()
|
2001-07-06 15:57:54 +00:00
|
|
|
{
|
2003-05-01 23:24:30 +00:00
|
|
|
// Makes sure the next operation will be stored.
|
2003-04-29 14:50:11 +00:00
|
|
|
undo_finished = true;
|
|
|
|
}
|
2002-05-26 19:40:17 +00:00
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-04-29 14:50:11 +00:00
|
|
|
void freezeUndo()
|
|
|
|
{
|
2003-05-01 23:24:30 +00:00
|
|
|
// This is dangerous and for internal use only.
|
2003-04-29 14:50:11 +00:00
|
|
|
undo_frozen = true;
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
|
|
|
2003-04-29 14:50:11 +00:00
|
|
|
void unFreezeUndo()
|
|
|
|
{
|
2003-05-01 23:24:30 +00:00
|
|
|
// This is dangerous and for internal use only.
|
2003-04-29 14:50:11 +00:00
|
|
|
undo_frozen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool textUndo(BufferView * bv)
|
|
|
|
{
|
2003-05-01 23:24:30 +00:00
|
|
|
return textUndoOrRedo(bv, bv->buffer()->undostack,
|
|
|
|
bv->buffer()->redostack);
|
2003-04-29 14:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool textRedo(BufferView * bv)
|
|
|
|
{
|
2003-05-01 23:24:30 +00:00
|
|
|
return textUndoOrRedo(bv, bv->buffer()->redostack,
|
|
|
|
bv->buffer()->undostack);
|
2002-05-26 19:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setUndo(BufferView * bv, Undo::undo_kind kind,
|
2003-05-23 10:33:40 +00:00
|
|
|
ParagraphList::iterator first)
|
2002-05-26 19:40:17 +00:00
|
|
|
{
|
2003-05-23 10:33:40 +00:00
|
|
|
setUndo(bv, kind, first, first);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setUndo(BufferView * bv, Undo::undo_kind kind,
|
|
|
|
ParagraphList::iterator first, ParagraphList::iterator last)
|
|
|
|
{
|
|
|
|
#warning DISABLED
|
|
|
|
return;
|
2002-05-26 19:40:17 +00:00
|
|
|
if (!undo_frozen) {
|
|
|
|
shared_ptr<Undo> u;
|
2003-05-23 10:33:40 +00:00
|
|
|
if (createUndo(bv, kind, first, last, u))
|
2002-05-26 19:40:17 +00:00
|
|
|
bv->buffer()->undostack.push(u);
|
|
|
|
bv->buffer()->redostack.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setCursorParUndo(BufferView * bv)
|
|
|
|
{
|
2003-05-23 10:33:40 +00:00
|
|
|
setUndo(bv, Undo::FINISH, bv->text->cursor.par());
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|