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>
This commit is contained in:
Cristian Adam
2022-02-07 15:37:36 +01:00
parent 44afba5254
commit 6eaa9f099a
10 changed files with 107 additions and 19 deletions

View File

@@ -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