External Help: Add home and bookmark buttons

Change-Id: Ia2442dfa435e964820ec6a721071fce4d4a04061
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2014-09-24 12:29:23 +02:00
parent 3f546f7bef
commit 85ac965116
4 changed files with 45 additions and 2 deletions

View File

@@ -60,8 +60,10 @@ const char C_HELP_SIDEBAR[] = "Help Sidebar";
const char C_HELP_EXTERNAL[] = "Help.ExternalWindow"; const char C_HELP_EXTERNAL[] = "Help.ExternalWindow";
const char CONTEXT_HELP[] = "Help.Context"; const char CONTEXT_HELP[] = "Help.Context";
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_BOOKMARK[] = "Help.AddBookmark";
} // Constants } // Constants
} // Help } // Help

View File

@@ -206,7 +206,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
// Add Home, Previous and Next actions (used in the toolbar) // Add Home, Previous and Next actions (used in the toolbar)
QAction *action = new QAction(QIcon(QLatin1String(IMAGEPATH "home.png")), QAction *action = new QAction(QIcon(QLatin1String(IMAGEPATH "home.png")),
tr("Home"), this); tr("Home"), this);
cmd = ActionManager::registerAction(action, "Help.Home", globalcontext); cmd = ActionManager::registerAction(action, Constants::HELP_HOME, globalcontext);
connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(home())); connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(home()));
helpButtonLayout->addWidget(toolButton(cmd, action)); helpButtonLayout->addWidget(toolButton(cmd, action));
@@ -234,7 +234,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
action = new QAction(QIcon(QLatin1String(IMAGEPATH "bookmark.png")), action = new QAction(QIcon(QLatin1String(IMAGEPATH "bookmark.png")),
tr("Add Bookmark"), this); tr("Add Bookmark"), this);
cmd = ActionManager::registerAction(action, "Help.AddBookmark", modecontext); cmd = ActionManager::registerAction(action, Constants::HELP_BOOKMARK, modecontext);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+M") : tr("Ctrl+M"))); cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+M") : tr("Ctrl+M")));
connect(action, SIGNAL(triggered()), this, SLOT(addBookmark())); connect(action, SIGNAL(triggered()), this, SLOT(addBookmark()));
helpButtonLayout->addWidget(toolButton(cmd, action)); helpButtonLayout->addWidget(toolButton(cmd, action));

View File

@@ -29,9 +29,11 @@
#include "helpwidget.h" #include "helpwidget.h"
#include "bookmarkmanager.h"
#include "helpconstants.h" #include "helpconstants.h"
#include "helpplugin.h" #include "helpplugin.h"
#include "helpviewer.h" #include "helpviewer.h"
#include "localhelpmanager.h"
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
@@ -81,6 +83,12 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
connect(m_switchToHelp, SIGNAL(triggered()), this, SLOT(helpModeButtonClicked())); connect(m_switchToHelp, SIGNAL(triggered()), this, SLOT(helpModeButtonClicked()));
layout->addWidget(toolButton(m_switchToHelp, cmd)); layout->addWidget(toolButton(m_switchToHelp, cmd));
m_homeAction = new QAction(QIcon(QLatin1String(":/help/images/home.png")),
tr("Home"), this);
cmd = Core::ActionManager::registerAction(m_homeAction, Constants::HELP_HOME, context);
connect(m_homeAction, &QAction::triggered, this, &HelpWidget::goHome);
layout->addWidget(toolButton(m_homeAction, cmd));
m_backAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")), m_backAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
tr("Back"), toolBar); tr("Back"), toolBar);
m_backMenu = new QMenu(toolBar); m_backMenu = new QMenu(toolBar);
@@ -99,6 +107,14 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
cmd->setDefaultKeySequence(QKeySequence::Forward); cmd->setDefaultKeySequence(QKeySequence::Forward);
layout->addWidget(toolButton(m_forwardAction, cmd)); layout->addWidget(toolButton(m_forwardAction, cmd));
m_addBookmarkAction = new QAction(QIcon(QLatin1String(":/help/images/bookmark.png")),
tr("Add Bookmark"), this);
cmd = Core::ActionManager::registerAction(m_addBookmarkAction, Constants::HELP_BOOKMARK, context);
cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+M") : tr("Ctrl+M")));
connect(m_addBookmarkAction, &QAction::triggered, this, &HelpWidget::addBookmark);
layout->addWidget(new Utils::StyledSeparator(toolBar));
layout->addWidget(toolButton(m_addBookmarkAction, cmd));
layout->addStretch(); layout->addStretch();
m_viewer = HelpPlugin::createHelpViewer(qreal(0.0)); m_viewer = HelpPlugin::createHelpViewer(qreal(0.0));
@@ -178,8 +194,10 @@ HelpWidget::~HelpWidget()
Core::ICore::removeContextObject(m_context); Core::ICore::removeContextObject(m_context);
Core::ActionManager::unregisterAction(m_copy, Core::Constants::COPY); Core::ActionManager::unregisterAction(m_copy, Core::Constants::COPY);
Core::ActionManager::unregisterAction(m_switchToHelp, Constants::CONTEXT_HELP); Core::ActionManager::unregisterAction(m_switchToHelp, Constants::CONTEXT_HELP);
Core::ActionManager::unregisterAction(m_homeAction, Constants::HELP_HOME);
Core::ActionManager::unregisterAction(m_forwardAction, Constants::HELP_NEXT); Core::ActionManager::unregisterAction(m_forwardAction, Constants::HELP_NEXT);
Core::ActionManager::unregisterAction(m_backAction, Constants::HELP_PREVIOUS); Core::ActionManager::unregisterAction(m_backAction, Constants::HELP_PREVIOUS);
Core::ActionManager::unregisterAction(m_addBookmarkAction, Constants::HELP_BOOKMARK);
if (m_scaleUp) if (m_scaleUp)
Core::ActionManager::unregisterAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE); Core::ActionManager::unregisterAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE);
if (m_scaleDown) if (m_scaleDown)
@@ -226,5 +244,24 @@ void HelpWidget::helpModeButtonClicked()
close(); close();
} }
void HelpWidget::goHome()
{
if (HelpViewer *viewer = currentViewer())
viewer->home();
}
void HelpWidget::addBookmark()
{
HelpViewer *viewer = currentViewer();
QTC_ASSERT(viewer, return);
const QString &url = viewer->source().toString();
if (url.isEmpty() || url == Help::Constants::AboutBlank)
return;
BookmarkManager *manager = &LocalHelpManager::bookmarkManager();
manager->showBookmarkDialog(this, viewer->title(), url);
}
} // Internal } // Internal
} // Help } // Help

View File

@@ -72,14 +72,18 @@ private slots:
void updateForwardMenu(); void updateForwardMenu();
void updateWindowTitle(); void updateWindowTitle();
void helpModeButtonClicked(); void helpModeButtonClicked();
void goHome();
void addBookmark();
private: private:
Core::IContext *m_context; Core::IContext *m_context;
QAction *m_switchToHelp; QAction *m_switchToHelp;
QAction *m_homeAction;
QMenu *m_backMenu; QMenu *m_backMenu;
QMenu *m_forwardMenu; QMenu *m_forwardMenu;
QAction *m_backAction; QAction *m_backAction;
QAction *m_forwardAction; QAction *m_forwardAction;
QAction *m_addBookmarkAction;
QAction *m_scaleUp; QAction *m_scaleUp;
QAction *m_scaleDown; QAction *m_scaleDown;
QAction *m_resetScale; QAction *m_resetScale;