* undo_funcs.C:

* undo.[Ch]: rely on std::vector<Paragraph *> instead of manually
    linked lists


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6923 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-05-02 13:11:39 +00:00
parent 507be88a4f
commit 4b8025d992
4 changed files with 27 additions and 25 deletions

View File

@ -3,6 +3,10 @@
* buffer.[Ch]: two instances of Paragraph * -> ParagraphList::iterator
* undo_funcs.C:
* undo.[Ch]: rely on std::vector<Paragraph *> instead of manually
linked lists
2003-05-02 Lars Gullik Bjønnes <larsbj@gullik.net>
* undo_funcs.C: almost only ws changes.

View File

@ -17,7 +17,8 @@
Undo::Undo(undo_kind kind_arg, int id_inset_arg,
int number_before_arg, int number_behind_arg,
int cursor_par_arg, int cursor_pos_arg,
Paragraph * par_arg)
std::vector<Paragraph *> const & par_arg)
: pars(par_arg)
{
kind = kind_arg;
number_of_inset_id = id_inset_arg;
@ -25,16 +26,13 @@ Undo::Undo(undo_kind kind_arg, int id_inset_arg,
number_of_behind_par = number_behind_arg;
number_of_cursor_par = cursor_par_arg;
cursor_pos = cursor_pos_arg;
par = par_arg;
}
Undo::~Undo()
{
Paragraph * tmppar;
while (par) {
tmppar = par;
par = par->next();
delete tmppar;
}
std::vector<Paragraph *>::iterator it = pars.begin();
std::vector<Paragraph *>::iterator end = pars.end();
for ( ; it != end; ++it)
delete *it;
}

View File

@ -12,6 +12,8 @@
#ifndef UNDO_H
#define UNDO_H
#include <vector>
class Paragraph;
///
@ -41,12 +43,12 @@ public:
///
int cursor_pos; // valid if >= 0
///
Paragraph * par;
std::vector<Paragraph *> pars;
///
Undo(undo_kind kind_arg, int id_inset_arg,
int number_before_arg, int number_behind_arg,
int cursor_par_arg, int cursor_pos_arg,
Paragraph * par_arg);
std::vector<Paragraph *> const & par_arg);
///
~Undo();
};

View File

@ -99,10 +99,10 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
// Replace the paragraphs with the undo informations.
Paragraph * undopar = undo.par;
Paragraph * undopar = undo.pars.empty() ? 0 : undo.pars[0];
// Otherwise the undo destructor would
// delete the paragraph.
undo.par = 0;
undo.pars.resize(0);
// 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
@ -325,7 +325,7 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
}
// Create a new Undo.
Paragraph * undopar = 0;
std::vector<Paragraph *> undo_pars;
Paragraph * start = first;
Paragraph * end = 0;
@ -342,29 +342,27 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
((before_number < 0) && (behind_number < 0))))
{
Paragraph * tmppar = start;
Paragraph * tmppar2 = new Paragraph(*tmppar, true);
undo_pars.push_back(new Paragraph(*tmppar, true));
// A memory optimization: Just store the layout
// information when only edit.
if (kind == Undo::EDIT) {
tmppar2->clearContents();
undo_pars.back()->clearContents();
}
undopar = tmppar2;
while (tmppar != end && tmppar->next()) {
tmppar = tmppar->next();
tmppar2->next(new Paragraph(*tmppar, true));
undo_pars.push_back(new Paragraph(*tmppar, true));
size_t const n = undo_pars.size();
undo_pars[n - 2]->next(undo_pars[n - 1]);
undo_pars[n - 1]->previous(undo_pars[n - 2]);
// a memory optimization: Just store the layout
// information when only edit
if (kind == Undo::EDIT) {
tmppar2->clearContents();
undo_pars.back()->clearContents();
}
tmppar2->next()->previous(tmppar2);
tmppar2 = tmppar2->next();
}
tmppar2->next(0);
undo_pars.back()->next(0);
}
int cursor_par = undoCursor(bv).par()->id();
@ -372,7 +370,7 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
u.reset(new Undo(kind, inset_id,
before_number, behind_number,
cursor_par, cursor_pos, undopar));
cursor_par, cursor_pos, undo_pars));
undo_finished = false;
return true;