diff --git a/src/juce_appframework/gui/components/controls/juce_TreeView.cpp b/src/juce_appframework/gui/components/controls/juce_TreeView.cpp index 8f20b5d940..7d9e942fb1 100644 --- a/src/juce_appframework/gui/components/controls/juce_TreeView.cpp +++ b/src/juce_appframework/gui/components/controls/juce_TreeView.cpp @@ -263,13 +263,37 @@ private: TreeViewContentComponent (const TreeViewContentComponent&); const TreeViewContentComponent& operator= (const TreeViewContentComponent&); - static void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers) + void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers) { - const bool shft = modifiers.isShiftDown(); - const bool cmd = modifiers.isCommandDown(); + TreeViewItem* firstSelected = 0; - item->setSelected (shft || (! cmd) || (cmd && ! item->isSelected()), - ! (shft || cmd)); + if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0)) + { + TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1); + jassert (lastSelected != 0); + + int rowStart = firstSelected->getRowNumberInTree(); + int rowEnd = lastSelected->getRowNumberInTree(); + if (rowStart > rowEnd) + swapVariables (rowStart, rowEnd); + + int ourRow = item->getRowNumberInTree(); + int otherEnd = ourRow < rowEnd ? (ourRow < rowStart ? (rowStart - 1) + : rowStart) + : (rowEnd + 1); + + if (ourRow > otherEnd) + swapVariables (ourRow, otherEnd); + + for (int i = ourRow; i <= otherEnd; ++i) + owner->getItemOnRow (i)->setSelected (true, false); + } + else + { + const bool cmd = modifiers.isCommandDown(); + + item->setSelected ((! cmd) || (! item->isSelected()), ! cmd); + } } }; diff --git a/src/juce_appframework/gui/components/filebrowser/juce_FileTreeComponent.cpp b/src/juce_appframework/gui/components/filebrowser/juce_FileTreeComponent.cpp index 22145a57be..f40cea53fc 100644 --- a/src/juce_appframework/gui/components/filebrowser/juce_FileTreeComponent.cpp +++ b/src/juce_appframework/gui/components/filebrowser/juce_FileTreeComponent.cpp @@ -253,7 +253,12 @@ FileTreeComponent::~FileTreeComponent() //============================================================================== const File FileTreeComponent::getSelectedFile() const { - const FileListTreeItem* const item = dynamic_cast (getSelectedItem (0)); + return getSelectedFile (0); +} + +const File FileTreeComponent::getSelectedFile (const int index) const throw() +{ + const FileListTreeItem* const item = dynamic_cast (getSelectedItem (index)); if (item != 0) return item->file; diff --git a/src/juce_appframework/gui/components/filebrowser/juce_FileTreeComponent.h b/src/juce_appframework/gui/components/filebrowser/juce_FileTreeComponent.h index 39d6a74bd7..813909c0c5 100644 --- a/src/juce_appframework/gui/components/filebrowser/juce_FileTreeComponent.h +++ b/src/juce_appframework/gui/components/filebrowser/juce_FileTreeComponent.h @@ -61,7 +61,17 @@ public: ~FileTreeComponent(); //============================================================================== - /** Returns the file that the user has currently selected. + /** Returns the number of selected files in the tree. + */ + int getNumSelectedFiles() const throw() { return TreeView::getNumSelectedItems(); } + + /** Returns one of the files that the user has currently selected. + + Returns File::nonexistent if none is selected. + */ + const File getSelectedFile (int index) const throw(); + + /** Returns the first of the files that the user has currently selected. Returns File::nonexistent if none is selected. */