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 <Catalog.h> 14 #include <Locale.h> 15 16 #include "CommonPropertyIDs.h" 17 #include "IconObject.h" 18 #include "Property.h" 19 #include "PropertyObject.h" 20 21 22 #undef B_TRANSLATION_CONTEXT 23 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-Properties" 24 25 26 // constructor 27 SetPropertiesCommand::SetPropertiesCommand(IconObject** objects, 28 int32 objectCount, 29 PropertyObject* previous, 30 PropertyObject* current) 31 : Command(), 32 fObjects(objects), 33 fObjectCount(objectCount), 34 35 fOldProperties(previous), 36 fNewProperties(current) 37 { 38 } 39 40 // destructor 41 SetPropertiesCommand::~SetPropertiesCommand() 42 { 43 delete[] fObjects; 44 delete fOldProperties; 45 delete fNewProperties; 46 } 47 48 // InitCheck 49 status_t 50 SetPropertiesCommand::InitCheck() 51 { 52 return fObjects && fOldProperties && fNewProperties 53 && fObjectCount > 0 && fOldProperties->CountProperties() > 0 54 && fOldProperties->ContainsSameProperties(*fNewProperties) ? 55 B_OK : B_NO_INIT; 56 } 57 58 // Perform 59 status_t 60 SetPropertiesCommand::Perform() 61 { 62 for (int32 i = 0; i < fObjectCount; i++) { 63 if (fObjects[i]) 64 fObjects[i]->SetToPropertyObject(fNewProperties); 65 } 66 return B_OK; 67 } 68 69 // Undo 70 status_t 71 SetPropertiesCommand::Undo() 72 { 73 for (int32 i = 0; i < fObjectCount; i++) { 74 if (fObjects[i]) 75 fObjects[i]->SetToPropertyObject(fOldProperties); 76 } 77 return B_OK; 78 } 79 80 // GetName 81 void 82 SetPropertiesCommand::GetName(BString& name) 83 { 84 if (fOldProperties->CountProperties() > 1) { 85 if (fObjectCount > 1) 86 name << B_TRANSLATE("Multi-paste properties"); 87 else 88 name << B_TRANSLATE("Paste properties"); 89 } else { 90 BString property = name_for_id( 91 fOldProperties->PropertyAt(0)->Identifier()); 92 if (fObjectCount > 1) { 93 name << B_TRANSLATE_COMMENT("Multi-set %property%", 94 "Don't translate %property%"); 95 } else { 96 name << B_TRANSLATE_COMMENT("Set %property%", 97 "Don't translate %property%"); 98 } 99 name.ReplaceFirst("%property%", property); 100 } 101 } 102