Add open online documentation button to help viewer

Change-Id: I21685005709332b1201aaf08804399ecbd82bf7c
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Tasuku Suzuki
2019-06-13 15:41:03 +09:00
parent e3b1106afa
commit 395b5ec185
6 changed files with 50 additions and 12 deletions

View File

@@ -49,6 +49,7 @@ const char HELP_HOME[] = "Help.Home";
const char HELP_PREVIOUS[] = "Help.Previous"; const char HELP_PREVIOUS[] = "Help.Previous";
const char HELP_NEXT[] = "Help.Next"; const char HELP_NEXT[] = "Help.Next";
const char HELP_ADDBOOKMARK[] = "Help.AddBookmark"; const char HELP_ADDBOOKMARK[] = "Help.AddBookmark";
const char HELP_OPENONLINE[] = "Help.OpenOnline";
const char HELP_INDEX[] = "Help.Index"; const char HELP_INDEX[] = "Help.Index";
const char HELP_CONTENTS[] = "Help.Contents"; const char HELP_CONTENTS[] = "Help.Contents";
const char HELP_SEARCH[] = "Help.Search"; const char HELP_SEARCH[] = "Help.Search";

View File

@@ -701,19 +701,8 @@ HelpViewer *HelpPluginPrivate::showHelpUrl(const QUrl &url, Core::HelpManager::H
return nullptr; return nullptr;
if (!HelpManager::findFile(url).isValid()) { if (!HelpManager::findFile(url).isValid()) {
const QString address = url.toString(); if (LocalHelpManager::openOnlineHelp(url))
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('/')))));
return nullptr; return nullptr;
}
} }
HelpViewer *viewer = viewerForHelpViewerLocation(location); HelpViewer *viewer = viewerForHelpViewerLocation(location);

View File

@@ -208,6 +208,11 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
layout->addWidget(new Utils::StyledSeparator(toolBar)); layout->addWidget(new Utils::StyledSeparator(toolBar));
layout->addWidget(Core::Command::toolButtonWithAppendedShortcut(m_addBookmarkAction, cmd)); 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) { if (style == ModeWidget) {
layout->addWidget(new Utils::StyledSeparator(toolBar)); layout->addWidget(new Utils::StyledSeparator(toolBar));
layout->addWidget(OpenPagesManager::instance().openPagesComboBox(), 10); layout->addWidget(OpenPagesManager::instance().openPagesComboBox(), 10);
@@ -453,6 +458,7 @@ void HelpWidget::setCurrentViewer(HelpViewer *viewer)
m_backAction->setEnabled(viewer->isBackwardAvailable()); m_backAction->setEnabled(viewer->isBackwardAvailable());
m_forwardAction->setEnabled(viewer->isForwardAvailable()); m_forwardAction->setEnabled(viewer->isForwardAvailable());
m_addBookmarkAction->setEnabled(isBookmarkable(viewer->source())); m_addBookmarkAction->setEnabled(isBookmarkable(viewer->source()));
m_openOnlineDocumentationAction->setEnabled(LocalHelpManager::canOpenOnlineHelp(viewer->source()));
if (m_style == ExternalWindow) if (m_style == ExternalWindow)
updateWindowTitle(); updateWindowTitle();
emit sourceChanged(viewer->source()); emit sourceChanged(viewer->source());
@@ -472,6 +478,7 @@ void HelpWidget::addViewer(HelpViewer *viewer)
connect(viewer, &HelpViewer::sourceChanged, this, [viewer, this](const QUrl &url) { connect(viewer, &HelpViewer::sourceChanged, this, [viewer, this](const QUrl &url) {
if (currentViewer() == viewer) { if (currentViewer() == viewer) {
m_addBookmarkAction->setEnabled(isBookmarkable(url)); m_addBookmarkAction->setEnabled(isBookmarkable(url));
m_openOnlineDocumentationAction->setEnabled(LocalHelpManager::canOpenOnlineHelp(url));
emit sourceChanged(url); emit sourceChanged(url);
} }
}); });
@@ -633,6 +640,13 @@ void HelpWidget::addBookmark()
manager->showBookmarkDialog(this, viewer->title(), url); manager->showBookmarkDialog(this, viewer->title(), url);
} }
void HelpWidget::openOnlineDocumentation()
{
HelpViewer *viewer = currentViewer();
QTC_ASSERT(viewer, return);
LocalHelpManager::openOnlineHelp(viewer->source());
}
void HelpWidget::copy() void HelpWidget::copy()
{ {
QTC_ASSERT(currentViewer(), return); QTC_ASSERT(currentViewer(), return);

View File

@@ -99,6 +99,7 @@ private:
void goHome(); void goHome();
void addBookmark(); void addBookmark();
void openOnlineDocumentation();
void copy(); void copy();
void forward(); void forward();
void backward(); void backward();
@@ -120,6 +121,7 @@ private:
QAction *m_backAction = nullptr; QAction *m_backAction = nullptr;
QAction *m_forwardAction = nullptr; QAction *m_forwardAction = nullptr;
QAction *m_addBookmarkAction = nullptr; QAction *m_addBookmarkAction = nullptr;
QAction *m_openOnlineDocumentationAction = nullptr;
QComboBox *m_filterComboBox = nullptr; QComboBox *m_filterComboBox = nullptr;
QAction *m_closeAction = nullptr; QAction *m_closeAction = nullptr;
QAction *m_scaleUp = nullptr; QAction *m_scaleUp = nullptr;

View File

@@ -36,6 +36,7 @@
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QDesktopServices>
#include <QFontDatabase> #include <QFontDatabase>
#include <QMutexLocker> #include <QMutexLocker>
@@ -445,3 +446,31 @@ void LocalHelpManager::updateFilterModel()
} }
emit m_instance->filterIndexChanged(m_currentFilterIndex); 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;
}

View File

@@ -105,6 +105,9 @@ public:
static void updateFilterModel(); static void updateFilterModel();
static bool canOpenOnlineHelp(const QUrl &url);
static bool openOnlineHelp(const QUrl &url);
signals: signals:
void filterIndexChanged(int index); void filterIndexChanged(int index);
void fallbackFontChanged(const QFont &font); void fallbackFontChanged(const QFont &font);