Browse Source

FileBrowserComponents and non-native FileChoosers will now correctly respect the initialFileOrDirectory parameter and actually select the file (if initialFileOrDirectory points to a file)

tags/2021-05-28
hogliux 7 years ago
parent
commit
3724a52ac8
4 changed files with 20 additions and 3 deletions
  1. +4
    -0
      modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp
  2. +6
    -1
      modules/juce_gui_basics/filebrowser/juce_FileChooser.h
  3. +9
    -1
      modules/juce_gui_basics/filebrowser/juce_FileListComponent.cpp
  4. +1
    -1
      modules/juce_gui_basics/filebrowser/juce_FileListComponent.h

+ 4
- 0
modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp View File

@@ -65,6 +65,7 @@ FileBrowserComponent::FileBrowserComponent (int flags_,
} }
fileList.reset (new DirectoryContentsList (this, thread)); fileList.reset (new DirectoryContentsList (this, thread));
fileList->setDirectory (currentRoot, true, true);
if ((flags & useTreeView) != 0) if ((flags & useTreeView) != 0)
{ {
@@ -124,6 +125,9 @@ FileBrowserComponent::FileBrowserComponent (int flags_,
setRoot (currentRoot); setRoot (currentRoot);
if (filename.isNotEmpty())
setFileName (filename);
thread.startThread (4); thread.startThread (4);
startTimer (2000); startTimer (2000);


+ 6
- 1
modules/juce_gui_basics/filebrowser/juce_FileChooser.h View File

@@ -66,7 +66,12 @@ public:
@param initialFileOrDirectory the file or directory that should be selected @param initialFileOrDirectory the file or directory that should be selected
when the dialog box opens. If this parameter is when the dialog box opens. If this parameter is
set to File(), a sensible default directory will set to File(), a sensible default directory will
be used instead.
be used instead. When using native dialogs, not
all platforms will actually select the file. For
example, on macOS, when initialFileOrDirectory is
a file, only the parent directory of
initialFileOrDirectory will be used as the initial
directory of the native file chooser.
Note: on iOS when saving a file, a user will not Note: on iOS when saving a file, a user will not
be able to change a file name, so it may be a good be able to change a file name, so it may be a good


+ 9
- 1
modules/juce_gui_basics/filebrowser/juce_FileListComponent.cpp View File

@@ -33,7 +33,8 @@ Image juce_createIconForFile (const File& file);
//============================================================================== //==============================================================================
FileListComponent::FileListComponent (DirectoryContentsList& listToShow) FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
: ListBox ({}, nullptr), : ListBox ({}, nullptr),
DirectoryContentsDisplayComponent (listToShow)
DirectoryContentsDisplayComponent (listToShow),
lastDirectory (listToShow.getDirectory())
{ {
setModel (this); setModel (this);
directoryContentsList.addChangeListener (this); directoryContentsList.addChangeListener (this);
@@ -70,12 +71,15 @@ void FileListComponent::setSelectedFile (const File& f)
{ {
if (directoryContentsList.getFile(i) == f) if (directoryContentsList.getFile(i) == f)
{ {
fileWaitingToBeSelected = File();
selectRow (i); selectRow (i);
return; return;
} }
} }
deselectAllRows(); deselectAllRows();
fileWaitingToBeSelected = f;
} }
//============================================================================== //==============================================================================
@@ -85,9 +89,13 @@ void FileListComponent::changeListenerCallback (ChangeBroadcaster*)
if (lastDirectory != directoryContentsList.getDirectory()) if (lastDirectory != directoryContentsList.getDirectory())
{ {
fileWaitingToBeSelected = File();
lastDirectory = directoryContentsList.getDirectory(); lastDirectory = directoryContentsList.getDirectory();
deselectAllRows(); deselectAllRows();
} }
if (fileWaitingToBeSelected != File())
setSelectedFile (fileWaitingToBeSelected);
} }
//============================================================================== //==============================================================================


+ 1
- 1
modules/juce_gui_basics/filebrowser/juce_FileListComponent.h View File

@@ -76,7 +76,7 @@ public:
private: private:
//============================================================================== //==============================================================================
File lastDirectory;
File lastDirectory, fileWaitingToBeSelected;
class ItemComponent; class ItemComponent;
void changeListenerCallback (ChangeBroadcaster*) override; void changeListenerCallback (ChangeBroadcaster*) override;


Loading…
Cancel
Save