* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "AddPointCommand.h"
#include <stdio.h>
#include <Catalog.h>
#include <Locale.h>
#include "VectorPath.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddPointCmd"
AddPointCommand::AddPointCommand(VectorPath* path,
int32 index,
const int32* selected,
int32 count)
: PathCommand(path),
fIndex(index),
fOldSelection(NULL),
fOldSelectionCount(count)
{
if (fOldSelectionCount > 0 && selected) {
fOldSelection = new int32[fOldSelectionCount];
memcpy(fOldSelection, selected, fOldSelectionCount * sizeof(int32));
}
}
AddPointCommand::~AddPointCommand()
{
delete[] fOldSelection;
}
status_t
AddPointCommand::Perform()
{
status_t status = InitCheck();
if (status < B_OK)
return status;
if (!fPath->GetPointsAt(fIndex, fPoint, fPointIn, fPointOut))
status = B_NO_INIT;
return status;
}
status_t
AddPointCommand::Undo()
{
status_t status = InitCheck();
if (status < B_OK)
return status;
if (fPath->RemovePoint(fIndex)) {
_Select(fOldSelection, fOldSelectionCount);
} else {
status = B_ERROR;
}
return status;
}
status_t
AddPointCommand::Redo()
{
status_t status = InitCheck();
if (status < B_OK)
return status;
AutoNotificationSuspender _(fPath);
if (fPath->AddPoint(fPoint, fIndex)) {
fPath->SetPoint(fIndex, fPoint, fPointIn, fPointOut, true);
_Select(&fIndex, 1);
} else {
status = B_ERROR;
}
return status;
}
void
AddPointCommand::GetName(BString& name)
{
name << B_TRANSLATE("Add vertex");
}