xref: /haiku/src/apps/icon-o-matic/style/AssignStyleCommand.cpp (revision 098eaec6305ae804d3eb6c8e6c6aad790fb4cfb1)
1 /*
2  * Copyright 2006, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "AssignStyleCommand.h"
10 
11 #include <Catalog.h>
12 #include <Locale.h>
13 
14 #include "PathSourceShape.h"
15 #include "Shape.h"
16 #include "Style.h"
17 
18 
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AssignStyleCmd"
21 
22 
23 // constructor
24 AssignStyleCommand::AssignStyleCommand(PathSourceShape* shape,
25 									   Style* style)
26 	: Command(),
27 	  fShape(shape),
28 	  fOldStyle(shape ? shape->Style() : NULL),
29 	  fNewStyle(style)
30 {
31 	if (fOldStyle)
32 		fOldStyle->AcquireReference();
33 	if (fNewStyle)
34 		fNewStyle->AcquireReference();
35 }
36 
37 // destructor
38 AssignStyleCommand::~AssignStyleCommand()
39 {
40 	if (fOldStyle)
41 		fOldStyle->ReleaseReference();
42 	if (fNewStyle)
43 		fNewStyle->ReleaseReference();
44 }
45 
46 // InitCheck
47 status_t
48 AssignStyleCommand::InitCheck()
49 {
50 	return fShape && fNewStyle ? B_OK : B_NO_INIT;
51 }
52 
53 // Perform
54 status_t
55 AssignStyleCommand::Perform()
56 {
57 	fShape->SetStyle(fNewStyle);
58 
59 	return B_OK;
60 }
61 
62 // Undo
63 status_t
64 AssignStyleCommand::Undo()
65 {
66 	fShape->SetStyle(fOldStyle);
67 
68 	return B_OK;
69 }
70 
71 // GetName
72 void
73 AssignStyleCommand::GetName(BString& name)
74 {
75 	name << B_TRANSLATE("Assign Style");
76 	if (fNewStyle)
77 		name << " \"" << fNewStyle->Name() << "\"";
78 }
79 
80