hbfloaterinvitemspicker.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * @file hbfloaterinvitemspicker.h
  3. * @brief Generic inventory items picker.
  4. * Also replaces LL's environment settings and materials pickers.
  5. *
  6. * $LicenseInfo:firstyear=2019&license=viewergpl$
  7. *
  8. * Copyright (c) 2019-2023, Henri Beauchamp
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_HBFLOATERINVENTORYPICKER_H
  34. #define LL_HBFLOATERINVENTORYPICKER_H
  35. #include "llfloater.h"
  36. #include "llfolderview.h"
  37. class LLButton;
  38. class LLCheckBoxCtrl;
  39. class LLFolderView;
  40. class LLInventoryPanel;
  41. class LLSearchEditor;
  42. class LLTextBox;
  43. class HBFloaterInvItemsPicker final : public LLFloater
  44. {
  45. protected:
  46. LOG_CLASS(HBFloaterInvItemsPicker);
  47. public:
  48. // The callback receives a vector containing the selected inventory items
  49. // names, another vector containing the corresponding item UUIDs (with the
  50. // same index), the configured user data pointer, and a boolean which is
  51. // true whenever the floater gets closed immediately after the callback has
  52. // returned.
  53. typedef void(*callback_t)(const std::vector<std::string>& names,
  54. const uuid_vec_t& ids, void* userdata,
  55. bool on_close);
  56. // Call this to select one or several inventory items. The callback
  57. // function will be passed the selected inventory name(s) and UUID(s), if
  58. // any.
  59. // The inventory picker floater will automatically become dependent on the
  60. // parent floater of 'ownerp', if there is one (and if owner is not NULL,
  61. // of course), else it will stay independent.
  62. HBFloaterInvItemsPicker(LLView* ownerp, callback_t cb, void* userdata);
  63. ~HBFloaterInvItemsPicker() override;
  64. // Use this method to restrict the inventory items asset type (and possibly
  65. // sub-type, such as for wearables and environment settings). Showing all
  66. // items of all types is the default behaviour when the floater is created.
  67. void setAssetType(LLAssetType::EType type, S32 sub_type = -1);
  68. // Use this method to (dis)allow multiple inventory items selection. Single
  69. // item selection is the default behaviour when the floater is created.
  70. void setAllowMultiple(bool allow_multiple = true);
  71. // Use this method to exclude the Library from the list of selectable items
  72. // (when the floater is created, the default behaviour is to show the
  73. // library).
  74. void setExcludeLibrary(bool exclude = true);
  75. // When 'auto_close' is true, the picker will auto-close when parented and
  76. // loosing focus (thus cancelling the picking action) and when the "Select"
  77. // button is pressed (else "Select" just invokes the callback). Auto-close
  78. // is the default behaviour when the floater is created.
  79. void setAutoClose(bool auto_close = true);
  80. // Causes the triggering of the callback with an empty selection when the
  81. // floater is closed in any way other than via the "Select" button (with
  82. // auto-close).
  83. LL_INLINE void callBackOnClose() { mCallBackOnClose = true; }
  84. // Shows or hides the "Apply immediately" check box (defaults to hidden).
  85. // When "Apply immediately" is shown and checked, any selection event in
  86. // the list triggers a callback invocation.
  87. void allowApplyImmediately(bool enable = true);
  88. // When shown, sets the "Apply immediately" check box status to checked or
  89. // not. Returns true on success, or false on failure (check box not shown).
  90. // When "Apply immediately" is shown and checked, any selection event in
  91. // the list triggers a callback invocation.
  92. bool setApplyImmediately(bool checked = true);
  93. // Sets the debug setting name associated with the "Apply immediately"
  94. // check box, enables/allows the latter, and syncs its state with the
  95. // corresponding debug setting (which will also be updated with the check
  96. // box status when changed by the user actions). The debug setting must be
  97. // a global one and of the boolean type (the method then succeeds and
  98. // returns true), otherwise this method complains with a warning and aborts
  99. // (returning false).
  100. bool setApplyImmediatelyControl(const char* control_name);
  101. // Sets the permissions mask for inventory filtering.
  102. void setFilterPermMask(PermissionMask mask);
  103. // Selects a given inventory object in the panel on opening, if possible
  104. // (the inventory object must exist, match the type, the permissions).
  105. // Set this *last* after any call to setAssetType() or setFilterPermMask(),
  106. // else the selection will not happen (it is cleared by the asset type and
  107. // permissions setters).
  108. void setSelection(const LLUUID& id);
  109. private:
  110. bool postBuild() override;
  111. void onClose(bool app_quitting) override;
  112. void onFocusLost() override;
  113. static void onBtnSelect(void* userdata);
  114. static void onBtnClose(void* userdata);
  115. static void onSearchEdit(const std::string& search_string, void* userdata);
  116. static void onInventorySelectionChange(LLFolderView* folderp, bool,
  117. void* userdata);
  118. private:
  119. LLInventoryPanel* mInventoryPanel;
  120. LLSearchEditor* mSearchEditor;
  121. LLCheckBoxCtrl* mApplyImmediatelyCheck;
  122. LLTextBox* mSelectToApplyText;
  123. LLButton* mSelectButton;
  124. LLUUID mSelectId;
  125. LLSaveFolderState mSavedFolderState;
  126. uuid_vec_t mSelectedInvIDs;
  127. std::vector<std::string> mSelectedInvNames;
  128. void (*mCallback)(const std::vector<std::string>&,
  129. const uuid_vec_t&, void*, bool);
  130. void* mCallbackUserdata;
  131. PermissionMask mPermissionMask;
  132. LLAssetType::EType mAssetType;
  133. S32 mSubType;
  134. bool mHasParentFloater;
  135. bool mAutoClose;
  136. bool mCallBackOnClose;
  137. bool mCanApplyImmediately;
  138. };
  139. #endif