forked from qt-creator/qt-creator
Added possibility to show/hide hidden files
Change-Id: Ibadad657193b67d8b09cc0a3b61ed3e5910a5e2c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
committed by
Daniel Teske
parent
9dd750c57a
commit
3e2e21897d
@@ -133,9 +133,11 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
|
|||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
m_listView(new QListView(this)),
|
m_listView(new QListView(this)),
|
||||||
m_fileSystemModel(new FolderNavigationModel(this)),
|
m_fileSystemModel(new FolderNavigationModel(this)),
|
||||||
|
m_filterHiddenFilesAction(new QAction(tr("Show Hidden Files"), this)),
|
||||||
m_filterModel(new DotRemovalFilter(this)),
|
m_filterModel(new DotRemovalFilter(this)),
|
||||||
m_title(new QLabel(this)),
|
m_title(new QLabel(this)),
|
||||||
m_autoSync(false)
|
m_autoSync(false),
|
||||||
|
m_toggleSync(new QToolButton(this))
|
||||||
{
|
{
|
||||||
m_fileSystemModel->setResolveSymlinks(false);
|
m_fileSystemModel->setResolveSymlinks(false);
|
||||||
m_fileSystemModel->setIconProvider(Core::FileIconProvider::instance());
|
m_fileSystemModel->setIconProvider(Core::FileIconProvider::instance());
|
||||||
@@ -147,6 +149,8 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
|
|||||||
#endif
|
#endif
|
||||||
m_fileSystemModel->setFilter(filters);
|
m_fileSystemModel->setFilter(filters);
|
||||||
m_filterModel->setSourceModel(m_fileSystemModel);
|
m_filterModel->setSourceModel(m_fileSystemModel);
|
||||||
|
m_filterHiddenFilesAction->setCheckable(true);
|
||||||
|
setHiddenFilesFilter(false);
|
||||||
m_listView->setIconSize(QSize(16,16));
|
m_listView->setIconSize(QSize(16,16));
|
||||||
m_listView->setModel(m_filterModel);
|
m_listView->setModel(m_filterModel);
|
||||||
m_listView->setFrameStyle(QFrame::NoFrame);
|
m_listView->setFrameStyle(QFrame::NoFrame);
|
||||||
@@ -161,11 +165,16 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
|
|||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
|
m_toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
|
||||||
|
m_toggleSync->setCheckable(true);
|
||||||
|
m_toggleSync->setToolTip(tr("Synchronize with Editor"));
|
||||||
|
setAutoSynchronization(true);
|
||||||
|
|
||||||
// connections
|
// connections
|
||||||
connect(m_listView, SIGNAL(activated(QModelIndex)),
|
connect(m_listView, SIGNAL(activated(QModelIndex)),
|
||||||
this, SLOT(slotOpenItem(QModelIndex)));
|
this, SLOT(slotOpenItem(QModelIndex)));
|
||||||
|
connect(m_filterHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setHiddenFilesFilter(bool)));
|
||||||
setAutoSynchronization(true);
|
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleAutoSynchronization()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderNavigationWidget::toggleAutoSynchronization()
|
void FolderNavigationWidget::toggleAutoSynchronization()
|
||||||
@@ -180,6 +189,7 @@ bool FolderNavigationWidget::autoSynchronization() const
|
|||||||
|
|
||||||
void FolderNavigationWidget::setAutoSynchronization(bool sync)
|
void FolderNavigationWidget::setAutoSynchronization(bool sync)
|
||||||
{
|
{
|
||||||
|
m_toggleSync->setChecked(sync);
|
||||||
if (sync == m_autoSync)
|
if (sync == m_autoSync)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -380,6 +390,22 @@ void FolderNavigationWidget::findOnFileSystem(const QString &pathIn)
|
|||||||
Find::FindPlugin::instance()->openFindDialog(fif);
|
Find::FindPlugin::instance()->openFindDialog(fif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FolderNavigationWidget::setHiddenFilesFilter(bool filter)
|
||||||
|
{
|
||||||
|
QDir::Filters filters = m_fileSystemModel->filter();
|
||||||
|
if (filter)
|
||||||
|
filters |= QDir::Hidden;
|
||||||
|
else
|
||||||
|
filters &= ~(QDir::Hidden);
|
||||||
|
m_fileSystemModel->setFilter(filters);
|
||||||
|
m_filterHiddenFilesAction->setChecked(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FolderNavigationWidget::hiddenFilesFilter() const
|
||||||
|
{
|
||||||
|
return m_filterHiddenFilesAction->isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------FolderNavigationWidgetFactory
|
// --------------------FolderNavigationWidgetFactory
|
||||||
FolderNavigationWidgetFactory::FolderNavigationWidgetFactory()
|
FolderNavigationWidgetFactory::FolderNavigationWidgetFactory()
|
||||||
{
|
{
|
||||||
@@ -412,18 +438,39 @@ QKeySequence FolderNavigationWidgetFactory::activationSequence() const
|
|||||||
Core::NavigationView FolderNavigationWidgetFactory::createWidget()
|
Core::NavigationView FolderNavigationWidgetFactory::createWidget()
|
||||||
{
|
{
|
||||||
Core::NavigationView n;
|
Core::NavigationView n;
|
||||||
FolderNavigationWidget *ptw = new FolderNavigationWidget;
|
FolderNavigationWidget *fnw = new FolderNavigationWidget;
|
||||||
n.widget = ptw;
|
n.widget = fnw;
|
||||||
QToolButton *toggleSync = new QToolButton;
|
QToolButton *filter = new QToolButton;
|
||||||
toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
|
filter->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER)));
|
||||||
toggleSync->setCheckable(true);
|
filter->setToolTip(tr("Filter Files"));
|
||||||
toggleSync->setChecked(ptw->autoSynchronization());
|
filter->setPopupMode(QToolButton::InstantPopup);
|
||||||
toggleSync->setToolTip(tr("Synchronize with Editor"));
|
filter->setProperty("noArrow", true);
|
||||||
connect(toggleSync, SIGNAL(clicked(bool)), ptw, SLOT(toggleAutoSynchronization()));
|
QMenu *filterMenu = new QMenu(filter);
|
||||||
n.dockToolBarWidgets << toggleSync;
|
filterMenu->addAction(fnw->m_filterHiddenFilesAction);
|
||||||
|
filter->setMenu(filterMenu);
|
||||||
|
n.dockToolBarWidgets << filter << fnw->m_toggleSync;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FolderNavigationWidgetFactory::saveSettings(int position, QWidget *widget)
|
||||||
|
{
|
||||||
|
FolderNavigationWidget *fnw = qobject_cast<FolderNavigationWidget *>(widget);
|
||||||
|
QTC_ASSERT(fnw, return);
|
||||||
|
QSettings *settings = Core::ICore::settings();
|
||||||
|
const QString baseKey = QLatin1String("FolderNavigationWidget.") + QString::number(position);
|
||||||
|
settings->setValue(baseKey + QLatin1String(".HiddenFilesFilter"), fnw->hiddenFilesFilter());
|
||||||
|
settings->setValue(baseKey + QLatin1String(".SyncWithEditor"), fnw->autoSynchronization());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderNavigationWidgetFactory::restoreSettings(int position, QWidget *widget)
|
||||||
|
{
|
||||||
|
FolderNavigationWidget *fnw = qobject_cast<FolderNavigationWidget *>(widget);
|
||||||
|
QTC_ASSERT(fnw, return);
|
||||||
|
QSettings *settings = Core::ICore::settings();
|
||||||
|
const QString baseKey = QLatin1String("FolderNavigationWidget.") + QString::number(position);
|
||||||
|
fnw->setHiddenFilesFilter(settings->value(baseKey + QLatin1String(".HiddenFilesFilter"), false).toBool());
|
||||||
|
fnw->setAutoSynchronization(settings->value(baseKey + QLatin1String(".SyncWithEditor"), true).toBool());
|
||||||
|
}
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public:
|
|||||||
|
|
||||||
static void findOnFileSystem(const QString &pathIn);
|
static void findOnFileSystem(const QString &pathIn);
|
||||||
static QString msgFindOnFileSystem();
|
static QString msgFindOnFileSystem();
|
||||||
|
bool hiddenFilesFilter() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setAutoSynchronization(bool sync);
|
void setAutoSynchronization(bool sync);
|
||||||
void toggleAutoSynchronization();
|
void toggleAutoSynchronization();
|
||||||
@@ -70,6 +72,7 @@ public slots:
|
|||||||
private slots:
|
private slots:
|
||||||
void setCurrentFile(const QString &filePath);
|
void setCurrentFile(const QString &filePath);
|
||||||
void slotOpenItem(const QModelIndex &viewIndex);
|
void slotOpenItem(const QModelIndex &viewIndex);
|
||||||
|
void setHiddenFilesFilter(bool filter);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void contextMenuEvent(QContextMenuEvent *ev);
|
virtual void contextMenuEvent(QContextMenuEvent *ev);
|
||||||
@@ -83,9 +86,13 @@ private:
|
|||||||
|
|
||||||
QListView *m_listView;
|
QListView *m_listView;
|
||||||
QFileSystemModel *m_fileSystemModel;
|
QFileSystemModel *m_fileSystemModel;
|
||||||
|
QAction *m_filterHiddenFilesAction;
|
||||||
QSortFilterProxyModel *m_filterModel;
|
QSortFilterProxyModel *m_filterModel;
|
||||||
QLabel *m_title;
|
QLabel *m_title;
|
||||||
bool m_autoSync;
|
bool m_autoSync;
|
||||||
|
QToolButton *m_toggleSync;
|
||||||
|
// FolderNavigationWidgetFactory needs private members to build a menu
|
||||||
|
friend class FolderNavigationWidgetFactory;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FolderNavigationWidgetFactory : public Core::INavigationWidgetFactory
|
class FolderNavigationWidgetFactory : public Core::INavigationWidgetFactory
|
||||||
@@ -100,6 +107,8 @@ public:
|
|||||||
Core::Id id() const;
|
Core::Id id() const;
|
||||||
QKeySequence activationSequence() const;
|
QKeySequence activationSequence() const;
|
||||||
Core::NavigationView createWidget();
|
Core::NavigationView createWidget();
|
||||||
|
void saveSettings(int position, QWidget *widget);
|
||||||
|
void restoreSettings(int position, QWidget *widget);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user