forked from qt-creator/qt-creator
File System View: Make keyboard navigation magical
Ensuring that there's always a current index is hard work since the data comes in asynchronously and is unsorted at first. Task-number: QTCREATORBUG-10250 Change-Id: I2cd1420bb447ad7257f6200bcffc454a214932aa Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -158,6 +158,8 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
|
|||||||
this, SLOT(slotOpenItem(QModelIndex)));
|
this, SLOT(slotOpenItem(QModelIndex)));
|
||||||
connect(m_filterHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setHiddenFilesFilter(bool)));
|
connect(m_filterHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setHiddenFilesFilter(bool)));
|
||||||
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleAutoSynchronization()));
|
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleAutoSynchronization()));
|
||||||
|
connect(m_filterModel, SIGNAL(layoutChanged()),
|
||||||
|
this, SLOT(ensureCurrentIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderNavigationWidget::toggleAutoSynchronization()
|
void FolderNavigationWidget::toggleAutoSynchronization()
|
||||||
@@ -225,10 +227,17 @@ bool FolderNavigationWidget::setCurrentDirectory(const QString &directory)
|
|||||||
setCurrentTitle(QString(), QString());
|
setCurrentTitle(QString(), QString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_listView->setRootIndex(m_filterModel->mapFromSource(index));
|
QModelIndex oldRootIndex = m_listView->rootIndex();
|
||||||
|
QModelIndex newRootIndex = m_filterModel->mapFromSource(index);
|
||||||
|
m_listView->setRootIndex(newRootIndex);
|
||||||
const QDir current(QDir::cleanPath(newDirectory));
|
const QDir current(QDir::cleanPath(newDirectory));
|
||||||
setCurrentTitle(current.dirName(),
|
setCurrentTitle(current.dirName(),
|
||||||
QDir::toNativeSeparators(current.absolutePath()));
|
QDir::toNativeSeparators(current.absolutePath()));
|
||||||
|
if (oldRootIndex.parent() == newRootIndex) { // cdUp, so select the old directory
|
||||||
|
m_listView->setCurrentIndex(oldRootIndex);
|
||||||
|
m_listView->scrollTo(oldRootIndex, QAbstractItemView::EnsureVisible);
|
||||||
|
}
|
||||||
|
|
||||||
return !directory.isEmpty();
|
return !directory.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,6 +374,17 @@ bool FolderNavigationWidget::hiddenFilesFilter() const
|
|||||||
return m_filterHiddenFilesAction->isChecked();
|
return m_filterHiddenFilesAction->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FolderNavigationWidget::ensureCurrentIndex()
|
||||||
|
{
|
||||||
|
QModelIndex index = m_listView->currentIndex();
|
||||||
|
if (!index.isValid()
|
||||||
|
|| index.parent() != m_listView->rootIndex()) {
|
||||||
|
index = m_listView->rootIndex().child(0, 0);
|
||||||
|
m_listView->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
m_listView->scrollTo(index);
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------FolderNavigationWidgetFactory
|
// --------------------FolderNavigationWidgetFactory
|
||||||
FolderNavigationWidgetFactory::FolderNavigationWidgetFactory()
|
FolderNavigationWidgetFactory::FolderNavigationWidgetFactory()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ 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);
|
void setHiddenFilesFilter(bool filter);
|
||||||
|
void ensureCurrentIndex();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void contextMenuEvent(QContextMenuEvent *ev);
|
virtual void contextMenuEvent(QContextMenuEvent *ev);
|
||||||
|
|||||||
Reference in New Issue
Block a user