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.

161 lines
6.5KB

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