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 23AssignStyleCommand::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 37AssignStyleCommand::~AssignStyleCommand() 38{ 39 if (fOldStyle) 40 fOldStyle->Release(); 41 if (fNewStyle) 42 fNewStyle->Release(); 43} 44 45// InitCheck 46status_t 47AssignStyleCommand::InitCheck() 48{ 49 return fShape && fNewStyle ? B_OK : B_NO_INIT; 50} 51 52// Perform 53status_t 54AssignStyleCommand::Perform() 55{ 56 fShape->SetStyle(fNewStyle); 57 58 return B_OK; 59} 60 61// Undo 62status_t 63AssignStyleCommand::Undo() 64{ 65 fShape->SetStyle(fOldStyle); 66 67 return B_OK; 68} 69 70// GetName 71void 72AssignStyleCommand::GetName(BString& name) 73{ 74 name << B_TRANSLATE("Assign Style"); 75 if (fNewStyle) 76 name << " \"" << fNewStyle->Name() << "\""; 77} 78 79