llfloateropenobject.cpp

Go to the documentation of this file.
00001 
00032 /*
00033  * Shows the contents of an object.
00034  * A floater wrapper for llpanelinventory
00035  */
00036 
00037 #include "llviewerprecompiledheaders.h"
00038 
00039 #include "llfloateropenobject.h"
00040 
00041 #include "llcachename.h"
00042 #include "llbutton.h"
00043 #include "lltextbox.h"
00044 
00045 #include "llagent.h"                    // for agent id
00046 #include "llalertdialog.h"
00047 #include "llinventoryview.h"
00048 #include "llinventorymodel.h"
00049 #include "llpanelinventory.h"
00050 #include "llselectmgr.h"
00051 #include "lluiconstants.h"
00052 #include "llviewerobject.h"
00053 #include "lluictrlfactory.h"
00054 #include "llviewerwindow.h"
00055 
00056 
00057 LLFloaterOpenObject* LLFloaterOpenObject::sInstance = NULL;
00058 
00059 LLFloaterOpenObject::LLFloaterOpenObject()
00060 :       LLFloater("object_contents"),
00061         mPanelInventory(NULL),
00062         mDirty(TRUE)
00063 {
00064         LLCallbackMap::map_t factory_map;
00065         factory_map["object_contents"] = LLCallbackMap(createPanelInventory, this);
00066         LLUICtrlFactory::getInstance()->buildFloater(this,"floater_openobject.xml",&factory_map);
00067 
00068         childSetAction("copy_to_inventory_button", onClickMoveToInventory, this);
00069         childSetAction("copy_and_wear_button", onClickMoveAndWear, this);
00070         childSetTextArg("object_name", "[DESC]", LLString("Object") ); // *Note: probably do not want to translate this
00071 }
00072 
00073 LLFloaterOpenObject::~LLFloaterOpenObject()
00074 {
00075         sInstance = NULL;
00076 }
00077 
00078 void LLFloaterOpenObject::refresh()
00079 {
00080         mPanelInventory->refresh();
00081 
00082         LLSelectNode* node = mObjectSelection->getFirstRootNode();
00083         if (node)
00084         {
00085                 std::string name = node->mName;
00086                 childSetTextArg("object_name", "[DESC]", name);
00087         }
00088 }
00089 
00090 void LLFloaterOpenObject::draw()
00091 {
00092         if (mDirty)
00093         {
00094                 refresh();
00095                 mDirty = FALSE;
00096         }
00097         LLFloater::draw();
00098 }
00099 
00100 // static
00101 void LLFloaterOpenObject::dirty()
00102 {
00103         if (sInstance) sInstance->mDirty = TRUE;
00104 }
00105 
00106 // static
00107 void LLFloaterOpenObject::show()
00108 {
00109         LLObjectSelectionHandle object_selection = LLSelectMgr::getInstance()->getSelection();
00110         if (object_selection->getRootObjectCount() != 1)
00111         {
00112                 gViewerWindow->alertXml("UnableToViewContentsMoreThanOne");
00113                 return;
00114         }
00115 
00116         // Create a new instance only if needed
00117         if (!sInstance)
00118         {
00119                 sInstance = new LLFloaterOpenObject();
00120                 sInstance->center();
00121         }
00122 
00123         sInstance->open();              /* Flawfinder: ignore */
00124         sInstance->setFocus(TRUE);
00125 
00126         sInstance->mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
00127 }
00128 
00129 
00130 void LLFloaterOpenObject::moveToInventory(bool wear)
00131 {
00132         if (mObjectSelection->getRootObjectCount() != 1)
00133         {
00134                 gViewerWindow->alertXml("OnlyCopyContentsOfSingleItem");
00135                 return;
00136         }
00137 
00138         LLSelectNode* node = mObjectSelection->getFirstRootNode();
00139         if (!node) return;
00140         LLViewerObject* object = node->getObject();
00141         if (!object) return;
00142 
00143         LLUUID object_id = object->getID();
00144         std::string name = node->mName;
00145 
00146         // Either create a sub-folder of clothing, or of the root folder.
00147         LLUUID parent_category_id;
00148         if (wear)
00149         {
00150                 parent_category_id = gInventory.findCategoryUUIDForType(
00151                         LLAssetType::AT_CLOTHING);
00152         }
00153         else
00154         {
00155                 parent_category_id = gAgent.getInventoryRootID();
00156         }
00157         LLUUID category_id = gInventory.createNewCategory(parent_category_id, 
00158                 LLAssetType::AT_NONE, 
00159                 name);
00160 
00161         LLCatAndWear* data = new LLCatAndWear;
00162         data->mCatID = category_id;
00163         data->mWear = wear;
00164 
00165         // Copy and/or move the items into the newly created folder.
00166         // Ignore any "you're going to break this item" messages.
00167         BOOL success = move_inv_category_world_to_agent(object_id, category_id, TRUE,
00168                                                                                                         callbackMoveInventory, 
00169                                                                                                         (void*)data);
00170         if (!success)
00171         {
00172                 delete data;
00173                 data = NULL;
00174 
00175                 gViewerWindow->alertXml("OpenObjectCannotCopy");
00176         }
00177 }
00178 
00179 // static
00180 void LLFloaterOpenObject::callbackMoveInventory(S32 result, void* data)
00181 {
00182         LLCatAndWear* cat = (LLCatAndWear*)data;
00183 
00184         if (result == 0)
00185         {
00186                 LLInventoryView::showAgentInventory();
00187                 LLInventoryView* view = LLInventoryView::getActiveInventory();
00188                 if (view)
00189                 {
00190                         view->getPanel()->setSelection(cat->mCatID, TAKE_FOCUS_NO);
00191                 }
00192         }
00193 
00194         delete cat;
00195 }
00196 
00197 
00198 // static
00199 void LLFloaterOpenObject::onClickMoveToInventory(void* data)
00200 {
00201         LLFloaterOpenObject* self = (LLFloaterOpenObject*)data;
00202         self->moveToInventory(false);
00203         self->close();
00204 }
00205 
00206 // static
00207 void LLFloaterOpenObject::onClickMoveAndWear(void* data)
00208 {
00209         LLFloaterOpenObject* self = (LLFloaterOpenObject*)data;
00210         self->moveToInventory(true);
00211         self->close();
00212 }
00213 
00214 //static
00215 void* LLFloaterOpenObject::createPanelInventory(void* data)
00216 {
00217         LLFloaterOpenObject* floater = (LLFloaterOpenObject*)data;
00218         floater->mPanelInventory = new LLPanelInventory("Object Contents", LLRect());
00219         return floater->mPanelInventory;
00220 }

Generated on Fri May 16 08:33:29 2008 for SecondLife by  doxygen 1.5.5