From d67da79e3d246fbe12be1d094e94623d60e5ec20 Mon Sep 17 00:00:00 2001 From: Karmo Rosental Date: Mon, 9 Jan 2017 16:46:37 +0200 Subject: [PATCH] Fixed #3047 and #3180. (#3184) --- include/FileBrowser.h | 3 ++- src/gui/FileBrowser.cpp | 39 ++++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/FileBrowser.h b/include/FileBrowser.h index 3239dcdc9e4..d5d80604ece 100644 --- a/include/FileBrowser.h +++ b/include/FileBrowser.h @@ -2,7 +2,7 @@ * FileBrowser.h - include file for FileBrowser * * Copyright (c) 2004-2014 Tobias Doerffel - * + * * This file is part of LMMS - http://lmms.io * * This program is free software; you can redistribute it and/or @@ -55,6 +55,7 @@ class FileBrowser : public SideBarWidget private slots: void reloadTree( void ); + void expandItems( QTreeWidgetItem * item=NULL ); // call with item=NULL to filter the entire tree bool filterItems( const QString & filter, QTreeWidgetItem * item=NULL ); void giveFocusToFilter(); diff --git a/src/gui/FileBrowser.cpp b/src/gui/FileBrowser.cpp index f188dfff02c..cb8f85519f8 100644 --- a/src/gui/FileBrowser.cpp +++ b/src/gui/FileBrowser.cpp @@ -3,7 +3,7 @@ * sample-file-browser * * Copyright (c) 2004-2014 Tobias Doerffel - * + * * This file is part of LMMS - http://lmms.io * * This program is free software; you can redistribute it and/or @@ -118,7 +118,7 @@ FileBrowser::~FileBrowser() -bool FileBrowser::filterItems(const QString & filter, QTreeWidgetItem * item) +bool FileBrowser::filterItems( const QString & filter, QTreeWidgetItem * item ) { // call with item=NULL to filter the entire tree bool anyMatched = false; @@ -169,7 +169,6 @@ bool FileBrowser::filterItems(const QString & filter, QTreeWidgetItem * item) - void FileBrowser::reloadTree( void ) { const QString text = m_filterEdit->text(); @@ -180,23 +179,38 @@ void FileBrowser::reloadTree( void ) { addItems( *it ); } - for(int i = 0; i < m_l->topLevelItemCount(); ++i) + expandItems(); + m_filterEdit->setText( text ); + filterItems( text ); +} + + + +void FileBrowser::expandItems( QTreeWidgetItem * item ) +{ + int numChildren = item ? item->childCount() : m_l->topLevelItemCount(); + for( int i = 0; i < numChildren; ++i ) { + QTreeWidgetItem * it = item ? item->child( i ) : m_l->topLevelItem(i); if ( m_recurse ) { - m_l->topLevelItem( i )->setExpanded( true); + it->setExpanded( true ); } - Directory *d = dynamic_cast ( m_l->topLevelItem( i ) ); + Directory *d = dynamic_cast ( it ); if( d ) { d->update(); d->setExpanded( false ); } + if( m_recurse && it->childCount() ) + { + expandItems(it); + } } - m_filterEdit->setText( text ); - filterItems( text ); } + + void FileBrowser::giveFocusToFilter() { if (!m_filterEdit->hasFocus()) @@ -208,6 +222,7 @@ void FileBrowser::giveFocusToFilter() } + void FileBrowser::addItems(const QString & path ) { if( m_dirsAsItems ) @@ -408,7 +423,7 @@ void FileBrowserTreeWidget::mousePressEvent(QMouseEvent * me ) m_previewPlayHandle = s; delete tf; } - else if( ( f->extension ()== "xiz" || f->extension() == "sf2" || f->extension() == "gig" ) && + else if( ( f->extension ()== "xiz" || f->extension() == "sf2" || f->extension() == "gig" ) && ! pluginFactory->pluginSupportingExtension(f->extension()).isNull() ) { m_previewPlayHandle = new PresetPreviewPlayHandle( f->fullName(), f->handling() == FileItem::LoadByPlugin ); @@ -794,8 +809,6 @@ bool Directory::addItems(const QString & path ) path, m_filter ) ); orphan = false; m_dirCount++; - //recurse for each dir - addItems( path + cur_file + QDir::separator() ); break; } else if( cur_file == d->text( 0 ) ) @@ -896,8 +909,8 @@ void FileItem::initPixmaps( void ) s_soundfontFilePixmap = new QPixmap( embed::getIconPixmap( "soundfont_file", 16, 16 ) ); } - - if ( s_vstPluginFilePixmap == NULL ) + + if ( s_vstPluginFilePixmap == NULL ) { s_vstPluginFilePixmap = new QPixmap( embed::getIconPixmap( "vst_plugin_file", 16, 16 ) );