PageRenderTime 35ms CodeModel.GetById 23ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llplacesinventorybridge.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 198 lines | 134 code | 27 blank | 37 comment | 22 complexity | b6bcefef715f4cdeed06acccd1a4d039 MD5 | raw file
  1/** 
  2 * @file llplacesinventorybridge.cpp
  3 * @brief Implementation of the Inventory-Folder-View-Bridge classes for Places Panel.
  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 "llmenugl.h"
 30
 31#include "llplacesinventorybridge.h"
 32
 33#include "llfloaterinventory.h" // for LLInventoryPanel
 34#include "llfolderview.h" // for FIRST_SELECTED_ITEM
 35#include "llinventorypanel.h"
 36
 37
 38static const std::string LANDMARKS_INVENTORY_LIST_NAME("landmarks_list");
 39
 40bool is_landmarks_panel(const LLInventoryPanel* inv_panel)
 41{
 42	if (NULL == inv_panel)
 43		return false;
 44	return inv_panel->getName() == LANDMARKS_INVENTORY_LIST_NAME;
 45}
 46
 47void fill_items_with_menu_items(std::vector<std::string>& items, LLMenuGL& menu)
 48{
 49	LLView::child_list_const_iter_t itor;
 50	for (itor = menu.beginChild(); itor != menu.endChild(); ++itor)
 51	{
 52		std::string name = (*itor)->getName();
 53		items.push_back(name);
 54	}
 55}
 56
 57// virtual
 58void LLPlacesLandmarkBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
 59{
 60	std::vector<std::string> items;
 61	std::vector<std::string> disabled_items;
 62
 63	if(isItemInTrash())
 64	{
 65		items.push_back(std::string("Purge Item"));
 66		if (!isItemRemovable())
 67		{
 68			disabled_items.push_back(std::string("Purge Item"));
 69		}
 70
 71		items.push_back(std::string("Restore Item"));
 72	}
 73	else
 74	{
 75		fill_items_with_menu_items(items, menu);
 76
 77		// Disabled items are processed via LLLandmarksPanel::isActionEnabled()
 78		// they should be synchronized with Places/My Landmarks/Gear menu. See EXT-1601 
 79	}
 80
 81	hide_context_entries(menu, items, disabled_items);
 82}
 83
 84
 85
 86void LLPlacesFolderBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
 87{
 88	{
 89		std::vector<std::string> items;
 90		std::vector<std::string> disabled_items;
 91
 92		LLInventoryPanel* inv_panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
 93		bool is_open = false;
 94		if (inv_panel)
 95		{
 96			LLFolderViewFolder* folder = dynamic_cast<LLFolderViewFolder*>(inv_panel->getRootFolder()->getItemByID(mUUID));
 97			is_open = (NULL != folder) && folder->isOpen();
 98		}
 99
100		// collect all items' names
101		fill_items_with_menu_items(items, menu);
102
103		// remove expand or collapse menu item depend on folder state
104		std::string collapse_expand_item_to_hide(is_open ? "expand" : "collapse");
105		std::vector<std::string>::iterator it = std::find(items.begin(), items.end(), collapse_expand_item_to_hide);
106		if (it != items.end())	items.erase(it);
107
108		// Disabled items are processed via LLLandmarksPanel::isActionEnabled()
109		// they should be synchronized with Places/My Landmarks/Gear menu. See EXT-1601 
110
111		// repeat parent functionality
112 		sSelf = getHandle(); // necessary for "New Folder" functionality
113
114		hide_context_entries(menu, items, disabled_items);
115	}
116}
117
118//virtual
119void LLPlacesFolderBridge::performAction(LLInventoryModel* model, std::string action)
120{
121	if ("expand" == action)
122	{
123		LLFolderViewFolder* act_folder = getFolder();
124		act_folder->toggleOpen();
125	}
126	else if ("collapse" == action)
127	{
128		LLFolderViewFolder* act_folder = getFolder();
129		act_folder->toggleOpen();
130	}
131	else
132	{
133		LLFolderBridge::performAction(model, action);
134	}
135}
136
137LLFolderViewFolder* LLPlacesFolderBridge::getFolder()
138{
139	LLFolderViewFolder* folder = NULL;
140	LLInventoryPanel* inv_panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
141	if (inv_panel)
142	{
143		folder = dynamic_cast<LLFolderViewFolder*>(inv_panel->getRootFolder()->getItemByID(mUUID));
144	}
145
146	return folder;
147}
148
149// virtual
150LLInvFVBridge* LLPlacesInventoryBridgeBuilder::createBridge(
151	LLAssetType::EType asset_type,
152	LLAssetType::EType actual_asset_type,
153	LLInventoryType::EType inv_type,
154	LLInventoryPanel* inventory,
155	LLFolderView* root,
156	const LLUUID& uuid,
157	U32 flags/* = 0x00*/) const
158{
159	LLInvFVBridge* new_listener = NULL;
160	switch(asset_type)
161	{
162	case LLAssetType::AT_LANDMARK:
163		if(!(inv_type == LLInventoryType::IT_LANDMARK))
164		{
165			llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << LLInventoryType::lookupHumanReadable(inv_type) << " on uuid " << uuid << llendl;
166		}
167		new_listener = new LLPlacesLandmarkBridge(inv_type, inventory, root, uuid, flags);
168		break;
169	case LLAssetType::AT_CATEGORY:
170		if (actual_asset_type == LLAssetType::AT_LINK_FOLDER)
171		{
172			// *TODO: Create a link folder handler instead if it is necessary
173			new_listener = LLInventoryFVBridgeBuilder::createBridge(
174				asset_type,
175				actual_asset_type,
176				inv_type,
177				inventory,
178				root,
179				uuid,
180				flags);
181			break;
182		}
183		new_listener = new LLPlacesFolderBridge(inv_type, inventory, root, uuid);
184		break;
185	default:
186		new_listener = LLInventoryFVBridgeBuilder::createBridge(
187			asset_type,
188			actual_asset_type,
189			inv_type,
190			inventory,
191			root,
192			uuid,
193			flags);
194	}
195	return new_listener;
196}
197
198// EOF