Commit 3c59cdd0 authored by Eike Ziller's avatar Eike Ziller Committed by Eike Ziller

Add index and filter combo box to external help window

Change-Id: Icc815379220c55d9d7dc5d154278ba21ce2e9984
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 286dd71a
......@@ -34,11 +34,11 @@
#include <utils/hostosinfo.h>
#include <QDebug>
#include <QTextStream>
#include <QAction>
#include <QShortcut>
#include <QToolButton>
#include <QTextStream>
/*!
\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;
}
......@@ -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;
......
......@@ -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";
......
......@@ -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);
......
......@@ -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)
......
......@@ -31,8 +31,6 @@
#include "helpviewer.h"
#include "localhelpmanager.h"
#include "openpagesmanager.h"
#include "topicchooser.h"
#include <utils/qtcassert.h>
......@@ -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<QString, QUrl> &links,
const QString &keyword, bool newPage)
{
TopicChooser tc(this, keyword, links);
if (tc.exec() == QDialog::Accepted)
open(tc.link(), newPage);
}
......@@ -49,13 +49,6 @@ public:
~CentralWidget();
static CentralWidget *instance();
void open(const QUrl &url, bool newPage = false);
public slots:
void showTopicChooser(const QMap<QString, QUrl> &links, const QString &key,
bool newPage = false);
};
} // namespace Internal
......
......@@ -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
......
......@@ -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<QString, Command*> 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<SideBarItem*> itemList;
itemList << m_contentItem << m_indexItem << m_searchItem << m_bookmarkItem
......@@ -375,7 +369,7 @@ void HelpPlugin::setupUi()
m_splitter->setSizes(QList<int>() << 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();
}
}
......
......@@ -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;
......
This diff is collapsed.
......@@ -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<QString, QUrl> &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
......
......@@ -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();
......
......@@ -73,6 +73,7 @@ public:
static QAbstractItemModel *filterModel();
static void setFilterIndex(int index);
static int filterIndex();
static void updateFilterModel();
......
......@@ -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()
......
......@@ -90,6 +90,8 @@ public:
IndexWindow();
~IndexWindow();
void setOpenInNewPageActionVisible(bool visible);
signals:
void linkActivated(const QUrl &link, bool newPage);
void linksActivated(const QMap<QString, QUrl> &links,
......@@ -105,6 +107,7 @@ private:
Utils::FancyLineEdit *m_searchLineEdit;
Utils::NavigationTreeView *m_indexWidget;
IndexFilterModel *m_filteredIndexModel;
bool m_isOpenInNewPageActionVisible;
};
} // Internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment