From e45d1fb725a907c0051b29b5b78bfe73069fb215 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 20 Jun 2007 13:23:30 +0000 Subject: [PATCH] added a flag to FileBrowserComponent so it can optionally use a treeview to show the files --- docs/JUCE changelist.txt | 2 +- .../filebrowser/juce_FileBrowserComponent.cpp | 24 +++++++++++++------ .../filebrowser/juce_FileBrowserComponent.h | 5 +++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/JUCE changelist.txt b/docs/JUCE changelist.txt index 5863b137ac..bfc8065c2d 100644 --- a/docs/JUCE changelist.txt +++ b/docs/JUCE changelist.txt @@ -10,7 +10,7 @@ Changelist for version 1.44 - changed the MouseEvent structure so that it now contains a pointer to the event component and also the original component. - added a PopupMenu::dismissAllActiveMenus() method. - added the JUCE_LOG_ASSERTIONS flag, which can automatically log assertion failures, even in release builds. -- new classes DirectoryContentsDisplayComponent and FileTreeComponent, allow a view of a directory as either a list or treeview. I've added a demo of the FileTreeComponent to the treeviews section of the Juce Demo. +- new classes DirectoryContentsDisplayComponent and FileTreeComponent, allow a view of a directory as either a list or treeview. I've added a demo of the FileTreeComponent to the treeviews section of the Juce Demo. There's also now an option in the FileBrowserComponent constructor to use a treeview. - small change to the strictness of the way TreeViews handle their root items. Be careful now to never delete a tree's root item until either the treeview has been deleted, or until you've removed the root from the tree using setRootItem (0). Not doing this can now cause a crash in the tree's destructor, where it expects the root to still be valid. diff --git a/src/juce_appframework/gui/components/filebrowser/juce_FileBrowserComponent.cpp b/src/juce_appframework/gui/components/filebrowser/juce_FileBrowserComponent.cpp index edee962eb5..93e4a4cb6a 100644 --- a/src/juce_appframework/gui/components/filebrowser/juce_FileBrowserComponent.cpp +++ b/src/juce_appframework/gui/components/filebrowser/juce_FileBrowserComponent.cpp @@ -39,6 +39,7 @@ BEGIN_JUCE_NAMESPACE #include "../../../../juce_core/text/juce_LocalisedStrings.h" #include "../../../../juce_core/basics/juce_SystemStats.h" #include "juce_FileListComponent.h" +#include "juce_FileTreeComponent.h" //============================================================================== @@ -56,7 +57,8 @@ public: FileBrowserComponent::FileBrowserComponent (FileChooserMode mode_, const File& initialFileOrDirectory, const FileFilter* fileFilter, - FilePreviewComponent* previewComp_) + FilePreviewComponent* previewComp_, + const bool useTreeView) : directoriesOnlyFilter (0), mode (mode_), listeners (2), @@ -84,13 +86,21 @@ FileBrowserComponent::FileBrowserComponent (FileChooserMode mode_, fileList = new DirectoryContentsList (fileFilter, thread); - // this component could alternatively be a FileTreeComponent - FileListComponent* const list = new FileListComponent (*fileList); - list->setOutlineThickness (1); + if (useTreeView) + { + FileTreeComponent* const tree = new FileTreeComponent (*fileList); + addAndMakeVisible (tree); + fileListComponent = tree; + } + else + { + FileListComponent* const list = new FileListComponent (*fileList); + list->setOutlineThickness (1); + addAndMakeVisible (list); + fileListComponent = list; + } - fileListComponent = list; - addAndMakeVisible (list); - list->addListener (this); + fileListComponent->addListener (this); addAndMakeVisible (currentPathBox = new ComboBox (T("path"))); currentPathBox->setEditableText (true); diff --git a/src/juce_appframework/gui/components/filebrowser/juce_FileBrowserComponent.h b/src/juce_appframework/gui/components/filebrowser/juce_FileBrowserComponent.h index 44ff25dcd1..81d3fb51fb 100644 --- a/src/juce_appframework/gui/components/filebrowser/juce_FileBrowserComponent.h +++ b/src/juce_appframework/gui/components/filebrowser/juce_FileBrowserComponent.h @@ -89,11 +89,14 @@ public: is deleted. @param previewComp an optional preview component that will be used to show previews of files that the user selects + @param useTreeView if this is false, the files are shown in a list; if true, + they are shown in a treeview */ FileBrowserComponent (FileChooserMode browserMode, const File& initialFileOrDirectory, const FileFilter* fileFilter, - FilePreviewComponent* previewComp); + FilePreviewComponent* previewComp, + const bool useTreeView = false); /** Destructor. */ ~FileBrowserComponent();