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)
This commit is contained in:
Blubbz0r 2015-05-25 15:33:46 +02:00
parent 355890375c
commit aa66cf5eda
2 changed files with 48 additions and 13 deletions

View File

@ -34,6 +34,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QFileDialog> #include <QFileDialog>
#include <QClipboard> #include <QClipboard>
#include <QDesktopServices>
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QModelIndex> #include <QModelIndex>
#include "common.h" #include "common.h"
@ -130,7 +131,7 @@ bool ResultsTree::AddErrorItem(const ErrorItem &item)
line.severity = item.severity; line.severity = item.severity;
//Create the base item for the error and ensure it has a proper //Create the base item for the error and ensure it has a proper
//file item as a parent //file item as a parent
QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(line.file, item.file0, hide), QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(item.files[0], item.file0, hide),
line, line,
hide, hide,
SeverityToIcon(line.severity)); SeverityToIcon(line.severity));
@ -530,12 +531,13 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
} }
//Create an action for the application //Create an action for the application
QAction *copyfilename = new QAction(tr("Copy filename"), &menu); QAction *copyfilename = new QAction(tr("Copy filename"), &menu);
QAction *copypath = new QAction(tr("Copy full path"), &menu); QAction *copypath = new QAction(tr("Copy full path"), &menu);
QAction *copymessage = new QAction(tr("Copy message"), &menu); QAction *copymessage = new QAction(tr("Copy message"), &menu);
QAction *copymessageid = new QAction(tr("Copy message id"), &menu); QAction *copymessageid = new QAction(tr("Copy message id"), &menu);
QAction *hide = new QAction(tr("Hide"), &menu); QAction *hide = new QAction(tr("Hide"), &menu);
QAction *hideallid = new QAction(tr("Hide all with id"), &menu); QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
if (multipleSelection) { if (multipleSelection) {
copyfilename->setDisabled(true); copyfilename->setDisabled(true);
@ -543,6 +545,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
copymessage->setDisabled(true); copymessage->setDisabled(true);
copymessageid->setDisabled(true); copymessageid->setDisabled(true);
hideallid->setDisabled(true); hideallid->setDisabled(true);
opencontainingfolder->setDisabled(true);
} }
menu.addAction(copyfilename); menu.addAction(copyfilename);
@ -551,6 +554,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addAction(copymessageid); menu.addAction(copymessageid);
menu.addAction(hide); menu.addAction(hide);
menu.addAction(hideallid); menu.addAction(hideallid);
menu.addAction(opencontainingfolder);
connect(copyfilename, SIGNAL(triggered()), this, SLOT(CopyFilename())); connect(copyfilename, SIGNAL(triggered()), this, SLOT(CopyFilename()));
connect(copypath, SIGNAL(triggered()), this, SLOT(CopyFullPath())); connect(copypath, SIGNAL(triggered()), this, SLOT(CopyFullPath()));
@ -558,6 +562,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
connect(copymessageid, SIGNAL(triggered()), this, SLOT(CopyMessageId())); connect(copymessageid, SIGNAL(triggered()), this, SLOT(CopyMessageId()));
connect(hide, SIGNAL(triggered()), this, SLOT(HideResult())); connect(hide, SIGNAL(triggered()), this, SLOT(HideResult()));
connect(hideallid, SIGNAL(triggered()), this, SLOT(HideAllIdResult())); connect(hideallid, SIGNAL(triggered()), this, SLOT(HideAllIdResult()));
connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(OpenContainingFolder()));
} }
//Start the menu //Start the menu
@ -705,12 +710,12 @@ QString ResultsTree::AskFileDir(const QString &file)
void ResultsTree::CopyFilename() void ResultsTree::CopyFilename()
{ {
CopyPath(mContextItem, false); CopyPathToClipboard(mContextItem, false);
} }
void ResultsTree::CopyFullPath() void ResultsTree::CopyFullPath()
{ {
CopyPath(mContextItem, true); CopyPathToClipboard(mContextItem, true);
} }
void ResultsTree::CopyMessage() void ResultsTree::CopyMessage()
@ -810,6 +815,16 @@ void ResultsTree::HideAllIdResult()
} }
} }
void ResultsTree::OpenContainingFolder()
{
QString filePath = GetFilePath(mContextItem, true);
if (!filePath.isEmpty())
{
filePath = QFileInfo(filePath).absolutePath();
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
}
}
void ResultsTree::Context(int application) void ResultsTree::Context(int application)
{ {
StartApplication(mContextItem, application); StartApplication(mContextItem, application);
@ -820,7 +835,13 @@ void ResultsTree::QuickStartApplication(const QModelIndex &index)
StartApplication(mModel.itemFromIndex(index)); StartApplication(mModel.itemFromIndex(index));
} }
void ResultsTree::CopyPath(QStandardItem *target, bool fullPath) void ResultsTree::CopyPathToClipboard(QStandardItem *target, bool fullPath)
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(GetFilePath(target, fullPath));
}
QString ResultsTree::GetFilePath(QStandardItem *target, bool fullPath)
{ {
if (target) { if (target) {
// Make sure we are working with the first column // Make sure we are working with the first column
@ -838,9 +859,10 @@ void ResultsTree::CopyPath(QStandardItem *target, bool fullPath)
pathStr = fi.fileName(); pathStr = fi.fileName();
} }
QClipboard *clipboard = QApplication::clipboard(); return pathStr;
clipboard->setText(pathStr);
} }
return QString();
} }
QString ResultsTree::SeverityToIcon(Severity::SeverityType severity) const QString ResultsTree::SeverityToIcon(Severity::SeverityType severity) const

View File

@ -223,6 +223,11 @@ protected slots:
*/ */
void HideAllIdResult(); void HideAllIdResult();
/**
* @brief Slot for context menu item to open the folder containing the current file.
*/
void OpenContainingFolder();
/** /**
* @brief Slot for selection change in the results tree. * @brief Slot for selection change in the results tree.
* *
@ -285,7 +290,15 @@ protected:
* @param target Error tree item to open * @param target Error tree item to open
* @param fullPath Are we copying full path or only filename? * @param fullPath Are we copying full path or only filename?
*/ */
void CopyPath(QStandardItem *target, bool fullPath); void CopyPathToClipboard(QStandardItem *target, bool fullPath);
/**
* @brief Helper function returning the filename/full path of the error tree item \a target.
*
* @param target The error tree item containing the filename/full path
* @param fullPath Whether or not to retrieve the full path or only the filename.
*/
QString GetFilePath(QStandardItem *target, bool fullPath);
/** /**
* @brief Context menu event (user right clicked on the tree) * @brief Context menu event (user right clicked on the tree)