Skip to content

Commit aa66cf5

Browse files
committed
Added context menu item Open containing folder
Note: This also fixes the Copy full path context menu item (was only putting file name into clipboard)
1 parent 3558903 commit aa66cf5

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

gui/resultstree.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <QFileInfo>
3535
#include <QFileDialog>
3636
#include <QClipboard>
37+
#include <QDesktopServices>
3738
#include <QContextMenuEvent>
3839
#include <QModelIndex>
3940
#include "common.h"
@@ -130,7 +131,7 @@ bool ResultsTree::AddErrorItem(const ErrorItem &item)
130131
line.severity = item.severity;
131132
//Create the base item for the error and ensure it has a proper
132133
//file item as a parent
133-
QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(line.file, item.file0, hide),
134+
QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(item.files[0], item.file0, hide),
134135
line,
135136
hide,
136137
SeverityToIcon(line.severity));
@@ -530,19 +531,21 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
530531
}
531532

532533
//Create an action for the application
533-
QAction *copyfilename = new QAction(tr("Copy filename"), &menu);
534-
QAction *copypath = new QAction(tr("Copy full path"), &menu);
535-
QAction *copymessage = new QAction(tr("Copy message"), &menu);
536-
QAction *copymessageid = new QAction(tr("Copy message id"), &menu);
537-
QAction *hide = new QAction(tr("Hide"), &menu);
538-
QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
534+
QAction *copyfilename = new QAction(tr("Copy filename"), &menu);
535+
QAction *copypath = new QAction(tr("Copy full path"), &menu);
536+
QAction *copymessage = new QAction(tr("Copy message"), &menu);
537+
QAction *copymessageid = new QAction(tr("Copy message id"), &menu);
538+
QAction *hide = new QAction(tr("Hide"), &menu);
539+
QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
540+
QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
539541

540542
if (multipleSelection) {
541543
copyfilename->setDisabled(true);
542544
copypath->setDisabled(true);
543545
copymessage->setDisabled(true);
544546
copymessageid->setDisabled(true);
545547
hideallid->setDisabled(true);
548+
opencontainingfolder->setDisabled(true);
546549
}
547550

548551
menu.addAction(copyfilename);
@@ -551,13 +554,15 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
551554
menu.addAction(copymessageid);
552555
menu.addAction(hide);
553556
menu.addAction(hideallid);
557+
menu.addAction(opencontainingfolder);
554558

555559
connect(copyfilename, SIGNAL(triggered()), this, SLOT(CopyFilename()));
556560
connect(copypath, SIGNAL(triggered()), this, SLOT(CopyFullPath()));
557561
connect(copymessage, SIGNAL(triggered()), this, SLOT(CopyMessage()));
558562
connect(copymessageid, SIGNAL(triggered()), this, SLOT(CopyMessageId()));
559563
connect(hide, SIGNAL(triggered()), this, SLOT(HideResult()));
560564
connect(hideallid, SIGNAL(triggered()), this, SLOT(HideAllIdResult()));
565+
connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(OpenContainingFolder()));
561566
}
562567

563568
//Start the menu
@@ -705,12 +710,12 @@ QString ResultsTree::AskFileDir(const QString &file)
705710

706711
void ResultsTree::CopyFilename()
707712
{
708-
CopyPath(mContextItem, false);
713+
CopyPathToClipboard(mContextItem, false);
709714
}
710715

711716
void ResultsTree::CopyFullPath()
712717
{
713-
CopyPath(mContextItem, true);
718+
CopyPathToClipboard(mContextItem, true);
714719
}
715720

716721
void ResultsTree::CopyMessage()
@@ -810,6 +815,16 @@ void ResultsTree::HideAllIdResult()
810815
}
811816
}
812817

818+
void ResultsTree::OpenContainingFolder()
819+
{
820+
QString filePath = GetFilePath(mContextItem, true);
821+
if (!filePath.isEmpty())
822+
{
823+
filePath = QFileInfo(filePath).absolutePath();
824+
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
825+
}
826+
}
827+
813828
void ResultsTree::Context(int application)
814829
{
815830
StartApplication(mContextItem, application);
@@ -820,7 +835,13 @@ void ResultsTree::QuickStartApplication(const QModelIndex &index)
820835
StartApplication(mModel.itemFromIndex(index));
821836
}
822837

823-
void ResultsTree::CopyPath(QStandardItem *target, bool fullPath)
838+
void ResultsTree::CopyPathToClipboard(QStandardItem *target, bool fullPath)
839+
{
840+
QClipboard *clipboard = QApplication::clipboard();
841+
clipboard->setText(GetFilePath(target, fullPath));
842+
}
843+
844+
QString ResultsTree::GetFilePath(QStandardItem *target, bool fullPath)
824845
{
825846
if (target) {
826847
// Make sure we are working with the first column
@@ -838,9 +859,10 @@ void ResultsTree::CopyPath(QStandardItem *target, bool fullPath)
838859
pathStr = fi.fileName();
839860
}
840861

841-
QClipboard *clipboard = QApplication::clipboard();
842-
clipboard->setText(pathStr);
862+
return pathStr;
843863
}
864+
865+
return QString();
844866
}
845867

846868
QString ResultsTree::SeverityToIcon(Severity::SeverityType severity) const

gui/resultstree.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ protected slots:
223223
*/
224224
void HideAllIdResult();
225225

226+
/**
227+
* @brief Slot for context menu item to open the folder containing the current file.
228+
*/
229+
void OpenContainingFolder();
230+
226231
/**
227232
* @brief Slot for selection change in the results tree.
228233
*
@@ -285,7 +290,15 @@ protected slots:
285290
* @param target Error tree item to open
286291
* @param fullPath Are we copying full path or only filename?
287292
*/
288-
void CopyPath(QStandardItem *target, bool fullPath);
293+
void CopyPathToClipboard(QStandardItem *target, bool fullPath);
294+
295+
/**
296+
* @brief Helper function returning the filename/full path of the error tree item \a target.
297+
*
298+
* @param target The error tree item containing the filename/full path
299+
* @param fullPath Whether or not to retrieve the full path or only the filename.
300+
*/
301+
QString GetFilePath(QStandardItem *target, bool fullPath);
289302

290303
/**
291304
* @brief Context menu event (user right clicked on the tree)

0 commit comments

Comments
 (0)