xref: /haiku/src/apps/icon-o-matic/style/AssignStyleCommand.cpp (revision 1026b0a1a76dc88927bb8175c470f638dc5464ee)
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 "Shape.h"
15 #include "Style.h"
16 
17 
18 #undef B_TRANSLATION_CONTEXT
19 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AssignStyleCmd"
20 
21 
22 // constructor
23 AssignStyleCommand::AssignStyleCommand(Shape* shape,
24 									   Style* style)
25 	: Command(),
26 	  fShape(shape),
27 	  fOldStyle(shape ? shape->Style() : NULL),
28 	  fNewStyle(style)
29 {
30 	if (fOldStyle)
31 		fOldStyle->Acquire();
32 	if (fNewStyle)
33 		fNewStyle->Acquire();
34 }
35 
36 // destructor
37 AssignStyleCommand::~AssignStyleCommand()
38 {
39 	if (fOldStyle)
40 		fOldStyle->Release();
41 	if (fNewStyle)
42 		fNewStyle->Release();
43 }
44 
45 // InitCheck
46 status_t
47 AssignStyleCommand::InitCheck()
48 {
49 	return fShape && fNewStyle ? B_OK : B_NO_INIT;
50 }
51 
52 // Perform
53 status_t
54 AssignStyleCommand::Perform()
55 {
56 	fShape->SetStyle(fNewStyle);
57 
58 	return B_OK;
59 }
60 
61 // Undo
62 status_t
63 AssignStyleCommand::Undo()
64 {
65 	fShape->SetStyle(fOldStyle);
66 
67 	return B_OK;
68 }
69 
70 // GetName
71 void
72 AssignStyleCommand::GetName(BString& name)
73 {
74 	name << B_TRANSLATE("Assign Style");
75 	if (fNewStyle)
76 		name << " \"" << fNewStyle->Name() << "\"";
77 }
78 
79