aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-03-29 15:48:04 +0200
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-03-29 15:48:17 +0200
commit6d6d59fc4361b49b7124025b96efc6c6079d0ddd (patch)
tree152183536d1b6e92a3be870d6791a3d0e1edb3b8 /src/plugins/projectexplorer
parent678f7d3e949887ea12f13ad6a9890a3579704117 (diff)
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.
Diffstat (limited to 'src/plugins/projectexplorer')
-rw-r--r--src/plugins/projectexplorer/foldernavigationwidget.cpp43
-rw-r--r--src/plugins/projectexplorer/foldernavigationwidget.h1
2 files changed, 19 insertions, 25 deletions
diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp
index cedab6f479..70d73a40c3 100644
--- a/src/plugins/projectexplorer/foldernavigationwidget.cpp
+++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp
@@ -99,6 +99,7 @@ bool DotRemovalFilter::filterAcceptsRow(int source_row, const QModelIndex &paren
return fileName != m_dot;
}
+// FolderNavigationModel: Shows path as tooltip.
class FolderNavigationModel : public QFileSystemModel
{
public:
@@ -141,7 +142,6 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
filters |= QDir::NoSymLinks;
#endif
m_fileSystemModel->setFilter(filters);
- m_fileSystemModel->setRootPath(QDir::rootPath());
m_filterModel->setSourceModel(m_fileSystemModel);
m_listView->setModel(m_filterModel);
m_listView->setFrameStyle(QFrame::NoFrame);
@@ -218,30 +218,20 @@ void FolderNavigationWidget::setCurrentFile(const QString &filePath)
bool FolderNavigationWidget::setCurrentDirectory(const QString &directory)
{
- return !directory.isEmpty() && setCurrentDirectory(m_fileSystemModel->index(directory));
-}
-
-bool FolderNavigationWidget::setCurrentDirectory(const QModelIndex &dirIndex)
-{
- const bool valid = dirIndex.isValid();
- if (valid) {
- // position view root on directory index.
- m_listView->setRootIndex(m_filterModel->mapFromSource(dirIndex));
- const QDir currentDir(m_fileSystemModel->filePath(dirIndex));
- setCurrentTitle(currentDir.dirName(), currentDir.absolutePath());
- } else {
- m_listView->setRootIndex(QModelIndex());
- setCurrentTitle(QString(), QString());
- }
- return valid;
+ const QString newDirectory = directory.isEmpty() ? QDir::rootPath() : directory;
+ if (debug)
+ qDebug() << "setcurdir" << directory << newDirectory;
+ // 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 QModelIndex index = m_fileSystemModel->setRootPath(newDirectory);
+ QTC_ASSERT(index.isValid(), return false)
+ m_listView->setRootIndex(m_filterModel->mapFromSource(index));
+ return !directory.isEmpty();
}
QString FolderNavigationWidget::currentDirectory() const
{
- const QModelIndex rootIndex = m_listView->rootIndex();
- if (rootIndex.isValid())
- return m_fileSystemModel->filePath(m_filterModel->mapToSource(rootIndex));
- return QString();
+ return m_fileSystemModel->rootPath();
}
void FolderNavigationWidget::slotOpenItem(const QModelIndex &viewIndex)
@@ -255,12 +245,17 @@ void FolderNavigationWidget::openItem(const QModelIndex &srcIndex)
const QString fileName = m_fileSystemModel->fileName(srcIndex);
if (fileName == QLatin1String("."))
return;
- if (fileName == QLatin1String("..")) { // cd up.
- setCurrentDirectory(srcIndex.parent().parent());
+ if (fileName == QLatin1String("..")) {
+ // 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;
}
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;
}
// Open file.
diff --git a/src/plugins/projectexplorer/foldernavigationwidget.h b/src/plugins/projectexplorer/foldernavigationwidget.h
index 9f3bdeb888..2f15ad8e07 100644
--- a/src/plugins/projectexplorer/foldernavigationwidget.h
+++ b/src/plugins/projectexplorer/foldernavigationwidget.h
@@ -83,7 +83,6 @@ protected:
private:
void setCurrentTitle(const QString &dirName, const QString &fullPath);
bool setCurrentDirectory(const QString &directory);
- bool setCurrentDirectory(const QModelIndex &dirIndex);
void openItem(const QModelIndex &srcIndex);
QModelIndex currentItem() const;
QString currentDirectory() const;