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.

158 lines
6.2KB

  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_H_INCLUDED
  18. #define JUCE_FILECHOOSERDIALOGBOX_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A file open/save dialog box.
  22. This is a Juce-based file dialog box; to use a native file chooser, see the
  23. FileChooser class.
  24. To use one of these, create it and call its show() method. e.g.
  25. @code
  26. {
  27. WildcardFileFilter wildcardFilter ("*.foo", String::empty, "Foo files");
  28. FileBrowserComponent browser (FileBrowserComponent::canSelectFiles,
  29. File::nonexistent,
  30. &wildcardFilter,
  31. nullptr);
  32. FileChooserDialogBox dialogBox ("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. if (dialogBox.show())
  38. {
  39. File selectedFile = browser.getSelectedFile (0);
  40. ...etc..
  41. }
  42. }
  43. @endcode
  44. @see FileChooser
  45. */
  46. class JUCE_API FileChooserDialogBox : public ResizableWindow,
  47. private ButtonListener, // (can't use Button::Listener due to idiotic VC2005 bug)
  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. @see FileBrowserComponent, FilePreviewComponent
  64. */
  65. FileChooserDialogBox (const String& title,
  66. const String& instructions,
  67. FileBrowserComponent& browserComponent,
  68. bool warnAboutOverwritingExistingFiles,
  69. Colour backgroundColour);
  70. /** Destructor. */
  71. ~FileChooserDialogBox();
  72. //==============================================================================
  73. #if JUCE_MODAL_LOOPS_PERMITTED
  74. /** Displays and runs the dialog box modally.
  75. This will show the box with the specified size, returning true if the user
  76. pressed 'ok', or false if they cancelled.
  77. Leave the width or height as 0 to use the default size
  78. */
  79. bool show (int width = 0, int height = 0);
  80. /** Displays and runs the dialog box modally.
  81. This will show the box with the specified size at the specified location,
  82. returning true if the user pressed 'ok', or false if they cancelled.
  83. Leave the width or height as 0 to use the default size.
  84. */
  85. bool showAt (int x, int y, int width, int height);
  86. #endif
  87. /** Sets the size of this dialog box to its default and positions it either in the
  88. centre of the screen, or centred around a component that is provided.
  89. */
  90. void centreWithDefaultSize (Component* componentToCentreAround = nullptr);
  91. //==============================================================================
  92. /** A set of colour IDs to use to change the colour of various aspects of the box.
  93. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  94. methods.
  95. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  96. */
  97. enum ColourIds
  98. {
  99. titleTextColourId = 0x1000850, /**< The colour to use to draw the box's title. */
  100. };
  101. private:
  102. class ContentComponent;
  103. ContentComponent* content;
  104. const bool warnAboutOverwritingExistingFiles;
  105. void buttonClicked (Button*) override;
  106. void closeButtonPressed();
  107. void selectionChanged() override;
  108. void fileClicked (const File&, const MouseEvent&) override;
  109. void fileDoubleClicked (const File&) override;
  110. void browserRootChanged (const File&) override;
  111. int getDefaultWidth() const;
  112. void okButtonPressed();
  113. void createNewFolder();
  114. void createNewFolderConfirmed (const String& name);
  115. static void okToOverwriteFileCallback (int result, FileChooserDialogBox*);
  116. static void createNewFolderCallback (int result, FileChooserDialogBox*, Component::SafePointer<AlertWindow>);
  117. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileChooserDialogBox)
  118. };
  119. #endif // JUCE_FILECHOOSERDIALOGBOX_H_INCLUDED