Audio plugin host https://kx.studio/carla
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.

juce_FileChooserDialogBox.h 6.8KB

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