2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "AddPathsCommand.h"
18 #include "PathContainer.h"
19 #include "VectorPath.h"
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddPathsCmd"
29 AddPathsCommand::AddPathsCommand(PathContainer
* container
,
30 VectorPath
** const paths
,
35 fContainer(container
),
36 fPaths(paths
&& count
> 0 ? new (nothrow
) VectorPath
*[count
] : NULL
),
38 fOwnsPaths(ownsPaths
),
42 if (!fContainer
|| !fPaths
)
45 memcpy(fPaths
, paths
, sizeof(VectorPath
*) * fCount
);
48 // Add references to paths
49 for (int32 i
= 0; i
< fCount
; i
++) {
50 if (fPaths
[i
] != NULL
)
51 fPaths
[i
]->AcquireReference();
57 AddPathsCommand::~AddPathsCommand()
59 if (!fPathsAdded
&& fPaths
) {
60 for (int32 i
= 0; i
< fCount
; i
++) {
61 if (fPaths
[i
] != NULL
)
62 fPaths
[i
]->ReleaseReference();
70 AddPathsCommand::InitCheck()
72 return fContainer
&& fPaths
? B_OK
: B_NO_INIT
;
77 AddPathsCommand::Perform()
79 // add paths to container
80 for (int32 i
= 0; i
< fCount
; i
++) {
81 if (fPaths
[i
] && !fContainer
->AddPath(fPaths
[i
], fIndex
+ i
)) {
83 for (int32 j
= i
- 1; j
>= 0; j
--)
84 fContainer
->RemovePath(fPaths
[j
]);
95 AddPathsCommand::Undo()
97 // remove paths from container
98 for (int32 i
= 0; i
< fCount
; i
++) {
99 fContainer
->RemovePath(fPaths
[i
]);
108 AddPathsCommand::GetName(BString
& name
)
112 name
<< B_TRANSLATE("Add Paths");
114 name
<< B_TRANSLATE("Add Path");
117 name
<< B_TRANSLATE("Assign Paths");
119 name
<< B_TRANSLATE("Assign Path");