hbfileselector.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /**
  2. * @file hbfileselector.h
  3. * @brief The HBFileSelector class declaration
  4. *
  5. * $LicenseInfo:firstyear=2014&license=viewergpl$
  6. *
  7. * Copyright (c) 2014, Henri Beauchamp
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_HBFILESELECTOR_H
  33. #define LL_HBFILESELECTOR_H
  34. #include <deque>
  35. #include <vector>
  36. #include "llerror.h"
  37. #include "hbfastmap.h"
  38. #include "llfloater.h"
  39. class LLButton;
  40. class LLCheckBoxCtrl;
  41. class LLFlyoutButton;
  42. class LLLineEditor;
  43. class LLScrollListCtrl;
  44. class LLTextBox;
  45. class HBFileSelector final : public LLFloater
  46. {
  47. protected:
  48. LOG_CLASS(HBFileSelector);
  49. public:
  50. ~HBFileSelector() override;
  51. bool postBuild() override;
  52. void draw() override;
  53. enum ELoadFilter
  54. {
  55. FFLOAD_ALL = 1,
  56. FFLOAD_TEXT = 2,
  57. FFLOAD_XML = 3,
  58. FFLOAD_XUI = 4,
  59. FFLOAD_SCRIPT = 5,
  60. FFLOAD_SOUND = 6,
  61. FFLOAD_ANIM = 7,
  62. FFLOAD_MODEL = 8,
  63. FFLOAD_OBJ = 9, // Not used (no loading of *.obj files)
  64. FFLOAD_TERRAIN = 10,
  65. FFLOAD_IMAGE = 11,
  66. FFLOAD_HDRI = 12,
  67. FFLOAD_LUA = 13,
  68. FFLOAD_GLTF = 14,
  69. FFLOAD_NONE = 255,
  70. };
  71. enum ESaveFilter
  72. {
  73. FFSAVE_ALL = 1,
  74. FFSAVE_TXT = 2,
  75. FFSAVE_XML = 3,
  76. FFSAVE_XUI = 4,
  77. FFSAVE_LSL = 5,
  78. FFSAVE_WAV = 6,
  79. FFSAVE_BVH = 7,
  80. FFSAVE_DAE = 8,
  81. FFSAVE_OBJ = 9,
  82. FFSAVE_RAW = 10,
  83. FFSAVE_TGA = 11,
  84. FFSAVE_PNG = 12,
  85. FFSAVE_JPG = 13,
  86. FFSAVE_J2C = 14,
  87. FFSAVE_BMP = 15,
  88. FFSAVE_GLTF = 16,
  89. FFSAVE_NONE = 255,
  90. };
  91. typedef void (*HBLoadFileCallback)(ELoadFilter type, std::string& filename,
  92. void* user_data);
  93. typedef void (*HBLoadFilesCallback)(ELoadFilter type,
  94. std::deque<std::string>& files,
  95. void* user_data);
  96. typedef void (*HBSaveFileCallback)(ESaveFilter type, std::string& filename,
  97. void* user_data);
  98. typedef void (*HBDirPickCallback)(std::string& dirname, void* user_data);
  99. static void loadFile(ELoadFilter filter, HBLoadFileCallback callback,
  100. void* user_data = NULL);
  101. static void loadFiles(ELoadFilter filter, HBLoadFilesCallback callback,
  102. void* user_data = NULL);
  103. static void saveFile(ESaveFilter filter, std::string suggestion,
  104. HBSaveFileCallback callback, void* user_data = NULL);
  105. static void pickDirectory(std::string suggestion,
  106. HBDirPickCallback callback,
  107. void* user_data = NULL);
  108. static bool isInUse() { return sInstance != NULL; }
  109. static void saveDefaultPaths(const std::string& filename);
  110. static void loadDefaultPaths(const std::string& filename);
  111. private:
  112. enum EContext
  113. {
  114. CONTEXT_UNKNOWN = 0,
  115. CONTEXT_DEFAULT = 1,
  116. CONTEXT_TXT = 2,
  117. CONTEXT_XML = 3,
  118. CONTEXT_XUI = 4,
  119. CONTEXT_LSL = 5,
  120. CONTEXT_SOUND = 6,
  121. CONTEXT_ANIM = 7,
  122. CONTEXT_MODEL = 8,
  123. CONTEXT_OBJ = 9, // Not used (using CONTEXT_MODEL for *.obj)
  124. CONTEXT_RAW = 10,
  125. CONTEXT_IMAGE = 11,
  126. CONTEXT_LUA = 12,
  127. CONTEXT_MATERIAL = 13,
  128. CONTEXT_END
  129. };
  130. HBFileSelector(ELoadFilter filter, HBLoadFileCallback callback,
  131. void* user_data);
  132. HBFileSelector(ELoadFilter filter, HBLoadFilesCallback callback,
  133. void* user_data);
  134. HBFileSelector(ESaveFilter filter, std::string& suggestion,
  135. HBSaveFileCallback callback, void* user_data);
  136. HBFileSelector(std::string& suggestion,
  137. HBDirPickCallback callback, void* user_data);
  138. void init(void* user_data);
  139. void setValidExtensions();
  140. void setPrompt();
  141. void setPathFromContext();
  142. bool isCurrentPathAtRoot();
  143. bool isFileExtensionValid(const std::string& filename);
  144. void setSelectionData();
  145. void doCallback();
  146. static void onButtonCreate(void* user_data);
  147. static void onButtonRefresh(void* user_data);
  148. static void onButtonCancel(void* user_data);
  149. static void onButtonOK(void* user_data);
  150. static void onButtonDirLevel(LLUICtrl* ctrl, void* user_data);
  151. static void onSelectDirectory(LLUICtrl*, void* user_data);
  152. static void onLevelDown(void* user_data);
  153. static void onSelectFile(LLUICtrl*, void* user_data);
  154. static void onCommitCheckBox(LLUICtrl*, void* user_data);
  155. static bool onHandleKeyCallback(KEY key, MASK mask, LLLineEditor* caller,
  156. void* user_data);
  157. static void onKeystrokeCallback(LLLineEditor* caller, void* user_data);
  158. private:
  159. void (*mLoadFileCallback)(ELoadFilter type,
  160. std::string& filename,
  161. void* user_data);
  162. void (*mLoadFilesCallback)(ELoadFilter type,
  163. std::deque<std::string>& files,
  164. void* user_data);
  165. void (*mSaveFileCallback)(ESaveFilter type,
  166. std::string& filename,
  167. void* user_data);
  168. void (*mDirPickCallback)(std::string& dirname,
  169. void* user_data);
  170. void* mCallbackUserData;
  171. LLFlyoutButton* mDirLevelFlyoutBtn;
  172. LLButton* mCreateBtn;
  173. LLButton* mRefreshBtn;
  174. LLButton* mCancelBtn;
  175. LLButton* mOKBtn;
  176. LLCheckBoxCtrl* mShowHiddenCheck;
  177. LLCheckBoxCtrl* mShowAllTypesCheck;
  178. LLLineEditor* mInputLine;
  179. LLScrollListCtrl* mDirectoriesList;
  180. LLScrollListCtrl* mFilesList;
  181. LLTextBox* mPromptTextBox;
  182. LLTextBox* mPathTextBox;
  183. ELoadFilter mLoadFilter;
  184. ESaveFilter mSaveFilter;
  185. EContext mContext;
  186. std::string mCurrentSelection;
  187. std::string mCurrentEntry;
  188. std::deque<std::string> mFiles;
  189. std::vector<std::string> mValidExtensions;
  190. std::string mFileTypeDescription;
  191. std::string mCurrentPath;
  192. bool mIsDirty;
  193. bool mCallbackDone;
  194. bool mMultiple;
  195. bool mSavePicker;
  196. bool mDirPicker;
  197. bool mCreatingDirectory;
  198. static HBFileSelector* sInstance;
  199. typedef fast_hmap<S32, std::string> context_map_t;
  200. static context_map_t sContextToPathMap;
  201. static std::string sLastPath;
  202. };
  203. #endif // LL_HBFILESELECTOR_H