The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
8.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #ifndef __JUCE_FILECHOOSER_JUCEHEADER__
  24. #define __JUCE_FILECHOOSER_JUCEHEADER__
  25. #include "juce_FilePreviewComponent.h"
  26. //==============================================================================
  27. /**
  28. Creates a dialog box to choose a file or directory to load or save.
  29. To use a FileChooser:
  30. - create one (as a local stack variable is the neatest way)
  31. - call one of its browseFor.. methods
  32. - if this returns true, the user has selected a file, so you can retrieve it
  33. with the getResult() method.
  34. e.g. @code
  35. void loadMooseFile()
  36. {
  37. FileChooser myChooser ("Please select the moose you want to load...",
  38. File::getSpecialLocation (File::userHomeDirectory),
  39. "*.moose");
  40. if (myChooser.browseForFileToOpen())
  41. {
  42. File mooseFile (myChooser.getResult());
  43. loadMoose (mooseFile);
  44. }
  45. }
  46. @endcode
  47. */
  48. class JUCE_API FileChooser
  49. {
  50. public:
  51. //==============================================================================
  52. /** Creates a FileChooser.
  53. After creating one of these, use one of the browseFor... methods to display it.
  54. @param dialogBoxTitle a text string to display in the dialog box to
  55. tell the user what's going on
  56. @param initialFileOrDirectory the file or directory that should be selected when
  57. the dialog box opens. If this parameter is set to
  58. File::nonexistent, a sensible default directory
  59. will be used instead.
  60. @param filePatternsAllowed a set of file patterns to specify which files can be
  61. selected - each pattern should be separated by a
  62. comma or semi-colon, e.g. "*" or "*.jpg;*.gif". An
  63. empty string means that all files are allowed
  64. @param useOSNativeDialogBox if true, then a native dialog box will be used if
  65. possible; if false, then a Juce-based browser dialog
  66. box will always be used
  67. @see browseForFileToOpen, browseForFileToSave, browseForDirectory
  68. */
  69. FileChooser (const String& dialogBoxTitle,
  70. const File& initialFileOrDirectory = File::nonexistent,
  71. const String& filePatternsAllowed = String::empty,
  72. const bool useOSNativeDialogBox = true);
  73. /** Destructor. */
  74. ~FileChooser();
  75. //==============================================================================
  76. /** Shows a dialog box to choose a file to open.
  77. This will display the dialog box modally, using an "open file" mode, so that
  78. it won't allow non-existent files or directories to be chosen.
  79. @param previewComponent an optional component to display inside the dialog
  80. box to show special info about the files that the user
  81. is browsing. The component will not be deleted by this
  82. object, so the caller must take care of it.
  83. @returns true if the user selected a file, in which case, use the getResult()
  84. method to find out what it was. Returns false if they cancelled instead.
  85. @see browseForFileToSave, browseForDirectory
  86. */
  87. bool browseForFileToOpen (FilePreviewComponent* previewComponent = 0);
  88. /** Same as browseForFileToOpen, but allows the user to select multiple files.
  89. The files that are returned can be obtained by calling getResults(). See
  90. browseForFileToOpen() for more info about the behaviour of this method.
  91. */
  92. bool browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent = 0);
  93. /** Shows a dialog box to choose a file to save.
  94. This will display the dialog box modally, using an "save file" mode, so it
  95. will allow non-existent files to be chosen, but not directories.
  96. @param warnAboutOverwritingExistingFiles if true, the dialog box will ask
  97. the user if they're sure they want to overwrite a file that already
  98. exists
  99. @returns true if the user chose a file and pressed 'ok', in which case, use
  100. the getResult() method to find out what the file was. Returns false
  101. if they cancelled instead.
  102. @see browseForFileToOpen, browseForDirectory
  103. */
  104. bool browseForFileToSave (const bool warnAboutOverwritingExistingFiles);
  105. /** Shows a dialog box to choose a directory.
  106. This will display the dialog box modally, using an "open directory" mode, so it
  107. will only allow directories to be returned, not files.
  108. @returns true if the user chose a directory and pressed 'ok', in which case, use
  109. the getResult() method to find out what they chose. Returns false
  110. if they cancelled instead.
  111. @see browseForFileToOpen, browseForFileToSave
  112. */
  113. bool browseForDirectory();
  114. //==============================================================================
  115. /** Returns the last file that was chosen by one of the browseFor methods.
  116. After calling the appropriate browseFor... method, this method lets you
  117. find out what file or directory they chose.
  118. Note that the file returned is only valid if the browse method returned true (i.e.
  119. if the user pressed 'ok' rather than cancelling).
  120. If you're using a multiple-file select, then use the getResults() method instead,
  121. to obtain the list of all files chosen.
  122. @see getResults
  123. */
  124. const File getResult() const;
  125. /** Returns a list of all the files that were chosen during the last call to a
  126. browse method.
  127. This array may be empty if no files were chosen, or can contain multiple entries
  128. if multiple files were chosen.
  129. @see getResult
  130. */
  131. const OwnedArray <File>& getResults() const;
  132. //==============================================================================
  133. juce_UseDebuggingNewOperator
  134. private:
  135. String title, filters;
  136. File startingFile;
  137. OwnedArray <File> results;
  138. bool useNativeDialogBox;
  139. bool showDialog (const bool isDirectory,
  140. const bool isSave,
  141. const bool warnAboutOverwritingExistingFiles,
  142. const bool selectMultipleFiles,
  143. FilePreviewComponent* const previewComponent);
  144. static void showPlatformDialog (OwnedArray<File>& results,
  145. const String& title,
  146. const File& file,
  147. const String& filters,
  148. bool isDirectory,
  149. bool isSave,
  150. bool warnAboutOverwritingExistingFiles,
  151. bool selectMultipleFiles,
  152. FilePreviewComponent* previewComponent);
  153. };
  154. #endif // __JUCE_FILECHOOSER_JUCEHEADER__