forked from qt-creator/qt-creator
FolderNavigationWidget: Fix file watcher leaks.
by modifying it to change the root path of the model instead of changing the top index of the view. Depends on fix for QTBUG-8632.
This commit is contained in:
@@ -99,6 +99,7 @@ bool DotRemovalFilter::filterAcceptsRow(int source_row, const QModelIndex &paren
|
|||||||
return fileName != m_dot;
|
return fileName != m_dot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FolderNavigationModel: Shows path as tooltip.
|
||||||
class FolderNavigationModel : public QFileSystemModel
|
class FolderNavigationModel : public QFileSystemModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -141,7 +142,6 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
|
|||||||
filters |= QDir::NoSymLinks;
|
filters |= QDir::NoSymLinks;
|
||||||
#endif
|
#endif
|
||||||
m_fileSystemModel->setFilter(filters);
|
m_fileSystemModel->setFilter(filters);
|
||||||
m_fileSystemModel->setRootPath(QDir::rootPath());
|
|
||||||
m_filterModel->setSourceModel(m_fileSystemModel);
|
m_filterModel->setSourceModel(m_fileSystemModel);
|
||||||
m_listView->setModel(m_filterModel);
|
m_listView->setModel(m_filterModel);
|
||||||
m_listView->setFrameStyle(QFrame::NoFrame);
|
m_listView->setFrameStyle(QFrame::NoFrame);
|
||||||
@@ -218,30 +218,20 @@ void FolderNavigationWidget::setCurrentFile(const QString &filePath)
|
|||||||
|
|
||||||
bool FolderNavigationWidget::setCurrentDirectory(const QString &directory)
|
bool FolderNavigationWidget::setCurrentDirectory(const QString &directory)
|
||||||
{
|
{
|
||||||
return !directory.isEmpty() && setCurrentDirectory(m_fileSystemModel->index(directory));
|
const QString newDirectory = directory.isEmpty() ? QDir::rootPath() : directory;
|
||||||
}
|
if (debug)
|
||||||
|
qDebug() << "setcurdir" << directory << newDirectory;
|
||||||
bool FolderNavigationWidget::setCurrentDirectory(const QModelIndex &dirIndex)
|
// Set the root path on the model instead of changing the top index
|
||||||
{
|
// of the view to cause the model to clean out its file watchers.
|
||||||
const bool valid = dirIndex.isValid();
|
const QModelIndex index = m_fileSystemModel->setRootPath(newDirectory);
|
||||||
if (valid) {
|
QTC_ASSERT(index.isValid(), return false)
|
||||||
// position view root on directory index.
|
m_listView->setRootIndex(m_filterModel->mapFromSource(index));
|
||||||
m_listView->setRootIndex(m_filterModel->mapFromSource(dirIndex));
|
return !directory.isEmpty();
|
||||||
const QDir currentDir(m_fileSystemModel->filePath(dirIndex));
|
|
||||||
setCurrentTitle(currentDir.dirName(), currentDir.absolutePath());
|
|
||||||
} else {
|
|
||||||
m_listView->setRootIndex(QModelIndex());
|
|
||||||
setCurrentTitle(QString(), QString());
|
|
||||||
}
|
|
||||||
return valid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FolderNavigationWidget::currentDirectory() const
|
QString FolderNavigationWidget::currentDirectory() const
|
||||||
{
|
{
|
||||||
const QModelIndex rootIndex = m_listView->rootIndex();
|
return m_fileSystemModel->rootPath();
|
||||||
if (rootIndex.isValid())
|
|
||||||
return m_fileSystemModel->filePath(m_filterModel->mapToSource(rootIndex));
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderNavigationWidget::slotOpenItem(const QModelIndex &viewIndex)
|
void FolderNavigationWidget::slotOpenItem(const QModelIndex &viewIndex)
|
||||||
@@ -255,12 +245,17 @@ void FolderNavigationWidget::openItem(const QModelIndex &srcIndex)
|
|||||||
const QString fileName = m_fileSystemModel->fileName(srcIndex);
|
const QString fileName = m_fileSystemModel->fileName(srcIndex);
|
||||||
if (fileName == QLatin1String("."))
|
if (fileName == QLatin1String("."))
|
||||||
return;
|
return;
|
||||||
if (fileName == QLatin1String("..")) { // cd up.
|
if (fileName == QLatin1String("..")) {
|
||||||
setCurrentDirectory(srcIndex.parent().parent());
|
// cd up: Special behaviour: The fileInfo of ".." is that of the parent directory.
|
||||||
|
const QString parentPath = m_fileSystemModel->fileInfo(srcIndex).absoluteFilePath();
|
||||||
|
if (parentPath != QDir::rootPath())
|
||||||
|
setCurrentDirectory(parentPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_fileSystemModel->isDir(srcIndex)) { // Change to directory
|
if (m_fileSystemModel->isDir(srcIndex)) { // Change to directory
|
||||||
setCurrentDirectory(srcIndex);
|
const QFileInfo fi = m_fileSystemModel->fileInfo(srcIndex);
|
||||||
|
if (fi.isReadable() && fi.isExecutable())
|
||||||
|
setCurrentDirectory(m_fileSystemModel->filePath(srcIndex));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Open file.
|
// Open file.
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void setCurrentTitle(const QString &dirName, const QString &fullPath);
|
void setCurrentTitle(const QString &dirName, const QString &fullPath);
|
||||||
bool setCurrentDirectory(const QString &directory);
|
bool setCurrentDirectory(const QString &directory);
|
||||||
bool setCurrentDirectory(const QModelIndex &dirIndex);
|
|
||||||
void openItem(const QModelIndex &srcIndex);
|
void openItem(const QModelIndex &srcIndex);
|
||||||
QModelIndex currentItem() const;
|
QModelIndex currentItem() const;
|
||||||
QString currentDirectory() const;
|
QString currentDirectory() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user