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