mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 05:40:59 +00:00
* 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:
parent
507be88a4f
commit
4b8025d992
@ -1,7 +1,11 @@
|
|||||||
|
|
||||||
2003-05-02 André Pönitz <poenitz@gmx.net>
|
2003-05-02 André Pönitz <poenitz@gmx.net>
|
||||||
|
|
||||||
* buffer.[Ch]: two instances of Paragraph * -> ParagraphList::iterator
|
* 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>
|
2003-05-02 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||||
|
|
||||||
|
14
src/undo.C
14
src/undo.C
@ -17,7 +17,8 @@
|
|||||||
Undo::Undo(undo_kind kind_arg, int id_inset_arg,
|
Undo::Undo(undo_kind kind_arg, int id_inset_arg,
|
||||||
int number_before_arg, int number_behind_arg,
|
int number_before_arg, int number_behind_arg,
|
||||||
int cursor_par_arg, int cursor_pos_arg,
|
int cursor_par_arg, int cursor_pos_arg,
|
||||||
Paragraph * par_arg)
|
std::vector<Paragraph *> const & par_arg)
|
||||||
|
: pars(par_arg)
|
||||||
{
|
{
|
||||||
kind = kind_arg;
|
kind = kind_arg;
|
||||||
number_of_inset_id = id_inset_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_behind_par = number_behind_arg;
|
||||||
number_of_cursor_par = cursor_par_arg;
|
number_of_cursor_par = cursor_par_arg;
|
||||||
cursor_pos = cursor_pos_arg;
|
cursor_pos = cursor_pos_arg;
|
||||||
par = par_arg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Undo::~Undo()
|
Undo::~Undo()
|
||||||
{
|
{
|
||||||
Paragraph * tmppar;
|
std::vector<Paragraph *>::iterator it = pars.begin();
|
||||||
while (par) {
|
std::vector<Paragraph *>::iterator end = pars.end();
|
||||||
tmppar = par;
|
for ( ; it != end; ++it)
|
||||||
par = par->next();
|
delete *it;
|
||||||
delete tmppar;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#ifndef UNDO_H
|
#ifndef UNDO_H
|
||||||
#define UNDO_H
|
#define UNDO_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class Paragraph;
|
class Paragraph;
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -41,12 +43,12 @@ public:
|
|||||||
///
|
///
|
||||||
int cursor_pos; // valid if >= 0
|
int cursor_pos; // valid if >= 0
|
||||||
///
|
///
|
||||||
Paragraph * par;
|
std::vector<Paragraph *> pars;
|
||||||
///
|
///
|
||||||
Undo(undo_kind kind_arg, int id_inset_arg,
|
Undo(undo_kind kind_arg, int id_inset_arg,
|
||||||
int number_before_arg, int number_behind_arg,
|
int number_before_arg, int number_behind_arg,
|
||||||
int cursor_par_arg, int cursor_pos_arg,
|
int cursor_par_arg, int cursor_pos_arg,
|
||||||
Paragraph * par_arg);
|
std::vector<Paragraph *> const & par_arg);
|
||||||
///
|
///
|
||||||
~Undo();
|
~Undo();
|
||||||
};
|
};
|
||||||
|
@ -99,10 +99,10 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
|
|||||||
|
|
||||||
// Replace the paragraphs with the undo informations.
|
// 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
|
// Otherwise the undo destructor would
|
||||||
// delete the paragraph.
|
// delete the paragraph.
|
||||||
undo.par = 0;
|
undo.pars.resize(0);
|
||||||
|
|
||||||
// Get last undo par and set the right(new) inset-owner of the
|
// 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
|
// 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.
|
// Create a new Undo.
|
||||||
Paragraph * undopar = 0;
|
std::vector<Paragraph *> undo_pars;
|
||||||
|
|
||||||
Paragraph * start = first;
|
Paragraph * start = first;
|
||||||
Paragraph * end = 0;
|
Paragraph * end = 0;
|
||||||
@ -342,29 +342,27 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
|
|||||||
((before_number < 0) && (behind_number < 0))))
|
((before_number < 0) && (behind_number < 0))))
|
||||||
{
|
{
|
||||||
Paragraph * tmppar = start;
|
Paragraph * tmppar = start;
|
||||||
Paragraph * tmppar2 = new Paragraph(*tmppar, true);
|
undo_pars.push_back(new Paragraph(*tmppar, true));
|
||||||
|
|
||||||
// A memory optimization: Just store the layout
|
// A memory optimization: Just store the layout
|
||||||
// information when only edit.
|
// information when only edit.
|
||||||
if (kind == Undo::EDIT) {
|
if (kind == Undo::EDIT) {
|
||||||
tmppar2->clearContents();
|
undo_pars.back()->clearContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
undopar = tmppar2;
|
|
||||||
|
|
||||||
while (tmppar != end && tmppar->next()) {
|
while (tmppar != end && tmppar->next()) {
|
||||||
tmppar = 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
|
// a memory optimization: Just store the layout
|
||||||
// information when only edit
|
// information when only edit
|
||||||
if (kind == Undo::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();
|
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,
|
u.reset(new Undo(kind, inset_id,
|
||||||
before_number, behind_number,
|
before_number, behind_number,
|
||||||
cursor_par, cursor_pos, undopar));
|
cursor_par, cursor_pos, undo_pars));
|
||||||
|
|
||||||
undo_finished = false;
|
undo_finished = false;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user