diff --git a/src/plugins/help/centralwidget.cpp b/src/plugins/help/centralwidget.cpp index 0080f062b85faf752ebe8c21e37be6c060e1868c..67dbc09c6528f002e9ebd2328a021f8eeec59430 100644 --- a/src/plugins/help/centralwidget.cpp +++ b/src/plugins/help/centralwidget.cpp @@ -209,7 +209,9 @@ void CentralWidget::closeTab(int index) if (!viewer || tabWidget->count() == 1) return; + emit viewerAboutToBeRemoved(index); tabWidget->removeTab(index); + emit viewerRemoved(index); QTimer::singleShot(0, viewer, SLOT(deleteLater())); } @@ -484,6 +486,13 @@ HelpViewer *CentralWidget::helpViewerAtIndex(int index) const return qobject_cast<HelpViewer*>(tabWidget->widget(index)); } +int CentralWidget::indexOf(HelpViewer *viewer) const +{ + if (!viewer) + return -1; + return tabWidget->indexOf(viewer); +} + HelpViewer *CentralWidget::currentHelpViewer() const { return qobject_cast<HelpViewer*>(tabWidget->currentWidget()); @@ -529,7 +538,7 @@ void CentralWidget::currentPageChanged(int index) tabWidget->setTabsClosable(tabWidget->count() > 1); tabWidget->cornerWidget(Qt::TopLeftCorner)->setEnabled(true); - emit currentViewerChanged(); + emit currentViewerChanged(index); } void CentralWidget::showTabBarContextMenu(const QPoint &point) @@ -711,6 +720,11 @@ void CentralWidget::copy() viewer->copy(); } +void CentralWidget::activateTab(int index) +{ + tabWidget->setCurrentIndex(index); +} + QString CentralWidget::quoteTabTitle(const QString &title) const { QString s = title; diff --git a/src/plugins/help/centralwidget.h b/src/plugins/help/centralwidget.h index 001118abc814df62860e171094f3ca8508dca286..78f92318fee4e7f74bedb65d69494578fad53874 100644 --- a/src/plugins/help/centralwidget.h +++ b/src/plugins/help/centralwidget.h @@ -77,6 +77,7 @@ public: bool find(const QString &txt, QTextDocument::FindFlags findFlags, bool incremental); void setLastShownPages(); HelpViewer *helpViewerAtIndex(int index) const; + int indexOf(HelpViewer *viewer) const; static CentralWidget *instance(); @@ -99,12 +100,13 @@ public slots: void showTopicChooser(const QMap<QString, QUrl> &links, const QString &keyword); void copy(); + void activateTab(int index); protected: void focusInEvent(QFocusEvent *event); signals: - void currentViewerChanged(); + void currentViewerChanged(int index); void copyAvailable(bool yes); void sourceChanged(const QUrl &url); void highlighted(const QString &link); @@ -112,6 +114,9 @@ signals: void backwardAvailable(bool available); void addNewBookmark(const QString &title, const QString &url); + void viewerAboutToBeRemoved(int index); + void viewerRemoved(int index); + private slots: void newTab(); void closeTab(); diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 367aead0f35e72a0e6510ad96ce5851ecbe36ce0..8960f2022844550466d624d96348e425a7ca518d 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -522,7 +522,7 @@ void HelpPlugin::createRightPaneSideBar() this)); connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this, SLOT(updateSideBarSource(QUrl))); - connect(m_centralWidget, SIGNAL(currentViewerChanged()), this, + connect(m_centralWidget, SIGNAL(currentViewerChanged(int)), this, SLOT(updateSideBarSource())); QAction *copyActionSideBar = new QAction(this); @@ -693,6 +693,13 @@ void HelpPlugin::extensionsInitialized() "index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR)); } m_helpEngine->setCustomValue(QLatin1String("DefaultHomePage"), url.toString()); + + connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this, + SLOT(rebuildViewerComboBox())); + connect(m_centralWidget, SIGNAL(currentViewerChanged(int)), this, + SLOT(updateViewerComboBoxIndex(int))); + connect(m_centralWidget, SIGNAL(viewerAboutToBeRemoved(int)), this, + SLOT(removeViewerFromComboBox(int))); } void HelpPlugin::shutdown() @@ -756,6 +763,31 @@ void HelpPlugin::fontChanged() #endif } +void HelpPlugin::rebuildViewerComboBox() +{ + m_documentsCombo->clear(); + + int i = 0; + while (HelpViewer *viewer = m_centralWidget->helpViewerAtIndex(i++)) + m_documentsCombo->addItem(viewer->documentTitle()); + + int index = m_centralWidget->indexOf(m_centralWidget->currentHelpViewer()); + if (index >= 0) + m_documentsCombo->setCurrentIndex(index); +} + +void HelpPlugin::removeViewerFromComboBox(int index) +{ + if (index >= 0) + m_documentsCombo->removeItem(index); +} + +void HelpPlugin::updateViewerComboBoxIndex(int index) +{ + if (index >= 0) + m_documentsCombo->setCurrentIndex(index); +} + HelpViewer* HelpPlugin::viewerForContextMode() { HelpViewer *viewer = 0; @@ -873,16 +905,25 @@ QToolBar *HelpPlugin::createToolBar() toolWidget->addSeparator(); QWidget *w = new QWidget; + toolWidget->addWidget(w); + QHBoxLayout *layout = new QHBoxLayout(w); layout->setMargin(0); layout->addSpacing(10); + m_documentsCombo = new QComboBox; + m_documentsCombo->setMinimumContentsLength(40); + layout->addWidget(m_documentsCombo); + + connect(m_documentsCombo, SIGNAL(activated(int)), m_centralWidget, + SLOT(activateTab(int))); + layout->addWidget(new QLabel(tr("Filtered by:"))); m_filterComboBox = new QComboBox; m_filterComboBox->setMinimumContentsLength(20); + layout->addWidget(m_filterComboBox); + connect(m_filterComboBox, SIGNAL(activated(QString)), this, SLOT(filterDocumentation(QString))); - layout->addWidget(m_filterComboBox); - toolWidget->addWidget(w); return toolWidget; } diff --git a/src/plugins/help/helpplugin.h b/src/plugins/help/helpplugin.h index 32a7d7428a164521fced112f7bd37eeab4e678b3..f679b483941a8af2a4a4a9c3a73e084d06a65aab 100644 --- a/src/plugins/help/helpplugin.h +++ b/src/plugins/help/helpplugin.h @@ -143,6 +143,10 @@ private slots: void fontChanged(); + void rebuildViewerComboBox(); + void removeViewerFromComboBox(int index); + void updateViewerComboBoxIndex(int index); + private: QToolBar *createToolBar(); void createRightPaneSideBar(); @@ -170,6 +174,7 @@ private: DocSettingsPage *m_docSettingsPage; FilterSettingsPage *m_filterSettingsPage; + QComboBox *m_documentsCombo; QComboBox *m_filterComboBox; Core::SideBar *m_sideBar; QWidget *m_rightPaneSideBar;