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
706711void ResultsTree::CopyFilename ()
707712{
708- CopyPath (mContextItem , false );
713+ CopyPathToClipboard (mContextItem , false );
709714}
710715
711716void ResultsTree::CopyFullPath ()
712717{
713- CopyPath (mContextItem , true );
718+ CopyPathToClipboard (mContextItem , true );
714719}
715720
716721void 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+
813828void 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
846868QString ResultsTree::SeverityToIcon (Severity::SeverityType severity) const
0 commit comments