From 530b0c62c3bb36986f010b658469e536b14f369e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Mon, 15 Sep 2025 15:49:16 +0200 Subject: [PATCH] Open parent directory if it doesn't exist --- src/filemanager.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/filemanager.cpp b/src/filemanager.cpp index 2f6a30c..dc0d066 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -678,10 +678,21 @@ void DirView::setDir(const QString &path) if(oldPath.left(ROOT_LEN) != path.left(ROOT_LEN)) _dirFileSystemModel->setRootPath(path.left(ROOT_LEN)); - _dirFileSystemModel->setDir(path); - setRootIndex(_dirFileSystemModel->index(path, 0)); + QString newPath = path; + if(!QFileInfo::exists(path)) + { + QDir dir(path); + do + { + dir.setPath(QDir::cleanPath(dir.filePath(".."))); + }while(!dir.exists() && !dir.isRoot()); + newPath = dir.path(); + } + + _dirFileSystemModel->setDir(newPath); + setRootIndex(_dirFileSystemModel->index(newPath, 0)); clearSelection(); - if(oldPath != path)emit dirChanged(path); + if(oldPath != newPath)emit dirChanged(newPath); } QString DirView::dir() const