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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. */
  48. class JUCE_API FileChooserDialogBox : public ResizableWindow,
  49. private Button::Listener,
  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. @see FileBrowserComponent, FilePreviewComponent
  66. */
  67. FileChooserDialogBox (const String& title,
  68. const String& instructions,
  69. FileBrowserComponent& browserComponent,
  70. bool warnAboutOverwritingExistingFiles,
  71. Colour backgroundColour);
  72. /** Destructor. */
  73. ~FileChooserDialogBox();
  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 buttonClicked (Button*) override;
  108. void closeButtonPressed();
  109. void selectionChanged() override;
  110. void fileClicked (const File&, const MouseEvent&) override;
  111. void fileDoubleClicked (const File&) override;
  112. void browserRootChanged (const File&) override;
  113. int getDefaultWidth() const;
  114. void okButtonPressed();
  115. void createNewFolder();
  116. void createNewFolderConfirmed (const String& name);
  117. static void okToOverwriteFileCallback (int result, FileChooserDialogBox*);
  118. static void createNewFolderCallback (int result, FileChooserDialogBox*, Component::SafePointer<AlertWindow>);
  119. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileChooserDialogBox)
  120. };
  121. } // namespace juce