From dda6b17dea22d8200616213bcc73e9a85dd08d4d Mon Sep 17 00:00:00 2001 From: Zhang TingAn Date: Wed, 18 Dec 2024 16:31:00 +0800 Subject: [PATCH] fix: Display the directory without selecting the file Log: as title --- src/plugins/codeeditor/gui/tabbar.cpp | 5 ++--- src/plugins/cxx/cmake/project/cmakeasynparse.cpp | 3 +++ src/plugins/project/mainframe/projecttree.cpp | 9 ++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/plugins/codeeditor/gui/tabbar.cpp b/src/plugins/codeeditor/gui/tabbar.cpp index f2874effe..7344b8e23 100644 --- a/src/plugins/codeeditor/gui/tabbar.cpp +++ b/src/plugins/codeeditor/gui/tabbar.cpp @@ -10,13 +10,13 @@ #include #include #include +#include #include #include #include #include #include -#include DWIDGET_USE_NAMESPACE @@ -137,8 +137,7 @@ void TabBarPrivate::showMenu(QPoint pos) menu.addSeparator(); menu.addAction(tr("Show Containing Folder"), [=]() { auto file = tabBar->tabToolTip(curIndex); - QFileInfo info(file); - QDesktopServices::openUrl(QUrl::fromLocalFile(info.absolutePath())); + DDesktopServices::showFileItem(file); }); menu.exec(QCursor::pos()); diff --git a/src/plugins/cxx/cmake/project/cmakeasynparse.cpp b/src/plugins/cxx/cmake/project/cmakeasynparse.cpp index 3d4e6335b..a13011652 100644 --- a/src/plugins/cxx/cmake/project/cmakeasynparse.cpp +++ b/src/plugins/cxx/cmake/project/cmakeasynparse.cpp @@ -187,6 +187,7 @@ void CmakeAsynParse::parseProject(QStandardItem *rootItem, const dpfservice::Pro cmakeFileItem->setToolTip(cmakeFileInfo.filePath()); cmakeParentItem->appendRow(cmakeFileItem); cmakeFileItem->setData(cmakeFileInfo.absoluteFilePath(), Project::FileIconRole); + cmakeFileItem->setData(cmakeFileInfo.absoluteFilePath(), Project::FilePathRole); // monitor cmake file change to refresh project tree. if (cmakeParentItem == rootItem) { @@ -260,6 +261,7 @@ void CmakeAsynParse::parseProject(QStandardItem *rootItem, const dpfservice::Pro srcItem->setText(srcFileInfo.fileName()); srcItem->setToolTip(srcFileInfo.filePath()); srcItem->setData(srcFileInfo.absoluteFilePath(), Project::FileIconRole); + srcItem->setData(srcFileInfo.absoluteFilePath(), Project::FilePathRole); if (srcFileInfo.isDir()) emit directoryCreated(rootItem, srcFileInfo.filePath()); @@ -346,6 +348,7 @@ QStandardItem *CmakeAsynParse::createParentItem(QStandardItem *rootItem, const Q item->setText(nameItem); item->setToolTip(basePath + relative); item->setData(basePath + relative, Project::FileIconRole); + item->setData(basePath + relative, Project::FilePathRole); // append to parent. QStandardItem *parentItem = findParentItem(rootItem, relative); emit directoryCreated(rootItem, basePath + relative); diff --git a/src/plugins/project/mainframe/projecttree.cpp b/src/plugins/project/mainframe/projecttree.cpp index e83f8981e..a0a353b58 100644 --- a/src/plugins/project/mainframe/projecttree.cpp +++ b/src/plugins/project/mainframe/projecttree.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include DWIDGET_USE_NAMESPACE @@ -259,9 +259,12 @@ void ProjectTree::doItemMenuRequest(QStandardItem *item, QContextMenuEvent *even menu->addSeparator(); QAction *showContainFolder = new QAction(tr("Show Containing Folder"), this); connect(showContainFolder, &QAction::triggered, [=]() { - QString filePath = item->toolTip(); + QString filePath = item->data(Project::ProjectItemRole::FilePathRole).toString(); QFileInfo info(filePath); - QDesktopServices::openUrl(QUrl::fromLocalFile(info.absolutePath())); + if (info.isFile()) + DDesktopServices::showFileItem(filePath); + else + DDesktopServices::showFolder(filePath); }); menu->addAction(showContainFolder);