From 0935d14f16279331e895f09124b77b92d3192a0d Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 28 Sep 2016 17:14:53 +0200 Subject: [PATCH] Fix Open with Designer / Linguist in case of mobile or embedded Qt They do not come with these Applications, so we look in other kits of the project, the default kit, all other kits, and then fall back to PATH. Task-number: QTCREATORBUG-16558 Change-Id: I3b1b92dc221ba3de8f36a31be4945c448944f3e9 Reviewed-by: Tobias Hunger --- .../qmakeprojectmanager/externaleditors.cpp | 47 +++++++++++++++---- .../qmakeprojectmanager/externaleditors.h | 6 +-- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/plugins/qmakeprojectmanager/externaleditors.cpp b/src/plugins/qmakeprojectmanager/externaleditors.cpp index 0d4791d028f..0b067e7a09b 100644 --- a/src/plugins/qmakeprojectmanager/externaleditors.cpp +++ b/src/plugins/qmakeprojectmanager/externaleditors.cpp @@ -25,6 +25,7 @@ #include "externaleditors.h" +#include #include #include #include @@ -142,23 +143,51 @@ QString ExternalQtEditor::displayName() const return m_displayName; } +static QString findFirstCommand(QVector qtVersions, + ExternalQtEditor::CommandForQtVersion command) +{ + foreach (QtSupport::BaseQtVersion *qt, qtVersions) { + if (qt) { + const QString binary = command(qt); + if (!binary.isEmpty()) + return binary; + } + } + return QString(); +} + bool ExternalQtEditor::getEditorLaunchData(const QString &fileName, LaunchData *data, QString *errorMessage) const { - // Get the binary either from the current Qt version of the project or Path - if (Project *project = SessionManager::projectForFile(Utils::FileName::fromString(fileName))) { + // Check in order for Qt version with the binary: + // - active kit of project + // - any other of the project + // - default kit + // - any other kit + // As fallback check PATH + data->workingDirectory.clear(); + QVector qtVersionsToCheck; // deduplicated after being filled + if (const Project *project = SessionManager::projectForFile(Utils::FileName::fromString(fileName))) { + data->workingDirectory = project->projectDirectory().toString(); + // active kit if (const Target *target = project->activeTarget()) { - if (const QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(target->kit())) { - data->binary = m_commandForQtVersion(qtVersion); - data->workingDirectory = project->projectDirectory().toString(); - } + qtVersionsToCheck << QtSupport::QtKitInformation::qtVersion(target->kit()); } + // all kits of project + qtVersionsToCheck += Utils::transform(project->targets(), [](Target *t) { + return QTC_GUARD(t) ? QtSupport::QtKitInformation::qtVersion(t->kit()) : nullptr; + }); } - if (data->binary.isEmpty()) { - data->workingDirectory.clear(); + // default kit + qtVersionsToCheck << QtSupport::QtKitInformation::qtVersion(KitManager::defaultKit()); + // all kits + qtVersionsToCheck += Utils::transform(KitManager::kits(), QtSupport::QtKitInformation::qtVersion); + qtVersionsToCheck = Utils::filteredUnique(qtVersionsToCheck); // can still contain nullptr + data->binary = findFirstCommand(qtVersionsToCheck, m_commandForQtVersion); + // fallback + if (data->binary.isEmpty()) data->binary = Utils::SynchronousProcess::locateBinary(m_commandForQtVersion(nullptr)); - } if (data->binary.isEmpty()) { *errorMessage = msgAppNotFound(id().toString()); return false; diff --git a/src/plugins/qmakeprojectmanager/externaleditors.h b/src/plugins/qmakeprojectmanager/externaleditors.h index d06026f28fd..5b2de682338 100644 --- a/src/plugins/qmakeprojectmanager/externaleditors.h +++ b/src/plugins/qmakeprojectmanager/externaleditors.h @@ -52,6 +52,9 @@ class ExternalQtEditor : public Core::IExternalEditor Q_OBJECT public: + // Member function pointer for a QtVersion function return a string (command) + using CommandForQtVersion = std::function; + static ExternalQtEditor *createLinguistEditor(); static ExternalQtEditor *createDesignerEditor(); @@ -69,9 +72,6 @@ public: }; protected: - // Member function pointer for a QtVersion function return a string (command) - using CommandForQtVersion = std::function; - ExternalQtEditor(Core::Id id, const QString &displayName, const QString &mimetype,