btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / icon-o-matic / shape / commands / RemoveShapesCommand.cpp
blobe54682ebeb77c9893d0c6caf99b73958d1525e5b
1 /*
2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
9 #include "RemoveShapesCommand.h"
11 #include <new>
12 #include <stdio.h>
13 #include <string.h>
15 #include <Catalog.h>
16 #include <Locale.h>
18 #include "ShapeContainer.h"
19 #include "Shape.h"
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemoveShapesCmd"
26 using std::nothrow;
28 // constructor
29 RemoveShapesCommand::RemoveShapesCommand(ShapeContainer* container,
30 int32* const indices,
31 int32 count)
32 : Command(),
33 fContainer(container),
34 fShapes(count > 0 ? new (nothrow) Shape*[count] : NULL),
35 fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
36 fCount(count),
37 fShapesRemoved(false)
39 if (!fContainer || !fShapes || !fIndices)
40 return;
42 memcpy(fIndices, indices, sizeof(int32) * fCount);
43 for (int32 i = 0; i < fCount; i++)
44 fShapes[i] = fContainer->ShapeAt(fIndices[i]);
47 // destructor
48 RemoveShapesCommand::~RemoveShapesCommand()
50 if (fShapesRemoved && fShapes) {
51 for (int32 i = 0; i < fCount; i++)
52 fShapes[i]->ReleaseReference();
54 delete[] fShapes;
55 delete[] fIndices;
58 // InitCheck
59 status_t
60 RemoveShapesCommand::InitCheck()
62 return fContainer && fShapes && fIndices ? B_OK : B_NO_INIT;
65 // Perform
66 status_t
67 RemoveShapesCommand::Perform()
69 status_t ret = B_OK;
71 // remove shapes from container
72 for (int32 i = 0; i < fCount; i++) {
73 if (fShapes[i] && !fContainer->RemoveShape(fShapes[i])) {
74 ret = B_ERROR;
75 break;
78 fShapesRemoved = true;
80 return ret;
83 // Undo
84 status_t
85 RemoveShapesCommand::Undo()
87 status_t ret = B_OK;
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])) {
92 ret = B_ERROR;
93 break;
96 fShapesRemoved = false;
98 return ret;
101 // GetName
102 void
103 RemoveShapesCommand::GetName(BString& name)
105 // if (fCount > 1)
106 // name << _GetString(MOVE_MODIFIERS, "Move Shapes");
107 // else
108 // name << _GetString(MOVE_MODIFIER, "Move Shape");
109 if (fCount > 1)
110 name << B_TRANSLATE("Remove Shapes");
111 else
112 name << B_TRANSLATE("Remove Shape");