Commit 85a6ea6c authored by Eike Ziller's avatar Eike Ziller Committed by Eike Ziller

(Help)SideBar fixes

1. Get rid of the need to remember the side bar items, instead use the
IDs for activation.
2. Fix issue with empty side bar that cannot be shown, if settings exist
but contain invalid item IDs.
3. Use actual IDs instead of translated window titles for item IDs. This
requires using a different settings group to avoid issues with 2. when
going back to earlier versions of Qt Creator.

Change-Id: I1a760aa5a019db3231803af1bb72f83db49ba6b0
Reviewed-by: default avatarLeena Miettinen <riitta-leena.miettinen@digia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 3c59cdd0
......@@ -32,6 +32,7 @@
#include "actionmanager/command.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QSettings>
#include <QPointer>
......@@ -294,7 +295,8 @@ void SideBar::readSettings(QSettings *settings, const QString &name)
} else {
insertSideBarWidget(0);
}
} else {
}
if (d->m_widgets.size() == 0) {
foreach (const QString &id, d->m_defaultVisible)
insertSideBarWidget(d->m_widgets.count(), id);
}
......@@ -315,25 +317,12 @@ void SideBar::readSettings(QSettings *settings, const QString &name)
}
}
void SideBar::activateItem(SideBarItem *item)
void SideBar::activateItem(const QString &id)
{
typedef QMap<QString, QPointer<SideBarItem> >::const_iterator Iterator;
QString id;
const Iterator cend = d->m_itemMap.constEnd();
for (Iterator it = d->m_itemMap.constBegin(); it != cend ; ++it) {
if (it.value().data() == item) {
id = it.key();
break;
}
}
if (id.isEmpty())
return;
QTC_ASSERT(d->m_itemMap.contains(id), return);
for (int i = 0; i < d->m_widgets.count(); ++i) {
if (d->m_widgets.at(i)->currentItemId() == id) {
item->widget()->setFocus();
d->m_itemMap.value(id)->widget()->setFocus();
return;
}
}
......@@ -341,7 +330,7 @@ void SideBar::activateItem(SideBarItem *item)
Internal::SideBarWidget *widget = d->m_widgets.first();
widget->setCurrentItem(id);
updateWidgets();
item->widget()->setFocus();
d->m_itemMap.value(id)->widget()->setFocus();
}
void SideBar::setShortcutMap(const QMap<QString, Core::Command*> &shortcutMap)
......
......@@ -98,7 +98,7 @@ public:
QStringList unavailableItemIds() const;
void makeItemAvailable(SideBarItem *item);
void setUnavailableItemIds(const QStringList &itemTitles);
QString idForTitle(const QString &itemId) const;
QString idForTitle(const QString &title) const;
SideBarItem *item(const QString &title);
......@@ -108,7 +108,7 @@ public:
void saveSettings(QSettings *settings, const QString &name);
void readSettings(QSettings *settings, const QString &name);
void closeAllWidgets();
void activateItem(SideBarItem *item);
void activateItem(const QString &id);
void setShortcutMap(const QMap<QString, Core::Command *> &shortcutMap);
QMap<QString, Core::Command *> shortcutMap() const;
......
......@@ -199,8 +199,11 @@ void SideBarWidget::setCurrentIndex(int)
emit currentWidgetChanged();
}
Core::Command *SideBarWidget::command(const QString &id) const
Core::Command *SideBarWidget::command(const QString &title) const
{
const QString id = m_sideBar->idForTitle(title);
if (id.isEmpty())
return 0;
const QMap<QString, Core::Command*> shortcutMap = m_sideBar->shortcutMap();
QMap<QString, Core::Command*>::const_iterator r = shortcutMap.find(id);
if (r != shortcutMap.end())
......
......@@ -61,7 +61,7 @@ public:
void updateAvailableItems();
void removeCurrentItem();
Core::Command *command(const QString &id) const;
Core::Command *command(const QString &title) const;
signals:
void splitMe();
......
......@@ -63,14 +63,18 @@ const char CONTEXT_HELP[] = "Help.Context";
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_ADDBOOKMARK[] = "Help.AddBookmark";
const char HELP_INDEX[] = "Help.Index";
const char HELP_CONTENTS[] = "Help.Contents";
const char HELP_SEARCH[] = "Help.Search";
const char HELP_BOOKMARKS[] = "Help.Bookmarks";
const char HELP_OPENPAGES[] = "Help.OpenPages";
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");
static const char SB_SEARCH[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Search");
} // Constants
} // Help
......
......@@ -96,6 +96,7 @@
using namespace Help::Internal;
static const char kExternalWindowStateKey[] = "Help/ExternalWindowState";
static const char kHelpModeSideBarKey[] = "Help/ModeSideBar";
#define IMAGEPATH ":/help/images/"
......@@ -105,10 +106,6 @@ HelpPlugin::HelpPlugin()
: m_mode(0),
m_centralWidget(0),
m_rightPaneSideBarWidget(0),
m_contentItem(0),
m_indexItem(0),
m_searchItem(0),
m_bookmarkItem(0),
m_sideBar(0),
m_setupNeeded(true),
m_helpManager(0),
......@@ -185,7 +182,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
// Add Contents, Index, and Context menu items
action = new QAction(QIcon::fromTheme(QLatin1String("help-contents")),
tr(Constants::SB_CONTENTS), this);
cmd = ActionManager::registerAction(action, "Help.Contents", globalcontext);
cmd = ActionManager::registerAction(action, Constants::HELP_CONTENTS, globalcontext);
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
connect(action, SIGNAL(triggered()), this, SLOT(activateContents()));
......@@ -263,7 +260,7 @@ void HelpPlugin::extensionsInitialized()
ExtensionSystem::IPlugin::ShutdownFlag HelpPlugin::aboutToShutdown()
{
if (m_sideBar)
m_sideBar->saveSettings(ICore::settings(), QLatin1String("HelpSideBar"));
m_sideBar->saveSettings(ICore::settings(), QLatin1String(kHelpModeSideBarKey));
return SynchronousShutdown;
}
......@@ -291,7 +288,7 @@ void HelpPlugin::setupUi()
IndexWindow *indexWindow = new IndexWindow();
indexWindow->setWindowTitle(tr(Constants::SB_INDEX));
m_indexItem = new SideBarItem(indexWindow, QLatin1String(Constants::SB_INDEX));
auto indexItem = new SideBarItem(indexWindow, QLatin1String(Constants::HELP_INDEX));
connect(indexWindow, &IndexWindow::linkActivated,
m_centralWidget, &HelpWidget::open);
......@@ -299,64 +296,64 @@ void HelpPlugin::setupUi()
m_centralWidget, &HelpWidget::showTopicChooser);
QMap<QString, Command*> shortcutMap;
QAction *action = new QAction(tr("Activate Help Index"), m_splitter);
QAction *action = new QAction(tr("Activate Help Index View"), 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(Constants::SB_INDEX), cmd);
shortcutMap.insert(QLatin1String(Constants::HELP_INDEX), cmd);
ContentWindow *contentWindow = new ContentWindow();
contentWindow->setWindowTitle(tr(Constants::SB_CONTENTS));
m_contentItem = new SideBarItem(contentWindow, QLatin1String(Constants::SB_CONTENTS));
auto contentItem = new SideBarItem(contentWindow, QLatin1String(Constants::HELP_CONTENTS));
connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget,
SLOT(setSource(QUrl)));
action = new QAction(tr("Activate Contents in Help mode"), m_splitter);
cmd = ActionManager::registerAction(action, "Help.ContentsShortcut", modecontext);
action = new QAction(tr("Activate Help Contents View"), m_splitter);
cmd = ActionManager::registerAction(action, Constants::HELP_CONTENTS, modecontext);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Shift+C") : tr("Ctrl+Shift+C")));
connect(action, SIGNAL(triggered()), this, SLOT(activateContents()));
shortcutMap.insert(QLatin1String(Constants::SB_CONTENTS), cmd);
shortcutMap.insert(QLatin1String(Constants::HELP_CONTENTS), cmd);
m_searchItem = new SearchSideBarItem;
connect(m_searchItem, SIGNAL(linkActivated(QUrl)), m_centralWidget,
auto searchItem = new SearchSideBarItem;
connect(searchItem, SIGNAL(linkActivated(QUrl)), m_centralWidget,
SLOT(setSourceFromSearch(QUrl)));
action = new QAction(tr("Activate Search in Help mode"), m_splitter);
cmd = ActionManager::registerAction(action, "Help.SearchShortcut", modecontext);
action = new QAction(tr("Activate Help Search View"), m_splitter);
cmd = ActionManager::registerAction(action, Constants::HELP_SEARCH, modecontext);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+/") : tr("Ctrl+Shift+/")));
connect(action, SIGNAL(triggered()), this, SLOT(activateSearch()));
shortcutMap.insert(m_searchItem->id(), cmd);
shortcutMap.insert(searchItem->id(), cmd);
BookmarkManager *manager = &LocalHelpManager::bookmarkManager();
BookmarkWidget *bookmarkWidget = new BookmarkWidget(manager, 0, false);
bookmarkWidget->setWindowTitle(tr(Constants::SB_BOOKMARKS));
m_bookmarkItem = new SideBarItem(bookmarkWidget, QLatin1String(Constants::SB_BOOKMARKS));
auto bookmarkItem = new SideBarItem(bookmarkWidget, QLatin1String(Constants::HELP_BOOKMARKS));
connect(bookmarkWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
SLOT(setSource(QUrl)));
connect(bookmarkWidget, SIGNAL(createPage(QUrl,bool)), &OpenPagesManager::instance(),
SLOT(createPage(QUrl,bool)));
action = new QAction(tr("Activate Bookmarks in Help mode"), m_splitter);
cmd = ActionManager::registerAction(action, "Help.BookmarkShortcut", modecontext);
action = new QAction(tr("Activate Help Bookmarks View"), m_splitter);
cmd = ActionManager::registerAction(action, Constants::HELP_BOOKMARKS, modecontext);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+B") : tr("Ctrl+Shift+B")));
connect(action, SIGNAL(triggered()), this, SLOT(activateBookmarks()));
shortcutMap.insert(QLatin1String(Constants::SB_BOOKMARKS), cmd);
shortcutMap.insert(QLatin1String(Constants::HELP_BOOKMARKS), cmd);
QWidget *openPagesWidget = OpenPagesManager::instance().openPagesWidget();
openPagesWidget->setWindowTitle(tr(Constants::SB_OPENPAGES));
m_openPagesItem = new SideBarItem(openPagesWidget, QLatin1String(Constants::SB_OPENPAGES));
auto openPagesItem = new SideBarItem(openPagesWidget, QLatin1String(Constants::HELP_OPENPAGES));
action = new QAction(tr("Activate Open Pages in Help mode"), m_splitter);
cmd = ActionManager::registerAction(action, "Help.PagesShortcut", modecontext);
action = new QAction(tr("Activate Open Help Pages View"), m_splitter);
cmd = ActionManager::registerAction(action, Constants::HELP_OPENPAGES, modecontext);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+O") : tr("Ctrl+Shift+O")));
connect(action, SIGNAL(triggered()), this, SLOT(activateOpenPages()));
shortcutMap.insert(QLatin1String(Constants::SB_OPENPAGES), cmd);
shortcutMap.insert(QLatin1String(Constants::HELP_OPENPAGES), cmd);
QList<SideBarItem*> itemList;
itemList << m_contentItem << m_indexItem << m_searchItem << m_bookmarkItem
<< m_openPagesItem;
itemList << contentItem << indexItem << searchItem << bookmarkItem
<< openPagesItem;
m_sideBar = new SideBar(itemList, QList<SideBarItem*>()
<< m_contentItem << m_openPagesItem);
<< contentItem << openPagesItem);
m_sideBar->setCloseWhenEmpty(true);
m_sideBar->setShortcutMap(shortcutMap);
connect(m_sideBar, SIGNAL(sideBarClosed()), this, SLOT(onSideBarVisibilityChanged()));
......@@ -365,7 +362,7 @@ void HelpPlugin::setupUi()
m_splitter->insertWidget(0, m_sideBar);
m_splitter->setStretchFactor(0, 0);
m_splitter->setStretchFactor(1, 1);
m_sideBar->readSettings(ICore::settings(), QLatin1String("HelpSideBar"));
m_sideBar->readSettings(ICore::settings(), QLatin1String(kHelpModeSideBarKey));
m_splitter->setSizes(QList<int>() << m_sideBar->size().width() << 300);
m_toggleSideBarAction = new QAction(QIcon(QLatin1String(Core::Constants::ICON_TOGGLE_SIDEBAR)),
......@@ -691,31 +688,31 @@ void HelpPlugin::showContextHelp()
void HelpPlugin::activateIndex()
{
activateHelpMode();
m_sideBar->activateItem(m_indexItem);
m_sideBar->activateItem(QLatin1String(Constants::HELP_INDEX));
}
void HelpPlugin::activateContents()
{
activateHelpMode();
m_sideBar->activateItem(m_contentItem);
m_sideBar->activateItem(QLatin1String(Constants::HELP_CONTENTS));
}
void HelpPlugin::activateSearch()
{
activateHelpMode();
m_sideBar->activateItem(m_searchItem);
m_sideBar->activateItem(QLatin1String(Constants::HELP_SEARCH));
}
void HelpPlugin::activateOpenPages()
{
activateHelpMode();
m_sideBar->activateItem(m_openPagesItem);
m_sideBar->activateItem(QLatin1String(Constants::HELP_OPENPAGES));
}
void HelpPlugin::activateBookmarks()
{
activateHelpMode();
m_sideBar->activateItem(m_bookmarkItem);
m_sideBar->activateItem(QLatin1String(Constants::HELP_BOOKMARKS));
}
void HelpPlugin::highlightSearchTermsInContextHelp()
......
......@@ -134,12 +134,6 @@ private:
CentralWidget *m_centralWidget;
HelpWidget *m_rightPaneSideBarWidget;
Core::SideBarItem *m_contentItem;
Core::SideBarItem *m_indexItem;
Core::SideBarItem *m_searchItem;
Core::SideBarItem *m_bookmarkItem;
Core::SideBarItem *m_openPagesItem;
DocSettingsPage *m_docSettingsPage;
FilterSettingsPage *m_filterSettingsPage;
GeneralSettingsPage *m_generalSettingsPage;
......
......@@ -60,7 +60,7 @@
#include <QStackedWidget>
#include <QToolButton>
static const char kSideBarSettingsKey[] = "HelpWindowSideBar";
static const char kSideBarSettingsKey[] = "Help/WindowSideBar";
namespace Help {
namespace Internal {
......@@ -179,7 +179,7 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
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 = Core::ActionManager::registerAction(m_addBookmarkAction, Constants::HELP_ADDBOOKMARK, 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));
......@@ -268,7 +268,7 @@ HelpWidget::~HelpWidget()
Core::ActionManager::unregisterAction(m_homeAction, Constants::HELP_HOME);
Core::ActionManager::unregisterAction(m_forwardAction, Constants::HELP_NEXT);
Core::ActionManager::unregisterAction(m_backAction, Constants::HELP_PREVIOUS);
Core::ActionManager::unregisterAction(m_addBookmarkAction, Constants::HELP_BOOKMARK);
Core::ActionManager::unregisterAction(m_addBookmarkAction, Constants::HELP_ADDBOOKMARK);
if (m_scaleUp)
Core::ActionManager::unregisterAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE);
if (m_scaleDown)
......@@ -283,18 +283,18 @@ void HelpWidget::addSideBar()
Core::Command *cmd;
auto indexWindow = new IndexWindow();
auto indexItem = new Core::SideBarItem(indexWindow, QLatin1String(Constants::SB_INDEX));
auto indexItem = new Core::SideBarItem(indexWindow, QLatin1String(Constants::HELP_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);
m_indexAction = new QAction(tr("Activate Help Index View"), 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);
shortcutMap.insert(QLatin1String(Constants::HELP_INDEX), cmd);
QList<Core::SideBarItem *> itemList;
itemList << indexItem;
......@@ -309,8 +309,8 @@ void HelpWidget::addSideBar()
m_sideBarSplitter->setSizes(QList<int>() << 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);
connect(m_indexAction, &QAction::triggered, m_sideBar, [this]() {
m_sideBar->activateItem(QLatin1String(Constants::HELP_INDEX));
});
}
......
......@@ -28,6 +28,7 @@
****************************************************************************/
#include "searchwidget.h"
#include "helpconstants.h"
#include "localhelpmanager.h"
#include "openpagesmanager.h"
......@@ -51,8 +52,6 @@
#include <QTextBrowser>
#include <QToolButton>
static const char SB_SEARCH[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Search");
using namespace Help::Internal;
SearchWidget::SearchWidget()
......@@ -271,9 +270,9 @@ void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
// #pragma mark -- SearchSideBarItem
SearchSideBarItem::SearchSideBarItem()
: SideBarItem(new SearchWidget, QLatin1String(SB_SEARCH))
: SideBarItem(new SearchWidget, QLatin1String(Constants::HELP_SEARCH))
{
widget()->setWindowTitle(tr(SB_SEARCH));
widget()->setWindowTitle(tr(Constants::SB_SEARCH));
connect(widget(), SIGNAL(linkActivated(QUrl)), this, SIGNAL(linkActivated(QUrl)));
}
......
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