diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 0ae2a61db0ef25d01ec60dd403369325eb953f6c..ff7a6299b47d2c91081929540713a3a9036ec433 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -75,6 +75,7 @@ #include #include #include +#include #include #include @@ -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 &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 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("No Documentation" "
%1
No documentation " - "available.
").arg(m_idFromContext)); + "available.").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) diff --git a/src/plugins/help/helpplugin.h b/src/plugins/help/helpplugin.h index eb2dd506beae430ac8d77d1670c1a42f32d25b52..0839ec4eaede5dc7abf6f73dbed4f983ded37cfb 100644 --- a/src/plugins/help/helpplugin.h +++ b/src/plugins/help/helpplugin.h @@ -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; diff --git a/src/plugins/help/qtwebkithelpviewer.cpp b/src/plugins/help/qtwebkithelpviewer.cpp index 777077154bc1c0acaba2907917831be8c0dd17e7..7d28578776a8ced2194e26827396c99a507062bf 100644 --- a/src/plugins/help/qtwebkithelpviewer.cpp +++ b/src/plugins/help/qtwebkithelpviewer.cpp @@ -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"));