Commit f5203964 authored by Daniel Teske's avatar Daniel Teske

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's avatarOrgad Shaneh <orgads@gmail.com>
parent 46bcfe65
......@@ -158,6 +158,8 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
this, SLOT(slotOpenItem(QModelIndex)));
connect(m_filterHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setHiddenFilesFilter(bool)));
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleAutoSynchronization()));
connect(m_filterModel, SIGNAL(layoutChanged()),
this, SLOT(ensureCurrentIndex()));
}
void FolderNavigationWidget::toggleAutoSynchronization()
......@@ -225,10 +227,17 @@ bool FolderNavigationWidget::setCurrentDirectory(const QString &directory)
setCurrentTitle(QString(), QString());
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));
setCurrentTitle(current.dirName(),
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();
}
......@@ -365,6 +374,17 @@ bool FolderNavigationWidget::hiddenFilesFilter() const
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()
{
......
......@@ -70,6 +70,7 @@ private slots:
void setCurrentFile(const QString &filePath);
void slotOpenItem(const QModelIndex &viewIndex);
void setHiddenFilesFilter(bool filter);
void ensureCurrentIndex();
protected:
virtual void contextMenuEvent(QContextMenuEvent *ev);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment