The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

154 lines
6.0KB

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