Commit 3f546f7b authored by Eike Ziller's avatar Eike Ziller

External Help: Make back/forward keyboard shortcuts work

Change-Id: I3e03877df8183f0c0cab4fae35ab41ce92125ccd
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 444fc88d
......@@ -60,6 +60,8 @@ const char C_HELP_SIDEBAR[] = "Help Sidebar";
const char C_HELP_EXTERNAL[] = "Help.ExternalWindow";
const char CONTEXT_HELP[] = "Help.Context";
const char HELP_PREVIOUS[] = "Help.Previous";
const char HELP_NEXT[] = "Help.Next";
} // Constants
} // Help
......
......@@ -212,7 +212,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
QAction *back = new QAction(QIcon(QLatin1String(IMAGEPATH "previous.png")),
tr("Previous Page"), this);
cmd = ActionManager::registerAction(back, "Help.Previous", modecontext);
cmd = ActionManager::registerAction(back, Constants::HELP_PREVIOUS, modecontext);
cmd->setDefaultKeySequence(QKeySequence::Back);
back->setEnabled(m_centralWidget->isBackwardAvailable());
connect(back, SIGNAL(triggered()), m_centralWidget, SLOT(backward()));
......@@ -221,7 +221,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
helpButtonLayout->addWidget(toolButton(cmd, back));
QAction *next = new QAction(QIcon(QLatin1String(IMAGEPATH "next.png")), tr("Next Page"), this);
cmd = ActionManager::registerAction(next, "Help.Next", modecontext);
cmd = ActionManager::registerAction(next, Constants::HELP_NEXT, modecontext);
cmd->setDefaultKeySequence(QKeySequence::Forward);
next->setEnabled(m_centralWidget->isForwardAvailable());
connect(next, SIGNAL(triggered()), m_centralWidget, SLOT(forward()));
......
......@@ -46,11 +46,17 @@
#include <QMenu>
#include <QToolButton>
static QToolButton *toolButton(QAction *action)
static QToolButton *toolButton(QAction *action, Core::Command *cmd = 0)
{
QToolButton *button = new QToolButton;
button->setDefaultAction(action);
button->setPopupMode(QToolButton::DelayedPopup);
if (cmd) {
action->setToolTip(cmd->stringWithAppendedShortcut(action->text()));
QObject::connect(cmd, &Core::Command::keySequenceChanged, action, [cmd, action]() {
action->setToolTip(cmd->stringWithAppendedShortcut(action->text()));
});
}
return button;
}
......@@ -65,29 +71,34 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
m_style(style)
{
Utils::StyledBar *toolBar = new Utils::StyledBar();
QHBoxLayout *layout = new QHBoxLayout(toolBar);
layout->setSpacing(0);
layout->setMargin(0);
Core::Command *cmd;
m_switchToHelp = new QAction(tr("Go to Help Mode"), toolBar);
cmd = Core::ActionManager::registerAction(m_switchToHelp, Constants::CONTEXT_HELP, context);
connect(m_switchToHelp, SIGNAL(triggered()), this, SLOT(helpModeButtonClicked()));
updateHelpModeButtonToolTip();
layout->addWidget(toolButton(m_switchToHelp, cmd));
QAction *back = new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
m_backAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
tr("Back"), toolBar);
m_backMenu = new QMenu(toolBar);
connect(m_backMenu, SIGNAL(aboutToShow()), this, SLOT(updateBackMenu()));
back->setMenu(m_backMenu);
QAction *forward = new QAction(QIcon(QLatin1String(":/help/images/next.png")),
m_backAction->setMenu(m_backMenu);
cmd = Core::ActionManager::registerAction(m_backAction, Constants::HELP_PREVIOUS, context);
cmd->setDefaultKeySequence(QKeySequence::Back);
layout->addWidget(toolButton(m_backAction, cmd));
m_forwardAction = new QAction(QIcon(QLatin1String(":/help/images/next.png")),
tr("Forward"), toolBar);
m_forwardMenu = new QMenu(toolBar);
connect(m_forwardMenu, SIGNAL(aboutToShow()), this, SLOT(updateForwardMenu()));
forward->setMenu(m_forwardMenu);
m_forwardAction->setMenu(m_forwardMenu);
cmd = Core::ActionManager::registerAction(m_forwardAction, Constants::HELP_NEXT, context);
cmd->setDefaultKeySequence(QKeySequence::Forward);
layout->addWidget(toolButton(m_forwardAction, cmd));
QHBoxLayout *layout = new QHBoxLayout(toolBar);
layout->setSpacing(0);
layout->setMargin(0);
layout->addWidget(toolButton(m_switchToHelp));
layout->addWidget(toolButton(back));
layout->addWidget(toolButton(forward));
layout->addStretch();
m_viewer = HelpPlugin::createHelpViewer(qreal(0.0));
......@@ -107,27 +118,20 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
m_context->setWidget(m_viewer);
Core::ICore::addContextObject(m_context);
back->setEnabled(m_viewer->isBackwardAvailable());
connect(back, SIGNAL(triggered()), m_viewer, SLOT(backward()));
connect(m_viewer, SIGNAL(backwardAvailable(bool)), back,
m_backAction->setEnabled(m_viewer->isBackwardAvailable());
connect(m_backAction, SIGNAL(triggered()), m_viewer, SLOT(backward()));
connect(m_viewer, SIGNAL(backwardAvailable(bool)), m_backAction,
SLOT(setEnabled(bool)));
forward->setEnabled(m_viewer->isForwardAvailable());
connect(forward, SIGNAL(triggered()), m_viewer, SLOT(forward()));
connect(m_viewer, SIGNAL(forwardAvailable(bool)), forward,
m_forwardAction->setEnabled(m_viewer->isForwardAvailable());
connect(m_forwardAction, SIGNAL(triggered()), m_viewer, SLOT(forward()));
connect(m_viewer, SIGNAL(forwardAvailable(bool)), m_forwardAction,
SLOT(setEnabled(bool)));
m_copy = new QAction(this);
Core::ActionManager::registerAction(m_copy, Core::Constants::COPY, context);
connect(m_copy, SIGNAL(triggered()), m_viewer, SLOT(copy()));
m_openHelpMode = new QAction(this);
Core::Command *cmd = Core::ActionManager::registerAction(m_openHelpMode,
Help::Constants::CONTEXT_HELP,
context);
connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updateHelpModeButtonToolTip()));
connect(m_openHelpMode, SIGNAL(triggered()), this, SLOT(helpModeButtonClicked()));
Core::ActionContainer *advancedMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED);
QTC_CHECK(advancedMenu);
if (advancedMenu) {
......@@ -173,7 +177,9 @@ HelpWidget::~HelpWidget()
{
Core::ICore::removeContextObject(m_context);
Core::ActionManager::unregisterAction(m_copy, Core::Constants::COPY);
Core::ActionManager::unregisterAction(m_openHelpMode, Help::Constants::CONTEXT_HELP);
Core::ActionManager::unregisterAction(m_switchToHelp, Constants::CONTEXT_HELP);
Core::ActionManager::unregisterAction(m_forwardAction, Constants::HELP_NEXT);
Core::ActionManager::unregisterAction(m_backAction, Constants::HELP_PREVIOUS);
if (m_scaleUp)
Core::ActionManager::unregisterAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE);
if (m_scaleDown)
......@@ -220,12 +226,5 @@ void HelpWidget::helpModeButtonClicked()
close();
}
void HelpWidget::updateHelpModeButtonToolTip()
{
Core::Command *cmd = Core::ActionManager::command(Constants::CONTEXT_HELP);
QTC_ASSERT(cmd, return);
m_switchToHelp->setToolTip(cmd->stringWithAppendedShortcut(m_switchToHelp->text()));
}
} // Internal
} // Help
......@@ -72,14 +72,14 @@ private slots:
void updateForwardMenu();
void updateWindowTitle();
void helpModeButtonClicked();
void updateHelpModeButtonToolTip();
private:
Core::IContext *m_context;
QAction *m_switchToHelp;
QMenu *m_backMenu;
QMenu *m_forwardMenu;
QAction *m_openHelpMode;
QAction *m_backAction;
QAction *m_forwardAction;
QAction *m_scaleUp;
QAction *m_scaleDown;
QAction *m_resetScale;
......
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