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.

163 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  19. #define __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  20. #include "juce_FileBrowserComponent.h"
  21. #include "../windows/juce_ResizableWindow.h"
  22. #include "../buttons/juce_TextButton.h"
  23. #include "../windows/juce_AlertWindow.h"
  24. //==============================================================================
  25. /**
  26. A file open/save dialog box.
  27. This is a Juce-based file dialog box; to use a native file chooser, see the
  28. FileChooser class.
  29. To use one of these, create it and call its show() method. e.g.
  30. @code
  31. {
  32. WildcardFileFilter wildcardFilter ("*.foo", String::empty, "Foo files");
  33. FileBrowserComponent browser (FileBrowserComponent::canSelectFiles,
  34. File::nonexistent,
  35. &wildcardFilter,
  36. nullptr);
  37. FileChooserDialogBox dialogBox ("Open some kind of file",
  38. "Please choose some kind of file that you want to open...",
  39. browser,
  40. false,
  41. Colours::lightgrey);
  42. if (dialogBox.show())
  43. {
  44. File selectedFile = browser.getSelectedFile (0);
  45. ...etc..
  46. }
  47. }
  48. @endcode
  49. @see FileChooser
  50. */
  51. class JUCE_API FileChooserDialogBox : public ResizableWindow,
  52. private ButtonListener, // (can't use Button::Listener due to idiotic VC2005 bug)
  53. private FileBrowserListener
  54. {
  55. public:
  56. //==============================================================================
  57. /** Creates a file chooser box.
  58. @param title the main title to show at the top of the box
  59. @param instructions an optional longer piece of text to show below the title in
  60. a smaller font, describing in more detail what's required.
  61. @param browserComponent a FileBrowserComponent that will be shown inside this dialog
  62. box. Make sure you delete this after (but not before!) the
  63. dialog box has been deleted.
  64. @param warnAboutOverwritingExistingFiles if true, then the user will be asked to confirm
  65. if they try to select a file that already exists. (This
  66. flag is only used when saving files)
  67. @param backgroundColour the background colour for the top level window
  68. @see FileBrowserComponent, FilePreviewComponent
  69. */
  70. FileChooserDialogBox (const String& title,
  71. const String& instructions,
  72. FileBrowserComponent& browserComponent,
  73. bool warnAboutOverwritingExistingFiles,
  74. const Colour& backgroundColour);
  75. /** Destructor. */
  76. ~FileChooserDialogBox();
  77. //==============================================================================
  78. #if JUCE_MODAL_LOOPS_PERMITTED
  79. /** Displays and runs the dialog box modally.
  80. This will show the box with the specified size, returning true if the user
  81. pressed 'ok', or false if they cancelled.
  82. Leave the width or height as 0 to use the default size
  83. */
  84. bool show (int width = 0, int height = 0);
  85. /** Displays and runs the dialog box modally.
  86. This will show the box with the specified size at the specified location,
  87. returning true if the user pressed 'ok', or false if they cancelled.
  88. Leave the width or height as 0 to use the default size.
  89. */
  90. bool showAt (int x, int y, int width, int height);
  91. #endif
  92. /** Sets the size of this dialog box to its default and positions it either in the
  93. centre of the screen, or centred around a component that is provided.
  94. */
  95. void centreWithDefaultSize (Component* componentToCentreAround = nullptr);
  96. //==============================================================================
  97. /** A set of colour IDs to use to change the colour of various aspects of the box.
  98. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  99. methods.
  100. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  101. */
  102. enum ColourIds
  103. {
  104. titleTextColourId = 0x1000850, /**< The colour to use to draw the box's title. */
  105. };
  106. private:
  107. class ContentComponent;
  108. ContentComponent* content;
  109. const bool warnAboutOverwritingExistingFiles;
  110. void buttonClicked (Button*);
  111. void closeButtonPressed();
  112. void selectionChanged();
  113. void fileClicked (const File&, const MouseEvent&);
  114. void fileDoubleClicked (const File&);
  115. void browserRootChanged (const File&);
  116. void okButtonPressed();
  117. void createNewFolder();
  118. void createNewFolderConfirmed (const String& name);
  119. static void okToOverwriteFileCallback (int result, FileChooserDialogBox*);
  120. static void createNewFolderCallback (int result, FileChooserDialogBox*, Component::SafePointer<AlertWindow>);
  121. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileChooserDialogBox);
  122. };
  123. #endif // __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__