HaikuDepot: notify work status from main window
[haiku.git] / src / apps / icon-o-matic / document / SetPropertiesCommand.cpp
blob8ad8ba729430a80051e63f9554fdac0e1cf5baa5
1 /*
2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
9 #include "SetPropertiesCommand.h"
11 #include <stdio.h>
13 #include <Catalog.h>
14 #include <Locale.h>
16 #include "CommonPropertyIDs.h"
17 #include "IconObject.h"
18 #include "Property.h"
19 #include "PropertyObject.h"
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-Properties"
26 // constructor
27 SetPropertiesCommand::SetPropertiesCommand(IconObject** objects,
28 int32 objectCount,
29 PropertyObject* previous,
30 PropertyObject* current)
31 : Command(),
32 fObjects(objects),
33 fObjectCount(objectCount),
35 fOldProperties(previous),
36 fNewProperties(current)
40 // destructor
41 SetPropertiesCommand::~SetPropertiesCommand()
43 delete[] fObjects;
44 delete fOldProperties;
45 delete fNewProperties;
48 // InitCheck
49 status_t
50 SetPropertiesCommand::InitCheck()
52 return fObjects && fOldProperties && fNewProperties
53 && fObjectCount > 0 && fOldProperties->CountProperties() > 0
54 && fOldProperties->ContainsSameProperties(*fNewProperties) ?
55 B_OK : B_NO_INIT;
58 // Perform
59 status_t
60 SetPropertiesCommand::Perform()
62 for (int32 i = 0; i < fObjectCount; i++) {
63 if (fObjects[i])
64 fObjects[i]->SetToPropertyObject(fNewProperties);
66 return B_OK;
69 // Undo
70 status_t
71 SetPropertiesCommand::Undo()
73 for (int32 i = 0; i < fObjectCount; i++) {
74 if (fObjects[i])
75 fObjects[i]->SetToPropertyObject(fOldProperties);
77 return B_OK;
80 // GetName
81 void
82 SetPropertiesCommand::GetName(BString& name)
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_CONTEXT("Multi Set ",
94 "Multi Set (property name)") << property;
95 else
96 name << B_TRANSLATE_CONTEXT("Set ", "Set (property name)")
97 << property;