1 /* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "SetPropertiesCommand.h" 10 11 #include <stdio.h> 12 13 #include "CommonPropertyIDs.h" 14 #include "IconObject.h" 15 #include "Property.h" 16 #include "PropertyObject.h" 17 18 // constructor 19 SetPropertiesCommand::SetPropertiesCommand(IconObject** objects, 20 int32 objectCount, 21 PropertyObject* previous, 22 PropertyObject* current) 23 : Command(), 24 fObjects(objects), 25 fObjectCount(objectCount), 26 27 fOldProperties(previous), 28 fNewProperties(current) 29 { 30 } 31 32 // destructor 33 SetPropertiesCommand::~SetPropertiesCommand() 34 { 35 delete[] fObjects; 36 delete fOldProperties; 37 delete fNewProperties; 38 } 39 40 // InitCheck 41 status_t 42 SetPropertiesCommand::InitCheck() 43 { 44 return fObjects && fOldProperties && fNewProperties 45 && fObjectCount > 0 && fOldProperties->CountProperties() > 0 46 && fOldProperties->ContainsSameProperties(*fNewProperties) ? 47 B_OK : B_NO_INIT; 48 } 49 50 // Perform 51 status_t 52 SetPropertiesCommand::Perform() 53 { 54 for (int32 i = 0; i < fObjectCount; i++) { 55 if (fObjects[i]) 56 fObjects[i]->SetToPropertyObject(fNewProperties); 57 } 58 return B_OK; 59 } 60 61 // Undo 62 status_t 63 SetPropertiesCommand::Undo() 64 { 65 for (int32 i = 0; i < fObjectCount; i++) { 66 if (fObjects[i]) 67 fObjects[i]->SetToPropertyObject(fOldProperties); 68 } 69 return B_OK; 70 } 71 72 // GetName 73 void 74 SetPropertiesCommand::GetName(BString& name) 75 { 76 if (fOldProperties->CountProperties() > 1) { 77 if (fObjectCount > 1) 78 name << "Multi Paste Properties"; 79 else 80 name << "Paste Properties"; 81 } else { 82 BString property = name_for_id( 83 fOldProperties->PropertyAt(0)->Identifier()); 84 if (fObjectCount > 1) 85 name << "Multi Set " << property; 86 else 87 name << "Set " << property; 88 } 89 } 90