From a0af1fa9278919f978b9cd26dfad69193f2dff30 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Wed, 12 Oct 2022 14:52:15 +0200 Subject: [PATCH] Utils: Keep User specified SideBar entries in file dialogs Change-Id: I0b218e889f351a2dc635aca147b82d752ba85205 Reviewed-by: hjk --- src/libs/utils/fileutils.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 821a31caf09..42d8f553894 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -494,12 +494,22 @@ void prepareNonNativeDialog(QFileDialog &dialog) // Checking QFileDialog::itemDelegate() seems to be the only way to determine // whether the dialog is native or not. if (dialog.itemDelegate()) { - QList sideBarUrls; - for (const FilePath &path : FSEngine::registeredDeviceRoots()) { - if (path.exists()) - sideBarUrls.append(filePathToQUrl(path)); + FilePaths sideBarPaths; + + // Check existing urls, remove paths that need a device and no longer exist. + for (const QUrl &url : dialog.sidebarUrls()) { + FilePath path = qUrlToFilePath(url); + if (!path.needsDevice() || path.exists()) + sideBarPaths.append(path); } - dialog.setSidebarUrls(sideBarUrls); + + // Add all device roots that are not already in the sidebar and exist. + for (const FilePath &path : FSEngine::registeredDeviceRoots()) { + if (!sideBarPaths.contains(path) && path.exists()) + sideBarPaths.append(path); + } + + dialog.setSidebarUrls(Utils::transform(sideBarPaths, filePathToQUrl)); dialog.setIconProvider(Utils::FileIconProvider::iconProvider()); } }