コード例 #1
0
bool FileChooser::showDialog (const int flags, FilePreviewComponent* const previewComp)
{
    FocusRestorer focusRestorer;

    results.clear();

    // the preview component needs to be the right size before you pass it in here..
    jassert (previewComp == nullptr || (previewComp->getWidth() > 10
                                         && previewComp->getHeight() > 10));

    const bool selectsDirectories = (flags & FileBrowserComponent::canSelectDirectories) != 0;
    const bool selectsFiles       = (flags & FileBrowserComponent::canSelectFiles) != 0;
    const bool isSave             = (flags & FileBrowserComponent::saveMode) != 0;
    const bool warnAboutOverwrite = (flags & FileBrowserComponent::warnAboutOverwriting) != 0;
    const bool selectMultiple     = (flags & FileBrowserComponent::canSelectMultipleItems) != 0;

    // You've set the flags for both saveMode and openMode!
    jassert (! (isSave && (flags & FileBrowserComponent::openMode) != 0));

   #if JUCE_WINDOWS
    if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
   #elif JUCE_MAC || JUCE_LINUX
    if (useNativeDialogBox)
   #else
    if (false)
   #endif
    {
        showPlatformDialog (results, title, startingFile, filters,
                            selectsDirectories, selectsFiles, isSave,
                            warnAboutOverwrite, selectMultiple, treatFilePackagesAsDirs,
                            previewComp);
    }
    else
    {
        ignoreUnused (selectMultiple);

        WildcardFileFilter wildcard (selectsFiles ? filters : String(),
                                     selectsDirectories ? "*" : String(),
                                     String());

        FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComp);

        FileChooserDialogBox box (title, String(),
                                  browserComponent, warnAboutOverwrite,
                                  browserComponent.findColour (AlertWindow::backgroundColourId));

        if (box.show())
        {
            for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
                results.add (browserComponent.getSelectedFile (i));
        }
    }

    return results.size() > 0;
}
コード例 #2
0
BEGIN_JUCE_NAMESPACE

#include "juce_FileChooserDialogBox.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../../../text/juce_LocalisedStrings.h"
#include "../windows/juce_AlertWindow.h"


//==============================================================================
FileChooserDialogBox::FileChooserDialogBox (const String& name,
                                            const String& instructions,
                                            FileBrowserComponent& chooserComponent,
                                            const bool warnAboutOverwritingExistingFiles_,
                                            const Colour& backgroundColour)
    : ResizableWindow (name, backgroundColour, true),
      warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
{
    content = new ContentComponent();
    content->setName (name);
    content->instructions = instructions;
    content->chooserComponent = &chooserComponent;

    content->addAndMakeVisible (&chooserComponent);

    content->okButton = new TextButton (chooserComponent.getActionVerb());
    content->addAndMakeVisible (content->okButton);
    content->okButton->addButtonListener (this);
    content->okButton->setEnabled (chooserComponent.currentFileIsValid());
    content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));

    content->cancelButton = new TextButton (TRANS("Cancel"));
    content->addAndMakeVisible (content->cancelButton);
    content->cancelButton->addButtonListener (this);
    content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));

    setContentComponent (content);

    setResizable (true, true);
    setResizeLimits (300, 300, 1200, 1000);

    content->chooserComponent->addListener (this);
}
コード例 #3
0
    //==============================================================================
    ContentComponent (const String& name, const String& instructions_, FileBrowserComponent& chooserComponent_)
        : Component (name),
          chooserComponent (chooserComponent_),
          okButton (chooserComponent_.getActionVerb()),
          cancelButton (TRANS ("Cancel")),
          newFolderButton (TRANS ("New Folder")),
          instructions (instructions_)
    {
        addAndMakeVisible (&chooserComponent);

        addAndMakeVisible (&okButton);
        okButton.addShortcut (KeyPress::returnKey);

        addAndMakeVisible (&cancelButton);
        cancelButton.addShortcut (KeyPress::escapeKey);

        addChildComponent (&newFolderButton);

        setInterceptsMouseClicks (false, true);
    }
コード例 #4
0
void ProjucerLookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
                                                      DirectoryContentsDisplayComponent* fileListComponent,
                                                      FilePreviewComponent* previewComp,
                                                      ComboBox* currentPathBox,
                                                      TextEditor* filenameBox,
                                                      Button* goUpButton)
{
    const auto sectionHeight = 22;
    const auto buttonWidth = 50;

    auto b = browserComp.getLocalBounds().reduced (20, 5);

    auto topSlice    = b.removeFromTop (sectionHeight);
    auto bottomSlice = b.removeFromBottom (sectionHeight);

    currentPathBox->setBounds (topSlice.removeFromLeft (topSlice.getWidth() - buttonWidth));
    currentPathBox->setColour (ComboBox::backgroundColourId,    findColour (backgroundColourId));
    currentPathBox->setColour (ComboBox::textColourId,          findColour (defaultTextColourId));
    currentPathBox->setColour (ComboBox::arrowColourId,         findColour (defaultTextColourId));

    topSlice.removeFromLeft (6);
    goUpButton->setBounds (topSlice);

    bottomSlice.removeFromLeft (50);
    filenameBox->setBounds (bottomSlice);
    filenameBox->setColour (TextEditor::backgroundColourId, findColour (backgroundColourId));
    filenameBox->setColour (TextEditor::textColourId,       findColour (defaultTextColourId));
    filenameBox->setColour (TextEditor::outlineColourId,    findColour (defaultTextColourId));
    filenameBox->applyFontToAllText (filenameBox->getFont());

    if (previewComp != nullptr)
        previewComp->setBounds (b.removeFromRight (b.getWidth() / 3));

    if (auto listAsComp = dynamic_cast<Component*> (fileListComponent))
        listAsComp->setBounds (b.reduced (0, 10));
}
コード例 #5
0
bool FileChooser::showDialog (const bool selectsDirectories,
                              const bool selectsFiles,
                              const bool isSave,
                              const bool warnAboutOverwritingExistingFiles,
                              const bool selectMultipleFiles,
                              FilePreviewComponent* const previewComponent)
{
    ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
    Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();

    if (currentlyFocused != 0)
        currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);

    results.clear();

    // the preview component needs to be the right size before you pass it in here..
    jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
                                        && previewComponent->getHeight() > 10));

#if JUCE_WINDOWS
    if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
#elif JUCE_MAC
    if (useNativeDialogBox && (previewComponent == 0))
#else
    if (false)
#endif
    {
        showPlatformDialog (results, title, startingFile, filters,
                            selectsDirectories, selectsFiles, isSave,
                            warnAboutOverwritingExistingFiles,
                            selectMultipleFiles,
                            previewComponent);
    }
    else
    {
        WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
                                     selectsDirectories ? "*" : String::empty,
                                     String::empty);

        int flags = isSave ? FileBrowserComponent::saveMode
                           : FileBrowserComponent::openMode;

        if (selectsFiles)
            flags |= FileBrowserComponent::canSelectFiles;

        if (selectsDirectories)
            flags |= FileBrowserComponent::canSelectDirectories;

        if (selectMultipleFiles)
            flags |= FileBrowserComponent::canSelectMultipleItems;

        FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);

        FileChooserDialogBox box (title, String::empty,
                                  browserComponent,
                                  warnAboutOverwritingExistingFiles,
                                  browserComponent.findColour (AlertWindow::backgroundColourId));

        if (box.show())
        {
            for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
                results.add (new File (browserComponent.getSelectedFile (i)));
        }
    }

    if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
        currentlyFocused->grabKeyboardFocus();

    return results.size() > 0;
}
コード例 #6
0
ファイル: juce_FileChooser.cpp プロジェクト: 0x4d52/ugen
bool FileChooser::showDialog (const bool selectsDirectories,
                              const bool selectsFiles,
                              const bool isSave,
                              const bool warnAboutOverwritingExistingFiles,
                              const bool selectMultipleFiles,
                              FilePreviewComponent* const previewComponent)
{
    WeakReference<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());

    results.clear();

    // the preview component needs to be the right size before you pass it in here..
    jassert (previewComponent == nullptr || (previewComponent->getWidth() > 10
                                               && previewComponent->getHeight() > 10));

   #if JUCE_WINDOWS
    if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
   #elif JUCE_MAC || JUCE_LINUX
    if (useNativeDialogBox && (previewComponent == nullptr))
   #else
    if (false)
   #endif
    {
        showPlatformDialog (results, title, startingFile, filters,
                            selectsDirectories, selectsFiles, isSave,
                            warnAboutOverwritingExistingFiles,
                            selectMultipleFiles,
                            previewComponent);
    }
    else
    {
        WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
                                     selectsDirectories ? "*" : String::empty,
                                     String::empty);

        int flags = isSave ? FileBrowserComponent::saveMode
                           : FileBrowserComponent::openMode;

        if (selectsFiles)
            flags |= FileBrowserComponent::canSelectFiles;

        if (selectsDirectories)
        {
            flags |= FileBrowserComponent::canSelectDirectories;

            if (! isSave)
                flags |= FileBrowserComponent::filenameBoxIsReadOnly;
        }

        if (selectMultipleFiles)
            flags |= FileBrowserComponent::canSelectMultipleItems;

        FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);

        FileChooserDialogBox box (title, String::empty,
                                  browserComponent,
                                  warnAboutOverwritingExistingFiles,
                                  browserComponent.findColour (AlertWindow::backgroundColourId));

        if (box.show())
        {
            for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
                results.add (browserComponent.getSelectedFile (i));
        }
    }

    if (previouslyFocused != nullptr)
        previouslyFocused->grabKeyboardFocus();

    return results.size() > 0;
}