PageRenderTime 30ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpanelcontents.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 200 lines | 122 code | 30 blank | 48 comment | 10 complexity | 8f407d38774d54145a6c11c679024e25 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelcontents.cpp
  3. * @brief Object contents panel in the tools floater.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. // file include
  28. #include "llpanelcontents.h"
  29. // linden library includes
  30. #include "lleconomy.h"
  31. #include "llerror.h"
  32. #include "llfloaterreg.h"
  33. #include "llfontgl.h"
  34. #include "llinventorydefines.h"
  35. #include "llmaterialtable.h"
  36. #include "llpermissionsflags.h"
  37. #include "llrect.h"
  38. #include "llstring.h"
  39. #include "llui.h"
  40. #include "m3math.h"
  41. #include "material_codes.h"
  42. // project includes
  43. #include "llagent.h"
  44. #include "llpanelobjectinventory.h"
  45. #include "llpreviewscript.h"
  46. #include "llresmgr.h"
  47. #include "llselectmgr.h"
  48. #include "lltool.h"
  49. #include "lltoolcomp.h"
  50. #include "lltoolmgr.h"
  51. #include "lltrans.h"
  52. #include "llviewerassettype.h"
  53. #include "llviewerinventory.h"
  54. #include "llviewerobject.h"
  55. #include "llviewerregion.h"
  56. #include "llviewerwindow.h"
  57. #include "llworld.h"
  58. //
  59. // Imported globals
  60. //
  61. //
  62. // Globals
  63. //
  64. const char* LLPanelContents::TENTATIVE_SUFFIX = "_tentative";
  65. const char* LLPanelContents::PERMS_OWNER_INTERACT_KEY = "perms_owner_interact";
  66. const char* LLPanelContents::PERMS_OWNER_CONTROL_KEY = "perms_owner_control";
  67. const char* LLPanelContents::PERMS_GROUP_INTERACT_KEY = "perms_group_interact";
  68. const char* LLPanelContents::PERMS_GROUP_CONTROL_KEY = "perms_group_control";
  69. const char* LLPanelContents::PERMS_ANYONE_INTERACT_KEY = "perms_anyone_interact";
  70. const char* LLPanelContents::PERMS_ANYONE_CONTROL_KEY = "perms_anyone_control";
  71. BOOL LLPanelContents::postBuild()
  72. {
  73. LLRect rect = this->getRect();
  74. setMouseOpaque(FALSE);
  75. childSetAction("button new script",&LLPanelContents::onClickNewScript, this);
  76. childSetAction("button permissions",&LLPanelContents::onClickPermissions, this);
  77. mPanelInventoryObject = getChild<LLPanelObjectInventory>("contents_inventory");
  78. return TRUE;
  79. }
  80. LLPanelContents::LLPanelContents()
  81. : LLPanel(),
  82. mPanelInventoryObject(NULL)
  83. {
  84. }
  85. LLPanelContents::~LLPanelContents()
  86. {
  87. // Children all cleaned up by default view destructor.
  88. }
  89. void LLPanelContents::getState(LLViewerObject *objectp )
  90. {
  91. if( !objectp )
  92. {
  93. getChildView("button new script")->setEnabled(FALSE);
  94. return;
  95. }
  96. LLUUID group_id; // used for SL-23488
  97. LLSelectMgr::getInstance()->selectGetGroup(group_id); // sets group_id as a side effect SL-23488
  98. // BUG? Check for all objects being editable?
  99. bool editable = gAgent.isGodlike()
  100. || (objectp->permModify()
  101. && ( objectp->permYouOwner() || ( !group_id.isNull() && gAgent.isInGroup(group_id) ))); // solves SL-23488
  102. BOOL all_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME );
  103. // Edit script button - ok if object is editable and there's an unambiguous destination for the object.
  104. getChildView("button new script")->setEnabled(
  105. editable &&
  106. all_volume &&
  107. ((LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() == 1)
  108. || (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 1)));
  109. }
  110. void LLPanelContents::refresh()
  111. {
  112. const BOOL children_ok = TRUE;
  113. LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject(children_ok);
  114. getState(object);
  115. if (mPanelInventoryObject)
  116. {
  117. mPanelInventoryObject->refresh();
  118. }
  119. }
  120. //
  121. // Static functions
  122. //
  123. // static
  124. void LLPanelContents::onClickNewScript(void *userdata)
  125. {
  126. const BOOL children_ok = TRUE;
  127. LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject(children_ok);
  128. if(object)
  129. {
  130. LLPermissions perm;
  131. perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null);
  132. perm.initMasks(
  133. PERM_ALL,
  134. PERM_ALL,
  135. PERM_NONE,
  136. PERM_NONE,
  137. PERM_MOVE | PERM_TRANSFER);
  138. std::string desc;
  139. LLViewerAssetType::generateDescriptionFor(LLAssetType::AT_LSL_TEXT, desc);
  140. LLPointer<LLViewerInventoryItem> new_item =
  141. new LLViewerInventoryItem(
  142. LLUUID::null,
  143. LLUUID::null,
  144. perm,
  145. LLUUID::null,
  146. LLAssetType::AT_LSL_TEXT,
  147. LLInventoryType::IT_LSL,
  148. "New Script",
  149. desc,
  150. LLSaleInfo::DEFAULT,
  151. LLInventoryItemFlags::II_FLAGS_NONE,
  152. time_corrected());
  153. object->saveScript(new_item, TRUE, true);
  154. // *NOTE: In order to resolve SL-22177, we needed to create
  155. // the script first, and then you have to click it in
  156. // inventory to edit it.
  157. // *TODO: The script creation should round-trip back to the
  158. // viewer so the viewer can auto-open the script and start
  159. // editing ASAP.
  160. #if 0
  161. LLFloaterReg::showInstance("preview_scriptedit", LLSD(inv_item->getUUID()), TAKE_FOCUS_YES);
  162. #endif
  163. }
  164. }
  165. // static
  166. void LLPanelContents::onClickPermissions(void *userdata)
  167. {
  168. LLPanelContents* self = (LLPanelContents*)userdata;
  169. gFloaterView->getParentFloater(self)->addDependentFloater(LLFloaterReg::showInstance("bulk_perms"));
  170. }