Skip to content

Commit

Permalink
Proposed fix 760 Improve search field
Browse files Browse the repository at this point in the history
  • Loading branch information
curlymorphic committed Jan 12, 2015
1 parent 3e0e5d3 commit 4206705
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
3 changes: 2 additions & 1 deletion include/FileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FileBrowser : public SideBarWidget
public:
FileBrowser( const QString & directories, const QString & filter,
const QString & title, const QPixmap & pm,
QWidget * parent, bool dirs_as_items = false );
QWidget * parent, bool dirs_as_items = false, bool recurse = false );
virtual ~FileBrowser();


Expand All @@ -73,6 +73,7 @@ public slots:
QString m_filter;

bool m_dirsAsItems;
bool m_recurse;

} ;

Expand Down
40 changes: 31 additions & 9 deletions src/gui/FileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ enum TreeWidgetItemTypes

FileBrowser::FileBrowser(const QString & directories, const QString & filter,
const QString & title, const QPixmap & pm,
QWidget * parent, bool dirs_as_items ) :
QWidget * parent, bool dirs_as_items, bool recurse ) :
SideBarWidget( title, pm, parent ),
m_directories( directories ),
m_filter( filter ),
m_dirsAsItems( dirs_as_items )
m_dirsAsItems( dirs_as_items ),
m_recurse( recurse )
{
setWindowTitle( tr( "Browser" ) );
m_l = new FileBrowserTreeWidget( contentParent() );
Expand Down Expand Up @@ -234,6 +235,19 @@ void FileBrowser::reloadTree( void )
{
addItems( *it );
}
for(int i = 0; i < m_l->topLevelItemCount(); ++i)
{
if ( m_recurse )
{
m_l->topLevelItem( i )->setExpanded( true);
}
Directory *d = dynamic_cast<Directory *> ( m_l->topLevelItem( i ) );
if( d )
{
d->update();
d->setExpanded( false );
}
}
m_filterEdit->setText( text );
filterItems( text );
}
Expand All @@ -245,8 +259,7 @@ void FileBrowser::addItems(const QString & path )
{
if( m_dirsAsItems )
{
m_l->addTopLevelItem( new Directory( path,
QString::null, m_filter ) );
m_l->addTopLevelItem( new Directory( path, QString::null, m_filter ) );
return;
}

Expand All @@ -265,23 +278,27 @@ void FileBrowser::addItems(const QString & path )
m_l->topLevelItem( i ) );
if( d == NULL || cur_file < d->text( 0 ) )
{
m_l->insertTopLevelItem( i,
new Directory( cur_file, path,
m_filter ) );
Directory *dd = new Directory( cur_file, path,
m_filter );
m_l->insertTopLevelItem( i,dd );
dd->update();
orphan = false;
break;
}
else if( cur_file == d->text( 0 ) )
{
d->addDirectory( path );
d->update();
orphan = false;
break;
}
}
if( orphan )
{
m_l->addTopLevelItem( new Directory( cur_file,
path, m_filter ) );
Directory *d = new Directory( cur_file,
path, m_filter );
d->update();
m_l->addTopLevelItem( d );
}
}
}
Expand Down Expand Up @@ -348,6 +365,7 @@ FileBrowserTreeWidget::FileBrowserTreeWidget(QWidget * parent ) :
SLOT( updateDirectory( QTreeWidgetItem * ) ) );
connect( this, SIGNAL( itemExpanded( QTreeWidgetItem * ) ),
SLOT( updateDirectory( QTreeWidgetItem * ) ) );

}


Expand Down Expand Up @@ -818,6 +836,8 @@ 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 ) )
Expand All @@ -832,6 +852,8 @@ bool Directory::addItems(const QString & path )
addChild( new Directory( cur_file, path,
m_filter ) );
m_dirCount++;
//recurse for each dir
addItems( path + cur_file + QDir::separator() );
}

added_something = true;
Expand Down
8 changes: 4 additions & 4 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,24 @@ MainWindow::MainWindow() :
"*.mmp *.mmpz *.xml *.mid *.flp",
tr( "My Projects" ),
embed::getIconPixmap( "project_file" ).transformed( QTransform().rotate( 90 ) ),
splitter ) );
splitter, false, true ) );
sideBar->appendTab( new FileBrowser(
ConfigManager::inst()->userSamplesDir() + "*" +
ConfigManager::inst()->factorySamplesDir(),
"*", tr( "My Samples" ),
embed::getIconPixmap( "sample_file" ).transformed( QTransform().rotate( 90 ) ),
splitter ) );
splitter, false, true ) );
sideBar->appendTab( new FileBrowser(
ConfigManager::inst()->userPresetsDir() + "*" +
ConfigManager::inst()->factoryPresetsDir(),
"*.xpf *.cs.xml *.xiz",
tr( "My Presets" ),
embed::getIconPixmap( "preset_file" ).transformed( QTransform().rotate( 90 ) ),
splitter ) );
splitter , false, true ) );
sideBar->appendTab( new FileBrowser( QDir::homePath(), "*",
tr( "My Home" ),
embed::getIconPixmap( "home" ).transformed( QTransform().rotate( 90 ) ),
splitter ) );
splitter, false, true ) );

QStringList root_paths;
#ifdef LMMS_BUILD_APPLE
Expand Down

0 comments on commit 4206705

Please sign in to comment.