From d408e4c22c4fb457e5cb4c8340d8ee4963f15c48 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 3 Feb 2022 16:52:50 +0100 Subject: [PATCH] CMakePM: Add "variable" link to CMake offline/online documentation This way an user can find quickly a CMake variable if needed. Change-Id: Ie885a34321cf2ce31ee662659e669de88b28801c Reviewed-by: Reviewed-by: Eike Ziller --- .../cmakebuildconfiguration.cpp | 15 +++++---- .../cmakekitinformation.cpp | 17 ++++++---- src/plugins/cmakeprojectmanager/cmaketool.cpp | 32 +++++++++++-------- src/plugins/cmakeprojectmanager/cmaketool.h | 4 +-- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index 4e4ba0ccd66..ce3d54f6468 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -494,8 +494,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) auto handleOptionsLink = [this](const QString &link) { const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfiguration->target()->kit()); - if (tool) - tool->openCMakeHelpUrl("%1/manual/cmake.1.html#options"); + CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake.1.html#options"); }; connect(bc->aspect(), &Utils::BaseAspect::labelLinkActivated, @@ -518,10 +517,14 @@ void CMakeBuildSettingsWidget::batchEditConfiguration() auto editor = new QPlainTextEdit(dialog); auto label = new QLabel(dialog); - label->setText(tr("Enter one CMake variable per line.\n" - "To set or change a variable, use -D:=.\n" - " can have one of the following values: FILEPATH, PATH, BOOL, INTERNAL, or STRING.\n" - "To unset a variable, use -U.\n")); + label->setText(tr("Enter one CMake variable per line.
" + "To set or change a variable, use -D<variable>:<type>=<value>.
" + "<type> can have one of the following values: FILEPATH, PATH, BOOL, INTERNAL, or STRING.
" + "To unset a variable, use -U<variable>.
")); + connect(label, &QLabel::linkActivated, this, [this](const QString &link) { + const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfiguration->target()->kit()); + CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake-variables.7.html"); + }); editor->setMinimumSize(800, 200); auto chooser = new Utils::VariableChooser(dialog); diff --git a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp index 0a5ea45db30..a0ec30783ae 100644 --- a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp +++ b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp @@ -925,15 +925,20 @@ private: QTC_ASSERT(!m_editor, return); + const CMakeTool *tool = CMakeKitAspect::cmakeTool(kit()); + m_dialog = new QDialog(m_summaryLabel->window()); m_dialog->setWindowTitle(tr("Edit CMake Configuration")); auto layout = new QVBoxLayout(m_dialog); m_editor = new QPlainTextEdit; auto editorLabel = new QLabel(m_dialog); - editorLabel->setText(tr("Enter one CMake variable per line.\n" - "To set a variable, use -D:=.\n" - " can have one of the following values: FILEPATH, PATH, " + editorLabel->setText(tr("Enter one CMake variable per line.
" + "To set a variable, use -D<variable>:<type>=<value>.
" + "<type> can have one of the following values: FILEPATH, PATH, " "BOOL, INTERNAL, or STRING.")); + connect(editorLabel, &QLabel::linkActivated, this, [=](const QString &link) { + CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake-variables.7.html"); + }); m_editor->setMinimumSize(800, 200); auto chooser = new VariableChooser(m_dialog); @@ -943,10 +948,8 @@ private: m_additionalEditor = new QLineEdit; auto additionalLabel = new QLabel(m_dialog); additionalLabel->setText(tr("Additional CMake options:")); - connect(additionalLabel, &QLabel::linkActivated, this, [this](const QString &link) { - const CMakeTool *tool = CMakeKitAspect::cmakeTool(kit()); - if (tool) - tool->openCMakeHelpUrl("%1/manual/cmake.1.html#options"); + connect(additionalLabel, &QLabel::linkActivated, this, [=](const QString &link) { + CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake.1.html#options"); }); auto additionalChooser = new VariableChooser(m_dialog); diff --git a/src/plugins/cmakeprojectmanager/cmaketool.cpp b/src/plugins/cmakeprojectmanager/cmaketool.cpp index 4e27988cbd9..f4cc060e659 100644 --- a/src/plugins/cmakeprojectmanager/cmaketool.cpp +++ b/src/plugins/cmakeprojectmanager/cmaketool.cpp @@ -382,26 +382,32 @@ FilePath CMakeTool::searchQchFile(const FilePath &executable) return {}; } -QString CMakeTool::documentationUrl(bool online) const +QString CMakeTool::documentationUrl(const Version &version, bool online) { - if (online) - return QString("https://cmake.org/cmake/help/v%1.%2") - .arg(version().major) - .arg(version().minor); + if (online) { + QString helpVersion = "latest"; + if (!(version.major == 0 && version.minor == 0)) + helpVersion = QString("v%1.%2").arg(version.major).arg(version.minor); + + return QString("https://cmake.org/cmake/help/%1").arg(helpVersion); + } return QString("qthelp://org.cmake.%1.%2.%3/doc") - .arg(version().major) - .arg(version().minor) - .arg(version().patch); + .arg(version.major) + .arg(version.minor) + .arg(version.patch); } -void CMakeTool::openCMakeHelpUrl(const QString &linkUrl) const +void CMakeTool::openCMakeHelpUrl(const CMakeTool *tool, const QString &linkUrl) { - if (!isValid()) - return; + bool online = true; + Version version; + if (tool && tool->isValid()) { + online = tool->qchFilePath().isEmpty(); + version = tool->version(); + } - const bool online = qchFilePath().isEmpty(); - Core::HelpManager::showHelpUrl(linkUrl.arg(documentationUrl(online))); + Core::HelpManager::showHelpUrl(linkUrl.arg(documentationUrl(version, online))); } void CMakeTool::readInformation() const diff --git a/src/plugins/cmakeprojectmanager/cmaketool.h b/src/plugins/cmakeprojectmanager/cmaketool.h index 58f727af8b7..dbe65b15cc8 100644 --- a/src/plugins/cmakeprojectmanager/cmaketool.h +++ b/src/plugins/cmakeprojectmanager/cmaketool.h @@ -112,8 +112,8 @@ public: QString detectionSource() const { return m_detectionSource; } void setDetectionSource(const QString &source) { m_detectionSource = source; } - QString documentationUrl(bool online) const; - void openCMakeHelpUrl(const QString &linkUrl) const; + static QString documentationUrl(const Version &version, bool online); + static void openCMakeHelpUrl(const CMakeTool *tool, const QString &linkUrl); private: void readInformation() const;