Skip to content

Commit

Permalink
fix: Display the directory without selecting the file
Browse files Browse the repository at this point in the history
Log: as title
  • Loading branch information
LiHua000 authored and deepin-mozart committed Dec 19, 2024
1 parent d6bffe8 commit 6a569fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/plugins/codeeditor/gui/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#include <DMenu>
#include <DDialog>
#include <DGuiApplicationHelper>
#include <DDesktopServices>

#include <QSignalBlocker>
#include <QFileInfo>
#include <QHBoxLayout>
#include <QClipboard>
#include <QGuiApplication>
#include <QDesktopServices>

DWIDGET_USE_NAMESPACE

Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/cxx/cmake/project/cmakeasynparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/project/mainframe/projecttree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <DPushButton>
#include <DLineEdit>
#include <DDialog>
#include <DDesktopServices>

#include <QDebug>
#include <QHeaderView>
Expand All @@ -26,7 +27,6 @@
#include <QApplication>
#include <QUrl>
#include <QClipboard>
#include <QDesktopServices>
#include <QScrollBar>

DWIDGET_USE_NAMESPACE
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6a569fe

Please sign in to comment.