forked from qt-creator/qt-creator
Help: Add tool button to change target for context help
Adds a button in the tool bar for the help widget. If the help widget is currently the target for context help, the button is "checked", and pressing it opens a menu with all the options. If the help widget is currently not the target for context help, the button is "unchecked" and pressing it makes the help widget the target for context help. The menu can in all cases be opened with a long button press. Fixes: QTCREATORBUG-17667 Change-Id: I748e18f36ebde03eaa779557dd09f7a2bc0bcb2d Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -105,6 +105,82 @@ static bool isBookmarkable(const QUrl &url)
|
||||
return !url.isEmpty() && url != QUrl(Help::Constants::AboutBlank);
|
||||
}
|
||||
|
||||
static bool isTargetOfContextHelp(HelpWidget::WidgetStyle style)
|
||||
{
|
||||
const Core::HelpManager::HelpViewerLocation option = LocalHelpManager::contextHelpOption();
|
||||
switch (style) {
|
||||
case HelpWidget::ModeWidget:
|
||||
return option == Core::HelpManager::HelpModeAlways;
|
||||
case HelpWidget::ExternalWindow:
|
||||
return option == Core::HelpManager::ExternalHelpAlways;
|
||||
case HelpWidget::SideBarWidget:
|
||||
return option == Core::HelpManager::SideBySideAlways
|
||||
|| option == Core::HelpManager::SideBySideIfPossible;
|
||||
}
|
||||
QTC_CHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
static QString helpTargetActionText(Core::HelpManager::HelpViewerLocation option)
|
||||
{
|
||||
switch (option) {
|
||||
case Core::HelpManager::SideBySideIfPossible:
|
||||
return HelpWidget::tr("Show Context Help Side-by-Side if Possible");
|
||||
case Core::HelpManager::SideBySideAlways:
|
||||
return HelpWidget::tr("Always Show Context Help Side-by-Side");
|
||||
case Core::HelpManager::HelpModeAlways:
|
||||
return HelpWidget::tr("Always Show Context Help in Help Mode");
|
||||
case Core::HelpManager::ExternalHelpAlways:
|
||||
return HelpWidget::tr("Always Show Context Help in External Window");
|
||||
}
|
||||
QTC_CHECK(false);
|
||||
return {};
|
||||
}
|
||||
|
||||
static Core::HelpManager::HelpViewerLocation optionForStyle(HelpWidget::WidgetStyle style)
|
||||
{
|
||||
switch (style) {
|
||||
case HelpWidget::ModeWidget:
|
||||
return Core::HelpManager::HelpModeAlways;
|
||||
case HelpWidget::ExternalWindow:
|
||||
return Core::HelpManager::ExternalHelpAlways;
|
||||
case HelpWidget::SideBarWidget:
|
||||
return Core::HelpManager::SideBySideIfPossible;
|
||||
}
|
||||
QTC_CHECK(false);
|
||||
return Core::HelpManager::SideBySideIfPossible;
|
||||
}
|
||||
|
||||
static QString helpTargetActionToolTip(HelpWidget::WidgetStyle style)
|
||||
{
|
||||
return helpTargetActionText(optionForStyle(style));
|
||||
}
|
||||
|
||||
static QMenu *createHelpTargetMenu(QWidget *parent)
|
||||
{
|
||||
auto menu = new QMenu(parent);
|
||||
|
||||
const auto addAction = [menu](Core::HelpManager::HelpViewerLocation option) {
|
||||
QAction *action = menu->addAction(helpTargetActionText(option));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(LocalHelpManager::contextHelpOption() == option);
|
||||
QObject::connect(action, &QAction::triggered, menu, [option] {
|
||||
LocalHelpManager::setContextHelpOption(option);
|
||||
});
|
||||
QObject::connect(LocalHelpManager::instance(),
|
||||
&LocalHelpManager::contextHelpOptionChanged,
|
||||
menu,
|
||||
[action, option](Core::HelpManager::HelpViewerLocation newOption) {
|
||||
action->setChecked(newOption == option);
|
||||
});
|
||||
};
|
||||
addAction(Core::HelpManager::SideBySideIfPossible);
|
||||
addAction(Core::HelpManager::SideBySideAlways);
|
||||
addAction(Core::HelpManager::HelpModeAlways);
|
||||
addAction(Core::HelpManager::ExternalHelpAlways);
|
||||
return menu;
|
||||
}
|
||||
|
||||
HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_model(this)
|
||||
@@ -245,7 +321,37 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
|
||||
m_openOnlineDocumentationAction = new QAction(Utils::Icons::ONLINE_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));
|
||||
layout->addWidget(
|
||||
Core::Command::toolButtonWithAppendedShortcut(m_openOnlineDocumentationAction, cmd));
|
||||
|
||||
auto helpTargetAction = new QAction(Utils::Icons::LINK_TOOLBAR.icon(),
|
||||
helpTargetActionToolTip(style),
|
||||
this);
|
||||
helpTargetAction->setCheckable(true);
|
||||
helpTargetAction->setChecked(isTargetOfContextHelp(style));
|
||||
cmd = Core::ActionManager::registerAction(helpTargetAction, "Help.OpenContextHelpHere", context);
|
||||
QToolButton *helpTargetButton = Core::Command::toolButtonWithAppendedShortcut(helpTargetAction,
|
||||
cmd);
|
||||
helpTargetButton->setProperty("noArrow", true);
|
||||
helpTargetButton->setPopupMode(QToolButton::DelayedPopup);
|
||||
helpTargetButton->setMenu(createHelpTargetMenu(helpTargetButton));
|
||||
connect(LocalHelpManager::instance(),
|
||||
&LocalHelpManager::contextHelpOptionChanged,
|
||||
[this, helpTargetAction] {
|
||||
helpTargetAction->setChecked(isTargetOfContextHelp(m_style));
|
||||
});
|
||||
connect(helpTargetAction,
|
||||
&QAction::triggered,
|
||||
this,
|
||||
[this, helpTargetAction, helpTargetButton](bool checked) {
|
||||
if (checked) {
|
||||
LocalHelpManager::setContextHelpOption(optionForStyle(m_style));
|
||||
} else {
|
||||
helpTargetAction->setChecked(true);
|
||||
helpTargetButton->showMenu();
|
||||
}
|
||||
});
|
||||
layout->addWidget(helpTargetButton);
|
||||
|
||||
if (supportsPages()) {
|
||||
layout->addWidget(new Utils::StyledSeparator(toolBar));
|
||||
|
@@ -231,7 +231,10 @@ Core::HelpManager::HelpViewerLocation LocalHelpManager::contextHelpOption()
|
||||
|
||||
void LocalHelpManager::setContextHelpOption(Core::HelpManager::HelpViewerLocation location)
|
||||
{
|
||||
if (location == contextHelpOption())
|
||||
return;
|
||||
Core::ICore::settings()->setValue(kContextHelpOptionKey, location);
|
||||
emit m_instance->contextHelpOptionChanged(location);
|
||||
}
|
||||
|
||||
bool LocalHelpManager::returnOnClose()
|
||||
|
@@ -130,6 +130,7 @@ signals:
|
||||
void fallbackFontChanged(const QFont &font);
|
||||
void returnOnCloseChanged();
|
||||
void scrollWheelZoomingEnabledChanged(bool enabled);
|
||||
void contextHelpOptionChanged(Core::HelpManager::HelpViewerLocation option);
|
||||
|
||||
private:
|
||||
static bool m_guiNeedsSetup;
|
||||
|
Reference in New Issue
Block a user