forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
namespace CMakeProjectManager::Internal {
|
||||
|
||||
void setupCMakeManager();
|
||||
void setupOnlineHelpManager();
|
||||
|
||||
} // CMakeProjectManager::Internal
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user