diff options
author | Cristian Adam <cristian.adam@qt.io> | 2022-02-07 15:37:36 +0100 |
---|---|---|
committer | Cristian Adam <cristian.adam@qt.io> | 2024-05-23 12:50:27 +0000 |
commit | 6eaa9f099a29a3e8d252fe20b534647e61f2d8b2 (patch) | |
tree | d405f58babd5c8f532346591685dcd0f35e143d5 /src/plugins/cmakeprojectmanager | |
parent | 44afba52549e0830c832d23426f13825adc6f20b (diff) |
Help: Allow open online documentation for CMake
Qt Creator opens by default the offline documentation of CMake.
But the user can click on the "Globe" to go to the online version
of the documentation.
Change-Id: I0b3a6bceb13784b232b539f1c04bd09aa3a11034
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/cmakeprojectmanager')
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp | 33 | ||||
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakeprojectmanager.h | 1 | ||||
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp | 2 |
3 files changed, 36 insertions, 0 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp index 9730c957fbf..7a80db87dd7 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp @@ -18,6 +18,7 @@ #include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/icore.h> +#include <coreplugin/helpmanager.h> #include <coreplugin/messagemanager.h> #include <coreplugin/modemanager.h> @@ -41,6 +42,7 @@ #include <utils/checkablemessagebox.h> #include <utils/utilsicons.h> +#include <QDesktopServices> #include <QMessageBox> using namespace Core; @@ -55,6 +57,9 @@ class CMakeManager final : public QObject public: CMakeManager(); + static bool isCMakeUrl(const QUrl &url); + static void openCMakeUrl(const QUrl &url); + private: void updateCmakeActions(Node *node); void clearCMakeCache(BuildSystem *buildSystem); @@ -80,6 +85,29 @@ private: bool m_canDebugCMake = false; }; +bool CMakeManager::isCMakeUrl(const QUrl &url) +{ + const QString address = url.toString(); + return address.startsWith("qthelp://org.cmake."); +} + +void CMakeManager::openCMakeUrl(const QUrl &url) +{ + QString urlPrefix = "https://cmake.org/cmake/help/"; + + QRegularExpression version("^.*\\.([0-9])\\.([0-9]+)\\.[0-9]+$"); + auto match = version.match(url.authority()); + if (match.hasMatch()) + urlPrefix.append(QString("v%1.%2").arg(match.captured(1)).arg(match.captured(2))); + else + urlPrefix.append("latest"); + + const QString address = url.toString(); + const QString doc("/doc"); + QDesktopServices::openUrl( + QUrl(urlPrefix + address.mid(address.lastIndexOf(doc) + doc.length()))); +} + CMakeManager::CMakeManager() { namespace PEC = ProjectExplorer::Constants; @@ -458,4 +486,9 @@ void setupCMakeManager() static CMakeManager theCMakeManager; } +void setupOnlineHelpManager() +{ + Core::HelpManager::addOnlineHelpHandler({CMakeManager::isCMakeUrl, CMakeManager::openCMakeUrl}); +} + } // CMakeProjectManager::Internal diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h index ba3a025f130..42e6a1c4e31 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h @@ -6,5 +6,6 @@ namespace CMakeProjectManager::Internal { void setupCMakeManager(); +void setupOnlineHelpManager(); } // CMakeProjectManager::Internal diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp index 9c2a23dc061..f91c1438d24 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp @@ -105,6 +105,8 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin { // Delay the restoration to allow the devices to load first. QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); }); + + setupOnlineHelpManager(); } void updateContextActions(ProjectExplorer::Node *node) |