forked from qt-creator/qt-creator
File System view: Select root folder when clicking outside item
If the shown items are not filling the whole view, there is some empty space at the bottom. Select the current root directory when the user click there. This avoids funny behavior. Without that change - select a file or subdirectory in a directory - collapse the parent directory - the selected file or subdirectory stays selected, but that is not visible - right-click into the empty space at the bottom - the context menu for the not-visibly selected item is shown - this is especially weird when e.g. choosing "New Folder" That is not an issue if the view fills the whole space, because then a visible item is selected when clicking. Change-Id: I0c65e091e659c20d7b384e96ecf69c36379ed936 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -299,6 +299,7 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent) : QWidget(parent
|
|||||||
m_listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
m_listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
m_listView->setDragEnabled(true);
|
m_listView->setDragEnabled(true);
|
||||||
m_listView->setDragDropMode(QAbstractItemView::DragOnly);
|
m_listView->setDragDropMode(QAbstractItemView::DragOnly);
|
||||||
|
m_listView->viewport()->installEventFilter(this);
|
||||||
showOnlyFirstColumn(m_listView);
|
showOnlyFirstColumn(m_listView);
|
||||||
setFocusProxy(m_listView);
|
setFocusProxy(m_listView);
|
||||||
|
|
||||||
@@ -521,6 +522,20 @@ void FolderNavigationWidget::syncWithFilePath(const Utils::FilePath &filePath)
|
|||||||
selectFile(filePath);
|
selectFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FolderNavigationWidget::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if (obj == m_listView->viewport()) {
|
||||||
|
if (event->type() == QEvent::MouseButtonPress) {
|
||||||
|
// select the current root when clicking outside any other item
|
||||||
|
auto me = static_cast<QMouseEvent *>(event);
|
||||||
|
const QModelIndex index = m_listView->indexAt(me->pos());
|
||||||
|
if (!index.isValid())
|
||||||
|
m_listView->setCurrentIndex(m_listView->rootIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool FolderNavigationWidget::autoSynchronization() const
|
bool FolderNavigationWidget::autoSynchronization() const
|
||||||
{
|
{
|
||||||
return m_autoSync;
|
return m_autoSync;
|
||||||
|
@@ -130,6 +130,8 @@ public:
|
|||||||
|
|
||||||
void syncWithFilePath(const Utils::FilePath &filePath);
|
void syncWithFilePath(const Utils::FilePath &filePath);
|
||||||
|
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent *ev) override;
|
void contextMenuEvent(QContextMenuEvent *ev) override;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user