ProjectExplorer: Improve "import project" keyboard event handling

Pressing return in the path chooser used to activate the "Configure"
button, which is not what users intend.

Fixes: QTCREATORBUG-17471
Change-Id: I86bc0dd9c976da35026654c7873dc4b63e45593c
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-06-06 17:59:30 +02:00
parent d96c2e5d16
commit 50dc5674d3
5 changed files with 24 additions and 0 deletions

View File

@@ -29,6 +29,7 @@
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <QPushButton> #include <QPushButton>
#include <QTimer>
#include <QVBoxLayout> #include <QVBoxLayout>
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -60,6 +61,14 @@ ImportWidget::ImportWidget(QWidget *parent) :
layout->addWidget(importButton); layout->addWidget(importButton);
connect(importButton, &QAbstractButton::clicked, this, &ImportWidget::handleImportRequest); connect(importButton, &QAbstractButton::clicked, this, &ImportWidget::handleImportRequest);
connect(m_pathChooser->lineEdit(), &QLineEdit::returnPressed, this, [this] {
if (m_pathChooser->isValid()) {
handleImportRequest();
// The next return should trigger the "Configure" button.
QTimer::singleShot(0, this, QOverload<>::of(&QWidget::setFocus));
}
});
detailsWidget->setWidget(widget); detailsWidget->setWidget(widget);
} }
@@ -70,6 +79,11 @@ void ImportWidget::setCurrentDirectory(const Utils::FilePath &dir)
m_pathChooser->setFileName(dir); m_pathChooser->setFileName(dir);
} }
bool ImportWidget::lineEditHasFocus() const
{
return m_pathChooser->lineEdit()->hasFocus();
}
void ImportWidget::handleImportRequest() void ImportWidget::handleImportRequest()
{ {
Utils::FilePath dir = m_pathChooser->fileName(); Utils::FilePath dir = m_pathChooser->fileName();

View File

@@ -44,6 +44,8 @@ public:
void setCurrentDirectory(const Utils::FilePath &dir); void setCurrentDirectory(const Utils::FilePath &dir);
bool lineEditHasFocus() const;
signals: signals:
void importFrom(const Utils::FilePath &dir); void importFrom(const Utils::FilePath &dir);

View File

@@ -95,6 +95,8 @@ protected:
void keyPressEvent(QKeyEvent *event) override void keyPressEvent(QKeyEvent *event) override
{ {
if (m_targetSetupPage && m_targetSetupPage->importLineEditHasFocus())
return;
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
event->accept(); event->accept();
if (m_targetSetupPage) if (m_targetSetupPage)

View File

@@ -328,6 +328,11 @@ void TargetSetupPage::setProjectImporter(ProjectImporter *importer)
initializePage(); initializePage();
} }
bool TargetSetupPage::importLineEditHasFocus() const
{
return m_importWidget->lineEditHasFocus();
}
void TargetSetupPage::setNoteText(const QString &text) void TargetSetupPage::setNoteText(const QString &text)
{ {
m_ui->descriptionLabel->setText(text); m_ui->descriptionLabel->setText(text);

View File

@@ -70,6 +70,7 @@ public:
void setPreferredKitPredicate(const ProjectExplorer::Kit::Predicate &predicate); void setPreferredKitPredicate(const ProjectExplorer::Kit::Predicate &predicate);
void setProjectPath(const QString &dir); void setProjectPath(const QString &dir);
void setProjectImporter(ProjectImporter *importer); void setProjectImporter(ProjectImporter *importer);
bool importLineEditHasFocus() const;
/// Sets whether the targetsetupage uses a scrollarea /// Sets whether the targetsetupage uses a scrollarea
/// to host the widgets from the factories /// to host the widgets from the factories