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