Commit 23d72b69 authored by Eike Ziller's avatar Eike Ziller

Fix selection when switching root in file system view

Don't jump to the (previously) selected file.
If the (previously) selected file is not a child of the new root,
then "select" the root directory, which also adapts the bread crumb.
Also show the selection instead of the parent in the bread crumb,
which is more natural when a root is selected and not wrong otherwise
either.

Change-Id: Ib5a58a034101e4e2617b4ae1a5ec9188d1a92eb5
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: Alessandro Portale's avatarAlessandro Portale <alessandro.portale@qt.io>
parent fa8a0da2
......@@ -196,7 +196,7 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent) : QWidget(parent
this,
[this](const QModelIndex &current, const QModelIndex &) {
m_crumbLabel->setPath(
Utils::FileName::fromString(m_fileSystemModel->filePath(current)).parentDir());
Utils::FileName::fromString(m_fileSystemModel->filePath(current)));
});
connect(m_crumbLabel, &Utils::FileCrumbLabel::pathClicked, [this](const Utils::FileName &path) {
const QModelIndex rootIndex = m_listView->rootIndex();
......@@ -218,13 +218,10 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent) : QWidget(parent
const auto directory = m_rootSelector->itemData(index).value<Utils::FileName>();
m_rootSelector->setToolTip(directory.toString());
setRootDirectory(directory);
});
connect(m_rootSelector,
static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
this,
[this] {
if (m_autoSync && Core::EditorManager::currentEditor())
selectFile(Core::EditorManager::currentEditor()->document()->filePath());
const QModelIndex rootIndex = m_listView->rootIndex();
const QModelIndex fileIndex = m_listView->currentIndex();
if (!isChildOf(fileIndex, rootIndex))
selectFile(directory);
});
}
......@@ -323,7 +320,7 @@ void FolderNavigationWidget::selectBestRootForFile(const Utils::FileName &filePa
void FolderNavigationWidget::selectFile(const Utils::FileName &filePath)
{
const QModelIndex fileIndex = m_fileSystemModel->index(filePath.toString());
if (fileIndex.isValid()) {
if (fileIndex.isValid() || filePath.isEmpty() /* Computer root */) {
// TODO This only scrolls to the right position if all directory contents are loaded.
// Unfortunately listening to directoryLoaded was still not enough (there might also
// be some delayed sorting involved?).
......
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