forked from qt-creator/qt-creator
Help Window: Add contents view to side bar
Change-Id: Id690c71471ed9a61bd7a926db70e1b1fb9fac8ab Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include "helpwidget.h"
|
#include "helpwidget.h"
|
||||||
|
|
||||||
#include "bookmarkmanager.h"
|
#include "bookmarkmanager.h"
|
||||||
|
#include "contentwindow.h"
|
||||||
#include "helpconstants.h"
|
#include "helpconstants.h"
|
||||||
#include "helpplugin.h"
|
#include "helpplugin.h"
|
||||||
#include "helpviewer.h"
|
#include "helpviewer.h"
|
||||||
@@ -256,6 +257,7 @@ HelpWidget::~HelpWidget()
|
|||||||
{
|
{
|
||||||
if (m_sideBar) {
|
if (m_sideBar) {
|
||||||
m_sideBar->saveSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey));
|
m_sideBar->saveSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey));
|
||||||
|
Core::ActionManager::unregisterAction(m_contentsAction, Constants::HELP_CONTENTS);
|
||||||
Core::ActionManager::unregisterAction(m_indexAction, Constants::HELP_INDEX);
|
Core::ActionManager::unregisterAction(m_indexAction, Constants::HELP_INDEX);
|
||||||
Core::ActionManager::unregisterAction(m_bookmarkAction, Constants::HELP_BOOKMARKS);
|
Core::ActionManager::unregisterAction(m_bookmarkAction, Constants::HELP_BOOKMARKS);
|
||||||
}
|
}
|
||||||
@@ -283,6 +285,18 @@ void HelpWidget::addSideBar()
|
|||||||
QMap<QString, Core::Command *> shortcutMap;
|
QMap<QString, Core::Command *> shortcutMap;
|
||||||
Core::Command *cmd;
|
Core::Command *cmd;
|
||||||
|
|
||||||
|
auto contentWindow = new ContentWindow;
|
||||||
|
auto contentItem = new Core::SideBarItem(contentWindow, QLatin1String(Constants::HELP_CONTENTS));
|
||||||
|
contentWindow->setOpenInNewPageActionVisible(false);
|
||||||
|
contentWindow->setWindowTitle(tr(Constants::SB_CONTENTS));
|
||||||
|
connect(contentWindow, &ContentWindow::linkActivated,
|
||||||
|
this, &HelpWidget::open);
|
||||||
|
m_contentsAction = new QAction(tr("Activate Help Contents View"), this);
|
||||||
|
cmd = Core::ActionManager::registerAction(m_contentsAction, Constants::HELP_CONTENTS, m_context->context());
|
||||||
|
cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Shift+C")
|
||||||
|
: tr("Ctrl+Shift+C")));
|
||||||
|
shortcutMap.insert(QLatin1String(Constants::HELP_CONTENTS), cmd);
|
||||||
|
|
||||||
auto indexWindow = new IndexWindow();
|
auto indexWindow = new IndexWindow();
|
||||||
auto indexItem = new Core::SideBarItem(indexWindow, QLatin1String(Constants::HELP_INDEX));
|
auto indexItem = new Core::SideBarItem(indexWindow, QLatin1String(Constants::HELP_INDEX));
|
||||||
indexWindow->setOpenInNewPageActionVisible(false);
|
indexWindow->setOpenInNewPageActionVisible(false);
|
||||||
@@ -311,14 +325,16 @@ void HelpWidget::addSideBar()
|
|||||||
shortcutMap.insert(QLatin1String(Constants::HELP_BOOKMARKS), cmd);
|
shortcutMap.insert(QLatin1String(Constants::HELP_BOOKMARKS), cmd);
|
||||||
|
|
||||||
QList<Core::SideBarItem *> itemList;
|
QList<Core::SideBarItem *> itemList;
|
||||||
itemList << indexItem << bookmarkItem;
|
itemList << contentItem << indexItem << bookmarkItem;
|
||||||
m_sideBar = new Core::SideBar(itemList, QList<Core::SideBarItem *>() << indexItem);
|
m_sideBar = new Core::SideBar(itemList,
|
||||||
|
QList<Core::SideBarItem *>() << contentItem << indexItem);
|
||||||
m_sideBar->setShortcutMap(shortcutMap);
|
m_sideBar->setShortcutMap(shortcutMap);
|
||||||
m_sideBar->setCloseWhenEmpty(true);
|
m_sideBar->setCloseWhenEmpty(true);
|
||||||
m_sideBarSplitter->insertWidget(0, m_sideBar);
|
m_sideBarSplitter->insertWidget(0, m_sideBar);
|
||||||
m_sideBarSplitter->setStretchFactor(0, 0);
|
m_sideBarSplitter->setStretchFactor(0, 0);
|
||||||
m_sideBarSplitter->setStretchFactor(1, 1);
|
m_sideBarSplitter->setStretchFactor(1, 1);
|
||||||
m_sideBar->setVisible(false);
|
m_sideBar->setVisible(false);
|
||||||
|
m_sideBar->resize(250, size().height());
|
||||||
m_sideBar->readSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey));
|
m_sideBar->readSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey));
|
||||||
m_sideBarSplitter->setSizes(QList<int>() << m_sideBar->size().width() << 300);
|
m_sideBarSplitter->setSizes(QList<int>() << m_sideBar->size().width() << 300);
|
||||||
m_toggleSideBarAction->setChecked(m_sideBar->isVisibleTo(this));
|
m_toggleSideBarAction->setChecked(m_sideBar->isVisibleTo(this));
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ private:
|
|||||||
|
|
||||||
Core::MiniSplitter *m_sideBarSplitter;
|
Core::MiniSplitter *m_sideBarSplitter;
|
||||||
Core::SideBar *m_sideBar;
|
Core::SideBar *m_sideBar;
|
||||||
|
QAction *m_contentsAction;
|
||||||
QAction *m_indexAction;
|
QAction *m_indexAction;
|
||||||
QAction *m_bookmarkAction;
|
QAction *m_bookmarkAction;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ using namespace Help::Internal;
|
|||||||
ContentWindow::ContentWindow()
|
ContentWindow::ContentWindow()
|
||||||
: m_contentWidget(0)
|
: m_contentWidget(0)
|
||||||
, m_expandDepth(-2)
|
, m_expandDepth(-2)
|
||||||
|
, m_isOpenInNewPageActionVisible(true)
|
||||||
{
|
{
|
||||||
m_contentModel = (&LocalHelpManager::helpEngine())->contentModel();
|
m_contentModel = (&LocalHelpManager::helpEngine())->contentModel();
|
||||||
m_contentWidget = new Utils::NavigationTreeView;
|
m_contentWidget = new Utils::NavigationTreeView;
|
||||||
@@ -75,6 +76,11 @@ ContentWindow::~ContentWindow()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContentWindow::setOpenInNewPageActionVisible(bool visible)
|
||||||
|
{
|
||||||
|
m_isOpenInNewPageActionVisible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
void ContentWindow::expandTOC()
|
void ContentWindow::expandTOC()
|
||||||
{
|
{
|
||||||
if (m_expandDepth > -2) {
|
if (m_expandDepth > -2) {
|
||||||
@@ -94,7 +100,7 @@ void ContentWindow::expandToDepth(int depth)
|
|||||||
|
|
||||||
bool ContentWindow::eventFilter(QObject *o, QEvent *e)
|
bool ContentWindow::eventFilter(QObject *o, QEvent *e)
|
||||||
{
|
{
|
||||||
if (m_contentWidget && o == m_contentWidget->viewport()
|
if (m_isOpenInNewPageActionVisible && m_contentWidget && o == m_contentWidget->viewport()
|
||||||
&& e->type() == QEvent::MouseButtonRelease) {
|
&& e->type() == QEvent::MouseButtonRelease) {
|
||||||
QMouseEvent *me = static_cast<QMouseEvent*>(e);
|
QMouseEvent *me = static_cast<QMouseEvent*>(e);
|
||||||
QItemSelectionModel *sm = m_contentWidget->selectionModel();
|
QItemSelectionModel *sm = m_contentWidget->selectionModel();
|
||||||
@@ -128,16 +134,14 @@ void ContentWindow::showContextMenu(const QPoint &pos)
|
|||||||
|
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
QAction *curTab = menu.addAction(tr("Open Link"));
|
QAction *curTab = menu.addAction(tr("Open Link"));
|
||||||
QAction *newTab = menu.addAction(tr("Open Link as New Page"));
|
QAction *newTab = 0;
|
||||||
if (!HelpViewer::canOpenPage(itm->url().path()))
|
if (m_isOpenInNewPageActionVisible)
|
||||||
newTab->setEnabled(false);
|
newTab = menu.addAction(tr("Open Link as New Page"));
|
||||||
|
|
||||||
menu.move(m_contentWidget->mapToGlobal(pos));
|
QAction *action = menu.exec(m_contentWidget->mapToGlobal(pos));
|
||||||
|
|
||||||
QAction *action = menu.exec();
|
|
||||||
if (curTab == action)
|
if (curTab == action)
|
||||||
emit linkActivated(itm->url(), false/*newPage*/);
|
emit linkActivated(itm->url(), false/*newPage*/);
|
||||||
else if (newTab == action)
|
else if (newTab && newTab == action)
|
||||||
emit linkActivated(itm->url(), true/*newPage*/);
|
emit linkActivated(itm->url(), true/*newPage*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ public:
|
|||||||
ContentWindow();
|
ContentWindow();
|
||||||
~ContentWindow();
|
~ContentWindow();
|
||||||
|
|
||||||
|
void setOpenInNewPageActionVisible(bool visible);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void linkActivated(const QUrl &link, bool newPage);
|
void linkActivated(const QUrl &link, bool newPage);
|
||||||
|
|
||||||
@@ -66,6 +68,7 @@ private:
|
|||||||
Utils::NavigationTreeView *m_contentWidget;
|
Utils::NavigationTreeView *m_contentWidget;
|
||||||
QHelpContentModel *m_contentModel;
|
QHelpContentModel *m_contentModel;
|
||||||
int m_expandDepth;
|
int m_expandDepth;
|
||||||
|
bool m_isOpenInNewPageActionVisible;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTENTWINDOW_H
|
#endif // CONTENTWINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user