2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "AddStylesCommand.h"
18 #include "StyleContainer.h"
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddStylesCmd"
29 AddStylesCommand::AddStylesCommand(StyleContainer
* container
,
34 fContainer(container
),
35 fStyles(styles
&& count
> 0 ? new (nothrow
) Style
*[count
] : NULL
),
40 if (!fContainer
|| !fStyles
)
43 memcpy(fStyles
, styles
, sizeof(Style
*) * fCount
);
47 AddStylesCommand::~AddStylesCommand()
49 if (!fStylesAdded
&& fStyles
) {
50 for (int32 i
= 0; i
< fCount
; i
++)
51 fStyles
[i
]->ReleaseReference();
58 AddStylesCommand::InitCheck()
60 return fContainer
&& fStyles
? B_OK
: B_NO_INIT
;
65 AddStylesCommand::Perform()
69 // add shapes to container
71 for (int32 i
= 0; i
< fCount
; i
++) {
72 if (fStyles
[i
] && !fContainer
->AddStyle(fStyles
[i
], index
)) {
75 for (int32 j
= i
- 1; j
>= 0; j
--)
76 fContainer
->RemoveStyle(fStyles
[j
]);
88 AddStylesCommand::Undo()
90 // remove shapes from container
91 for (int32 i
= 0; i
< fCount
; i
++) {
92 fContainer
->RemoveStyle(fStyles
[i
]);
101 AddStylesCommand::GetName(BString
& name
)
104 name
<< B_TRANSLATE("Add Styles");
106 name
<< B_TRANSLATE("Add Style");