[GB.QT4.EXT]
* NEW: Better undo/redo management. git-svn-id: svn://localhost/gambas/trunk@5293 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
6704db30ee
commit
6ec8947f88
@ -103,6 +103,7 @@ public:
|
|||||||
GCommandDocument(GDocument *doc);
|
GCommandDocument(GDocument *doc);
|
||||||
void process(GDocument *doc) const;
|
void process(GDocument *doc) const;
|
||||||
void print() const;
|
void print() const;
|
||||||
|
bool equals(GCommandDocument *o) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
GCommandDocument::GCommandDocument(GDocument *doc)
|
GCommandDocument::GCommandDocument(GDocument *doc)
|
||||||
@ -134,6 +135,12 @@ void GCommandDocument::print() const
|
|||||||
qDebug("- %d %d [%d %d %d %d]", cx, cy, sx, sy, sx2, sy2);
|
qDebug("- %d %d [%d %d %d %d]", cx, cy, sx, sy, sx2, sy2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GCommandDocument::equals(GCommandDocument *o) const
|
||||||
|
{
|
||||||
|
return view == o->view && cx == o->cx && cy == o->cy
|
||||||
|
&& sx == o->sx && sy == o->sy && sx2 == o->sx2 && sy2 == o->sy2;
|
||||||
|
}
|
||||||
|
|
||||||
class GCommand
|
class GCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -141,6 +148,7 @@ public:
|
|||||||
{
|
{
|
||||||
None, Begin, End, Move, Insert, Delete, Indent, Unindent
|
None, Begin, End, Move, Insert, Delete, Indent, Unindent
|
||||||
};
|
};
|
||||||
|
GCommandDocument info;
|
||||||
|
|
||||||
virtual ~GCommand() { }
|
virtual ~GCommand() { }
|
||||||
virtual Type type() const { return None; }
|
virtual Type type() const { return None; }
|
||||||
@ -156,7 +164,6 @@ class GBeginCommand: public GCommand
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool _linked;
|
bool _linked;
|
||||||
GCommandDocument info;
|
|
||||||
|
|
||||||
GBeginCommand(GCommandDocument *info, bool linked = false) { _linked = linked; this->info = *info; }
|
GBeginCommand(GCommandDocument *info, bool linked = false) { _linked = linked; this->info = *info; }
|
||||||
Type type() const { return Begin; }
|
Type type() const { return Begin; }
|
||||||
@ -184,7 +191,6 @@ class GDeleteCommand: public GCommand
|
|||||||
public:
|
public:
|
||||||
int x, y, x2, y2;
|
int x, y, x2, y2;
|
||||||
GString str;
|
GString str;
|
||||||
GCommandDocument info;
|
|
||||||
|
|
||||||
GDeleteCommand(GCommandDocument *info, int y, int x, int y2, int x2, const GString &str)
|
GDeleteCommand(GCommandDocument *info, int y, int x, int y2, int x2, const GString &str)
|
||||||
{
|
{
|
||||||
@ -205,13 +211,13 @@ public:
|
|||||||
if (info.view != o->info.view)
|
if (info.view != o->info.view)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (x2 != o->x || y2 != o->y)
|
if (x2 != o->x || y2 != o->y || o->y != o->y2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
o->str.prepend(str);
|
o->str.prepend(str);
|
||||||
o->x = x;
|
o->x = x;
|
||||||
o->y = y;
|
o->y = y;
|
||||||
o->info = info;
|
//o->info = info;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,19 +930,42 @@ void GDocument::addUndo(GCommand *c)
|
|||||||
{
|
{
|
||||||
if (c->merge(undoList.last()))
|
if (c->merge(undoList.last()))
|
||||||
{
|
{
|
||||||
//qDebug(" MERGE");
|
#if DEBUG_UNDO
|
||||||
|
qDebug(" MERGE");
|
||||||
|
#endif
|
||||||
delete c;
|
delete c;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (c->remove(undoList.last()))
|
else if (c->remove(undoList.last()))
|
||||||
{
|
{
|
||||||
//qDebug(" REMOVE");
|
#if DEBUG_UNDO
|
||||||
|
qDebug(" REMOVE");
|
||||||
|
#endif
|
||||||
delete c;
|
delete c;
|
||||||
delete undoList.take();
|
delete undoList.take();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c->type() == GCommand::End && undoList.count() >= 2 && undoList.at(undoList.count() - 2)->type() == GCommand::Begin)
|
||||||
|
{
|
||||||
|
GCommand *o = undoList.take();
|
||||||
|
GCommand *begin = undoList.take();
|
||||||
|
#if DEBUG_UNDO
|
||||||
|
qDebug(" NO BEGIN / END");
|
||||||
|
#endif
|
||||||
|
o->info = begin->info;
|
||||||
|
delete begin;
|
||||||
|
delete c;
|
||||||
|
addUndo(o);
|
||||||
|
return;
|
||||||
|
/*else
|
||||||
|
{
|
||||||
|
undoList.append(begin);
|
||||||
|
undoList.append(o);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
undoList.append(c);
|
undoList.append(c);
|
||||||
|
|
||||||
if (!redoList.isEmpty())
|
if (!redoList.isEmpty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user