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/editormanager.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/helpmanager.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <coreplugin/modemanager.h>
|
#include <coreplugin/modemanager.h>
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@
|
|||||||
#include <utils/checkablemessagebox.h>
|
#include <utils/checkablemessagebox.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
@@ -55,6 +57,9 @@ class CMakeManager final : public QObject
|
|||||||
public:
|
public:
|
||||||
CMakeManager();
|
CMakeManager();
|
||||||
|
|
||||||
|
static bool isCMakeUrl(const QUrl &url);
|
||||||
|
static void openCMakeUrl(const QUrl &url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCmakeActions(Node *node);
|
void updateCmakeActions(Node *node);
|
||||||
void clearCMakeCache(BuildSystem *buildSystem);
|
void clearCMakeCache(BuildSystem *buildSystem);
|
||||||
@@ -80,6 +85,29 @@ private:
|
|||||||
bool m_canDebugCMake = false;
|
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()
|
CMakeManager::CMakeManager()
|
||||||
{
|
{
|
||||||
namespace PEC = ProjectExplorer::Constants;
|
namespace PEC = ProjectExplorer::Constants;
|
||||||
@@ -458,4 +486,9 @@ void setupCMakeManager()
|
|||||||
static CMakeManager theCMakeManager;
|
static CMakeManager theCMakeManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setupOnlineHelpManager()
|
||||||
|
{
|
||||||
|
Core::HelpManager::addOnlineHelpHandler({CMakeManager::isCMakeUrl, CMakeManager::openCMakeUrl});
|
||||||
|
}
|
||||||
|
|
||||||
} // CMakeProjectManager::Internal
|
} // CMakeProjectManager::Internal
|
||||||
|
|||||||
@@ -6,5 +6,6 @@
|
|||||||
namespace CMakeProjectManager::Internal {
|
namespace CMakeProjectManager::Internal {
|
||||||
|
|
||||||
void setupCMakeManager();
|
void setupCMakeManager();
|
||||||
|
void setupOnlineHelpManager();
|
||||||
|
|
||||||
} // CMakeProjectManager::Internal
|
} // CMakeProjectManager::Internal
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
|||||||
{
|
{
|
||||||
// Delay the restoration to allow the devices to load first.
|
// Delay the restoration to allow the devices to load first.
|
||||||
QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); });
|
QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); });
|
||||||
|
|
||||||
|
setupOnlineHelpManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateContextActions(ProjectExplorer::Node *node)
|
void updateContextActions(ProjectExplorer::Node *node)
|
||||||
|
|||||||
@@ -103,5 +103,11 @@ void setBlockedDocumentation(const QStringList &fileNames)
|
|||||||
m_instance->setBlockedDocumentation(fileNames);
|
m_instance->setBlockedDocumentation(fileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addOnlineHelpHandler(const OnlineHelpHandler &handler)
|
||||||
|
{
|
||||||
|
if (checkInstance())
|
||||||
|
m_instance->addOnlineHelpHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
} // HelpManager
|
} // HelpManager
|
||||||
} // Core
|
} // Core
|
||||||
|
|||||||
@@ -48,5 +48,11 @@ CORE_EXPORT QByteArray fileData(const QUrl &url);
|
|||||||
CORE_EXPORT void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways);
|
CORE_EXPORT void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways);
|
||||||
CORE_EXPORT void showHelpUrl(const QString &url, HelpViewerLocation location = HelpModeAlways);
|
CORE_EXPORT void showHelpUrl(const QString &url, HelpViewerLocation location = HelpModeAlways);
|
||||||
|
|
||||||
|
struct CORE_EXPORT OnlineHelpHandler {
|
||||||
|
std::function<bool(QUrl)> handlesUrl;
|
||||||
|
std::function<void(QUrl)> openUrl;
|
||||||
|
};
|
||||||
|
CORE_EXPORT void addOnlineHelpHandler(const OnlineHelpHandler &handler);
|
||||||
|
|
||||||
} // HelpManager
|
} // HelpManager
|
||||||
} // Core
|
} // Core
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public:
|
|||||||
virtual QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword) = 0;
|
virtual QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword) = 0;
|
||||||
virtual QByteArray fileData(const QUrl &url) = 0;
|
virtual QByteArray fileData(const QUrl &url) = 0;
|
||||||
virtual void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways) = 0;
|
virtual void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways) = 0;
|
||||||
|
virtual void addOnlineHelpHandler(const OnlineHelpHandler &handler) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // HelpManager
|
} // HelpManager
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "helpmanager.h"
|
#include "helpmanager.h"
|
||||||
|
#include "localhelpmanager.h"
|
||||||
|
|
||||||
#include "helptr.h"
|
#include "helptr.h"
|
||||||
|
|
||||||
@@ -282,6 +283,11 @@ void HelpManager::showHelpUrl(const QUrl &url, Core::HelpManager::HelpViewerLoca
|
|||||||
emit m_instance->helpRequested(url, location);
|
emit m_instance->helpRequested(url, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HelpManager::addOnlineHelpHandler(const Core::HelpManager::OnlineHelpHandler &handler)
|
||||||
|
{
|
||||||
|
LocalHelpManager::addOnlineHelpHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList HelpManager::registeredNamespaces()
|
QStringList HelpManager::registeredNamespaces()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!d->m_needsSetup, return {});
|
QTC_ASSERT(!d->m_needsSetup, return {});
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public:
|
|||||||
const QUrl &url,
|
const QUrl &url,
|
||||||
Core::HelpManager::HelpViewerLocation location = Core::HelpManager::HelpModeAlways) override;
|
Core::HelpManager::HelpViewerLocation location = Core::HelpManager::HelpModeAlways) override;
|
||||||
|
|
||||||
|
void addOnlineHelpHandler(const Core::HelpManager::OnlineHelpHandler &handler) override;
|
||||||
|
|
||||||
static void setupHelpManager();
|
static void setupHelpManager();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ QHelpEngine* LocalHelpManager::m_guiEngine = nullptr;
|
|||||||
QMutex LocalHelpManager::m_bkmarkMutex;
|
QMutex LocalHelpManager::m_bkmarkMutex;
|
||||||
BookmarkManager* LocalHelpManager::m_bookmarkManager = nullptr;
|
BookmarkManager* LocalHelpManager::m_bookmarkManager = nullptr;
|
||||||
|
|
||||||
|
QList<Core::HelpManager::OnlineHelpHandler> LocalHelpManager::m_onlineHelpHandlerList;
|
||||||
|
|
||||||
const char kHelpHomePageKey[] = "Help/HomePage";
|
const char kHelpHomePageKey[] = "Help/HomePage";
|
||||||
const char kFontFamilyKey[] = "Help/FallbackFontFamily";
|
const char kFontFamilyKey[] = "Help/FallbackFontFamily";
|
||||||
const char kFontStyleNameKey[] = "Help/FallbackFontStyleName";
|
const char kFontStyleNameKey[] = "Help/FallbackFontStyleName";
|
||||||
@@ -96,6 +98,8 @@ LocalHelpManager::LocalHelpManager(QObject *parent)
|
|||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
qRegisterMetaType<Help::Internal::LocalHelpManager::HelpData>("Help::Internal::LocalHelpManager::HelpData");
|
qRegisterMetaType<Help::Internal::LocalHelpManager::HelpData>("Help::Internal::LocalHelpManager::HelpData");
|
||||||
|
|
||||||
|
addOnlineHelpHandler({LocalHelpManager::isQtUrl, LocalHelpManager::openQtUrl});
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalHelpManager::~LocalHelpManager()
|
LocalHelpManager::~LocalHelpManager()
|
||||||
@@ -507,6 +511,14 @@ QHelpFilterEngine *LocalHelpManager::filterEngine()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool LocalHelpManager::canOpenOnlineHelp(const QUrl &url)
|
bool LocalHelpManager::canOpenOnlineHelp(const QUrl &url)
|
||||||
|
{
|
||||||
|
return Utils::anyOf(
|
||||||
|
m_onlineHelpHandlerList, [url](const Core::HelpManager::OnlineHelpHandler &handler) {
|
||||||
|
return handler.handlesUrl(url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalHelpManager::isQtUrl(const QUrl &url)
|
||||||
{
|
{
|
||||||
const QString address = url.toString();
|
const QString address = url.toString();
|
||||||
return address.startsWith("qthelp://org.qt-project.")
|
return address.startsWith("qthelp://org.qt-project.")
|
||||||
@@ -514,12 +526,11 @@ bool LocalHelpManager::canOpenOnlineHelp(const QUrl &url)
|
|||||||
|| address.startsWith("qthelp://com.trolltech.");
|
|| address.startsWith("qthelp://com.trolltech.");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalHelpManager::openOnlineHelp(const QUrl &url)
|
void LocalHelpManager::openQtUrl(const QUrl &url)
|
||||||
{
|
{
|
||||||
static const QString unversionedLocalDomainName
|
static const QString unversionedLocalDomainName
|
||||||
= QString("org.qt-project.%1").arg(Utils::appInfo().id);
|
= QString("org.qt-project.%1").arg(Utils::appInfo().id);
|
||||||
|
|
||||||
if (canOpenOnlineHelp(url)) {
|
|
||||||
QString urlPrefix = "http://doc.qt.io/";
|
QString urlPrefix = "http://doc.qt.io/";
|
||||||
if (url.authority().startsWith(unversionedLocalDomainName)) {
|
if (url.authority().startsWith(unversionedLocalDomainName)) {
|
||||||
urlPrefix.append(Utils::appInfo().id);
|
urlPrefix.append(Utils::appInfo().id);
|
||||||
@@ -539,12 +550,26 @@ bool LocalHelpManager::openOnlineHelp(const QUrl &url)
|
|||||||
}
|
}
|
||||||
const QString address = url.toString();
|
const QString address = url.toString();
|
||||||
QDesktopServices::openUrl(QUrl(urlPrefix + address.mid(address.lastIndexOf(QLatin1Char('/')))));
|
QDesktopServices::openUrl(QUrl(urlPrefix + address.mid(address.lastIndexOf(QLatin1Char('/')))));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalHelpManager::openOnlineHelp(const QUrl &url)
|
||||||
|
{
|
||||||
|
return Utils::anyOf(
|
||||||
|
m_onlineHelpHandlerList, [url](const Core::HelpManager::OnlineHelpHandler &handler) {
|
||||||
|
if (handler.handlesUrl(url)) {
|
||||||
|
handler.openUrl(url);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QMultiMap<QString, QUrl> LocalHelpManager::linksForKeyword(const QString &keyword)
|
QMultiMap<QString, QUrl> LocalHelpManager::linksForKeyword(const QString &keyword)
|
||||||
{
|
{
|
||||||
return HelpManager::linksForKeyword(&LocalHelpManager::helpEngine(), keyword, std::nullopt);
|
return HelpManager::linksForKeyword(&LocalHelpManager::helpEngine(), keyword, std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalHelpManager::addOnlineHelpHandler(const Core::HelpManager::OnlineHelpHandler &handler)
|
||||||
|
{
|
||||||
|
LocalHelpManager::m_onlineHelpHandlerList.push_back(handler);
|
||||||
|
}
|
||||||
|
|||||||
@@ -101,9 +101,13 @@ public:
|
|||||||
|
|
||||||
static bool canOpenOnlineHelp(const QUrl &url);
|
static bool canOpenOnlineHelp(const QUrl &url);
|
||||||
static bool openOnlineHelp(const QUrl &url);
|
static bool openOnlineHelp(const QUrl &url);
|
||||||
|
static bool isQtUrl(const QUrl &url);
|
||||||
|
static void openQtUrl(const QUrl &url);
|
||||||
|
|
||||||
static QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword);
|
static QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword);
|
||||||
|
|
||||||
|
static void addOnlineHelpHandler(const Core::HelpManager::OnlineHelpHandler &handler);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void fallbackFontChanged(const QFont &font);
|
void fallbackFontChanged(const QFont &font);
|
||||||
void fontZoomChanged(int percentage);
|
void fontZoomChanged(int percentage);
|
||||||
@@ -121,6 +125,8 @@ private:
|
|||||||
|
|
||||||
static QMutex m_bkmarkMutex;
|
static QMutex m_bkmarkMutex;
|
||||||
static BookmarkManager *m_bookmarkManager;
|
static BookmarkManager *m_bookmarkManager;
|
||||||
|
|
||||||
|
static QList<Core::HelpManager::OnlineHelpHandler> m_onlineHelpHandlerList;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user