Guest User

Qt Creator File System View Patch

a guest
Oct 12th, 2012
698
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp
  2. index 85d75a2..1a79146 100644
  3. --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp
  4. +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp
  5. @@ -34,6 +34,9 @@
  6.  
  7.  #include <extensionsystem/pluginmanager.h>
  8.  
  9. +#include <projectexplorer/projectexplorer.h>
  10. +#include <projectexplorer/project.h>
  11. +
  12.  #include <coreplugin/actionmanager/command.h>
  13.  #include <coreplugin/icore.h>
  14.  #include <coreplugin/fileiconprovider.h>
  15. @@ -56,7 +59,7 @@
  16.  #include <QToolButton>
  17.  #include <QPushButton>
  18.  #include <QLabel>
  19. -#include <QListView>
  20. +#include <QTreeView>
  21.  #include <QSortFilterProxyModel>
  22.  #include <QAction>
  23.  #include <QMenu>
  24. @@ -132,7 +135,7 @@ QVariant FolderNavigationModel::data(const QModelIndex &index, int role) const
  25.    */
  26.  FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
  27.      : QWidget(parent),
  28. -      m_listView(new QListView(this)),
  29. +      m_listView(new QTreeView(this)),
  30.        m_fileSystemModel(new FolderNavigationModel(this)),
  31.        m_filterModel(new DotRemovalFilter(this)),
  32.        m_title(new QLabel(this)),
  33. @@ -140,7 +143,7 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
  34.  {
  35.      m_fileSystemModel->setResolveSymlinks(false);
  36.      m_fileSystemModel->setIconProvider(Core::FileIconProvider::instance());
  37. -    QDir::Filters filters = QDir::AllDirs | QDir::Files | QDir::Drives
  38. +    QDir::Filters filters = QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot
  39.                              | QDir::Readable| QDir::Writable
  40.                              | QDir::Executable | QDir::Hidden;
  41.  #ifdef Q_OS_WIN // Symlinked directories can cause file watcher warnings on Win32.
  42. @@ -152,6 +155,11 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
  43.      m_listView->setModel(m_filterModel);
  44.      m_listView->setFrameStyle(QFrame::NoFrame);
  45.      m_listView->setAttribute(Qt::WA_MacShowFocusRect, false);
  46. +
  47. +    for( int i = 1; i < m_fileSystemModel->columnCount(); ++i )
  48. +        m_listView->hideColumn(i);
  49. +    m_listView->setHeaderHidden(true);
  50. +
  51.      setFocusProxy(m_listView);
  52.  
  53.      QVBoxLayout *layout = new QVBoxLayout();
  54. @@ -187,29 +195,42 @@ void FolderNavigationWidget::setAutoSynchronization(bool sync)
  55.      m_autoSync = sync;
  56.  
  57.      if (m_autoSync) {
  58. +        syncProject( ProjectExplorerPlugin::instance()->currentProject() );
  59. +        setCurrentFile(Core::DocumentManager::currentFile());
  60. +        connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
  61. +                this, SLOT(syncProject(ProjectExplorer::Project*)));
  62.          connect(Core::DocumentManager::instance(), SIGNAL(currentFileChanged(QString)),
  63.                  this, SLOT(setCurrentFile(QString)));
  64. -        setCurrentFile(Core::DocumentManager::currentFile());
  65.      } else {
  66. -        disconnect(Core::DocumentManager::instance(), SIGNAL(currentFileChanged(QString)),
  67. +        disconnect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
  68. +                this, SLOT(syncProject(ProjectExplorer::Project*)));
  69. +       disconnect(Core::DocumentManager::instance(), SIGNAL(currentFileChanged(QString)),
  70.                  this, SLOT(setCurrentFile(QString)));
  71.      }
  72.  }
  73.  
  74. +void FolderNavigationWidget::syncProject(ProjectExplorer::Project* project)
  75. +{
  76. +    if( !project ) return;
  77. +
  78. +    setCurrentDirectory( project->projectDirectory() );
  79. +    m_listView->expandAll();
  80. +}
  81. +
  82.  void FolderNavigationWidget::setCurrentFile(const QString &filePath)
  83.  {
  84.      // Try to find directory of current file
  85.      bool pathOpened = false;
  86. -    if (!filePath.isEmpty())  {
  87. -        const QFileInfo fi(filePath);
  88. -        if (fi.exists())
  89. -            pathOpened = setCurrentDirectory(fi.absolutePath());
  90. -    }
  91. -    if (!pathOpened)  // Default to home.
  92. -        setCurrentDirectory(Utils::PathChooser::homePath());
  93. +//    if (!filePath.isEmpty())  {
  94. +//        const QFileInfo fi(filePath);
  95. +//        if (fi.exists())
  96. +//            pathOpened = setCurrentDirectory(fi.absolutePath());
  97. +//    }
  98. +//    if (!pathOpened)  // Default to home.
  99. +//        setCurrentDirectory(Utils::PathChooser::homePath());
  100.  
  101.      // Select the current file.
  102. -    if (pathOpened) {
  103. +//    if (pathOpened) {
  104.          const QModelIndex fileIndex = m_fileSystemModel->index(filePath);
  105.          if (fileIndex.isValid()) {
  106.              QItemSelectionModel *selections = m_listView->selectionModel();
  107. @@ -218,7 +239,7 @@ void FolderNavigationWidget::setCurrentFile(const QString &filePath)
  108.                                                   | QItemSelectionModel::Clear);
  109.              m_listView->scrollTo(mainIndex);
  110.          }
  111. -    }
  112. +//    }
  113.  }
  114.  
  115.  bool FolderNavigationWidget::setCurrentDirectory(const QString &directory)
  116. diff --git a/src/plugins/projectexplorer/foldernavigationwidget.h b/src/plugins/projectexplorer/foldernavigationwidget.h
  117. index a5aff62..68384c8 100644
  118. --- a/src/plugins/projectexplorer/foldernavigationwidget.h
  119. +++ b/src/plugins/projectexplorer/foldernavigationwidget.h
  120. @@ -37,7 +37,7 @@
  121.  
  122.  QT_BEGIN_NAMESPACE
  123.  class QLabel;
  124. -class QListView;
  125. +class QTreeView;
  126.  class QSortFilterProxyModel;
  127.  class QModelIndex;
  128.  class QFileSystemModel;
  129. @@ -70,6 +70,7 @@ public slots:
  130.  
  131.  private slots:
  132.      void setCurrentFile(const QString &filePath);
  133. +    void syncProject(ProjectExplorer::Project* project);
  134.      void slotOpenItem(const QModelIndex &viewIndex);
  135.  
  136.  protected:
  137. @@ -82,7 +83,7 @@ private:
  138.      QModelIndex currentItem() const;
  139.      QString currentDirectory() const;
  140.  
  141. -    QListView *m_listView;
  142. +    QTreeView *m_listView;
  143.      QFileSystemModel *m_fileSystemModel;
  144.      QSortFilterProxyModel *m_filterModel;
  145.      QLabel *m_title;
RAW Paste Data