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.1KB

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