ui: added options for context menu when clicking file name in code view
* copy full path * open containing folder
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
#include "qt/element/QtCodeFileTitleButton.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/messaging/type/MessageActivateFile.h"
|
||||
#include "utility/messaging/type/MessageProjectEdit.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "qt/utility/QtContextMenu.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
@@ -20,6 +26,16 @@ QtCodeFileTitleButton::QtCodeFileTitleButton(QWidget* parent)
|
||||
setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
|
||||
|
||||
connect(this, SIGNAL(clicked()), this, SLOT(clickedTitle()));
|
||||
|
||||
m_copyFullPathAction = new QAction(tr("Copy Full Path"), this);
|
||||
m_copyFullPathAction->setStatusTip(tr("Copies the path of this file to the clipboard"));
|
||||
m_copyFullPathAction->setToolTip(tr("Copies the path of this file to the clipboard"));
|
||||
connect(m_copyFullPathAction, SIGNAL(triggered()), this, SLOT(copyFullPath()));
|
||||
|
||||
m_openContainingFolderAction = new QAction(tr("Open Containing Folder"), this);
|
||||
m_openContainingFolderAction->setStatusTip(tr("Opens the folder that contains this file"));
|
||||
m_openContainingFolderAction->setToolTip(tr("Opens the folder that contains this file"));
|
||||
connect(m_openContainingFolderAction, SIGNAL(triggered()), this, SLOT(openContainingFolder()));
|
||||
}
|
||||
|
||||
QtCodeFileTitleButton::~QtCodeFileTitleButton()
|
||||
@@ -91,6 +107,21 @@ void QtCodeFileTitleButton::checkModification()
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFileTitleButton::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
if (!m_filePath.empty())
|
||||
{
|
||||
std::vector<QAction*> actions;
|
||||
actions.push_back(m_copyFullPathAction);
|
||||
actions.push_back(m_openContainingFolderAction);
|
||||
QtContextMenu::getInstance()->showExtended(event, this, actions);
|
||||
}
|
||||
else if (text().size())
|
||||
{
|
||||
QPushButton::contextMenuEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFileTitleButton::clickedTitle()
|
||||
{
|
||||
if (!m_filePath.empty())
|
||||
@@ -102,3 +133,23 @@ void QtCodeFileTitleButton::clickedTitle()
|
||||
MessageProjectEdit().dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFileTitleButton::copyFullPath()
|
||||
{
|
||||
const std::string pathString = (QSysInfo::windowsVersion() != QSysInfo::WV_None) ? m_filePath.getBackslashedString() : m_filePath.str();
|
||||
QApplication::clipboard()->setText(pathString.c_str());
|
||||
}
|
||||
|
||||
void QtCodeFileTitleButton::openContainingFolder()
|
||||
{
|
||||
FilePath dir = m_filePath.parentDirectory();
|
||||
if (dir.exists())
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl(("file:///" + dir.str()).c_str(), QUrl::TolerantMode));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Unable to open directory: " + dir.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,19 @@ public:
|
||||
|
||||
void checkModification();
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
|
||||
private slots:
|
||||
void clickedTitle();
|
||||
void copyFullPath();
|
||||
void openContainingFolder();
|
||||
|
||||
private:
|
||||
FilePath m_filePath;
|
||||
TimePoint m_modificationTime;
|
||||
QAction* m_copyFullPathAction;
|
||||
QAction* m_openContainingFolderAction;
|
||||
};
|
||||
|
||||
#endif // QT_CODE_FILE_TITLE_BUTTON_H
|
||||
|
||||
Reference in New Issue
Block a user