From f4151efc330089948a8730ad09cc99c861d540e8 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Tue, 30 Dec 2025 13:50:30 +0800 Subject: [PATCH] fix: handle file selection when traversing to file path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When traversing to a file path in SMB browser, the original implementation would incorrectly navigate to the parent directory without selecting the file. This fix ensures that when a file path is encountered during traversal, the file is properly opened and the parent directory is navigated to with the file pre-selected. The changes include: 1. Using synchronous file info creation to ensure immediate availability 2. Publishing kOpenFiles signal to open the target file 3. Setting the parent URL with a query parameter to pre-select the file 4. Maintaining the navigation to parent directory but with file selection Log: Fixed file selection issue when navigating to file paths in SMB browser Influence: 1. Test navigating to file paths in SMB shares - should open file and navigate to parent with file selected 2. Verify file opening functionality works correctly 3. Check that directory navigation still functions normally 4. Test with various file types and SMB share configurations 5. Verify query parameter handling for file selection fix: 修复遍历到文件路径时的文件选择问题 当在SMB浏览器中遍历到文件路径时,原实现会错误地导航到父目录而不选择文 件。此修复确保当在遍历过程中遇到文件路径时,文件被正确打开并且导航到父目 录时文件被预选中。 修改包括: 1. 使用同步文件信息创建以确保即时可用性 2. 发布kOpenFiles信号以打开目标文件 3. 设置父URL的查询参数以预选文件 4. 保持导航到父目录但带有文件选择功能 Log: 修复了SMB浏览器中导航到文件路径时的文件选择问题 Influence: 1. 测试在SMB共享中导航到文件路径 - 应打开文件并导航到父目录且文件被选中 2. 验证文件打开功能正常工作 3. 检查目录导航功能仍然正常 4. 测试各种文件类型和SMB共享配置 5. 验证文件选择的查询参数处理 BUG: https://pms.uniontech.com/bug-view-342967.html --- .../events/traversprehandler.cpp | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/src/plugins/filemanager/dfmplugin-smbbrowser/events/traversprehandler.cpp b/src/plugins/filemanager/dfmplugin-smbbrowser/events/traversprehandler.cpp index 573540ab89..7e40a6b4ba 100644 --- a/src/plugins/filemanager/dfmplugin-smbbrowser/events/traversprehandler.cpp +++ b/src/plugins/filemanager/dfmplugin-smbbrowser/events/traversprehandler.cpp @@ -91,33 +91,10 @@ void travers_prehandler::networkAccessPrehandler(quint64 winId, const QUrl &url, static QString kRecordFilePath = QString("/tmp/dfm_smb_mount_%1.ini").arg(getuid()); static QString kRecordGroup = "defaultSmbPath"; static QRegularExpression kRegx { "/|\\.|:" }; - auto recordSubPath = [](const QString &smbRoot, const QString &subPath) { - QFile record(kRecordFilePath); - if (!record.exists() && record.open(QIODevice::NewOnly)) { - record.close(); - fmDebug() << "Created new record file:" << kRecordFilePath; - } - auto key(smbRoot); - key = key.replace(kRegx, "_"); - QSettings sets(kRecordFilePath, QSettings::IniFormat); - sets.setValue(QString("%1/%2").arg(kRecordGroup).arg(key), subPath); - }; - auto readSubPath = [](const QString &smbRoot) { - auto key(smbRoot); - key = key.replace(kRegx, "_"); - QSettings sets(kRecordFilePath, QSettings::IniFormat); - return sets.value(QString("%1/%2").arg(kRecordGroup).arg(key), "").toString(); - }; - DevMngIns->mountNetworkDeviceAsync(mountSource, [=](bool ok, const DFMMOUNT::OperationErrorInfo &err, const QString &mpt) { fmInfo() << "mount done: " << netUrl << ok << err.code << err.message << mpt; if (!mpt.isEmpty()) { - if (err.code == DFMMOUNT::DeviceError::kNoError) - recordSubPath(mountSource, subPath); - QString jumpTo(subPath); - if (jumpTo.isEmpty()) - jumpTo = readSubPath(mountSource); - doChangeCurrentUrl(winId, mpt, jumpTo, netUrl); + doChangeCurrentUrl(winId, mpt, subPath, netUrl); } else if (ok || err.code == DFMMOUNT::DeviceError::kGIOErrorAlreadyMounted) { if (isSmb) onSmbRootMounted(mountSource, after); } else { @@ -175,9 +152,14 @@ void travers_prehandler::doChangeCurrentUrl(quint64 winId, const QString &mpt, c targetPath.append(subPath); QUrl url = QUrl::fromLocalFile(targetPath); - FileInfoPointer fileInfo = InfoFactory::create(url); - if (fileInfo && fileInfo->isAttributes(FileInfo::FileIsType::kIsFile)) - url = fileInfo->urlOf(FileInfo::FileUrlInfoType::kParentUrl); + FileInfoPointer fileInfo = InfoFactory::create(url, Global::kCreateFileInfoSync); + if (fileInfo && fileInfo->isAttributes(FileInfo::FileIsType::kIsFile)) { + dpfSignalDispatcher->publish(GlobalEventType::kOpenFiles, winId, QList { url }); + + QUrl parentUrl = fileInfo->urlOf(UrlInfoType::kParentUrl); + parentUrl.setQuery("selectUrl=" + url.toString()); + url = parentUrl; + } dpfSignalDispatcher->publish(GlobalEventType::kChangeCurrentUrl, winId, url); // remove sourceUrl from history stack.