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.

162 lines
6.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  18. #define __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  19. #include "juce_FileBrowserComponent.h"
  20. #include "../windows/juce_ResizableWindow.h"
  21. #include "../buttons/juce_TextButton.h"
  22. #include "../windows/juce_AlertWindow.h"
  23. //==============================================================================
  24. /**
  25. A file open/save dialog box.
  26. This is a Juce-based file dialog box; to use a native file chooser, see the
  27. FileChooser class.
  28. To use one of these, create it and call its show() method. e.g.
  29. @code
  30. {
  31. WildcardFileFilter wildcardFilter ("*.foo", String::empty, "Foo files");
  32. FileBrowserComponent browser (FileBrowserComponent::canSelectFiles,
  33. File::nonexistent,
  34. &wildcardFilter,
  35. nullptr);
  36. FileChooserDialogBox dialogBox ("Open some kind of file",
  37. "Please choose some kind of file that you want to open...",
  38. browser,
  39. false,
  40. Colours::lightgrey);
  41. if (dialogBox.show())
  42. {
  43. File selectedFile = browser.getSelectedFile (0);
  44. ...etc..
  45. }
  46. }
  47. @endcode
  48. @see FileChooser
  49. */
  50. class JUCE_API FileChooserDialogBox : public ResizableWindow,
  51. private ButtonListener, // (can't use Button::Listener due to idiotic VC2005 bug)
  52. private FileBrowserListener
  53. {
  54. public:
  55. //==============================================================================
  56. /** Creates a file chooser box.
  57. @param title the main title to show at the top of the box
  58. @param instructions an optional longer piece of text to show below the title in
  59. a smaller font, describing in more detail what's required.
  60. @param browserComponent a FileBrowserComponent that will be shown inside this dialog
  61. box. Make sure you delete this after (but not before!) the
  62. dialog box has been deleted.
  63. @param warnAboutOverwritingExistingFiles if true, then the user will be asked to confirm
  64. if they try to select a file that already exists. (This
  65. flag is only used when saving files)
  66. @param backgroundColour the background colour for the top level window
  67. @see FileBrowserComponent, FilePreviewComponent
  68. */
  69. FileChooserDialogBox (const String& title,
  70. const String& instructions,
  71. FileBrowserComponent& browserComponent,
  72. bool warnAboutOverwritingExistingFiles,
  73. Colour backgroundColour);
  74. /** Destructor. */
  75. ~FileChooserDialogBox();
  76. //==============================================================================
  77. #if JUCE_MODAL_LOOPS_PERMITTED
  78. /** Displays and runs the dialog box modally.
  79. This will show the box with the specified size, returning true if the user
  80. pressed 'ok', or false if they cancelled.
  81. Leave the width or height as 0 to use the default size
  82. */
  83. bool show (int width = 0, int height = 0);
  84. /** Displays and runs the dialog box modally.
  85. This will show the box with the specified size at the specified location,
  86. returning true if the user pressed 'ok', or false if they cancelled.
  87. Leave the width or height as 0 to use the default size.
  88. */
  89. bool showAt (int x, int y, int width, int height);
  90. #endif
  91. /** Sets the size of this dialog box to its default and positions it either in the
  92. centre of the screen, or centred around a component that is provided.
  93. */
  94. void centreWithDefaultSize (Component* componentToCentreAround = nullptr);
  95. //==============================================================================
  96. /** A set of colour IDs to use to change the colour of various aspects of the box.
  97. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  98. methods.
  99. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  100. */
  101. enum ColourIds
  102. {
  103. titleTextColourId = 0x1000850, /**< The colour to use to draw the box's title. */
  104. };
  105. private:
  106. class ContentComponent;
  107. ContentComponent* content;
  108. const bool warnAboutOverwritingExistingFiles;
  109. void buttonClicked (Button*);
  110. void closeButtonPressed();
  111. void selectionChanged();
  112. void fileClicked (const File&, const MouseEvent&);
  113. void fileDoubleClicked (const File&);
  114. void browserRootChanged (const File&);
  115. void okButtonPressed();
  116. void createNewFolder();
  117. void createNewFolderConfirmed (const String& name);
  118. static void okToOverwriteFileCallback (int result, FileChooserDialogBox*);
  119. static void createNewFolderCallback (int result, FileChooserDialogBox*, Component::SafePointer<AlertWindow>);
  120. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileChooserDialogBox)
  121. };
  122. #endif // __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__