fileDialog.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _FILEDIALOG_H_
  23. #define _FILEDIALOG_H_
  24. #include "console/simBase.h"
  25. // [03/14/07] The file dialogs need refactoring, and will be refactored in Jugg.
  26. // Things that might need to change:
  27. // - The interface is not in fact platform agnotsic, it is win32 oriented.
  28. // - Filter format is highly windows specific, and is a little fragile, both for
  29. // win32 and for other platforms.
  30. // - Platform specific path strings are exposed to the console, because the
  31. // protected validators save them as such.
  32. // - Several of the FDS_XXX values are not options we want to give the user, such
  33. // as NOT warning on file overwrite. The values FDS_OVERWRITEPROMPT,
  34. // FDS_MUSTEXIST, and FDS_CHANGEPATH are not good things to give the user.
  35. // - The Execute method is virtual for good reason. It should be implemented for
  36. // each subclass. If common behavior is needed for Execute(), it can be
  37. // factored out in hidden platform specific code.
  38. /// @defgroup SystemDialogs Using System Dialogs
  39. /// @ingroup SystemDialogs
  40. /// FileDialogOpaqueData is both defined and implemented on a platform specific
  41. /// basis.
  42. class FileDialogOpaqueData;
  43. /// @ingroup SystemDialogs
  44. /// @internal
  45. /// Platform Agnostic Structure for holding information about a file dialog.
  46. struct FileDialogData
  47. {
  48. public:
  49. FileDialogData();
  50. ~FileDialogData();
  51. enum DialogStyle
  52. {
  53. FDS_OPEN = BIT(0),///< This is an open dialog.
  54. FDS_SAVE = BIT(1),///< This is a save dialog.
  55. FDS_OVERWRITEPROMPT = BIT(2),///< Can only be used in conjunction with style SaveDialog: prompt for a confirmation if a file will be overwritten.
  56. FDS_MUSTEXIST = BIT(3),///< The user may only select files that actually exist.
  57. FDS_MULTIPLEFILES = BIT(4),///< Can only be used in conjunction with style OpenDialog: allows selecting multiple files.
  58. FDS_CHANGEPATH = BIT(5),///< Change the current working path to the directory where the file(s) chosen by the user are.
  59. FDS_BROWSEFOLDER = BIT(6) ///< Select folders instead of files
  60. };
  61. U8 mStyle; ///< Specifies the Style of the File Dialog @see DialogStyle
  62. StringTableEntry mFilters; ///< List of Filters pipe separated e.g. "BMP Files (*.bmp)|*.bmp|JPG Files (*.jpg)|*.jpg"
  63. //StringTableEntry mFiles; // this is never used ///< Should only be referenced when using dialogStyle OpenDialog AND MultipleFiles: List of Files returned pipe separated
  64. StringTableEntry mFile; ///< Should be referenced when dialogStyle MultipleFiles is NOT used: the file path of the user selected file.
  65. StringTableEntry mDefaultPath; ///< Default path of dialog
  66. StringTableEntry mDefaultFile; ///< Default selected file of dialog
  67. StringTableEntry mTitle; ///< Title to display in file dialog
  68. FileDialogOpaqueData *mOpaqueData; ///< Stores platform specific info about the dialog
  69. };
  70. /// @ingroup SystemDialogs
  71. /// FileDialog is a platform agnostic dialog interface for querying the user for
  72. /// file locations. It is designed to be used through the exposed
  73. /// scripting interface.
  74. ///
  75. /// FileDialog is the base class for Native File Dialog controls in Torque. It provides these
  76. /// basic areas of functionality:
  77. ///
  78. /// - Inherits from SimObject and is exposed to the scripting interface
  79. /// - Provides blocking interface to allow instant return to script execution
  80. /// - Simple object configuration makes practical use easy and effective
  81. ///
  82. /// @attention
  83. /// FileDialog is *NOT* intended to be used directly in script and is only exposed to script
  84. /// to expose generic file dialog attributes.
  85. /// @see OpenFileDialog for a practical example on opening a file
  86. /// @see SaveFileDialog for a practical example of saving a file
  87. ///
  88. ///
  89. /// @{
  90. class FileDialog : public SimObject
  91. {
  92. typedef SimObject Parent;
  93. protected:
  94. FileDialogData mData; ///< Stores platform agnostic information about the dialogs properties
  95. bool mChangePath; ///< Exposed ChangePath Property
  96. bool mBoolTranslator; ///< Internally used to translate boolean values into their respective bits of dialog style
  97. public:
  98. FileDialog();
  99. virtual ~FileDialog();
  100. DECLARE_CONOBJECT(FileDialog);
  101. static void initPersistFields();
  102. virtual bool Execute();
  103. FileDialogData &getData() { return mData; };
  104. protected:
  105. /// @name FileDialog Properties
  106. /// @{
  107. /// @@property DefaultPath (String) : <i>Path to use as the default when the dialog is shown.</i>
  108. /// @code %fd.DefaultPath = "/source/myGameProject/data/images"; @endcode
  109. ///
  110. /// @li @b ChangePath (bool) : <c>Will change the working path of the tools to the selected path when not canceled</c>
  111. /// @code %fd.ChangePath = true; // Change Working Path on Success @endcode
  112. /// @internal
  113. static bool setDefaultPath( void *object, const char *index, const char *data );
  114. static bool setDefaultFile( void *object, const char *index, const char *data );
  115. static bool setFilters( void *object, const char *index, const char *data );
  116. static bool setChangePath( void *object, const char *index, const char *data );
  117. static const char* getChangePath(void* obj, const char* data);
  118. ///
  119. /// @}
  120. static bool setFile( void *object, const char *index, const char *data );
  121. };
  122. /// @}
  123. class OpenFileDialog : public FileDialog
  124. {
  125. typedef FileDialog Parent;
  126. /// Field Values
  127. /// @{
  128. /// @internal
  129. bool mMustExist; ///< Corresponds to FDS_MUSTEXIST flag on the PlatformFileDlgData structure
  130. bool mMultipleFiles; ///< Corresponds to the FDS_MULTIPLEFILES flag on the PlatformFileDlgData structure
  131. /// @}
  132. public:
  133. OpenFileDialog();
  134. virtual ~OpenFileDialog();
  135. DECLARE_CONOBJECT(OpenFileDialog); /// @internal
  136. static void initPersistFields();
  137. protected:
  138. ///
  139. /// @}
  140. /// Must Exist Property
  141. static bool setMustExist( void *object, const char *index, const char *data );
  142. static const char*getMustExist(void* obj, const char* data);
  143. /// Multiple Files Property
  144. static bool setMultipleFiles( void *object, const char *index, const char *data );
  145. static const char* getMultipleFiles(void* obj, const char* data);
  146. };
  147. class OpenFolderDialog : public OpenFileDialog
  148. {
  149. typedef OpenFileDialog Parent;
  150. public:
  151. StringTableEntry mMustExistInDir;
  152. OpenFolderDialog();
  153. DECLARE_CONOBJECT(OpenFolderDialog);
  154. static void initPersistFields();
  155. };
  156. class SaveFileDialog : public FileDialog
  157. {
  158. typedef FileDialog Parent;
  159. public:
  160. SaveFileDialog();
  161. virtual ~SaveFileDialog();
  162. DECLARE_CONOBJECT(SaveFileDialog);
  163. bool mOverwritePrompt;
  164. static void initPersistFields();
  165. protected:
  166. // Overwrite Prompt Property
  167. static bool setOverwritePrompt( void *object, const char *index, const char *data );
  168. static const char* getOverwritePrompt(void* obj, const char* data);
  169. };
  170. #endif // _FILEDIALOG_H_