forked from qt-creator/qt-creator
Help: Fix finding latest Qt documentation link for Qt5
The identifiers changed to use org.qt-project. Also simplify the logic the does the id highlighting. Task-number: QTCREATORBUG-10331 Change-Id: I3b6eb80138d8fafeb84772b95435acd68818ada1 Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
This commit is contained in:
@@ -75,6 +75,7 @@
|
|||||||
#include <coreplugin/find/findplugin.h>
|
#include <coreplugin/find/findplugin.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/styledbar.h>
|
#include <utils/styledbar.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -617,6 +618,9 @@ void HelpPlugin::createRightPaneContextViewer()
|
|||||||
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
|
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(m_helpViewerForSideBar, SIGNAL(loadFinished()),
|
||||||
|
this, SLOT(highlightSearchTermsInContextHelp()));
|
||||||
|
|
||||||
// force setup, as we might have never switched to full help mode
|
// force setup, as we might have never switched to full help mode
|
||||||
// thus the help engine might still run without collection file setup
|
// thus the help engine might still run without collection file setup
|
||||||
m_helpManager->setupGuiHelpEngine();
|
m_helpManager->setupGuiHelpEngine();
|
||||||
@@ -870,6 +874,34 @@ HelpViewer *HelpPlugin::viewerForContextMode()
|
|||||||
return viewer;
|
return viewer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QUrl findBestLink(const QMap<QString, QUrl> &links, QString *highlightId)
|
||||||
|
{
|
||||||
|
if (highlightId)
|
||||||
|
highlightId->clear();
|
||||||
|
if (links.isEmpty())
|
||||||
|
return QUrl();
|
||||||
|
QUrl source = links.first();
|
||||||
|
// workaround to show the latest Qt version
|
||||||
|
int version = 0;
|
||||||
|
QRegExp exp(QLatin1String("(\\d+)"));
|
||||||
|
foreach (const QUrl &link, links) {
|
||||||
|
const QString &authority = link.authority();
|
||||||
|
if (authority.startsWith(QLatin1String("com.trolltech."))
|
||||||
|
|| authority.startsWith(QLatin1String("org.qt-project."))) {
|
||||||
|
if (exp.indexIn(authority) >= 0) {
|
||||||
|
const int tmpVersion = exp.cap(1).toInt();
|
||||||
|
if (tmpVersion > version) {
|
||||||
|
source = link;
|
||||||
|
version = tmpVersion;
|
||||||
|
if (highlightId)
|
||||||
|
*highlightId = source.fragment();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
void HelpPlugin::activateContext()
|
void HelpPlugin::activateContext()
|
||||||
{
|
{
|
||||||
createRightPaneContextViewer();
|
createRightPaneContextViewer();
|
||||||
@@ -885,64 +917,28 @@ void HelpPlugin::activateContext()
|
|||||||
|
|
||||||
// Find out what to show
|
// Find out what to show
|
||||||
QMap<QString, QUrl> links;
|
QMap<QString, QUrl> links;
|
||||||
|
QString idFromContext;
|
||||||
if (IContext *context = Core::ICore::currentContextObject()) {
|
if (IContext *context = Core::ICore::currentContextObject()) {
|
||||||
m_idFromContext = context->contextHelpId();
|
idFromContext = context->contextHelpId();
|
||||||
links = HelpManager::linksForIdentifier(m_idFromContext);
|
links = HelpManager::linksForIdentifier(idFromContext);
|
||||||
// Maybe the id is already an URL
|
// Maybe the id is already an URL
|
||||||
if (links.isEmpty() && LocalHelpManager::isValidUrl(m_idFromContext))
|
if (links.isEmpty() && LocalHelpManager::isValidUrl(idFromContext))
|
||||||
links.insert(m_idFromContext, m_idFromContext);
|
links.insert(idFromContext, idFromContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HelpViewer* viewer = viewerForContextMode()) {
|
if (HelpViewer* viewer = viewerForContextMode()) {
|
||||||
if (links.isEmpty()) {
|
QUrl source = findBestLink(links, &m_contextHelpHighlightId);
|
||||||
|
if (!source.isValid()) {
|
||||||
// No link found or no context object
|
// No link found or no context object
|
||||||
viewer->setSource(QUrl(Help::Constants::AboutBlank));
|
viewer->setSource(QUrl(Help::Constants::AboutBlank));
|
||||||
viewer->setHtml(tr("<html><head><title>No Documentation</title>"
|
viewer->setHtml(tr("<html><head><title>No Documentation</title>"
|
||||||
"</head><body><br/><center><b>%1</b><br/>No documentation "
|
"</head><body><br/><center><b>%1</b><br/>No documentation "
|
||||||
"available.</center></body></html>").arg(m_idFromContext));
|
"available.</center></body></html>").arg(idFromContext));
|
||||||
} else {
|
} else {
|
||||||
int version = 0;
|
|
||||||
QRegExp exp(QLatin1String("(\\d+)"));
|
|
||||||
QUrl source = *links.begin();
|
|
||||||
const QLatin1String qtRefDoc = QLatin1String("com.trolltech.qt");
|
|
||||||
|
|
||||||
// workaround to show the latest Qt version
|
|
||||||
foreach (const QUrl &tmp, links) {
|
|
||||||
const QString &authority = tmp.authority();
|
|
||||||
if (authority.startsWith(qtRefDoc)) {
|
|
||||||
if (exp.indexIn(authority) >= 0) {
|
|
||||||
const int tmpVersion = exp.cap(1).toInt();
|
|
||||||
if (tmpVersion > version) {
|
|
||||||
source = tmp;
|
|
||||||
version = tmpVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const QUrl &oldSource = viewer->source();
|
const QUrl &oldSource = viewer->source();
|
||||||
if (source != oldSource) {
|
if (source != oldSource) {
|
||||||
viewer->stop();
|
viewer->stop();
|
||||||
const QString &fragment = source.fragment();
|
viewer->setSource(source); // triggers loadFinished which triggers id highlighting
|
||||||
const bool isQtRefDoc = source.authority().startsWith(qtRefDoc);
|
|
||||||
if (isQtRefDoc) {
|
|
||||||
// workaround for qt properties
|
|
||||||
m_idFromContext = fragment;
|
|
||||||
|
|
||||||
if (!m_idFromContext.isEmpty()) {
|
|
||||||
connect(viewer, SIGNAL(loadFinished()), this,
|
|
||||||
SLOT(highlightSearchTerms()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
viewer->setSource(source);
|
|
||||||
|
|
||||||
if (isQtRefDoc && !m_idFromContext.isEmpty()) {
|
|
||||||
if (source.toString().remove(fragment)
|
|
||||||
== oldSource.toString().remove(oldSource.fragment())) {
|
|
||||||
highlightSearchTerms();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
viewer->scrollToAnchor(source.fragment());
|
viewer->scrollToAnchor(source.fragment());
|
||||||
}
|
}
|
||||||
@@ -1094,13 +1090,15 @@ void HelpPlugin::addBookmark()
|
|||||||
manager->showBookmarkDialog(m_centralWidget, viewer->title(), url);
|
manager->showBookmarkDialog(m_centralWidget, viewer->title(), url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpPlugin::highlightSearchTerms()
|
void HelpPlugin::highlightSearchTermsInContextHelp()
|
||||||
{
|
{
|
||||||
if (HelpViewer* viewer = viewerForContextMode()) {
|
qDebug() << "highlight" << m_contextHelpHighlightId;
|
||||||
disconnect(viewer, SIGNAL(loadFinished()), this,
|
if (m_contextHelpHighlightId.isEmpty())
|
||||||
SLOT(highlightSearchTerms()));
|
return;
|
||||||
viewer->highlightId(m_idFromContext);
|
HelpViewer* viewer = viewerForContextMode();
|
||||||
}
|
QTC_ASSERT(viewer, return);
|
||||||
|
viewer->highlightId(m_contextHelpHighlightId);
|
||||||
|
m_contextHelpHighlightId.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpPlugin::handleHelpRequest(const QUrl &url)
|
void HelpPlugin::handleHelpRequest(const QUrl &url)
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ private slots:
|
|||||||
void updateCloseButton();
|
void updateCloseButton();
|
||||||
void setupHelpEngineIfNeeded();
|
void setupHelpEngineIfNeeded();
|
||||||
|
|
||||||
void highlightSearchTerms();
|
void highlightSearchTermsInContextHelp();
|
||||||
void handleHelpRequest(const QUrl &url);
|
void handleHelpRequest(const QUrl &url);
|
||||||
|
|
||||||
void slotAboutToShowBackMenu();
|
void slotAboutToShowBackMenu();
|
||||||
@@ -166,7 +166,7 @@ private:
|
|||||||
|
|
||||||
QToolButton *m_closeButton;
|
QToolButton *m_closeButton;
|
||||||
|
|
||||||
QString m_idFromContext;
|
QString m_contextHelpHighlightId;
|
||||||
|
|
||||||
Core::IMode* m_oldMode;
|
Core::IMode* m_oldMode;
|
||||||
bool m_connectWindow;
|
bool m_connectWindow;
|
||||||
|
|||||||
@@ -499,7 +499,20 @@ QUrl QtWebKitHelpViewer::source() const
|
|||||||
|
|
||||||
void QtWebKitHelpViewer::setSource(const QUrl &url)
|
void QtWebKitHelpViewer::setSource(const QUrl &url)
|
||||||
{
|
{
|
||||||
|
QUrl oldWithoutFragment = source();
|
||||||
|
oldWithoutFragment.setFragment(QString());
|
||||||
|
|
||||||
m_webView->load(url);
|
m_webView->load(url);
|
||||||
|
|
||||||
|
// if the new url only changes the anchor,
|
||||||
|
// then webkit does not send loadStarted nor loadFinished,
|
||||||
|
// so we should do that manually in that case
|
||||||
|
QUrl newWithoutFragment = url;
|
||||||
|
newWithoutFragment.setFragment(QString());
|
||||||
|
if (oldWithoutFragment == newWithoutFragment) {
|
||||||
|
slotLoadStarted();
|
||||||
|
slotLoadFinished();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtWebKitHelpViewer::scrollToAnchor(const QString &anchor)
|
void QtWebKitHelpViewer::scrollToAnchor(const QString &anchor)
|
||||||
@@ -509,6 +522,8 @@ void QtWebKitHelpViewer::scrollToAnchor(const QString &anchor)
|
|||||||
|
|
||||||
void QtWebKitHelpViewer::highlightId(const QString &id)
|
void QtWebKitHelpViewer::highlightId(const QString &id)
|
||||||
{
|
{
|
||||||
|
if (m_oldHighlightId == id)
|
||||||
|
return;
|
||||||
const QWebElement &document = m_webView->page()->mainFrame()->documentElement();
|
const QWebElement &document = m_webView->page()->mainFrame()->documentElement();
|
||||||
const QWebElementCollection &collection = document.findAll(QLatin1String("h3.fn a"));
|
const QWebElementCollection &collection = document.findAll(QLatin1String("h3.fn a"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user