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 "bookmarkmanager.h"
|
||||
#include "contentwindow.h"
|
||||
#include "helpconstants.h"
|
||||
#include "helpplugin.h"
|
||||
#include "helpviewer.h"
|
||||
@@ -256,6 +257,7 @@ HelpWidget::~HelpWidget()
|
||||
{
|
||||
if (m_sideBar) {
|
||||
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_bookmarkAction, Constants::HELP_BOOKMARKS);
|
||||
}
|
||||
@@ -283,6 +285,18 @@ void HelpWidget::addSideBar()
|
||||
QMap<QString, Core::Command *> shortcutMap;
|
||||
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 indexItem = new Core::SideBarItem(indexWindow, QLatin1String(Constants::HELP_INDEX));
|
||||
indexWindow->setOpenInNewPageActionVisible(false);
|
||||
@@ -311,14 +325,16 @@ void HelpWidget::addSideBar()
|
||||
shortcutMap.insert(QLatin1String(Constants::HELP_BOOKMARKS), cmd);
|
||||
|
||||
QList<Core::SideBarItem *> itemList;
|
||||
itemList << indexItem << bookmarkItem;
|
||||
m_sideBar = new Core::SideBar(itemList, QList<Core::SideBarItem *>() << indexItem);
|
||||
itemList << contentItem << indexItem << bookmarkItem;
|
||||
m_sideBar = new Core::SideBar(itemList,
|
||||
QList<Core::SideBarItem *>() << contentItem << 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->resize(250, size().height());
|
||||
m_sideBar->readSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey));
|
||||
m_sideBarSplitter->setSizes(QList<int>() << m_sideBar->size().width() << 300);
|
||||
m_toggleSideBarAction->setChecked(m_sideBar->isVisibleTo(this));
|
||||
|
||||
@@ -140,6 +140,7 @@ private:
|
||||
|
||||
Core::MiniSplitter *m_sideBarSplitter;
|
||||
Core::SideBar *m_sideBar;
|
||||
QAction *m_contentsAction;
|
||||
QAction *m_indexAction;
|
||||
QAction *m_bookmarkAction;
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ using namespace Help::Internal;
|
||||
ContentWindow::ContentWindow()
|
||||
: m_contentWidget(0)
|
||||
, m_expandDepth(-2)
|
||||
, m_isOpenInNewPageActionVisible(true)
|
||||
{
|
||||
m_contentModel = (&LocalHelpManager::helpEngine())->contentModel();
|
||||
m_contentWidget = new Utils::NavigationTreeView;
|
||||
@@ -75,6 +76,11 @@ ContentWindow::~ContentWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void ContentWindow::setOpenInNewPageActionVisible(bool visible)
|
||||
{
|
||||
m_isOpenInNewPageActionVisible = visible;
|
||||
}
|
||||
|
||||
void ContentWindow::expandTOC()
|
||||
{
|
||||
if (m_expandDepth > -2) {
|
||||
@@ -94,7 +100,7 @@ void ContentWindow::expandToDepth(int depth)
|
||||
|
||||
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) {
|
||||
QMouseEvent *me = static_cast<QMouseEvent*>(e);
|
||||
QItemSelectionModel *sm = m_contentWidget->selectionModel();
|
||||
@@ -128,16 +134,14 @@ void ContentWindow::showContextMenu(const QPoint &pos)
|
||||
|
||||
QMenu menu;
|
||||
QAction *curTab = menu.addAction(tr("Open Link"));
|
||||
QAction *newTab = menu.addAction(tr("Open Link as New Page"));
|
||||
if (!HelpViewer::canOpenPage(itm->url().path()))
|
||||
newTab->setEnabled(false);
|
||||
QAction *newTab = 0;
|
||||
if (m_isOpenInNewPageActionVisible)
|
||||
newTab = menu.addAction(tr("Open Link as New Page"));
|
||||
|
||||
menu.move(m_contentWidget->mapToGlobal(pos));
|
||||
|
||||
QAction *action = menu.exec();
|
||||
QAction *action = menu.exec(m_contentWidget->mapToGlobal(pos));
|
||||
if (curTab == action)
|
||||
emit linkActivated(itm->url(), false/*newPage*/);
|
||||
else if (newTab == action)
|
||||
else if (newTab && newTab == action)
|
||||
emit linkActivated(itm->url(), true/*newPage*/);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ public:
|
||||
ContentWindow();
|
||||
~ContentWindow();
|
||||
|
||||
void setOpenInNewPageActionVisible(bool visible);
|
||||
|
||||
signals:
|
||||
void linkActivated(const QUrl &link, bool newPage);
|
||||
|
||||
@@ -66,6 +68,7 @@ private:
|
||||
Utils::NavigationTreeView *m_contentWidget;
|
||||
QHelpContentModel *m_contentModel;
|
||||
int m_expandDepth;
|
||||
bool m_isOpenInNewPageActionVisible;
|
||||
};
|
||||
|
||||
#endif // CONTENTWINDOW_H
|
||||
|
||||
Reference in New Issue
Block a user