PageRenderTime 42ms CodeModel.GetById 31ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llplacesinventorypanel.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 186 lines | 111 code | 31 blank | 44 comment | 12 complexity | 9e160943eae099d12ef96d9b00d8fe71 MD5 | raw file
  1/** 
  2 * @file llplacesinventorypanel.cpp
  3 * @brief LLPlacesInventoryPanel  class definition
  4 *
  5 * $LicenseInfo:firstyear=2009&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#include "llscrollcontainer.h"
 30
 31#include "llplacesinventorypanel.h"
 32
 33#include "llfoldervieweventlistener.h"
 34#include "llinventorybridge.h"
 35#include "llinventoryfunctions.h"
 36#include "llpanellandmarks.h"
 37#include "llplacesinventorybridge.h"
 38#include "llviewerfoldertype.h"
 39
 40static LLDefaultChildRegistry::Register<LLPlacesInventoryPanel> r("places_inventory_panel");
 41
 42static const LLPlacesInventoryBridgeBuilder PLACES_INVENTORY_BUILDER;
 43
 44LLPlacesInventoryPanel::LLPlacesInventoryPanel(const Params& p) : 
 45	LLInventoryPanel(p),
 46	mSavedFolderState(NULL)
 47
 48{
 49	mInvFVBridgeBuilder = &PLACES_INVENTORY_BUILDER;
 50	mSavedFolderState = new LLSaveFolderState();
 51	mSavedFolderState->setApply(FALSE);
 52}
 53
 54
 55LLPlacesInventoryPanel::~LLPlacesInventoryPanel()
 56{
 57	delete mSavedFolderState;
 58}
 59
 60void LLPlacesInventoryPanel::buildFolderView(const LLInventoryPanel::Params& params)
 61{
 62	// Determine the root folder in case specified, and
 63	// build the views starting with that folder.
 64	const LLFolderType::EType preferred_type = LLViewerFolderType::lookupTypeFromNewCategoryName(params.start_folder);
 65
 66	LLUUID root_id;
 67
 68	if ("LIBRARY" == params.start_folder())
 69	{
 70		root_id = gInventory.getLibraryRootFolderID();
 71	}
 72	else
 73	{
 74		root_id = (preferred_type != LLFolderType::FT_NONE ? gInventory.findCategoryUUIDForType(preferred_type) : LLUUID::null);
 75	}
 76
 77	LLRect folder_rect(0,
 78		0,
 79		getRect().getWidth(),
 80		0);
 81	LLPlacesFolderView::Params p;
 82	p.name = getName();
 83	p.title = getLabel();
 84	p.rect = folder_rect;
 85	p.listener =  mInvFVBridgeBuilder->createBridge(LLAssetType::AT_CATEGORY,
 86													LLAssetType::AT_CATEGORY,
 87													LLInventoryType::IT_CATEGORY,
 88													this,
 89													NULL,
 90													root_id);
 91	p.parent_panel = this;
 92	p.allow_multiselect = mAllowMultiSelect;
 93	p.use_ellipses = true;	// truncate inventory item text so remove horizontal scroller
 94	mFolderRoot = (LLFolderView*)LLUICtrlFactory::create<LLPlacesFolderView>(p);
 95}
 96
 97
 98// save current folder open state
 99void LLPlacesInventoryPanel::saveFolderState()
100{
101	mSavedFolderState->setApply(FALSE);
102	mFolderRoot->applyFunctorRecursively(*mSavedFolderState);
103}
104
105// re-open folders which state was saved
106void LLPlacesInventoryPanel::restoreFolderState()
107{
108	mSavedFolderState->setApply(TRUE);
109	mFolderRoot->applyFunctorRecursively(*mSavedFolderState);
110	LLOpenFoldersWithSelection opener;
111	mFolderRoot->applyFunctorRecursively(opener);
112	mFolderRoot->scrollToShowSelection();
113}
114
115S32	LLPlacesInventoryPanel::notify(const LLSD& info) 
116{
117	if(info.has("action"))
118	{
119		std::string str_action = info["action"];
120		if(str_action == "select_first")
121		{
122			return mFolderRoot->notify(info);
123		}
124		else if(str_action == "select_last")
125		{
126			return mFolderRoot->notify(info);
127		}
128	}
129	return 0;
130}
131
132/************************************************************************/
133/* PROTECTED METHODS                                                    */
134/************************************************************************/
135
136
137
138/************************************************************************/
139/*              LLPlacesFolderView implementation                       */
140/************************************************************************/
141
142//////////////////////////////////////////////////////////////////////////
143//  PUBLIC METHODS
144//////////////////////////////////////////////////////////////////////////
145
146LLPlacesFolderView::LLPlacesFolderView(const LLFolderView::Params& p)
147: LLFolderView(p)
148{
149	// we do not need auto select functionality in places landmarks, so override default behavior.
150	// this disables applying of the LLSelectFirstFilteredItem in LLFolderView::doIdle.
151	// Fixed issues: EXT-1631, EXT-4994.
152	mAutoSelectOverride = TRUE;
153}
154
155BOOL LLPlacesFolderView::handleRightMouseDown(S32 x, S32 y, MASK mask)
156{
157	// let children to change selection first
158	childrenHandleRightMouseDown(x, y, mask);
159	mParentLandmarksPanel->setCurrentSelectedList((LLPlacesInventoryPanel*)getParentPanel());
160
161	// then determine its type and set necessary menu handle
162	if (getCurSelectedItem())
163	{
164		LLInventoryType::EType inventory_type = getCurSelectedItem()->getListener()->getInventoryType();
165		inventory_type_menu_handle_t::iterator it_handle = mMenuHandlesByInventoryType.find(inventory_type);
166
167		if (it_handle != mMenuHandlesByInventoryType.end())
168		{
169			mPopupMenuHandle = (*it_handle).second;
170		}
171		else
172		{
173			llwarns << "Requested menu handle for non-setup inventory type: " << inventory_type << llendl;
174		}
175
176	}
177
178	return LLFolderView::handleRightMouseDown(x, y, mask);
179}
180
181void LLPlacesFolderView::setupMenuHandle(LLInventoryType::EType asset_type, LLHandle<LLView> menu_handle)
182{
183	mMenuHandlesByInventoryType[asset_type] = menu_handle;
184}
185
186// EOF