Commit 1b6ad087 authored by kh1's avatar kh1

Move help manager into core.

 - lessens open file handles
 - improves help plugin startup further

Task-number: QTCREATORBUG-337
Reviewed-by: ck
parent 40b983a9
......@@ -144,6 +144,11 @@ MimeDatabase *CoreImpl::mimeDatabase() const
return m_mainwindow->mimeDatabase();
}
HelpManager *CoreImpl::helpManager() const
{
return m_mainwindow->helpManager();
}
QSettings *CoreImpl::settings(QSettings::Scope scope) const
{
return m_mainwindow->settings(scope);
......
......@@ -67,6 +67,7 @@ public:
VCSManager *vcsManager() const;
ModeManager *modeManager() const;
MimeDatabase *mimeDatabase() const;
HelpManager *helpManager() const;
QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const;
SettingsDatabase *settingsDatabase() const;
......
......@@ -6,6 +6,7 @@ QT += xml \
script \
svg \
sql
CONFIG += help
include(../../qtcreatorplugin.pri)
include(../../libs/utils/utils.pri)
include(../../shared/scriptwrapper/scriptwrapper.pri)
......@@ -86,7 +87,8 @@ SOURCES += mainwindow.cpp \
editortoolbar.cpp \
ssh/ne7sshobject.cpp \
ssh/sshconnection.cpp \
ssh/sshkeygenerator.cpp
ssh/sshkeygenerator.cpp \
helpmanager.cpp
HEADERS += mainwindow.h \
editmode.h \
......@@ -171,7 +173,8 @@ HEADERS += mainwindow.h \
editortoolbar.h \
ssh/ne7sshobject.h \
ssh/sshconnection.h \
ssh/sshkeygenerator.h
ssh/sshkeygenerator.h \
helpmanager.h
FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.ui \
......
This diff is collapsed.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef HELPMANAGER_H
#define HELPMANAGER_H
#include "core_global.h"
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QUrl>
#include <QtCore/QVariant>
QT_FORWARD_DECLARE_CLASS(QHelpEngineCore)
QT_FORWARD_DECLARE_CLASS(QSqlQuery)
namespace Core {
class CORE_EXPORT HelpManager : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(HelpManager)
public:
explicit HelpManager(QObject *parent = 0);
virtual ~HelpManager();
static HelpManager* instance();
static QString collectionFilePath();
void registerDocumentation(const QStringList &fileNames);
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, int maxHits = INT_MAX) const;
QUrl findFile(const QUrl &url) const;
void handleHelpRequest(const QString &url);
QStringList registeredNamespaces() const;
QString namespaceFromFile(const QString &file) const;
QString fileFromNamespace(const QString &nameSpace) const;
signals:
void setupFinished();
void documentationChanged();
void helpRequested(const QUrl &url);
private slots:
void setupHelpManager();
private:
void verifyDocumenation();
private:
bool m_needsSetup;
QHelpEngineCore *m_helpEngine;
QStringList m_filesToRegister;
QStringList m_nameSpacesToUnregister;
static HelpManager *m_instance;
};
} // Core
#endif // HELPMANAGER_H
......@@ -50,6 +50,7 @@ namespace Core {
class ActionManager;
class EditorManager;
class FileManager;
class HelpManager;
class IContext;
class MessageManager;
class MimeDatabase;
......@@ -96,6 +97,7 @@ public:
virtual VCSManager *vcsManager() const = 0;
virtual ModeManager *modeManager() const = 0;
virtual MimeDatabase *mimeDatabase() const = 0;
virtual HelpManager *helpManager() const = 0;
virtual QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const = 0;
virtual SettingsDatabase *settingsDatabase() const = 0;
......
......@@ -37,6 +37,7 @@
#include "fancytabwidget.h"
#include "filemanager.h"
#include "generalsettings.h"
#include "helpmanager.h"
#include "ifilefactory.h"
#include "messagemanager.h"
#include "modemanager.h"
......@@ -132,6 +133,7 @@ MainWindow::MainWindow() :
m_statusBarManager(0),
m_modeManager(0),
m_mimeDatabase(new MimeDatabase),
m_helpManager(new HelpManager),
m_navigationWidget(0),
m_rightPaneWidget(0),
m_versionDialog(0),
......@@ -288,6 +290,9 @@ MainWindow::~MainWindow()
m_modeManager = 0;
delete m_mimeDatabase;
m_mimeDatabase = 0;
delete m_helpManager;
m_helpManager = 0;
}
bool MainWindow::init(QString *errorMessage)
......@@ -1011,6 +1016,11 @@ MimeDatabase *MainWindow::mimeDatabase() const
return m_mimeDatabase;
}
HelpManager *MainWindow::helpManager() const
{
return m_helpManager;
}
IContext *MainWindow::contextObject(QWidget *widget)
{
return m_contextWidgets.value(widget);
......
......@@ -52,6 +52,7 @@ class ActionManager;
class StatusBarWidget;
class EditorManager;
class FileManager;
class HelpManager;
class IContext;
class IWizard;
class MessageManager;
......@@ -107,6 +108,7 @@ public:
Core::VariableManager *variableManager() const;
Core::ModeManager *modeManager() const;
Core::MimeDatabase *mimeDatabase() const;
Core::HelpManager *helpManager() const;
VCSManager *vcsManager() const;
QSettings *settings(QSettings::Scope scope) const;
......@@ -193,6 +195,7 @@ private:
StatusBarManager *m_statusBarManager;
ModeManager *m_modeManager;
MimeDatabase *m_mimeDatabase;
HelpManager *m_helpManager;
FancyTabWidget *m_modeStack;
NavigationWidget *m_navigationWidget;
RightPaneWidget *m_rightPaneWidget;
......
TEMPLATE = lib
TARGET = CppEditor
DEFINES += CPPEDITOR_LIBRARY
CONFIG += help
include(../../qtcreatorplugin.pri)
include(../../libs/utils/utils.pri)
include(../../shared/indenter/indenter.pri)
......
......@@ -32,6 +32,7 @@
#include "cppplugin.h"
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cppmodelmanagerinterface.h>
......@@ -60,7 +61,6 @@
#include <QtGui/QToolTip>
#include <QtGui/QTextCursor>
#include <QtGui/QTextBlock>
#include <QtHelp/QHelpEngineCore>
using namespace CppEditor::Internal;
using namespace CPlusPlus;
......@@ -68,27 +68,11 @@ using namespace Core;
CppHoverHandler::CppHoverHandler(QObject *parent)
: QObject(parent)
, m_helpEngineNeedsSetup(false)
{
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
ICore *core = ICore::instance();
QFileInfo fi(core->settings()->fileName());
// FIXME shouldn't the help engine create the directory if it doesn't exist?
QDir directory(fi.absolutePath()+"/qtcreator");
if (!directory.exists())
directory.mkpath(directory.absolutePath());
m_helpEngine = new QHelpEngineCore(directory.absolutePath()
+ QLatin1String("/helpcollection.qhc"), this);
if (!m_helpEngine->setupData())
qWarning() << "Could not initialize help engine:" << m_helpEngine->error();
m_helpEngine->setAutoSaveFilter(false);
m_helpEngine->setCurrentFilter(tr("Unfiltered"));
m_helpEngineNeedsSetup = m_helpEngine->registeredDocumentations().count() == 0;
// Listen for editor opened events in order to connect to tooltip/helpid requests
connect(core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
connect(ICore::instance()->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
this, SLOT(editorOpened(Core::IEditor *)));
}
......@@ -297,19 +281,13 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
}
}
if (m_helpEngineNeedsSetup
&& m_helpEngine->registeredDocumentations().count() > 0) {
m_helpEngine->setupData();
m_helpEngineNeedsSetup = false;
}
QMap<QString, QUrl> helpLinks;
if (m_toolTip.isEmpty()) {
foreach (const Document::Include &incl, doc->includes()) {
if (incl.line() == lineNumber) {
m_toolTip = QDir::toNativeSeparators(incl.fileName());
m_helpId = QFileInfo(incl.fileName()).fileName();
helpLinks = m_helpEngine->linksForIdentifier(m_helpId);
helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
break;
}
}
......@@ -388,7 +366,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
// To show their help anyway, try stripping scopes until we find something.
const QString startHelpId = m_helpId;
while (!m_helpId.isEmpty()) {
helpLinks = m_helpEngine->linksForIdentifier(m_helpId);
helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
if (!helpLinks.isEmpty())
break;
......
......@@ -33,7 +33,6 @@
#include <QtCore/QObject>
QT_BEGIN_NAMESPACE
class QHelpEngineCore;
class QPoint;
QT_END_NAMESPACE
......@@ -70,10 +69,8 @@ private:
void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos);
CppTools::CppModelManagerInterface *m_modelManager;
QHelpEngineCore *m_helpEngine;
QString m_helpId;
QString m_toolTip;
bool m_helpEngineNeedsSetup;
};
} // namespace Internal
......
......@@ -45,6 +45,7 @@
#include <coreplugin/designmode.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
......@@ -282,14 +283,8 @@ void FormEditorW::fullInit()
m_integration = new QtCreatorIntegration(m_formeditor, this);
m_formeditor->setIntegration(m_integration);
// Connect Qt Designer help request to HelpManager.
// TODO: Use Core::HelpManager once it has been introduced.
foreach(QObject *object, ExtensionSystem::PluginManager::instance()->allObjects()) {
if (!qstrcmp(object->metaObject()->className(), "Help::HelpManager")) {
connect(m_integration, SIGNAL(creatorHelpRequested(QString)),
object, SLOT(handleHelpRequest(QString)));
break;
}
}
connect(m_integration, SIGNAL(creatorHelpRequested(QUrl)),
Core::HelpManager::instance(), SIGNAL(helpRequested(QUrl)));
/**
* This will initialize our TabOrder, Signals and slots and Buddy editors.
......
......@@ -61,6 +61,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
#include <QtCore/QUrl>
enum { indentation = 4 };
......@@ -101,7 +102,8 @@ QtCreatorIntegration::QtCreatorIntegration(QDesignerFormEditorInterface *core, F
void QtCreatorIntegration::slotDesignerHelpRequested(const QString &manual, const QString &document)
{
// Pass on as URL.
emit creatorHelpRequested(QString::fromLatin1("qthelp://com.trolltech.%1/qdoc/%2").arg(manual, document));
emit creatorHelpRequested(QUrl(QString::fromLatin1("qthelp://com.trolltech.%1/qdoc/%2")
.arg(manual, document)));
}
void QtCreatorIntegration::updateSelection()
......
......@@ -34,6 +34,8 @@
#include "qt_private/qdesigner_integration_p.h"
QT_FORWARD_DECLARE_CLASS(QUrl)
namespace Designer {
namespace Internal {
......@@ -49,7 +51,7 @@ public:
bool supportsToSlotNavigation() { return true; }
signals:
void creatorHelpRequested(const QString &url);
void creatorHelpRequested(const QUrl &url);
public slots:
void updateSelection();
......
......@@ -45,7 +45,6 @@
#include <QtGui/QStackedWidget>
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpEngineCore>
#include <QtHelp/QHelpSearchEngine>
using namespace Help::Internal;
......@@ -85,7 +84,7 @@ CentralWidget::~CentralWidget()
}
}
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
QHelpEngineCore *engine = &LocalHelpManager::helpEngine();
engine->setCustomValue(QLatin1String("LastShownPages"), currentPages);
engine->setCustomValue(QLatin1String("LastShownPagesZoom"), zoomFactors);
engine->setCustomValue(QLatin1String("LastTabPage"), currentIndex());
......@@ -314,7 +313,7 @@ void CentralWidget::highlightSearchTerms()
{
if (HelpViewer *viewer = currentHelpViewer()) {
QHelpSearchEngine *searchEngine =
HelpManager::instance().helpEngine().searchEngine();
LocalHelpManager::helpEngine().searchEngine();
QList<QHelpSearchQuery> queryList = searchEngine->query();
QStringList terms;
......
......@@ -29,7 +29,8 @@
#include "docsettingspage.h"
#include "helpconstants.h"
#include "helpmanager.h"
#include <coreplugin/helpmanager.h>
#include <QtCore/QCoreApplication>
......@@ -37,8 +38,6 @@
#include <QtGui/QKeyEvent>
#include <QtGui/QMessageBox>
#include <QtHelp/QHelpEngineCore>
using namespace Help::Internal;
DocSettingsPage::DocSettingsPage()
......@@ -80,10 +79,10 @@ QWidget *DocSettingsPage::createPage(QWidget *parent)
m_ui.docsListWidget->installEventFilter(this);
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
const QStringList &nameSpaces = engine->registeredDocumentations();
Core::HelpManager *manager = Core::HelpManager::instance();
const QStringList &nameSpaces = manager->registeredNamespaces();
foreach (const QString &nameSpace, nameSpaces)
addItem(nameSpace, engine->documentationFileName(nameSpace));
addItem(nameSpace, manager->fileFromNamespace(nameSpace));
m_filesToRegister.clear();
m_filesToUnregister.clear();
......@@ -103,11 +102,11 @@ void DocSettingsPage::addDocumentation()
return;
m_recentDialogPath = QFileInfo(files.first()).canonicalPath();
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
const QStringList &nameSpaces = engine.registeredDocumentations();
Core::HelpManager *manager = Core::HelpManager::instance();
const QStringList &nameSpaces = manager->registeredNamespaces();
foreach (const QString &file, files) {
const QString &nameSpace = engine.namespaceName(file);
const QString &nameSpace = manager->namespaceFromFile(file);
if (nameSpace.isEmpty())
continue;
......@@ -130,14 +129,10 @@ void DocSettingsPage::removeDocumentation()
void DocSettingsPage::apply()
{
HelpManager* manager = &HelpManager::instance();
Core::HelpManager *manager = Core::HelpManager::instance();
manager->unregisterDocumentation(m_filesToUnregister.keys());
manager->registerDocumentation(m_filesToRegister.values());
if (manager->guiEngineNeedsUpdate()) {
// 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
emit documentationChanged();
}
m_filesToRegister.clear();
m_filesToUnregister.clear();
......@@ -172,10 +167,10 @@ void DocSettingsPage::removeDocumentation(const QList<QListWidgetItem*> items)
return;
int row = 0;
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
Core::HelpManager *manager = Core::HelpManager::instance();
foreach (QListWidgetItem* item, items) {
const QString &nameSpace = item->text();
const QString &docPath = engine->documentationFileName(nameSpace);
const QString &docPath = manager->fileFromNamespace(nameSpace);
if (m_filesToRegister.value(nameSpace) != docPath) {
if (!m_filesToUnregister.contains(nameSpace))
......
......@@ -55,9 +55,6 @@ public:
void finish() {}
virtual bool matches(const QString &s) const;
signals:
void documentationChanged();
private slots:
void addDocumentation();
void removeDocumentation();
......
......@@ -33,16 +33,19 @@
#include "helpconstants.h"
#include "helpmanager.h"
#include <coreplugin/helpmanager.h>
#include <QtCore/QCoreApplication>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
#include <QtHelp/QHelpEngineCore>
#include <QtHelp/QHelpEngine>
using namespace Help::Internal;
FilterSettingsPage::FilterSettingsPage()
: m_helpManager(0)
{
}
......@@ -76,6 +79,7 @@ QWidget *FilterSettingsPage::createPage(QWidget *parent)
QWidget *widget = new QWidget(parent);
m_ui.setupUi(widget);
m_helpManager->setupGuiHelpEngine();
updateFilterPage(); // does call setupData on the engine
connect(m_ui.attributeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
......@@ -86,6 +90,8 @@ 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()),
this, SLOT(updateFilterPage()));
if (m_searchKeywords.isEmpty()) {
m_searchKeywords = m_ui.filterGroupBox->title() + QLatin1Char(' ')
......@@ -100,7 +106,7 @@ void FilterSettingsPage::updateFilterPage()
m_ui.attributeWidget->clear();
m_filterMapBackup.clear();
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
const QStringList &filters = engine.customFilters();
foreach (const QString &filter, filters) {
const QStringList &attributes = engine.filterAttributes(filter);
......@@ -210,7 +216,7 @@ void FilterSettingsPage::apply()
}
if (changed) {
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
QHelpEngineCore *engine = &LocalHelpManager::helpEngine();
foreach (const QString &filter, m_removedFilters)
engine->removeCustomFilter(filter);
......@@ -228,3 +234,8 @@ bool FilterSettingsPage::matches(const QString &s) const
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}
void FilterSettingsPage::setHelpManager(LocalHelpManager *manager)
{
m_helpManager = manager;
}
......@@ -36,6 +36,8 @@
namespace Help {
namespace Internal {
class LocalHelpManager;
class FilterSettingsPage : public Core::IOptionsPage
{
Q_OBJECT
......@@ -55,6 +57,8 @@ public:
void finish() {}
virtual bool matches(const QString &s) const;
void setHelpManager(LocalHelpManager *manager);
signals:
void filtersChanged();
......@@ -73,6 +77,8 @@ private:
QString m_searchKeywords;
QStringList m_removedFilters;
LocalHelpManager *m_helpManager;
};
} // namespace Help
......
......@@ -44,7 +44,7 @@
#include <QtGui/QApplication>
#include <QtGui/QFileDialog>
#include <QtHelp/QHelpEngineCore>
#include <QtHelp/QHelpEngine>
#if !defined(QT_NO_WEBKIT)
#include <QtWebKit/QWebSettings>
......@@ -94,7 +94,7 @@ QWidget *GeneralSettingsPage::createPage(QWidget *parent)
m_ui.sizeComboBox->setEditable(false);
m_ui.styleComboBox->setEditable(false);
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
m_font = qVariantValue<QFont>(engine.customValue(QLatin1String("font"), m_font));
updateFontSize();
......@@ -163,7 +163,7 @@ void GeneralSettingsPage::apply()
if (weight >= 0) // Weight < 0 asserts...
newFont.setWeight(weight);
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
QHelpEngineCore *engine = &LocalHelpManager::helpEngine();
engine->setCustomValue(QLatin1String("font"), newFont);
if (newFont != m_font)
......@@ -197,7 +197,7 @@ void GeneralSettingsPage::setBlankPage()
void GeneralSettingsPage::setDefaultPage()
{
const QString &defaultHomePage = HelpManager::helpEngineCore()
const QString &defaultHomePage = LocalHelpManager::helpEngine()
.customValue(QLatin1String("DefaultHomePage"), QString()).toString();
m_ui.homePageLineEdit->setText(defaultHomePage);
}
......@@ -214,7 +214,7 @@ void GeneralSettingsPage::importBookmarks()
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
const BookmarkManager &manager = HelpManager::bookmarkManager();
const BookmarkManager &manager = LocalHelpManager::bookmarkManager();
XbelReader reader(manager.treeBookmarkModel(), manager.listBookmarkModel());