diff --git a/src/plugins/help/helpconstants.h b/src/plugins/help/helpconstants.h index a212159ceb3..294424af7dc 100644 --- a/src/plugins/help/helpconstants.h +++ b/src/plugins/help/helpconstants.h @@ -49,6 +49,7 @@ const char HELP_HOME[] = "Help.Home"; const char HELP_PREVIOUS[] = "Help.Previous"; const char HELP_NEXT[] = "Help.Next"; const char HELP_ADDBOOKMARK[] = "Help.AddBookmark"; +const char HELP_OPENONLINE[] = "Help.OpenOnline"; const char HELP_INDEX[] = "Help.Index"; const char HELP_CONTENTS[] = "Help.Contents"; const char HELP_SEARCH[] = "Help.Search"; diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 7e8bf80c81d..c06619f3bc9 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -701,19 +701,8 @@ HelpViewer *HelpPluginPrivate::showHelpUrl(const QUrl &url, Core::HelpManager::H return nullptr; if (!HelpManager::findFile(url).isValid()) { - const QString address = url.toString(); - if (address.startsWith("qthelp://org.qt-project.") - || address.startsWith("qthelp://com.nokia.") - || address.startsWith("qthelp://com.trolltech.")) { - // local help not installed, resort to external web help - QString urlPrefix = "http://doc.qt.io/"; - if (url.authority().startsWith(qtcreatorUnversionedID)) - urlPrefix.append(QString::fromLatin1("qtcreator")); - else - urlPrefix.append("qt-5"); - QDesktopServices::openUrl(QUrl(urlPrefix + address.mid(address.lastIndexOf(QLatin1Char('/'))))); + if (LocalHelpManager::openOnlineHelp(url)) return nullptr; - } } HelpViewer *viewer = viewerForHelpViewerLocation(location); diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp index 64f76e4e6cb..74557c3c712 100644 --- a/src/plugins/help/helpwidget.cpp +++ b/src/plugins/help/helpwidget.cpp @@ -208,6 +208,11 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget layout->addWidget(new Utils::StyledSeparator(toolBar)); layout->addWidget(Core::Command::toolButtonWithAppendedShortcut(m_addBookmarkAction, cmd)); + m_openOnlineDocumentationAction = new QAction(Utils::Icons::EXPORTFILE_TOOLBAR.icon(), tr("Open Online Documentation..."), this); + cmd = Core::ActionManager::registerAction(m_openOnlineDocumentationAction, Constants::HELP_OPENONLINE, context); + connect(m_openOnlineDocumentationAction, &QAction::triggered, this, &HelpWidget::openOnlineDocumentation); + layout->addWidget(Core::Command::toolButtonWithAppendedShortcut(m_openOnlineDocumentationAction, cmd)); + if (style == ModeWidget) { layout->addWidget(new Utils::StyledSeparator(toolBar)); layout->addWidget(OpenPagesManager::instance().openPagesComboBox(), 10); @@ -453,6 +458,7 @@ void HelpWidget::setCurrentViewer(HelpViewer *viewer) m_backAction->setEnabled(viewer->isBackwardAvailable()); m_forwardAction->setEnabled(viewer->isForwardAvailable()); m_addBookmarkAction->setEnabled(isBookmarkable(viewer->source())); + m_openOnlineDocumentationAction->setEnabled(LocalHelpManager::canOpenOnlineHelp(viewer->source())); if (m_style == ExternalWindow) updateWindowTitle(); emit sourceChanged(viewer->source()); @@ -472,6 +478,7 @@ void HelpWidget::addViewer(HelpViewer *viewer) connect(viewer, &HelpViewer::sourceChanged, this, [viewer, this](const QUrl &url) { if (currentViewer() == viewer) { m_addBookmarkAction->setEnabled(isBookmarkable(url)); + m_openOnlineDocumentationAction->setEnabled(LocalHelpManager::canOpenOnlineHelp(url)); emit sourceChanged(url); } }); @@ -633,6 +640,13 @@ void HelpWidget::addBookmark() manager->showBookmarkDialog(this, viewer->title(), url); } +void HelpWidget::openOnlineDocumentation() +{ + HelpViewer *viewer = currentViewer(); + QTC_ASSERT(viewer, return); + LocalHelpManager::openOnlineHelp(viewer->source()); +} + void HelpWidget::copy() { QTC_ASSERT(currentViewer(), return); diff --git a/src/plugins/help/helpwidget.h b/src/plugins/help/helpwidget.h index fb084c99f3e..bc38dcaa070 100644 --- a/src/plugins/help/helpwidget.h +++ b/src/plugins/help/helpwidget.h @@ -99,6 +99,7 @@ private: void goHome(); void addBookmark(); + void openOnlineDocumentation(); void copy(); void forward(); void backward(); @@ -120,6 +121,7 @@ private: QAction *m_backAction = nullptr; QAction *m_forwardAction = nullptr; QAction *m_addBookmarkAction = nullptr; + QAction *m_openOnlineDocumentationAction = nullptr; QComboBox *m_filterComboBox = nullptr; QAction *m_closeAction = nullptr; QAction *m_scaleUp = nullptr; diff --git a/src/plugins/help/localhelpmanager.cpp b/src/plugins/help/localhelpmanager.cpp index 140aa4a9350..828af819844 100644 --- a/src/plugins/help/localhelpmanager.cpp +++ b/src/plugins/help/localhelpmanager.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -445,3 +446,31 @@ void LocalHelpManager::updateFilterModel() } emit m_instance->filterIndexChanged(m_currentFilterIndex); } + +bool LocalHelpManager::canOpenOnlineHelp(const QUrl &url) +{ + const QString address = url.toString(); + if (address.startsWith("qthelp://org.qt-project.") + || address.startsWith("qthelp://com.nokia.") + || address.startsWith("qthelp://com.trolltech.")) { + return true; + } + return false; +} + +bool LocalHelpManager::openOnlineHelp(const QUrl &url) +{ + static const QString qtcreatorUnversionedID = "org.qt-project.qtcreator"; + + if (canOpenOnlineHelp(url)) { + QString urlPrefix = "http://doc.qt.io/"; + if (url.authority().startsWith(qtcreatorUnversionedID)) + urlPrefix.append(QString::fromLatin1("qtcreator")); + else + urlPrefix.append("qt-5"); + const QString address = url.toString(); + QDesktopServices::openUrl(QUrl(urlPrefix + address.mid(address.lastIndexOf(QLatin1Char('/'))))); + return true; + } + return false; +} diff --git a/src/plugins/help/localhelpmanager.h b/src/plugins/help/localhelpmanager.h index 7b330ade309..8e4e8ce0036 100644 --- a/src/plugins/help/localhelpmanager.h +++ b/src/plugins/help/localhelpmanager.h @@ -105,6 +105,9 @@ public: static void updateFilterModel(); + static bool canOpenOnlineHelp(const QUrl &url); + static bool openOnlineHelp(const QUrl &url); + signals: void filterIndexChanged(int index); void fallbackFontChanged(const QFont &font);