forked from qt-creator/qt-creator
Utils::PathChooser: Allow the core plugin to extend the context menu
And then use this to add the "Open in Graphical Shell" and "Open in Terminal" actions. Those actions cannot be implemented in Utils directly since the Core::FileUtils depends on the Options dialog. This affects all PathChoosers, and there's currently no way for a PathChooser to opt out or have a different context menu. That can be added at a later point. Change-Id: I22121c19d66f08785381c7e0bca5317628eb6342 Task-number: QTCREATORBUG-14736 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMenu>
|
||||
#include <QPushButton>
|
||||
#include <QStandardPaths>
|
||||
|
||||
@@ -66,6 +67,8 @@ static QString appBundleExpandedPath(const QString &path)
|
||||
return path;
|
||||
}
|
||||
|
||||
Utils::PathChooser::AboutToShowContextMenuHandler Utils::PathChooser::s_aboutToShowContextMenuHandler;
|
||||
|
||||
namespace Utils {
|
||||
|
||||
// ------------------ BinaryVersionToolTipEventFilter
|
||||
@@ -221,6 +224,9 @@ PathChooser::PathChooser(QWidget *parent) :
|
||||
{
|
||||
d->m_hLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
d->m_lineEdit->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
connect(d->m_lineEdit, &FancyLineEdit::customContextMenuRequested, this, &PathChooser::contextMenuRequested);
|
||||
connect(d->m_lineEdit, &FancyLineEdit::validReturnPressed, this, &PathChooser::returnPressed);
|
||||
connect(d->m_lineEdit, &QLineEdit::textChanged, this, [this] { emit changed(rawPath()); });
|
||||
connect(d->m_lineEdit, &FancyLineEdit::validChanged, this, &PathChooser::validChanged);
|
||||
@@ -422,6 +428,18 @@ void PathChooser::slotBrowse()
|
||||
triggerChanged();
|
||||
}
|
||||
|
||||
void PathChooser::contextMenuRequested(const QPoint &pos)
|
||||
{
|
||||
if (QMenu *menu = d->m_lineEdit->createStandardContextMenu()) {
|
||||
menu->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
if (s_aboutToShowContextMenuHandler)
|
||||
s_aboutToShowContextMenuHandler(this, menu);
|
||||
|
||||
menu->popup(d->m_lineEdit->mapToGlobal(pos));
|
||||
}
|
||||
}
|
||||
|
||||
bool PathChooser::isValid() const
|
||||
{
|
||||
return d->m_lineEdit->isValid();
|
||||
@@ -437,6 +455,11 @@ void PathChooser::triggerChanged()
|
||||
d->m_lineEdit->triggerChanged();
|
||||
}
|
||||
|
||||
void PathChooser::setAboutToShowContextMenuHandler(PathChooser::AboutToShowContextMenuHandler handler)
|
||||
{
|
||||
s_aboutToShowContextMenuHandler = handler;
|
||||
}
|
||||
|
||||
FancyLineEdit::ValidationFunction PathChooser::defaultValidationFunction() const
|
||||
{
|
||||
return std::bind(&PathChooser::validatePath, this, std::placeholders::_1, std::placeholders::_2);
|
||||
|
||||
Reference in New Issue
Block a user