2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "RemoveShapesCommand.h"
18 #include "ShapeContainer.h"
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemoveShapesCmd"
29 RemoveShapesCommand::RemoveShapesCommand(ShapeContainer
* container
,
33 fContainer(container
),
34 fShapes(count
> 0 ? new (nothrow
) Shape
*[count
] : NULL
),
35 fIndices(count
> 0 ? new (nothrow
) int32
[count
] : NULL
),
39 if (!fContainer
|| !fShapes
|| !fIndices
)
42 memcpy(fIndices
, indices
, sizeof(int32
) * fCount
);
43 for (int32 i
= 0; i
< fCount
; i
++)
44 fShapes
[i
] = fContainer
->ShapeAt(fIndices
[i
]);
48 RemoveShapesCommand::~RemoveShapesCommand()
50 if (fShapesRemoved
&& fShapes
) {
51 for (int32 i
= 0; i
< fCount
; i
++)
52 fShapes
[i
]->ReleaseReference();
60 RemoveShapesCommand::InitCheck()
62 return fContainer
&& fShapes
&& fIndices
? B_OK
: B_NO_INIT
;
67 RemoveShapesCommand::Perform()
71 // remove shapes from container
72 for (int32 i
= 0; i
< fCount
; i
++) {
73 if (fShapes
[i
] && !fContainer
->RemoveShape(fShapes
[i
])) {
78 fShapesRemoved
= true;
85 RemoveShapesCommand::Undo()
89 // add shapes to container at remembered indices
90 for (int32 i
= 0; i
< fCount
; i
++) {
91 if (fShapes
[i
] && !fContainer
->AddShape(fShapes
[i
], fIndices
[i
])) {
96 fShapesRemoved
= false;
103 RemoveShapesCommand::GetName(BString
& name
)
106 // name << _GetString(MOVE_MODIFIERS, "Move Shapes");
108 // name << _GetString(MOVE_MODIFIER, "Move Shape");
110 name
<< B_TRANSLATE("Remove Shapes");
112 name
<< B_TRANSLATE("Remove Shape");