PageRenderTime 41ms CodeModel.GetById 26ms app.highlight 12ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28
 29// file include
 30#include "llpanelcontents.h"
 31
 32// linden library includes
 33#include "lleconomy.h"
 34#include "llerror.h"
 35#include "llfloaterreg.h"
 36#include "llfontgl.h"
 37#include "llinventorydefines.h"
 38#include "llmaterialtable.h"
 39#include "llpermissionsflags.h"
 40#include "llrect.h"
 41#include "llstring.h"
 42#include "llui.h"
 43#include "m3math.h"
 44#include "material_codes.h"
 45
 46// project includes
 47#include "llagent.h"
 48#include "llpanelobjectinventory.h"
 49#include "llpreviewscript.h"
 50#include "llresmgr.h"
 51#include "llselectmgr.h"
 52#include "lltool.h"
 53#include "lltoolcomp.h"
 54#include "lltoolmgr.h"
 55#include "lltrans.h"
 56#include "llviewerassettype.h"
 57#include "llviewerinventory.h"
 58#include "llviewerobject.h"
 59#include "llviewerregion.h"
 60#include "llviewerwindow.h"
 61#include "llworld.h"
 62
 63//
 64// Imported globals
 65//
 66
 67
 68//
 69// Globals
 70//
 71const char* LLPanelContents::TENTATIVE_SUFFIX = "_tentative";
 72const char* LLPanelContents::PERMS_OWNER_INTERACT_KEY = "perms_owner_interact";
 73const char* LLPanelContents::PERMS_OWNER_CONTROL_KEY = "perms_owner_control";
 74const char* LLPanelContents::PERMS_GROUP_INTERACT_KEY = "perms_group_interact";
 75const char* LLPanelContents::PERMS_GROUP_CONTROL_KEY = "perms_group_control";
 76const char* LLPanelContents::PERMS_ANYONE_INTERACT_KEY = "perms_anyone_interact";
 77const char* LLPanelContents::PERMS_ANYONE_CONTROL_KEY = "perms_anyone_control";
 78
 79BOOL LLPanelContents::postBuild()
 80{
 81	LLRect rect = this->getRect();
 82
 83	setMouseOpaque(FALSE);
 84
 85	childSetAction("button new script",&LLPanelContents::onClickNewScript, this);
 86	childSetAction("button permissions",&LLPanelContents::onClickPermissions, this);
 87
 88	mPanelInventoryObject = getChild<LLPanelObjectInventory>("contents_inventory");
 89
 90	return TRUE;
 91}
 92
 93LLPanelContents::LLPanelContents()
 94	:	LLPanel(),
 95		mPanelInventoryObject(NULL)
 96{
 97}
 98
 99
100LLPanelContents::~LLPanelContents()
101{
102	// Children all cleaned up by default view destructor.
103}
104
105
106void LLPanelContents::getState(LLViewerObject *objectp )
107{
108	if( !objectp )
109	{
110		getChildView("button new script")->setEnabled(FALSE);
111		return;
112	}
113
114	LLUUID group_id;			// used for SL-23488
115	LLSelectMgr::getInstance()->selectGetGroup(group_id);  // sets group_id as a side effect SL-23488
116
117	// BUG? Check for all objects being editable?
118	bool editable = gAgent.isGodlike()
119					|| (objectp->permModify()
120					       && ( objectp->permYouOwner() || ( !group_id.isNull() && gAgent.isInGroup(group_id) )));  // solves SL-23488
121	BOOL all_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME );
122
123	// Edit script button - ok if object is editable and there's an unambiguous destination for the object.
124	getChildView("button new script")->setEnabled(
125		editable &&
126		all_volume &&
127		((LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() == 1)
128			|| (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 1)));
129
130}
131
132void LLPanelContents::refresh()
133{
134	const BOOL children_ok = TRUE;
135	LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject(children_ok);
136
137	getState(object);
138	if (mPanelInventoryObject)
139	{
140		mPanelInventoryObject->refresh();
141	}	
142}
143
144
145
146//
147// Static functions
148//
149
150// static
151void LLPanelContents::onClickNewScript(void *userdata)
152{
153	const BOOL children_ok = TRUE;
154	LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject(children_ok);
155	if(object)
156	{
157		LLPermissions perm;
158		perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null);
159		perm.initMasks(
160			PERM_ALL,
161			PERM_ALL,
162			PERM_NONE,
163			PERM_NONE,
164			PERM_MOVE | PERM_TRANSFER);
165		std::string desc;
166		LLViewerAssetType::generateDescriptionFor(LLAssetType::AT_LSL_TEXT, desc);
167		LLPointer<LLViewerInventoryItem> new_item =
168			new LLViewerInventoryItem(
169				LLUUID::null,
170				LLUUID::null,
171				perm,
172				LLUUID::null,
173				LLAssetType::AT_LSL_TEXT,
174				LLInventoryType::IT_LSL,
175				"New Script",
176				desc,
177				LLSaleInfo::DEFAULT,
178				LLInventoryItemFlags::II_FLAGS_NONE,
179				time_corrected());
180		object->saveScript(new_item, TRUE, true);
181
182		// *NOTE: In order to resolve SL-22177, we needed to create
183		// the script first, and then you have to click it in
184		// inventory to edit it.
185		// *TODO: The script creation should round-trip back to the
186		// viewer so the viewer can auto-open the script and start
187		// editing ASAP.
188#if 0
189		LLFloaterReg::showInstance("preview_scriptedit", LLSD(inv_item->getUUID()), TAKE_FOCUS_YES);
190#endif
191	}
192}
193
194
195// static
196void LLPanelContents::onClickPermissions(void *userdata)
197{
198	LLPanelContents* self = (LLPanelContents*)userdata;
199	gFloaterView->getParentFloater(self)->addDependentFloater(LLFloaterReg::showInstance("bulk_perms"));
200}