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.

164 lines
6.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A file open/save dialog box.
  24. This is a Juce-based file dialog box; to use a native file chooser, see the
  25. FileChooser class.
  26. To use one of these, create it and call its show() method. e.g.
  27. @code
  28. {
  29. WildcardFileFilter wildcardFilter ("*.foo", String(), "Foo files");
  30. FileBrowserComponent browser (FileBrowserComponent::canSelectFiles,
  31. File(),
  32. &wildcardFilter,
  33. nullptr);
  34. FileChooserDialogBox dialogBox ("Open some kind of file",
  35. "Please choose some kind of file that you want to open...",
  36. browser,
  37. false,
  38. Colours::lightgrey);
  39. if (dialogBox.show())
  40. {
  41. File selectedFile = browser.getSelectedFile (0);
  42. ...etc..
  43. }
  44. }
  45. @endcode
  46. @see FileChooser
  47. @tags{GUI}
  48. */
  49. class JUCE_API FileChooserDialogBox : public ResizableWindow,
  50. private FileBrowserListener
  51. {
  52. public:
  53. //==============================================================================
  54. /** Creates a file chooser box.
  55. @param title the main title to show at the top of the box
  56. @param instructions an optional longer piece of text to show below the title in
  57. a smaller font, describing in more detail what's required.
  58. @param browserComponent a FileBrowserComponent that will be shown inside this dialog
  59. box. Make sure you delete this after (but not before!) the
  60. dialog box has been deleted.
  61. @param warnAboutOverwritingExistingFiles if true, then the user will be asked to confirm
  62. if they try to select a file that already exists. (This
  63. flag is only used when saving files)
  64. @param backgroundColour the background colour for the top level window
  65. @param parentComponent an optional component which should be the parent
  66. for the file chooser. If this is a nullptr then the
  67. dialog box will be a top-level window. AUv3s on iOS
  68. must specify this parameter as opening a top-level window
  69. in an AUv3 is forbidden due to sandbox restrictions.
  70. @see FileBrowserComponent, FilePreviewComponent
  71. */
  72. FileChooserDialogBox (const String& title,
  73. const String& instructions,
  74. FileBrowserComponent& browserComponent,
  75. bool warnAboutOverwritingExistingFiles,
  76. Colour backgroundColour,
  77. Component* parentComponent = nullptr);
  78. /** Destructor. */
  79. ~FileChooserDialogBox() override;
  80. //==============================================================================
  81. #if JUCE_MODAL_LOOPS_PERMITTED
  82. /** Displays and runs the dialog box modally.
  83. This will show the box with the specified size, returning true if the user
  84. pressed 'ok', or false if they cancelled.
  85. Leave the width or height as 0 to use the default size
  86. */
  87. bool show (int width = 0, int height = 0);
  88. /** Displays and runs the dialog box modally.
  89. This will show the box with the specified size at the specified location,
  90. returning true if the user pressed 'ok', or false if they cancelled.
  91. Leave the width or height as 0 to use the default size.
  92. */
  93. bool showAt (int x, int y, int width, int height);
  94. #endif
  95. /** Sets the size of this dialog box to its default and positions it either in the
  96. centre of the screen, or centred around a component that is provided.
  97. */
  98. void centreWithDefaultSize (Component* componentToCentreAround = nullptr);
  99. //==============================================================================
  100. /** A set of colour IDs to use to change the colour of various aspects of the box.
  101. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  102. methods.
  103. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  104. */
  105. enum ColourIds
  106. {
  107. titleTextColourId = 0x1000850, /**< The colour to use to draw the box's title. */
  108. };
  109. private:
  110. class ContentComponent;
  111. ContentComponent* content;
  112. const bool warnAboutOverwritingExistingFiles;
  113. void closeButtonPressed();
  114. void selectionChanged() override;
  115. void fileClicked (const File&, const MouseEvent&) override;
  116. void fileDoubleClicked (const File&) override;
  117. void browserRootChanged (const File&) override;
  118. int getDefaultWidth() const;
  119. void okButtonPressed();
  120. void createNewFolder();
  121. void createNewFolderConfirmed (const String& name);
  122. static void okToOverwriteFileCallback (int result, FileChooserDialogBox*);
  123. static void createNewFolderCallback (int result, FileChooserDialogBox*, Component::SafePointer<AlertWindow>);
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileChooserDialogBox)
  125. };
  126. } // namespace juce