Implemented DataEditor::Redo(), and RemoveRedos(); the latter will now be
called by AddChange(). Fixed ApplyChanges() to only apply changes up to (and incl.) the last change; it won't apply all changes anymore. DataEditor::Undo() and Redo() now lock themselves. Added some more simple tests to DiskProbe. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6102 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -248,6 +248,8 @@ DataEditor::AddChange(DataChange *change)
|
|||||||
if (change == NULL)
|
if (change == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
RemoveRedos();
|
||||||
|
|
||||||
fChanges.AddItem(change);
|
fChanges.AddItem(change);
|
||||||
fLastChange = change;
|
fLastChange = change;
|
||||||
}
|
}
|
||||||
@@ -299,7 +301,10 @@ DataEditor::Insert(off_t offset, const uint8 *text, size_t length)
|
|||||||
void
|
void
|
||||||
DataEditor::ApplyChanges()
|
DataEditor::ApplyChanges()
|
||||||
{
|
{
|
||||||
int32 count = fChanges.CountItems();
|
if (fLastChange == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int32 count = fChanges.IndexOf(fLastChange) + 1;
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
DataChange *change = fChanges.ItemAt(i);
|
DataChange *change = fChanges.ItemAt(i);
|
||||||
@@ -308,15 +313,32 @@ DataEditor::ApplyChanges()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** This method will be called by DataEditor::AddChange()
|
||||||
|
* immediately before a change is applied.
|
||||||
|
* It removes all pending redo nodes from the list that would
|
||||||
|
* come after the current change.
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
DataEditor::RemoveRedos()
|
DataEditor::RemoveRedos()
|
||||||
{
|
{
|
||||||
|
if (fLastChange == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int32 start = fChanges.IndexOf(fLastChange) + 1;
|
||||||
|
|
||||||
|
for (int32 i = fChanges.CountItems(); i-- > start; ) {
|
||||||
|
DataChange *change = fChanges.RemoveItemAt(i);
|
||||||
|
delete change;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DataEditor::Undo()
|
DataEditor::Undo()
|
||||||
{
|
{
|
||||||
|
BAutolock locker(fLock);
|
||||||
|
|
||||||
if (!CanUndo())
|
if (!CanUndo())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -335,6 +357,17 @@ DataEditor::Undo()
|
|||||||
status_t
|
status_t
|
||||||
DataEditor::Redo()
|
DataEditor::Redo()
|
||||||
{
|
{
|
||||||
|
BAutolock locker(fLock);
|
||||||
|
|
||||||
|
if (!CanRedo())
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
int32 index = fChanges.IndexOf(fLastChange);
|
||||||
|
fLastChange = fChanges.ItemAt(index + 1);
|
||||||
|
|
||||||
|
fLastChange->Apply(fRealViewOffset, fView, fRealViewSize);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -348,7 +381,7 @@ DataEditor::CanUndo() const
|
|||||||
bool
|
bool
|
||||||
DataEditor::CanRedo() const
|
DataEditor::CanRedo() const
|
||||||
{
|
{
|
||||||
return fLastChange != NULL && fChanges.IndexOf(fLastChange) < fChanges.CountItems() - 1;
|
return fChanges.IndexOf(fLastChange) < fChanges.CountItems() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -131,6 +131,29 @@ DiskProbe::DiskProbe()
|
|||||||
if (printBlock(editor, "undo (location 0):") < B_OK)
|
if (printBlock(editor, "undo (location 0):") < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
status = editor.Redo();
|
||||||
|
if (status < B_OK)
|
||||||
|
fprintf(stderr, "Could not redo: %s\n", strerror(status));
|
||||||
|
if (printBlock(editor, "redo (location 0):") < B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
status = editor.Redo();
|
||||||
|
editor.SetViewOffset(700);
|
||||||
|
if (status < B_OK)
|
||||||
|
fprintf(stderr, "Could not redo: %s\n", strerror(status));
|
||||||
|
if (printBlock(editor, "redo (location 700):") < B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
status = editor.Redo();
|
||||||
|
if (status == B_OK)
|
||||||
|
fprintf(stderr, "Could apply redo (non-expected behaviour)!\n");
|
||||||
|
|
||||||
|
status = editor.Undo();
|
||||||
|
if (status < B_OK)
|
||||||
|
fprintf(stderr, "Could not undo: %s\n", strerror(status));
|
||||||
|
if (printBlock(editor, "undo (location 700):") < B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user