Commit 43895b03 authored by Eike Ziller's avatar Eike Ziller

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: default avatarKarsten Heimrich <karsten.heimrich@digia.com>
parent 94ca9e56
......@@ -75,6 +75,7 @@
#include <coreplugin/find/findplugin.h>
#include <texteditor/texteditorconstants.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <QDir>
......@@ -617,6 +618,9 @@ void HelpPlugin::createRightPaneContextViewer()
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
// thus the help engine might still run without collection file setup
m_helpManager->setupGuiHelpEngine();
......@@ -870,6 +874,34 @@ HelpViewer *HelpPlugin::viewerForContextMode()
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()
{
createRightPaneContextViewer();
......@@ -885,64 +917,28 @@ void HelpPlugin::activateContext()
// Find out what to show
QMap<QString, QUrl> links;
QString idFromContext;
if (IContext *context = Core::ICore::currentContextObject()) {
m_idFromContext = context->contextHelpId();
links = HelpManager::linksForIdentifier(m_idFromContext);
idFromContext = context->contextHelpId();
links = HelpManager::linksForIdentifier(idFromContext);
// Maybe the id is already an URL
if (links.isEmpty() && LocalHelpManager::isValidUrl(m_idFromContext))
links.insert(m_idFromContext, m_idFromContext);
if (links.isEmpty() && LocalHelpManager::isValidUrl(idFromContext))
links.insert(idFromContext, idFromContext);
}
if (HelpViewer* viewer = viewerForContextMode()) {
if (links.isEmpty()) {
QUrl source = findBestLink(links, &m_contextHelpHighlightId);
if (!source.isValid()) {
// No link found or no context object
viewer->setSource(QUrl(Help::Constants::AboutBlank));
viewer->setHtml(tr("<html><head><title>No Documentation</title>"
"</head><body><br/><center><b>%1</b><br/>No documentation "
"available.</center></body></html>").arg(m_idFromContext));
"available.</center></body></html>").arg(idFromContext));
} 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();
if (source != oldSource) {
viewer->stop();
const QString &fragment = source.fragment();
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();
}
}
viewer->setSource(source); // triggers loadFinished which triggers id highlighting
} else {
viewer->scrollToAnchor(source.fragment());
}
......@@ -1094,13 +1090,15 @@ void HelpPlugin::addBookmark()
manager->showBookmarkDialog(m_centralWidget, viewer->title(), url);
}
void HelpPlugin::highlightSearchTerms()
void HelpPlugin::highlightSearchTermsInContextHelp()
{
if (HelpViewer* viewer = viewerForContextMode()) {
disconnect(viewer, SIGNAL(loadFinished()), this,
SLOT(highlightSearchTerms()));
viewer->highlightId(m_idFromContext);
}
qDebug() << "highlight" << m_contextHelpHighlightId;
if (m_contextHelpHighlightId.isEmpty())
return;
HelpViewer* viewer = viewerForContextMode();
QTC_ASSERT(viewer, return);
viewer->highlightId(m_contextHelpHighlightId);
m_contextHelpHighlightId.clear();
}
void HelpPlugin::handleHelpRequest(const QUrl &url)
......
......@@ -111,7 +111,7 @@ private slots:
void updateCloseButton();
void setupHelpEngineIfNeeded();
void highlightSearchTerms();
void highlightSearchTermsInContextHelp();
void handleHelpRequest(const QUrl &url);
void slotAboutToShowBackMenu();
......@@ -166,7 +166,7 @@ private:
QToolButton *m_closeButton;
QString m_idFromContext;
QString m_contextHelpHighlightId;
Core::IMode* m_oldMode;
bool m_connectWindow;
......
......@@ -499,7 +499,20 @@ QUrl QtWebKitHelpViewer::source() const
void QtWebKitHelpViewer::setSource(const QUrl &url)
{
QUrl oldWithoutFragment = source();
oldWithoutFragment.setFragment(QString());
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)
......@@ -509,6 +522,8 @@ void QtWebKitHelpViewer::scrollToAnchor(const QString &anchor)
void QtWebKitHelpViewer::highlightId(const QString &id)
{
if (m_oldHighlightId == id)
return;
const QWebElement &document = m_webView->page()->mainFrame()->documentElement();
const QWebElementCollection &collection = document.findAll(QLatin1String("h3.fn a"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment