2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "RemoveTransformersCommand.h"
18 #include "ShapeContainer.h"
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemoveTransformersCmd"
29 RemoveTransformersCommand::RemoveTransformersCommand(Shape
* container
,
33 fContainer(container
),
34 fTransformers(count
> 0 ? new (nothrow
) Transformer
*[count
] : NULL
),
35 fIndices(count
> 0 ? new (nothrow
) int32
[count
] : NULL
),
37 fTransformersRemoved(false)
39 if (!fContainer
|| !fTransformers
|| !fIndices
)
42 memcpy(fIndices
, indices
, sizeof(int32
) * fCount
);
43 for (int32 i
= 0; i
< fCount
; i
++)
44 fTransformers
[i
] = fContainer
->TransformerAt(fIndices
[i
]);
48 RemoveTransformersCommand::~RemoveTransformersCommand()
50 if (fTransformersRemoved
&& fTransformers
) {
51 for (int32 i
= 0; i
< fCount
; i
++)
52 delete fTransformers
[i
];
54 delete[] fTransformers
;
60 RemoveTransformersCommand::InitCheck()
62 return fContainer
&& fTransformers
&& fIndices
? B_OK
: B_NO_INIT
;
67 RemoveTransformersCommand::Perform()
71 // remove shapes from container
72 for (int32 i
= 0; i
< fCount
; i
++) {
74 && !fContainer
->RemoveTransformer(fTransformers
[i
])) {
79 fTransformersRemoved
= true;
86 RemoveTransformersCommand::Undo()
90 // add shapes to container at remembered indices
91 for (int32 i
= 0; i
< fCount
; i
++) {
93 && !fContainer
->AddTransformer(fTransformers
[i
], fIndices
[i
])) {
98 fTransformersRemoved
= false;
105 RemoveTransformersCommand::GetName(BString
& name
)
108 // name << _GetString(MOVE_TRANSFORMERS, "Move Transformers");
110 // name << _GetString(MOVE_TRANSFORMER, "Move Transformer");
112 name
<< B_TRANSLATE("Remove Transformers");
114 name
<< B_TRANSLATE("Remove Transformer");