From 3c59cdd0319fbf1099f378907aeac514d1d57810 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 1 Oct 2014 17:52:57 +0200 Subject: [PATCH] Add index and filter combo box to external help window Change-Id: Icc815379220c55d9d7dc5d154278ba21ce2e9984 Reviewed-by: Eike Ziller --- .../coreplugin/actionmanager/command.cpp | 23 +- .../coreplugin/actionmanager/command.h | 4 +- src/plugins/coreplugin/coreconstants.h | 3 + src/plugins/coreplugin/mainwindow.cpp | 2 +- src/plugins/coreplugin/navigationwidget.cpp | 4 +- src/plugins/help/centralwidget.cpp | 18 -- src/plugins/help/centralwidget.h | 7 - src/plugins/help/helpconstants.h | 7 + src/plugins/help/helpplugin.cpp | 54 ++-- src/plugins/help/helpplugin.h | 2 +- src/plugins/help/helpwidget.cpp | 268 ++++++++++++------ src/plugins/help/helpwidget.h | 15 + src/plugins/help/localhelpmanager.cpp | 5 + src/plugins/help/localhelpmanager.h | 1 + src/shared/help/indexwindow.cpp | 12 +- src/shared/help/indexwindow.h | 3 + 16 files changed, 276 insertions(+), 152 deletions(-) diff --git a/src/plugins/coreplugin/actionmanager/command.cpp b/src/plugins/coreplugin/actionmanager/command.cpp index 5e35070aa5f..2f9f2b043a9 100644 --- a/src/plugins/coreplugin/actionmanager/command.cpp +++ b/src/plugins/coreplugin/actionmanager/command.cpp @@ -34,11 +34,11 @@ #include -#include -#include - #include #include +#include +#include + /*! \class Core::Command @@ -425,3 +425,20 @@ bool Action::hasAttribute(Command::CommandAttribute attr) const { return (m_attributes & attr); } + + +QToolButton *Command::toolButtonWithAppendedShortcut(QAction *action, Command *cmd) +{ + QToolButton *button = new QToolButton; + button->setDefaultAction(action); + if (cmd) { + action->setToolTip(cmd->stringWithAppendedShortcut(action->text())); + QObject::connect(cmd, &Core::Command::keySequenceChanged, action, [cmd, action]() { + action->setToolTip(cmd->stringWithAppendedShortcut(action->text())); + }); + QObject::connect(action, &QAction::changed, cmd, [cmd, action]() { + action->setToolTip(cmd->stringWithAppendedShortcut(action->text())); + }); + } + return button; +} diff --git a/src/plugins/coreplugin/actionmanager/command.h b/src/plugins/coreplugin/actionmanager/command.h index ab54adb7710..72af5cc3cbe 100644 --- a/src/plugins/coreplugin/actionmanager/command.h +++ b/src/plugins/coreplugin/actionmanager/command.h @@ -37,8 +37,9 @@ QT_BEGIN_NAMESPACE class QAction; -class QShortcut; class QKeySequence; +class QShortcut; +class QToolButton; QT_END_NAMESPACE @@ -87,6 +88,7 @@ public: virtual void setKeySequence(const QKeySequence &key) = 0; virtual QString stringWithAppendedShortcut(const QString &str) const = 0; + static QToolButton *toolButtonWithAppendedShortcut(QAction *action, Command *cmd); virtual bool isScriptable() const = 0; virtual bool isScriptable(const Context &) const = 0; diff --git a/src/plugins/coreplugin/coreconstants.h b/src/plugins/coreplugin/coreconstants.h index a3688a4062d..e3b7aa2853f 100644 --- a/src/plugins/coreplugin/coreconstants.h +++ b/src/plugins/coreplugin/coreconstants.h @@ -101,6 +101,9 @@ const char TOGGLE_SIDEBAR[] = "QtCreator.ToggleSidebar"; const char TOGGLE_MODE_SELECTOR[] = "QtCreator.ToggleModeSelector"; const char TOGGLE_FULLSCREEN[] = "QtCreator.ToggleFullScreen"; +const char TR_SHOW_SIDEBAR[] = QT_TRANSLATE_NOOP("Core", "Show Sidebar"); +const char TR_HIDE_SIDEBAR[] = QT_TRANSLATE_NOOP("Core", "Hide Sidebar"); + const char MINIMIZE_WINDOW[] = "QtCreator.MinimizeWindow"; const char ZOOM_WINDOW[] = "QtCreator.ZoomWindow"; const char CLOSE_WINDOW[] = "QtCreator.CloseWindow"; diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index b369b2ff3ac..a81c0bc990f 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -682,7 +682,7 @@ void MainWindow::registerDefaultActions() // Show Sidebar Action m_toggleSideBarAction = new QAction(QIcon(QLatin1String(Constants::ICON_TOGGLE_SIDEBAR)), - tr("Show Sidebar"), this); + tr(Constants::TR_SHOW_SIDEBAR), this); m_toggleSideBarAction->setCheckable(true); cmd = ActionManager::registerAction(m_toggleSideBarAction, Constants::TOGGLE_SIDEBAR, globalContext); cmd->setAttribute(Command::CA_UpdateText); diff --git a/src/plugins/coreplugin/navigationwidget.cpp b/src/plugins/coreplugin/navigationwidget.cpp index a09d511471a..a06c318f101 100644 --- a/src/plugins/coreplugin/navigationwidget.cpp +++ b/src/plugins/coreplugin/navigationwidget.cpp @@ -220,9 +220,9 @@ void NavigationWidget::updateToggleText() d->m_toggleSideBarAction->setEnabled(haveData && NavigationWidgetPlaceHolder::m_current); if (isShown()) - d->m_toggleSideBarAction->setToolTip(tr("Hide Sidebar")); + d->m_toggleSideBarAction->setToolTip(tr(Constants::TR_HIDE_SIDEBAR)); else - d->m_toggleSideBarAction->setToolTip(tr("Show Sidebar")); + d->m_toggleSideBarAction->setToolTip(tr(Constants::TR_SHOW_SIDEBAR)); } void NavigationWidget::placeHolderChanged(NavigationWidgetPlaceHolder *holder) diff --git a/src/plugins/help/centralwidget.cpp b/src/plugins/help/centralwidget.cpp index fa052a69d85..0fcb2fd3dda 100644 --- a/src/plugins/help/centralwidget.cpp +++ b/src/plugins/help/centralwidget.cpp @@ -31,8 +31,6 @@ #include "helpviewer.h" #include "localhelpmanager.h" -#include "openpagesmanager.h" -#include "topicchooser.h" #include @@ -76,19 +74,3 @@ CentralWidget *CentralWidget::instance() Q_ASSERT(gStaticCentralWidget); return gStaticCentralWidget; } - -void CentralWidget::open(const QUrl &url, bool newPage) -{ - if (newPage) - OpenPagesManager::instance().createPage(url); - else - setSource(url); -} - -void CentralWidget::showTopicChooser(const QMap &links, - const QString &keyword, bool newPage) -{ - TopicChooser tc(this, keyword, links); - if (tc.exec() == QDialog::Accepted) - open(tc.link(), newPage); -} diff --git a/src/plugins/help/centralwidget.h b/src/plugins/help/centralwidget.h index 808175a0c9a..0f99366e707 100644 --- a/src/plugins/help/centralwidget.h +++ b/src/plugins/help/centralwidget.h @@ -49,13 +49,6 @@ public: ~CentralWidget(); static CentralWidget *instance(); - - void open(const QUrl &url, bool newPage = false); - -public slots: - void showTopicChooser(const QMap &links, const QString &key, - bool newPage = false); - }; } // namespace Internal diff --git a/src/plugins/help/helpconstants.h b/src/plugins/help/helpconstants.h index 15343c1c70b..7132fff6d93 100644 --- a/src/plugins/help/helpconstants.h +++ b/src/plugins/help/helpconstants.h @@ -64,6 +64,13 @@ const char HELP_HOME[] = "Help.Home"; const char HELP_PREVIOUS[] = "Help.Previous"; const char HELP_NEXT[] = "Help.Next"; const char HELP_BOOKMARK[] = "Help.AddBookmark"; +const char HELP_INDEX[] = "Help.Index"; + +static const char SB_INDEX[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Index"); +static const char SB_CONTENTS[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Contents"); +static const char SB_BOOKMARKS[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Bookmarks"); + +static const char SB_OPENPAGES[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Open Pages"); } // Constants } // Help diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 429541278b0..06043bb8bd2 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -95,12 +95,6 @@ using namespace Help::Internal; -static const char SB_INDEX[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Index"); -static const char SB_CONTENTS[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Contents"); -static const char SB_BOOKMARKS[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Bookmarks"); - -static const char SB_OPENPAGES[] = "OpenPages"; - static const char kExternalWindowStateKey[] = "Help/ExternalWindowState"; #define IMAGEPATH ":/help/images/" @@ -116,7 +110,7 @@ HelpPlugin::HelpPlugin() m_searchItem(0), m_bookmarkItem(0), m_sideBar(0), - m_firstModeChange(true), + m_setupNeeded(true), m_helpManager(0), m_openPagesManager(0) { @@ -190,12 +184,12 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) // Add Contents, Index, and Context menu items action = new QAction(QIcon::fromTheme(QLatin1String("help-contents")), - tr(SB_CONTENTS), this); + tr(Constants::SB_CONTENTS), this); cmd = ActionManager::registerAction(action, "Help.Contents", globalcontext); ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); connect(action, SIGNAL(triggered()), this, SLOT(activateContents())); - action = new QAction(tr(SB_INDEX), this); + action = new QAction(tr(Constants::SB_INDEX), this); cmd = ActionManager::registerAction(action, "Help.Index", globalcontext); ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); connect(action, SIGNAL(triggered()), this, SLOT(activateIndex())); @@ -296,24 +290,24 @@ void HelpPlugin::setupUi() Context modecontext(Constants::C_MODE_HELP); IndexWindow *indexWindow = new IndexWindow(); - indexWindow->setWindowTitle(tr(SB_INDEX)); - m_indexItem = new SideBarItem(indexWindow, QLatin1String(SB_INDEX)); + indexWindow->setWindowTitle(tr(Constants::SB_INDEX)); + m_indexItem = new SideBarItem(indexWindow, QLatin1String(Constants::SB_INDEX)); connect(indexWindow, &IndexWindow::linkActivated, - m_centralWidget, &CentralWidget::open); + m_centralWidget, &HelpWidget::open); connect(indexWindow, &IndexWindow::linksActivated, - m_centralWidget, &CentralWidget::showTopicChooser); + m_centralWidget, &HelpWidget::showTopicChooser); QMap shortcutMap; - QAction *action = new QAction(tr("Activate Index in Help mode"), m_splitter); - Command *cmd = ActionManager::registerAction(action, "Help.IndexShortcut", modecontext); + QAction *action = new QAction(tr("Activate Help Index"), m_splitter); + Command *cmd = ActionManager::registerAction(action, Constants::HELP_INDEX, modecontext); cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+I") : tr("Ctrl+Shift+I"))); connect(action, SIGNAL(triggered()), this, SLOT(activateIndex())); - shortcutMap.insert(QLatin1String(SB_INDEX), cmd); + shortcutMap.insert(QLatin1String(Constants::SB_INDEX), cmd); ContentWindow *contentWindow = new ContentWindow(); - contentWindow->setWindowTitle(tr(SB_CONTENTS)); - m_contentItem = new SideBarItem(contentWindow, QLatin1String(SB_CONTENTS)); + contentWindow->setWindowTitle(tr(Constants::SB_CONTENTS)); + m_contentItem = new SideBarItem(contentWindow, QLatin1String(Constants::SB_CONTENTS)); connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); @@ -321,7 +315,7 @@ void HelpPlugin::setupUi() cmd = ActionManager::registerAction(action, "Help.ContentsShortcut", modecontext); cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Shift+C") : tr("Ctrl+Shift+C"))); connect(action, SIGNAL(triggered()), this, SLOT(activateContents())); - shortcutMap.insert(QLatin1String(SB_CONTENTS), cmd); + shortcutMap.insert(QLatin1String(Constants::SB_CONTENTS), cmd); m_searchItem = new SearchSideBarItem; connect(m_searchItem, SIGNAL(linkActivated(QUrl)), m_centralWidget, @@ -335,8 +329,8 @@ void HelpPlugin::setupUi() BookmarkManager *manager = &LocalHelpManager::bookmarkManager(); BookmarkWidget *bookmarkWidget = new BookmarkWidget(manager, 0, false); - bookmarkWidget->setWindowTitle(tr(SB_BOOKMARKS)); - m_bookmarkItem = new SideBarItem(bookmarkWidget, QLatin1String(SB_BOOKMARKS)); + bookmarkWidget->setWindowTitle(tr(Constants::SB_BOOKMARKS)); + m_bookmarkItem = new SideBarItem(bookmarkWidget, QLatin1String(Constants::SB_BOOKMARKS)); connect(bookmarkWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); connect(bookmarkWidget, SIGNAL(createPage(QUrl,bool)), &OpenPagesManager::instance(), @@ -346,17 +340,17 @@ void HelpPlugin::setupUi() cmd = ActionManager::registerAction(action, "Help.BookmarkShortcut", modecontext); cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+B") : tr("Ctrl+Shift+B"))); connect(action, SIGNAL(triggered()), this, SLOT(activateBookmarks())); - shortcutMap.insert(QLatin1String(SB_BOOKMARKS), cmd); + shortcutMap.insert(QLatin1String(Constants::SB_BOOKMARKS), cmd); QWidget *openPagesWidget = OpenPagesManager::instance().openPagesWidget(); - openPagesWidget->setWindowTitle(tr("Open Pages")); - m_openPagesItem = new SideBarItem(openPagesWidget, QLatin1String(SB_OPENPAGES)); + openPagesWidget->setWindowTitle(tr(Constants::SB_OPENPAGES)); + m_openPagesItem = new SideBarItem(openPagesWidget, QLatin1String(Constants::SB_OPENPAGES)); action = new QAction(tr("Activate Open Pages in Help mode"), m_splitter); cmd = ActionManager::registerAction(action, "Help.PagesShortcut", modecontext); cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+O") : tr("Ctrl+Shift+O"))); connect(action, SIGNAL(triggered()), this, SLOT(activateOpenPages())); - shortcutMap.insert(QLatin1String(SB_OPENPAGES), cmd); + shortcutMap.insert(QLatin1String(Constants::SB_OPENPAGES), cmd); QList itemList; itemList << m_contentItem << m_indexItem << m_searchItem << m_bookmarkItem @@ -375,7 +369,7 @@ void HelpPlugin::setupUi() m_splitter->setSizes(QList() << m_sideBar->size().width() << 300); m_toggleSideBarAction = new QAction(QIcon(QLatin1String(Core::Constants::ICON_TOGGLE_SIDEBAR)), - tr("Show Sidebar"), this); + tr(Core::Constants::TR_SHOW_SIDEBAR), this); m_toggleSideBarAction->setCheckable(true); m_toggleSideBarAction->setChecked(m_sideBar->isVisibleTo(m_splitter)); connect(m_toggleSideBarAction, SIGNAL(triggered(bool)), this, SLOT(setSideBarVisible(bool))); @@ -458,6 +452,7 @@ HelpViewer *HelpPlugin::externalHelpViewer() { if (m_externalWindow) return m_externalWindow->currentViewer(); + doSetupIfNeeded(); m_externalWindow = createHelpWidget(Core::Context(Constants::C_HELP_EXTERNAL), HelpWidget::ExternalWindow); if (m_externalWindowState.isNull()) { @@ -774,17 +769,18 @@ void HelpPlugin::onSideBarVisibilityChanged() { bool visible = m_sideBar->isVisibleTo(m_splitter); m_toggleSideBarAction->setChecked(visible); - m_toggleSideBarAction->setToolTip(visible ? tr("Hide Sidebar") : tr("Show Sidebar")); + m_toggleSideBarAction->setToolTip(visible ? tr(Core::Constants::TR_HIDE_SIDEBAR) + : tr(Core::Constants::TR_SHOW_SIDEBAR)); } void HelpPlugin::doSetupIfNeeded() { m_helpManager->setupGuiHelpEngine(); - if (m_firstModeChange) { + if (m_setupNeeded) { qApp->processEvents(); setupUi(); resetFilter(); - m_firstModeChange = false; + m_setupNeeded = false; OpenPagesManager::instance().setupInitialPages(); } } diff --git a/src/plugins/help/helpplugin.h b/src/plugins/help/helpplugin.h index 233ca3f0793..a8abe0dfd29 100644 --- a/src/plugins/help/helpplugin.h +++ b/src/plugins/help/helpplugin.h @@ -147,7 +147,7 @@ private: Core::SideBar *m_sideBar; - bool m_firstModeChange; + bool m_setupNeeded; LocalHelpManager *m_helpManager; OpenPagesManager *m_openPagesManager; Core::MiniSplitter *m_splitter; diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp index 089b3f754a5..9e53c3ef81c 100644 --- a/src/plugins/help/helpwidget.cpp +++ b/src/plugins/help/helpwidget.cpp @@ -33,8 +33,10 @@ #include "helpconstants.h" #include "helpplugin.h" #include "helpviewer.h" +#include "indexwindow.h" #include "localhelpmanager.h" #include "openpagesmanager.h" +#include "topicchooser.h" #include #include @@ -42,6 +44,8 @@ #include #include #include +#include +#include #include #include #include @@ -56,19 +60,7 @@ #include #include -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; -} +static const char kSideBarSettingsKey[] = "HelpWindowSideBar"; namespace Help { namespace Internal { @@ -76,79 +68,35 @@ namespace Internal { HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget *parent) : QWidget(parent), m_style(style), + m_toggleSideBarAction(0), m_switchToHelp(0), m_filterComboBox(0), m_closeAction(0), m_scaleUp(0), m_scaleDown(0), m_resetScale(0), - m_printer(0) + m_printer(0), + m_sideBar(0), + m_indexAction(0) { + m_viewerStack = new QStackedWidget; + + auto hLayout = new QHBoxLayout(this); + hLayout->setMargin(0); + hLayout->setSpacing(0); + + m_sideBarSplitter = new Core::MiniSplitter(this); + m_sideBarSplitter->setOpaqueResize(false); + hLayout->addWidget(m_sideBarSplitter); + Utils::StyledBar *toolBar = new Utils::StyledBar(); QHBoxLayout *layout = new QHBoxLayout(toolBar); layout->setSpacing(0); layout->setMargin(0); - Core::Command *cmd; - if (style != ModeWidget) { - 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())); - 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")), - tr("Back"), toolBar); - connect(m_backAction, &QAction::triggered, this, &HelpWidget::backward); - m_backMenu = new QMenu(toolBar); - connect(m_backMenu, SIGNAL(aboutToShow()), this, SLOT(updateBackMenu())); - 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); - connect(m_forwardAction, &QAction::triggered, this, &HelpWidget::forward); - m_forwardMenu = new QMenu(toolBar); - connect(m_forwardMenu, SIGNAL(aboutToShow()), this, SLOT(updateForwardMenu())); - 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)); - - 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)); - - if (style == ModeWidget) { - layout->addWidget(new Utils::StyledSeparator(toolBar)); - layout->addWidget(OpenPagesManager::instance().openPagesComboBox(), 10); - m_filterComboBox = new QComboBox; - m_filterComboBox->setMinimumContentsLength(15); - m_filterComboBox->setModel(LocalHelpManager::filterModel()); - layout->addWidget(m_filterComboBox); - connect(m_filterComboBox, static_cast(&QComboBox::activated), - LocalHelpManager::instance(), &LocalHelpManager::setFilterIndex); - connect(LocalHelpManager::instance(), &LocalHelpManager::filterIndexChanged, - m_filterComboBox, &QComboBox::setCurrentIndex); - } - - layout->addStretch(); - - m_viewerStack = new QStackedWidget; - - QVBoxLayout *vLayout = new QVBoxLayout(this); + auto rightSide = new QWidget(this); + m_sideBarSplitter->insertWidget(1, rightSide); + QVBoxLayout *vLayout = new QVBoxLayout(rightSide); vLayout->setMargin(0); vLayout->setSpacing(0); vLayout->addWidget(toolBar); @@ -160,9 +108,103 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget m_context = new Core::IContext(this); m_context->setContext(context); - m_context->setWidget(m_viewerStack); + m_context->setWidget(m_sideBarSplitter); Core::ICore::addContextObject(m_context); + Core::Command *cmd; + QToolButton *button; + + if (style == ExternalWindow) { + static int windowId = 0; + Core::ICore::registerWindow(this, + Core::Context(Core::Id("Help.Window.").withSuffix(++windowId))); + setAttribute(Qt::WA_DeleteOnClose); + setAttribute(Qt::WA_QuitOnClose, false); // don't prevent Qt Creator from closing + + m_toggleSideBarAction = new QAction(QIcon(QLatin1String(Core::Constants::ICON_TOGGLE_SIDEBAR)), + tr(Core::Constants::TR_SHOW_SIDEBAR), toolBar); + m_toggleSideBarAction->setCheckable(true); + m_toggleSideBarAction->setChecked(false); + cmd = Core::ActionManager::registerAction(m_toggleSideBarAction, + Core::Constants::TOGGLE_SIDEBAR, context); + connect(m_toggleSideBarAction, &QAction::toggled, m_toggleSideBarAction, + [this](bool checked) { + m_toggleSideBarAction->setText(checked ? tr(Core::Constants::TR_HIDE_SIDEBAR) + : tr(Core::Constants::TR_SHOW_SIDEBAR)); + }); + addSideBar(); + connect(m_toggleSideBarAction, &QAction::triggered, m_sideBar, &Core::SideBar::setVisible); + connect(m_sideBar, &Core::SideBar::sideBarClosed, m_toggleSideBarAction, [this]() { + m_toggleSideBarAction->setChecked(false); + }); + layout->addWidget(Core::Command::toolButtonWithAppendedShortcut(m_toggleSideBarAction, cmd)); + } + + if (style != ModeWidget) { + 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())); + layout->addWidget(Core::Command::toolButtonWithAppendedShortcut(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(Core::Command::toolButtonWithAppendedShortcut(m_homeAction, cmd)); + + m_backAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")), + tr("Back"), toolBar); + connect(m_backAction, &QAction::triggered, this, &HelpWidget::backward); + m_backMenu = new QMenu(toolBar); + connect(m_backMenu, SIGNAL(aboutToShow()), this, SLOT(updateBackMenu())); + m_backAction->setMenu(m_backMenu); + cmd = Core::ActionManager::registerAction(m_backAction, Constants::HELP_PREVIOUS, context); + cmd->setDefaultKeySequence(QKeySequence::Back); + button = Core::Command::toolButtonWithAppendedShortcut(m_backAction, cmd); + button->setPopupMode(QToolButton::DelayedPopup); + layout->addWidget(button); + + m_forwardAction = new QAction(QIcon(QLatin1String(":/help/images/next.png")), + tr("Forward"), toolBar); + connect(m_forwardAction, &QAction::triggered, this, &HelpWidget::forward); + m_forwardMenu = new QMenu(toolBar); + connect(m_forwardMenu, SIGNAL(aboutToShow()), this, SLOT(updateForwardMenu())); + m_forwardAction->setMenu(m_forwardMenu); + cmd = Core::ActionManager::registerAction(m_forwardAction, Constants::HELP_NEXT, context); + cmd->setDefaultKeySequence(QKeySequence::Forward); + button = Core::Command::toolButtonWithAppendedShortcut(m_forwardAction, cmd); + button->setPopupMode(QToolButton::DelayedPopup); + layout->addWidget(button); + + 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(Core::Command::toolButtonWithAppendedShortcut(m_addBookmarkAction, cmd)); + + if (style == ModeWidget) { + layout->addWidget(new Utils::StyledSeparator(toolBar)); + layout->addWidget(OpenPagesManager::instance().openPagesComboBox(), 10); + } else { + layout->addWidget(new QLabel(), 10); + } + if (style != SideBarWidget) { + m_filterComboBox = new QComboBox; + m_filterComboBox->setMinimumContentsLength(15); + m_filterComboBox->setModel(LocalHelpManager::filterModel()); + m_filterComboBox->setCurrentIndex(LocalHelpManager::filterIndex()); + layout->addWidget(m_filterComboBox); + connect(m_filterComboBox, static_cast(&QComboBox::activated), + LocalHelpManager::instance(), &LocalHelpManager::setFilterIndex); + connect(LocalHelpManager::instance(), &LocalHelpManager::filterIndexChanged, + m_filterComboBox, &QComboBox::setCurrentIndex); + } + + layout->addStretch(); + m_printAction = new QAction(this); Core::ActionManager::registerAction(m_printAction, Core::Constants::PRINT, context); connect(m_printAction, &QAction::triggered, this, [this]() { print(currentViewer()); }); @@ -194,22 +236,13 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT); } - if (style == ModeWidget) { + if (style != ExternalWindow) { m_closeAction = new QAction(QIcon(QLatin1String(Core::Constants::ICON_BUTTON_CLOSE)), QString(), toolBar); connect(m_closeAction, SIGNAL(triggered()), this, SIGNAL(closeButtonClicked())); - layout->addWidget(toolButton(m_closeAction)); - } else if (style == SideBarWidget) { - m_closeAction = new QAction(QIcon(QLatin1String(Core::Constants::ICON_BUTTON_CLOSE)), - QString(), toolBar); - connect(m_closeAction, SIGNAL(triggered()), this, SIGNAL(closeButtonClicked())); - layout->addWidget(toolButton(m_closeAction)); - } else if (style == ExternalWindow) { - static int windowId = 0; - Core::ICore::registerWindow(this, - Core::Context(Core::Id("Help.Window.").withSuffix(++windowId))); - setAttribute(Qt::WA_DeleteOnClose); - setAttribute(Qt::WA_QuitOnClose, false); // don't prevent Qt Creator from closing + button = new QToolButton; + button->setDefaultAction(m_closeAction); + layout->addWidget(button); } if (style != ModeWidget) { @@ -221,9 +254,15 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget HelpWidget::~HelpWidget() { + if (m_sideBar) { + m_sideBar->saveSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey)); + Core::ActionManager::unregisterAction(m_indexAction, Constants::HELP_INDEX); + } Core::ICore::removeContextObject(m_context); Core::ActionManager::unregisterAction(m_copy, Core::Constants::COPY); Core::ActionManager::unregisterAction(m_printAction, Core::Constants::PRINT); + if (m_toggleSideBarAction) + Core::ActionManager::unregisterAction(m_toggleSideBarAction, Core::Constants::TOGGLE_SIDEBAR); if (m_switchToHelp) Core::ActionManager::unregisterAction(m_switchToHelp, Constants::CONTEXT_HELP); Core::ActionManager::unregisterAction(m_homeAction, Constants::HELP_HOME); @@ -238,6 +277,43 @@ HelpWidget::~HelpWidget() Core::ActionManager::unregisterAction(m_resetScale, TextEditor::Constants::RESET_FONT_SIZE); } +void HelpWidget::addSideBar() +{ + QMap shortcutMap; + Core::Command *cmd; + + auto indexWindow = new IndexWindow(); + auto indexItem = new Core::SideBarItem(indexWindow, QLatin1String(Constants::SB_INDEX)); + indexWindow->setOpenInNewPageActionVisible(false); + indexWindow->setWindowTitle(tr(Constants::SB_INDEX)); + connect(indexWindow, &IndexWindow::linkActivated, + this, &HelpWidget::open); + connect(indexWindow, &IndexWindow::linksActivated, + this, &HelpWidget::showTopicChooser); + m_indexAction = new QAction(tr("Activate Help Index"), this); + cmd = Core::ActionManager::registerAction(m_indexAction, Constants::HELP_INDEX, m_context->context()); + cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+I") + : tr("Ctrl+Shift+I"))); + shortcutMap.insert(QLatin1String(Constants::SB_INDEX), cmd); + + QList itemList; + itemList << indexItem; + m_sideBar = new Core::SideBar(itemList, QList() << indexItem); + m_sideBar->setShortcutMap(shortcutMap); + m_sideBar->setCloseWhenEmpty(true); + m_sideBarSplitter->insertWidget(0, m_sideBar); + m_sideBarSplitter->setStretchFactor(0, 0); + m_sideBarSplitter->setStretchFactor(1, 1); + m_sideBar->setVisible(false); + m_sideBar->readSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey)); + m_sideBarSplitter->setSizes(QList() << m_sideBar->size().width() << 300); + m_toggleSideBarAction->setChecked(m_sideBar->isVisibleTo(this)); + + connect(m_indexAction, &QAction::triggered, m_sideBar, [this, indexItem]() { + m_sideBar->activateItem(indexItem); + }); +} + HelpViewer *HelpWidget::currentViewer() const { return qobject_cast(m_viewerStack->currentWidget()); @@ -319,6 +395,22 @@ HelpViewer *HelpWidget::viewerAt(int index) const return qobject_cast(m_viewerStack->widget(index)); } +void HelpWidget::open(const QUrl &url, bool newPage) +{ + if (newPage) + OpenPagesManager::instance().createPage(url); + else + setSource(url); +} + +void HelpWidget::showTopicChooser(const QMap &links, + const QString &keyword, bool newPage) +{ + TopicChooser tc(this, keyword, links); + if (tc.exec() == QDialog::Accepted) + open(tc.link(), newPage); +} + void HelpWidget::setSource(const QUrl &url) { HelpViewer* viewer = currentViewer(); diff --git a/src/plugins/help/helpwidget.h b/src/plugins/help/helpwidget.h index bd00034881b..d81e9a17ae1 100644 --- a/src/plugins/help/helpwidget.h +++ b/src/plugins/help/helpwidget.h @@ -44,6 +44,11 @@ class QPrinter; class QStackedWidget; QT_END_NAMESPACE +namespace Core { +class MiniSplitter; +class SideBar; +} + namespace Help { namespace Internal { @@ -74,6 +79,10 @@ public: int viewerCount() const; HelpViewer *viewerAt(int index) const; + void open(const QUrl &url, bool newPage = false); + void showTopicChooser(const QMap &links, const QString &key, + bool newPage = false); + public slots: void setSource(const QUrl &url); void setSourceFromSearch(const QUrl &url); @@ -106,9 +115,11 @@ private: void resetScale(); void print(HelpViewer *viewer); void highlightSearchTerms(); + void addSideBar(); Core::IContext *m_context; WidgetStyle m_style; + QAction *m_toggleSideBarAction; QAction *m_switchToHelp; QAction *m_homeAction; QMenu *m_backMenu; @@ -126,6 +137,10 @@ private: QStackedWidget *m_viewerStack; QPrinter *m_printer; + + Core::MiniSplitter *m_sideBarSplitter; + Core::SideBar *m_sideBar; + QAction *m_indexAction; }; } // Internal diff --git a/src/plugins/help/localhelpmanager.cpp b/src/plugins/help/localhelpmanager.cpp index 80b0fcd293b..6bff49b950a 100644 --- a/src/plugins/help/localhelpmanager.cpp +++ b/src/plugins/help/localhelpmanager.cpp @@ -253,6 +253,11 @@ void LocalHelpManager::setFilterIndex(int index) emit m_instance->filterIndexChanged(m_currentFilterIndex); } +int LocalHelpManager::filterIndex() +{ + return m_currentFilterIndex; +} + void LocalHelpManager::updateFilterModel() { const QHelpEngine &engine = helpEngine(); diff --git a/src/plugins/help/localhelpmanager.h b/src/plugins/help/localhelpmanager.h index f1eefe42dd6..1dc88d7149d 100644 --- a/src/plugins/help/localhelpmanager.h +++ b/src/plugins/help/localhelpmanager.h @@ -73,6 +73,7 @@ public: static QAbstractItemModel *filterModel(); static void setFilterIndex(int index); + static int filterIndex(); static void updateFilterModel(); diff --git a/src/shared/help/indexwindow.cpp b/src/shared/help/indexwindow.cpp index 6f5029a927f..bd4fc153cac 100644 --- a/src/shared/help/indexwindow.cpp +++ b/src/shared/help/indexwindow.cpp @@ -57,6 +57,7 @@ using namespace Help::Internal; IndexWindow::IndexWindow() : m_searchLineEdit(0) , m_indexWidget(0) + , m_isOpenInNewPageActionVisible(true) { QVBoxLayout *layout = new QVBoxLayout(this); @@ -110,6 +111,11 @@ IndexWindow::~IndexWindow() { } +void IndexWindow::setOpenInNewPageActionVisible(bool visible) +{ + m_isOpenInNewPageActionVisible = visible; +} + void IndexWindow::filterIndices(const QString &filter) { QModelIndex bestMatch; @@ -154,13 +160,15 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) if (idx.isValid()) { QMenu menu; QAction *curTab = menu.addAction(tr("Open Link")); - QAction *newTab = menu.addAction(tr("Open Link as New Page")); + QAction *newTab = 0; + if (m_isOpenInNewPageActionVisible) + newTab = menu.addAction(tr("Open Link as New Page")); menu.move(m_indexWidget->mapToGlobal(ctxtEvent->pos())); QAction *action = menu.exec(); if (curTab == action) open(idx); - else if (newTab == action) + else if (newTab && newTab == action) open(idx, true/*newPage*/); } } else if (m_indexWidget && obj == m_indexWidget->viewport() diff --git a/src/shared/help/indexwindow.h b/src/shared/help/indexwindow.h index 0be2a52d882..eebd4858143 100644 --- a/src/shared/help/indexwindow.h +++ b/src/shared/help/indexwindow.h @@ -90,6 +90,8 @@ public: IndexWindow(); ~IndexWindow(); + void setOpenInNewPageActionVisible(bool visible); + signals: void linkActivated(const QUrl &link, bool newPage); void linksActivated(const QMap &links, @@ -105,6 +107,7 @@ private: Utils::FancyLineEdit *m_searchLineEdit; Utils::NavigationTreeView *m_indexWidget; IndexFilterModel *m_filteredIndexModel; + bool m_isOpenInNewPageActionVisible; }; } // Internal