Commit d66369e2 authored by hjk's avatar hjk
Browse files

Core/Help: Clean up HelpManager interface and users



Change-Id: Ia6edf583f2a002d7c6f4878df670a78614ea087d
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 975e1be2
......@@ -114,7 +114,7 @@ void CorePlugin::extensionsInitialized()
bool CorePlugin::delayedInitialize()
{
HelpManager::instance()->setupHelpManager();
HelpManager::setupHelpManager();
return true;
}
......
......@@ -99,7 +99,7 @@ HelpManager::~HelpManager()
delete d;
}
HelpManager *HelpManager::instance()
QObject *HelpManager::instance()
{
Q_ASSERT(m_instance);
return m_instance;
......@@ -145,7 +145,7 @@ void HelpManager::registerDocumentation(const QStringList &files)
}
}
if (docsChanged)
emit documentationChanged();
emit m_instance->documentationChanged();
}
void HelpManager::unregisterDocumentation(const QStringList &nameSpaces)
......@@ -166,7 +166,7 @@ void HelpManager::unregisterDocumentation(const QStringList &nameSpaces)
}
}
if (docsChanged)
emit documentationChanged();
emit m_instance->documentationChanged();
}
static QUrl buildQUrl(const QString &ns, const QString &folder,
......@@ -181,7 +181,7 @@ static QUrl buildQUrl(const QString &ns, const QString &folder,
}
// This should go into Qt 4.8 once we start using it for Qt Creator
QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key) const
QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key)
{
QMap<QString, QUrl> links;
if (d->m_needsSetup)
......@@ -214,7 +214,7 @@ QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key) const
return links;
}
QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id) const
QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id)
{
if (d->m_needsSetup)
return QMap<QString, QUrl>();
......@@ -223,7 +223,7 @@ QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id) const
// This should go into Qt 4.8 once we start using it for Qt Creator
QStringList HelpManager::findKeywords(const QString &key, Qt::CaseSensitivity caseSensitivity,
int maxHits) const
int maxHits)
{
if (d->m_needsSetup)
return QStringList();
......@@ -267,14 +267,14 @@ QStringList HelpManager::findKeywords(const QString &key, Qt::CaseSensitivity ca
return keywordsSorted + keywords.toList();
}
QUrl HelpManager::findFile(const QUrl &url) const
QUrl HelpManager::findFile(const QUrl &url)
{
if (d->m_needsSetup)
return QUrl();
return d->m_helpEngine->findFile(url);
}
QByteArray HelpManager::fileData(const QUrl &url) const
QByteArray HelpManager::fileData(const QUrl &url)
{
if (d->m_needsSetup)
return QByteArray();
......@@ -283,24 +283,24 @@ QByteArray HelpManager::fileData(const QUrl &url) const
void HelpManager::handleHelpRequest(const QString &url)
{
emit helpRequested(QUrl(url));
emit m_instance->helpRequested(QUrl(url));
}
QStringList HelpManager::registeredNamespaces() const
QStringList HelpManager::registeredNamespaces()
{
if (d->m_needsSetup)
return QStringList();
return d->m_helpEngine->registeredDocumentations();
}
QString HelpManager::namespaceFromFile(const QString &file) const
QString HelpManager::namespaceFromFile(const QString &file)
{
if (d->m_needsSetup)
return QString();
return d->m_helpEngine->namespaceName(file);
}
QString HelpManager::fileFromNamespace(const QString &nameSpace) const
QString HelpManager::fileFromNamespace(const QString &nameSpace)
{
if (d->m_needsSetup)
return QString();
......@@ -314,17 +314,17 @@ void HelpManager::setCustomValue(const QString &key, const QVariant &value)
return;
}
if (d->m_helpEngine->setCustomValue(key, value))
emit collectionFileChanged();
emit m_instance->collectionFileChanged();
}
QVariant HelpManager::customValue(const QString &key, const QVariant &value) const
QVariant HelpManager::customValue(const QString &key, const QVariant &value)
{
if (d->m_needsSetup)
return QVariant();
return d->m_helpEngine->customValue(key, value);
}
HelpManager::Filters HelpManager::filters() const
HelpManager::Filters HelpManager::filters()
{
if (d->m_needsSetup)
return Filters();
......@@ -336,7 +336,7 @@ HelpManager::Filters HelpManager::filters() const
return filters;
}
HelpManager::Filters HelpManager::fixedFilters() const
HelpManager::Filters HelpManager::fixedFilters()
{
Filters fixedFilters;
if (d->m_needsSetup)
......@@ -365,7 +365,7 @@ HelpManager::Filters HelpManager::fixedFilters() const
return fixedFilters;
}
HelpManager::Filters HelpManager::userDefinedFilters() const
HelpManager::Filters HelpManager::userDefinedFilters()
{
if (d->m_needsSetup)
return Filters();
......@@ -383,7 +383,7 @@ void HelpManager::removeUserDefinedFilter(const QString &filter)
return;
if (d->m_helpEngine->removeCustomFilter(filter))
emit collectionFileChanged();
emit m_instance->collectionFileChanged();
}
void HelpManager::addUserDefinedFilter(const QString &filter, const QStringList &attr)
......@@ -392,7 +392,7 @@ void HelpManager::addUserDefinedFilter(const QString &filter, const QStringList
return;
if (d->m_helpEngine->addCustomFilter(filter, attr))
emit collectionFileChanged();
emit m_instance->collectionFileChanged();
}
// -- private slots
......@@ -403,7 +403,7 @@ void HelpManager::setupHelpManager()
return;
d->m_needsSetup = false;
d->m_helpEngine = new QHelpEngineCore(collectionFilePath(), this);
d->m_helpEngine = new QHelpEngineCore(collectionFilePath(), m_instance);
d->m_helpEngine->setAutoSaveFilter(false);
d->m_helpEngine->setCurrentFilter(tr("Unfiltered"));
d->m_helpEngine->setupData();
......@@ -425,7 +425,7 @@ void HelpManager::setupHelpManager()
for (it = d->m_customValues.constBegin(); it != d->m_customValues.constEnd(); ++it)
setCustomValue(it.key(), it.value());
emit setupFinished();
emit m_instance->setupFinished();
}
// -- private
......
......@@ -55,37 +55,37 @@ class CORE_EXPORT HelpManager : public QObject
public:
typedef QHash<QString, QStringList> Filters;
static HelpManager* instance();
static QObject *instance();
static QString collectionFilePath();
void registerDocumentation(const QStringList &fileNames);
void unregisterDocumentation(const QStringList &nameSpaces);
static void registerDocumentation(const QStringList &fileNames);
static void unregisterDocumentation(const QStringList &nameSpaces);
QMap<QString, QUrl> linksForKeyword(const QString &key) const;
QMap<QString, QUrl> linksForIdentifier(const QString &id) const;
QStringList findKeywords(const QString &key,
static QMap<QString, QUrl> linksForKeyword(const QString &key);
static QMap<QString, QUrl> linksForIdentifier(const QString &id);
static QStringList findKeywords(const QString &key,
Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive,
int maxHits = INT_MAX) const;
int maxHits = INT_MAX);
QUrl findFile(const QUrl &url) const;
QByteArray fileData(const QUrl &url) const;
static QUrl findFile(const QUrl &url);
static QByteArray fileData(const QUrl &url);
QStringList registeredNamespaces() const;
QString namespaceFromFile(const QString &file) const;
QString fileFromNamespace(const QString &nameSpace) const;
static QStringList registeredNamespaces();
static QString namespaceFromFile(const QString &file);
static QString fileFromNamespace(const QString &nameSpace);
void setCustomValue(const QString &key, const QVariant &value);
QVariant customValue(const QString &key, const QVariant &value = QVariant()) const;
static void setCustomValue(const QString &key, const QVariant &value);
static QVariant customValue(const QString &key, const QVariant &value = QVariant());
Filters filters() const;
Filters fixedFilters() const;
static Filters filters();
static Filters fixedFilters();
Filters userDefinedFilters() const;
void removeUserDefinedFilter(const QString &filter);
void addUserDefinedFilter(const QString &filter, const QStringList &attr);
static Filters userDefinedFilters();
static void removeUserDefinedFilter(const QString &filter);
static void addUserDefinedFilter(const QString &filter, const QStringList &attr);
public slots:
void handleHelpRequest(const QString &url);
static void handleHelpRequest(const QString &url);
signals:
void setupFinished();
......@@ -95,10 +95,10 @@ signals:
private:
explicit HelpManager(QObject *parent = 0);
virtual ~HelpManager();
~HelpManager();
void setupHelpManager();
void verifyDocumenation();
static void setupHelpManager();
static void verifyDocumenation();
friend class Core::Internal::CorePlugin; // setupHelpManager
friend class Core::Internal::MainWindow; // constructor/destructor
};
......
......@@ -422,11 +422,6 @@ MimeDatabase *ICore::mimeDatabase()
return m_mainwindow->mimeDatabase();
}
HelpManager *ICore::helpManager()
{
return m_mainwindow->helpManager();
}
QSettings *ICore::settings(QSettings::Scope scope)
{
return m_mainwindow->settings(scope);
......
......@@ -53,7 +53,6 @@ class ActionManager;
class Context;
class EditorManager;
class DocumentManager;
class HelpManager;
class IContext;
class MessageManager;
class MimeDatabase;
......@@ -96,7 +95,6 @@ public:
static ProgressManager *progressManager();
static VcsManager *vcsManager();
static MimeDatabase *mimeDatabase();
static HelpManager *helpManager();
static QSettings *settings(QSettings::Scope scope = QSettings::UserScope);
static SettingsDatabase *settingsDatabase();
......
......@@ -79,12 +79,11 @@ void CppHoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
setToolTip(cppElement->tooltip);
QStringList candidates = cppElement->helpIdCandidates;
candidates.removeDuplicates();
HelpManager *hm = HelpManager::instance();
foreach (const QString &helpId, candidates) {
if (helpId.isEmpty())
continue;
const QMap<QString, QUrl> helpLinks = hm->linksForIdentifier(helpId);
const QMap<QString, QUrl> helpLinks = Core::HelpManager::linksForIdentifier(helpId);
if (!helpLinks.isEmpty()) {
setLastHelpItemIdentified(TextEditor::HelpItem(helpId,
cppElement->helpMark,
......
......@@ -479,8 +479,7 @@ void QmlEngine::errorMessageBoxFinished(int result)
break;
}
case QMessageBox::Help: {
Core::HelpManager *helpManager = Core::HelpManager::instance();
helpManager->handleHelpRequest(QLatin1String("qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html"));
Core::HelpManager::handleHelpRequest(QLatin1String("qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html"));
// fall through
}
default:
......
......@@ -38,6 +38,7 @@
#include <QKeyEvent>
#include <QMessageBox>
using namespace Core;
using namespace Help::Internal;
DocSettingsPage::DocSettingsPage()
......@@ -59,11 +60,10 @@ QWidget *DocSettingsPage::createPage(QWidget *parent)
m_ui.docsListWidget->installEventFilter(this);
Core::HelpManager *manager = Core::HelpManager::instance();
const QStringList &nameSpaces = manager->registeredNamespaces();
const QStringList nameSpaces = HelpManager::registeredNamespaces();
foreach (const QString &nameSpace, nameSpaces) {
addItem(nameSpace, manager->fileFromNamespace(nameSpace));
m_filesToRegister.insert(nameSpace, manager->fileFromNamespace(nameSpace));
addItem(nameSpace, HelpManager::fileFromNamespace(nameSpace));
m_filesToRegister.insert(nameSpace, HelpManager::fileFromNamespace(nameSpace));
}
m_filesToUnregister.clear();
......@@ -84,10 +84,9 @@ void DocSettingsPage::addDocumentation()
m_recentDialogPath = QFileInfo(files.first()).canonicalPath();
NameSpaceToPathHash docsUnableToRegister;
Core::HelpManager *manager = Core::HelpManager::instance();
foreach (const QString &file, files) {
const QString filePath = QDir::cleanPath(file);
const QString &nameSpace = manager->namespaceFromFile(filePath);
const QString &nameSpace = HelpManager::namespaceFromFile(filePath);
if (nameSpace.isEmpty()) {
docsUnableToRegister.insertMulti(QLatin1String("UnknownNamespace"),
QDir::toNativeSeparators(filePath));
......@@ -150,10 +149,8 @@ void DocSettingsPage::removeDocumentation()
void DocSettingsPage::apply()
{
Core::HelpManager *manager = Core::HelpManager::instance();
manager->unregisterDocumentation(m_filesToUnregister.keys());
manager->registerDocumentation(m_filesToRegister.values());
HelpManager::unregisterDocumentation(m_filesToUnregister.keys());
HelpManager::registerDocumentation(m_filesToRegister.values());
m_filesToUnregister.clear();
}
......@@ -166,7 +163,7 @@ bool DocSettingsPage::matches(const QString &s) const
bool DocSettingsPage::eventFilter(QObject *object, QEvent *event)
{
if (object != m_ui.docsListWidget)
return Core::IOptionsPage::eventFilter(object, event);
return IOptionsPage::eventFilter(object, event);
if (event->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
......@@ -178,7 +175,7 @@ bool DocSettingsPage::eventFilter(QObject *object, QEvent *event)
}
}
return Core::IOptionsPage::eventFilter(object, event);
return IOptionsPage::eventFilter(object, event);
}
void DocSettingsPage::removeDocumentation(const QList<QListWidgetItem*> items)
......@@ -187,12 +184,11 @@ void DocSettingsPage::removeDocumentation(const QList<QListWidgetItem*> items)
return;
int row = 0;
Core::HelpManager *manager = Core::HelpManager::instance();
foreach (QListWidgetItem* item, items) {
const QString nameSpace = item->text();
m_filesToRegister.remove(nameSpace);
m_filesToUnregister.insertMulti(nameSpace, QDir::cleanPath(manager->fileFromNamespace(nameSpace)));
m_filesToUnregister.insertMulti(nameSpace, QDir::cleanPath(HelpManager::fileFromNamespace(nameSpace)));
row = m_ui.docsListWidget->row(item);
delete m_ui.docsListWidget->takeItem(row);
......
......@@ -40,6 +40,7 @@
#include <QMessageBox>
using namespace Help::Internal;
using namespace Core;
FilterSettingsPage::FilterSettingsPage()
{
......@@ -65,7 +66,7 @@ QWidget *FilterSettingsPage::createPage(QWidget *parent)
connect(m_ui.filterAddButton, SIGNAL(clicked()), this, SLOT(addFilter()));
connect(m_ui.filterRemoveButton, SIGNAL(clicked()), this,
SLOT(removeFilter()));
connect(Core::HelpManager::instance(), SIGNAL(documentationChanged()),
connect(HelpManager::instance(), SIGNAL(documentationChanged()),
this, SLOT(updateFilterPage()));
if (m_searchKeywords.isEmpty()) {
......@@ -84,14 +85,13 @@ void FilterSettingsPage::updateFilterPage()
QString lastTrUnfiltered;
const QString trUnfiltered = tr("Unfiltered");
Core::HelpManager *manager = Core::HelpManager::instance();
if (manager->customValue(Help::Constants::WeAddedFilterKey).toInt() == 1) {
if (HelpManager::customValue(Help::Constants::WeAddedFilterKey).toInt() == 1) {
lastTrUnfiltered =
manager->customValue(Help::Constants::PreviousFilterNameKey).toString();
HelpManager::customValue(Help::Constants::PreviousFilterNameKey).toString();
}
Core::HelpManager::Filters filters = manager->userDefinedFilters();
Core::HelpManager::Filters::const_iterator it;
HelpManager::Filters filters = HelpManager::userDefinedFilters();
HelpManager::Filters::const_iterator it;
for (it = filters.constBegin(); it != filters.constEnd(); ++it) {
const QString &filter = it.key();
if (filter == trUnfiltered || filter == lastTrUnfiltered)
......@@ -104,7 +104,7 @@ void FilterSettingsPage::updateFilterPage()
m_ui.filterWidget->addItems(m_filterMap.keys());
QSet<QString> attributes;
filters = manager->filters();
filters = HelpManager::filters();
for (it = filters.constBegin(); it != filters.constEnd(); ++it)
attributes += it.value().toSet();
......@@ -213,13 +213,12 @@ void FilterSettingsPage::apply()
}
if (changed) {
Core::HelpManager *manager = Core::HelpManager::instance();
foreach (const QString &filter, m_removedFilters)
manager->removeUserDefinedFilter(filter);
HelpManager::removeUserDefinedFilter(filter);
FilterMap::const_iterator it;
for (it = m_filterMap.constBegin(); it != m_filterMap.constEnd(); ++it)
manager->addUserDefinedFilter(it.key(), it.value());
HelpManager::addUserDefinedFilter(it.key(), it.value());
// emit this signal to the help plugin, since we don't want
// to force gui help engine setup if we are not in help mode
......@@ -229,7 +228,7 @@ void FilterSettingsPage::apply()
void FilterSettingsPage::finish()
{
disconnect(Core::HelpManager::instance(), SIGNAL(documentationChanged()),
disconnect(HelpManager::instance(), SIGNAL(documentationChanged()),
this, SLOT(updateFilterPage()));
}
......
......@@ -53,6 +53,7 @@
#include <QWebSettings>
#endif
using namespace Core;
using namespace Help::Internal;
GeneralSettingsPage::GeneralSettingsPage()
......@@ -78,27 +79,25 @@ QWidget *GeneralSettingsPage::createPage(QWidget *parent)
m_ui->sizeComboBox->setEditable(false);
m_ui->styleComboBox->setEditable(false);
Core::HelpManager *manager = Core::HelpManager::instance();
m_font = qvariant_cast<QFont>(manager->customValue(QLatin1String("font"),
m_font));
m_font = qvariant_cast<QFont>(HelpManager::customValue(QLatin1String("font"), m_font));
updateFontSize();
updateFontStyle();
updateFontFamily();
m_homePage = manager->customValue(QLatin1String("HomePage"), QString())
m_homePage = HelpManager::customValue(QLatin1String("HomePage"), QString())
.toString();
if (m_homePage.isEmpty()) {
m_homePage = manager->customValue(QLatin1String("DefaultHomePage"),
m_homePage = HelpManager::customValue(QLatin1String("DefaultHomePage"),
Help::Constants::AboutBlank).toString();
}
m_ui->homePageLineEdit->setText(m_homePage);
m_startOption = manager->customValue(QLatin1String("StartOption"),
m_startOption = HelpManager::customValue(QLatin1String("StartOption"),
Help::Constants::ShowLastPages).toInt();
m_ui->helpStartComboBox->setCurrentIndex(m_startOption);
m_contextOption = manager->customValue(QLatin1String("ContextHelpOption"),
m_contextOption = HelpManager::customValue(QLatin1String("ContextHelpOption"),
Help::Constants::SideBySideIfPossible).toInt();
m_ui->contextHelpComboBox->setCurrentIndex(m_contextOption);
......@@ -120,7 +119,7 @@ QWidget *GeneralSettingsPage::createPage(QWidget *parent)
m_searchKeywords.remove(QLatin1Char('&'));
}
m_returnOnClose = manager->customValue(QLatin1String("ReturnOnClose"),
m_returnOnClose = HelpManager::customValue(QLatin1String("ReturnOnClose"),
false).toBool();
m_ui->m_returnOnClose->setChecked(m_returnOnClose);
......@@ -157,10 +156,9 @@ void GeneralSettingsPage::apply()
if (weight >= 0) // Weight < 0 asserts...
newFont.setWeight(weight);
Core::HelpManager *manager = Core::HelpManager::instance();
if (newFont != m_font) {
m_font = newFont;
manager->setCustomValue(QLatin1String("font"), newFont);
HelpManager::setCustomValue(QLatin1String("font"), newFont);
emit fontChanged();
}
......@@ -170,19 +168,19 @@ void GeneralSettingsPage::apply()
m_ui->homePageLineEdit->setText(homePage);
if (m_homePage != homePage) {
m_homePage = homePage;
manager->setCustomValue(QLatin1String("HomePage"), homePage);
HelpManager::setCustomValue(QLatin1String("HomePage"), homePage);
}
const int startOption = m_ui->helpStartComboBox->currentIndex();
if (m_startOption != startOption) {
m_startOption = startOption;
manager->setCustomValue(QLatin1String("StartOption"), startOption);
HelpManager::setCustomValue(QLatin1String("StartOption"), startOption);
}
const int helpOption = m_ui->contextHelpComboBox->currentIndex();
if (m_contextOption != helpOption) {
m_contextOption = helpOption;
manager->setCustomValue(QLatin1String("ContextHelpOption"), helpOption);
HelpManager::setCustomValue(QLatin1String("ContextHelpOption"), helpOption);
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Help::Constants::ID_MODE_HELP));
......@@ -195,7 +193,7 @@ void GeneralSettingsPage::apply()
const bool close = m_ui->m_returnOnClose->isChecked();
if (m_returnOnClose != close) {
m_returnOnClose = close;
manager->setCustomValue(QLatin1String("ReturnOnClose"), close);
HelpManager::setCustomValue(QLatin1String("ReturnOnClose"), close);
emit returnOnCloseChanged();
}
}
......@@ -214,9 +212,8 @@ void GeneralSettingsPage::setBlankPage()
void GeneralSettingsPage::setDefaultPage()
{
const QString &defaultHomePage = Core::HelpManager::instance()
->customValue(QLatin1String("DefaultHomePage"), QString()).toString();
m_ui->homePageLineEdit->setText(defaultHomePage);
m_ui->homePageLineEdit->setText(
HelpManager::customValue(QLatin1String("DefaultHomePage"), QString()).toString());
}
void GeneralSettingsPage::importBookmarks()
......
......@@ -62,9 +62,9 @@ QList<FilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<Locator::FilterE
{
QStringList keywords;
if (entry.length() < 2)
keywords = Core::HelpManager::instance()->findKeywords(entry, caseSensitivity(entry), 200);
keywords = Core::HelpManager::findKeywords(entry, caseSensitivity(entry), 200);
else
keywords = Core::HelpManager::instance()->findKeywords(entry, caseSensitivity(entry));
keywords = Core::HelpManager::findKeywords(entry, caseSensitivity(entry));
QList<FilterEntry> entries;
foreach (const QString &keyword, keywords) {
......@@ -79,7 +79,7 @@ QList<FilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<Locator::FilterE
void HelpIndexFilter::accept(FilterEntry selection) const
{
const QString &key = selection.displayName;
const QMap<QString, QUrl> &links = Core::HelpManager::instance()->linksForKeyword(key);
const QMap<QString, QUrl> &links = Core::HelpManager::linksForKeyword(key);
if (links.size() == 1) {
emit linkActivated(links.begin().value());
......
This diff is collapsed.
......@@ -49,6 +49,7 @@
#include <coreplugin/helpmanager.h>
#include <coreplugin/modemanager.h>
using namespace Core;
using namespace Help::Internal;
OpenPagesManager *OpenPagesManager::m_instance = 0;
......@@ -235,12 +236,11 @@ void OpenPagesManager::closeCurrentPage()
if (indexes.isEmpty())
return;
Core::HelpManager *manager = Core::HelpManager::instance();
const bool closeOnReturn = manager->customValue(QLatin1String("ReturnOnClose"),
const bool closeOnReturn = HelpManager::customValue(QLatin1String("ReturnOnClose"),
false).toBool();
if (m_model->rowCount() == 1 && closeOnReturn) {