Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3183: Fix file factory delimeter position #5378

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions include/FileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class FileBrowser : public SideBarWidget
{
Q_OBJECT
public:
/**
Create a file browser side bar widget
@param directories '*'-separated list of directories to search for.
If a directory of factory files should be in the list it
must be the last one (for the factory files delimiter to work)
@param filter Filter as used in QDir::match
@param recurse *to be documented*
*/
FileBrowser( const QString & directories, const QString & filter,
const QString & title, const QPixmap & pm,
QWidget * parent, bool dirs_as_items = false, bool recurse = false );
Expand All @@ -69,8 +77,8 @@ private slots:

QLineEdit * m_filterEdit;

QString m_directories;
QString m_filter;
QString m_directories; //!< Directories to search, split with '*'
QString m_filter; //!< Filter as used in QDir::match()

bool m_dirsAsItems;
bool m_recurse;
Expand Down Expand Up @@ -159,7 +167,14 @@ class Directory : public QTreeWidgetItem
static QPixmap * s_folderOpenedPixmap;
static QPixmap * s_folderLockedPixmap;

//! Directories that lead here
//! Initially, this is just set to the current path of a directory
//! If, however, you have e.g. 'TripleOscillator/xyz' in two of the
//! file browser's search directories 'a' and 'b', this will have two
//! entries 'a/TripleOscillator' and 'b/TripleOscillator'
//! and 'xyz' in the tree widget
QStringList m_directories;
//! Filter as used in QDir::match()
QString m_filter;

int m_dirCount;
Expand Down
43 changes: 35 additions & 8 deletions src/gui/FileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void FileBrowser::addItems(const QString & path )
return;
}

// try to add all directories from file system alphabetically into the tree
QDir cdir( path );
QStringList files = cdir.entryList( QDir::Dirs, QDir::Name );
for( QStringList::const_iterator it = files.constBegin();
Expand All @@ -247,6 +248,7 @@ void FileBrowser::addItems(const QString & path )
m_l->topLevelItem( i ) );
if( d == NULL || cur_file < d->text( 0 ) )
{
// insert before item, we're done
Directory *dd = new Directory( cur_file, path,
m_filter );
m_l->insertTopLevelItem( i,dd );
Expand All @@ -256,6 +258,11 @@ void FileBrowser::addItems(const QString & path )
}
else if( cur_file == d->text( 0 ) )
{
// imagine we have subdirs named "TripleOscillator/xyz" in
// two directories from m_directories
// then only add one tree widget for both
// so we don't add a new Directory - we just
// add the path to the current directory
d->addDirectory( path );
d->update();
orphan = false;
Expand All @@ -264,6 +271,8 @@ void FileBrowser::addItems(const QString & path )
}
if( orphan )
{
// it has not yet been added yet, so it's (lexically)
// larger than all other dirs => append it at the bottom
Directory *d = new Directory( cur_file,
path, m_filter );
d->update();
Expand Down Expand Up @@ -761,21 +770,29 @@ void Directory::update( void )
if( !childCount() )
{
m_dirCount = 0;
// for all paths leading here, add their items
for( QStringList::iterator it = m_directories.begin();
it != m_directories.end(); ++it )
{
int top_index = childCount();
int filesBeforeAdd = childCount() - m_dirCount;
if( addItems( fullName( *it ) ) &&
( *it ).contains(
ConfigManager::inst()->dataDir() ) )
{
QTreeWidgetItem * sep = new QTreeWidgetItem;
sep->setText( 0,
FileBrowserTreeWidget::tr(
"--- Factory files ---" ) );
sep->setIcon( 0, embed::getIconPixmap(
"factory_files" ) );
insertChild( m_dirCount + top_index, sep );
// factory file directory is added
// note: those are always added last
int filesNow = childCount() - m_dirCount;
if(filesNow > filesBeforeAdd) // any file appended?
{
QTreeWidgetItem * sep = new QTreeWidgetItem;
sep->setText( 0,
FileBrowserTreeWidget::tr(
"--- Factory files ---" ) );
sep->setIcon( 0, embed::getIconPixmap(
"factory_files" ) );
// add delimeter after last file before appending our files
insertChild( filesBeforeAdd + m_dirCount, sep );
}
}
}
}
Expand All @@ -796,6 +813,7 @@ bool Directory::addItems(const QString & path )

bool added_something = false;

// try to add all directories from file system alphabetically into the tree
QStringList files = thisDir.entryList( QDir::Dirs, QDir::Name );
for( QStringList::const_iterator it = files.constBegin();
it != files.constEnd(); ++it )
Expand All @@ -810,6 +828,7 @@ bool Directory::addItems(const QString & path )
child( i ) );
if( d == NULL || cur_file < d->text( 0 ) )
{
// insert before item, we're done
insertChild( i, new Directory( cur_file,
path, m_filter ) );
orphan = false;
Expand All @@ -818,13 +837,21 @@ bool Directory::addItems(const QString & path )
}
else if( cur_file == d->text( 0 ) )
{
// imagine we have top-level subdirs named "TripleOscillator" in
// two directories from FileBrowser::m_directories
// and imagine both have a sub folder named "xyz"
// then only add one tree widget for both
// so we don't add a new Directory - we just
// add the path to the current directory
d->addDirectory( path );
orphan = false;
break;
}
}
if( orphan )
{
// it has not yet been added yet, so it's (lexically)
// larger than all other dirs => append it at the bottom
addChild( new Directory( cur_file, path,
m_filter ) );
m_dirCount++;
Expand Down