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 ...@@ -144,6 +144,11 @@ MimeDatabase *CoreImpl::mimeDatabase() const
return m_mainwindow->mimeDatabase(); return m_mainwindow->mimeDatabase();
} }
HelpManager *CoreImpl::helpManager() const
{
return m_mainwindow->helpManager();
}
QSettings *CoreImpl::settings(QSettings::Scope scope) const QSettings *CoreImpl::settings(QSettings::Scope scope) const
{ {
return m_mainwindow->settings(scope); return m_mainwindow->settings(scope);
......
...@@ -67,6 +67,7 @@ public: ...@@ -67,6 +67,7 @@ public:
VCSManager *vcsManager() const; VCSManager *vcsManager() const;
ModeManager *modeManager() const; ModeManager *modeManager() const;
MimeDatabase *mimeDatabase() const; MimeDatabase *mimeDatabase() const;
HelpManager *helpManager() const;
QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const; QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const;
SettingsDatabase *settingsDatabase() const; SettingsDatabase *settingsDatabase() const;
......
...@@ -6,6 +6,7 @@ QT += xml \ ...@@ -6,6 +6,7 @@ QT += xml \
script \ script \
svg \ svg \
sql sql
CONFIG += help
include(../../qtcreatorplugin.pri) include(../../qtcreatorplugin.pri)
include(../../libs/utils/utils.pri) include(../../libs/utils/utils.pri)
include(../../shared/scriptwrapper/scriptwrapper.pri) include(../../shared/scriptwrapper/scriptwrapper.pri)
...@@ -86,7 +87,8 @@ SOURCES += mainwindow.cpp \ ...@@ -86,7 +87,8 @@ SOURCES += mainwindow.cpp \
editortoolbar.cpp \ editortoolbar.cpp \
ssh/ne7sshobject.cpp \ ssh/ne7sshobject.cpp \
ssh/sshconnection.cpp \ ssh/sshconnection.cpp \
ssh/sshkeygenerator.cpp ssh/sshkeygenerator.cpp \
helpmanager.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
editmode.h \ editmode.h \
...@@ -171,7 +173,8 @@ HEADERS += mainwindow.h \ ...@@ -171,7 +173,8 @@ HEADERS += mainwindow.h \
editortoolbar.h \ editortoolbar.h \
ssh/ne7sshobject.h \ ssh/ne7sshobject.h \
ssh/sshconnection.h \ ssh/sshconnection.h \
ssh/sshkeygenerator.h ssh/sshkeygenerator.h \
helpmanager.h
FORMS += dialogs/newdialog.ui \ FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.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 { ...@@ -50,6 +50,7 @@ namespace Core {
class ActionManager; class ActionManager;
class EditorManager; class EditorManager;
class FileManager; class FileManager;
class HelpManager;
class IContext; class IContext;
class MessageManager; class MessageManager;
class MimeDatabase; class MimeDatabase;
...@@ -96,6 +97,7 @@ public: ...@@ -96,6 +97,7 @@ public:
virtual VCSManager *vcsManager() const = 0; virtual VCSManager *vcsManager() const = 0;
virtual ModeManager *modeManager() const = 0; virtual ModeManager *modeManager() const = 0;
virtual MimeDatabase *mimeDatabase() const = 0; virtual MimeDatabase *mimeDatabase() const = 0;
virtual HelpManager *helpManager() const = 0;
virtual QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const = 0; virtual QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const = 0;
virtual SettingsDatabase *settingsDatabase() const = 0; virtual SettingsDatabase *settingsDatabase() const = 0;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "fancytabwidget.h" #include "fancytabwidget.h"
#include "filemanager.h" #include "filemanager.h"
#include "generalsettings.h" #include "generalsettings.h"
#include "helpmanager.h"
#include "ifilefactory.h" #include "ifilefactory.h"
#include "messagemanager.h" #include "messagemanager.h"
#include "modemanager.h" #include "modemanager.h"
...@@ -132,6 +133,7 @@ MainWindow::MainWindow() : ...@@ -132,6 +133,7 @@ MainWindow::MainWindow() :
m_statusBarManager(0), m_statusBarManager(0),
m_modeManager(0), m_modeManager(0),
m_mimeDatabase(new MimeDatabase), m_mimeDatabase(new MimeDatabase),
m_helpManager(new HelpManager),
m_navigationWidget(0), m_navigationWidget(0),
m_rightPaneWidget(0), m_rightPaneWidget(0),
m_versionDialog(0), m_versionDialog(0),
...@@ -288,6 +290,9 @@ MainWindow::~MainWindow() ...@@ -288,6 +290,9 @@ MainWindow::~MainWindow()
m_modeManager = 0; m_modeManager = 0;
delete m_mimeDatabase; delete m_mimeDatabase;
m_mimeDatabase = 0; m_mimeDatabase = 0;
delete m_helpManager;
m_helpManager = 0;
} }
bool MainWindow::init(QString *errorMessage) bool MainWindow::init(QString *errorMessage)
...@@ -1011,6 +1016,11 @@ MimeDatabase *MainWindow::mimeDatabase() const ...@@ -1011,6 +1016,11 @@ MimeDatabase *MainWindow::mimeDatabase() const
return m_mimeDatabase; return m_mimeDatabase;
} }
HelpManager *MainWindow::helpManager() const
{
return m_helpManager;
}
IContext *MainWindow::contextObject(QWidget *widget) IContext *MainWindow::contextObject(QWidget *widget)
{ {
return m_contextWidgets.value(widget); return m_contextWidgets.value(widget);
......
...@@ -52,6 +52,7 @@ class ActionManager; ...@@ -52,6 +52,7 @@ class ActionManager;
class StatusBarWidget; class StatusBarWidget;
class EditorManager; class EditorManager;
class FileManager; class FileManager;
class HelpManager;
class IContext; class IContext;
class IWizard; class IWizard;
class MessageManager; class MessageManager;
...@@ -107,6 +108,7 @@ public: ...@@ -107,6 +108,7 @@ public:
Core::VariableManager *variableManager() const; Core::VariableManager *variableManager() const;
Core::ModeManager *modeManager() const; Core::ModeManager *modeManager() const;
Core::MimeDatabase *mimeDatabase() const; Core::MimeDatabase *mimeDatabase() const;
Core::HelpManager *helpManager() const;
VCSManager *vcsManager() const; VCSManager *vcsManager() const;
QSettings *settings(QSettings::Scope scope) const; QSettings *settings(QSettings::Scope scope) const;
...@@ -193,6 +195,7 @@ private: ...@@ -193,6 +195,7 @@ private:
StatusBarManager *m_statusBarManager; StatusBarManager *m_statusBarManager;
ModeManager *m_modeManager; ModeManager *m_modeManager;
MimeDatabase *m_mimeDatabase; MimeDatabase *m_mimeDatabase;
HelpManager *m_helpManager;
FancyTabWidget *m_modeStack; FancyTabWidget *m_modeStack;
NavigationWidget *m_navigationWidget; NavigationWidget *m_navigationWidget;
RightPaneWidget *m_rightPaneWidget; RightPaneWidget *m_rightPaneWidget;
......
TEMPLATE = lib TEMPLATE = lib
TARGET = CppEditor TARGET = CppEditor
DEFINES += CPPEDITOR_LIBRARY DEFINES += CPPEDITOR_LIBRARY
CONFIG += help
include(../../qtcreatorplugin.pri) include(../../qtcreatorplugin.pri)
include(../../libs/utils/utils.pri) include(../../libs/utils/utils.pri)
include(../../shared/indenter/indenter.pri) include(../../shared/indenter/indenter.pri)
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "cppplugin.h" #include "cppplugin.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cppmodelmanagerinterface.h> #include <cpptools/cppmodelmanagerinterface.h>
...@@ -60,7 +61,6 @@ ...@@ -60,7 +61,6 @@
#include <QtGui/QToolTip> #include <QtGui/QToolTip>
#include <QtGui/QTextCursor> #include <QtGui/QTextCursor>
#include <QtGui/QTextBlock> #include <QtGui/QTextBlock>
#include <QtHelp/QHelpEngineCore>
using namespace CppEditor::Internal; using namespace CppEditor::Internal;
using namespace CPlusPlus; using namespace CPlusPlus;
...@@ -68,27 +68,11 @@ using namespace Core; ...@@ -68,27 +68,11 @@ using namespace Core;
CppHoverHandler::CppHoverHandler(QObject *parent) CppHoverHandler::CppHoverHandler(QObject *parent)
: QObject(parent) : QObject(parent)
, m_helpEngineNeedsSetup(false)
{ {
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>(); 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 // 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 *))); this, SLOT(editorOpened(Core::IEditor *)));
} }
...@@ -297,19 +281,13 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -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; QMap<QString, QUrl> helpLinks;
if (m_toolTip.isEmpty()) { if (m_toolTip.isEmpty()) {
foreach (const Document::Include &incl, doc->includes()) { foreach (const Document::Include &incl, doc->includes()) {
if (incl.line() == lineNumber) { if (incl.line() == lineNumber) {
m_toolTip = QDir::toNativeSeparators(incl.fileName()); m_toolTip = QDir::toNativeSeparators(incl.fileName());
m_helpId = QFileInfo(incl.fileName()).fileName(); m_helpId = QFileInfo(incl.fileName()).fileName();
helpLinks = m_helpEngine->linksForIdentifier(m_helpId); helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
break; break;
} }
} }
...@@ -388,7 +366,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -388,7 +366,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
// To show their help anyway, try stripping scopes until we find something. // To show their help anyway, try stripping scopes until we find something.
const QString startHelpId = m_helpId; const QString startHelpId = m_helpId;
while (!m_helpId.isEmpty()) { while (!m_helpId.isEmpty()) {
helpLinks = m_helpEngine->linksForIdentifier(m_helpId); helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
if (!helpLinks.isEmpty()) if (!helpLinks.isEmpty())
break; break;
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include <QtCore/QObject> #include <QtCore/QObject>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QHelpEngineCore;
class QPoint; class QPoint;
QT_END_NAMESPACE QT_END_NAMESPACE
...@@ -70,10 +69,8 @@ private: ...@@ -70,10 +69,8 @@ private:
void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos); void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos);
CppTools::CppModelManagerInterface *m_modelManager; CppTools::CppModelManagerInterface *m_modelManager;
QHelpEngineCore *m_helpEngine;
QString m_helpId; QString m_helpId;
QString m_toolTip; QString m_toolTip;
bool m_helpEngineNeedsSetup;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <coreplugin/designmode.h> #include <coreplugin/designmode.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
...@@ -282,14 +283,8 @@ void FormEditorW::fullInit() ...@@ -282,14 +283,8 @@ void FormEditorW::fullInit()
m_integration = new QtCreatorIntegration(m_formeditor, this); m_integration = new QtCreatorIntegration(m_formeditor, this);
m_formeditor->setIntegration(m_integration); m_formeditor->setIntegration(m_integration);
// Connect Qt Designer help request to HelpManager. // Connect Qt Designer help request to HelpManager.
// TODO: Use Core::HelpManager once it has been introduced. connect(m_integration, SIGNAL(creatorHelpRequested(QUrl)),
foreach(QObject *object, ExtensionSystem::PluginManager::instance()->allObjects()) { Core::HelpManager::instance(), SIGNAL(helpRequested(QUrl)));
if (!qstrcmp(object->metaObject()->className(), "Help::HelpManager")) {
connect(m_integration, SIGNAL(creatorHelpRequested(QString)),
object, SLOT(handleHelpRequest(QString)));
break;
}
}
/** /**
* This will initialize our TabOrder, Signals and slots and Buddy editors. * This will initialize our TabOrder, Signals and slots and Buddy editors.
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QUrl>
enum { indentation = 4 }; enum { indentation = 4 };
...@@ -101,7 +102,8 @@ QtCreatorIntegration::QtCreatorIntegration(QDesignerFormEditorInterface *core, F ...@@ -101,7 +102,8 @@ QtCreatorIntegration::QtCreatorIntegration(QDesignerFormEditorInterface *core, F
void QtCreatorIntegration::slotDesignerHelpRequested(const QString &manual, const QString &document) void QtCreatorIntegration::slotDesignerHelpRequested(const QString &manual, const QString &document)
{ {
// Pass on as URL. // 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() void QtCreatorIntegration::updateSelection()
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include "qt_private/qdesigner_integration_p.h" #include "qt_private/qdesigner_integration_p.h"
QT_FORWARD_DECLARE_CLASS(QUrl)
namespace Designer { namespace Designer {
namespace Internal { namespace Internal {
...@@ -49,7 +51,7 @@ public: ...@@ -49,7 +51,7 @@ public:
bool supportsToSlotNavigation() { return true; } bool supportsToSlotNavigation() { return true; }
signals: signals:
void creatorHelpRequested(const QString &url); void creatorHelpRequested(const QUrl &url);
public slots: public slots:
void updateSelection(); void updateSelection();
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include <QtGui/QStackedWidget> #include <QtGui/QStackedWidget>
#include <QtHelp/QHelpEngine> #include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpEngineCore>
#include <QtHelp/QHelpSearchEngine> #include <QtHelp/QHelpSearchEngine>
using namespace Help::Internal; using namespace Help::Internal;
...@@ -85,7 +84,7 @@ CentralWidget::~CentralWidget() ...@@ -85,7 +84,7 @@ CentralWidget::~CentralWidget()
} }
} }
QHelpEngineCore *engine = &HelpManager::helpEngineCore(); QHelpEngineCore *engine = &LocalHelpManager::helpEngine();
engine->setCustomValue(QLatin1String("LastShownPages"), currentPages); engine->setCustomValue(QLatin1String("LastShownPages"), currentPages);
engine->setCustomValue(QLatin1String("LastShownPagesZoom"), zoomFactors); engine->setCustomValue(QLatin1String("LastShownPagesZoom"), zoomFactors);
engine->setCustomValue(QLatin1String("LastTabPage"), currentIndex()); engine->setCustomValue(QLatin1String("LastTabPage"), currentIndex());
...@@ -314,7 +313,7 @@ void CentralWidget::highlightSearchTerms() ...@@ -314,7 +313,7 @@ void CentralWidget::highlightSearchTerms()
{ {
if (HelpViewer *viewer = currentHelpViewer()) { if (HelpViewer *viewer = currentHelpViewer()) {
QHelpSearchEngine *searchEngine = QHelpSearchEngine *searchEngine =
HelpManager::instance().helpEngine().searchEngine(); LocalHelpManager::helpEngine().searchEngine();
QList<QHelpSearchQuery> queryList = searchEngine->query(); QList<QHelpSearchQuery> queryList = searchEngine->query();
QStringList terms; QStringList terms;
......
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
#include "docsettingspage.h" #include "docsettingspage.h"
#include "helpconstants.h" #include "helpconstants.h"
#include "helpmanager.h"
#include <coreplugin/helpmanager.h>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
...@@ -37,8 +38,6 @@ ...@@ -37,8 +38,6 @@
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtHelp/QHelpEngineCore>
using namespace Help::Internal; using namespace Help::Internal;
DocSettingsPage::DocSettingsPage() DocSettingsPage::DocSettingsPage()
...@@ -80,10 +79,10 @@ QWidget *DocSettingsPage::createPage(QWidget *parent) ...@@ -80,10 +79,10 @@ QWidget *DocSettingsPage::createPage(QWidget *parent)
m_ui.docsListWidget->installEventFilter(this); m_ui.docsListWidget->installEventFilter(this);
QHelpEngineCore *engine = &HelpManager::helpEngineCore(); Core::HelpManager *manager = Core::HelpManager::instance();
const QStringList &nameSpaces = engine->registeredDocumentations(); const QStringList &nameSpaces = manager->registeredNamespaces();
foreach (const QString &nameSpace, nameSpaces) foreach (const QString &nameSpace, nameSpaces)
addItem(nameSpace, engine->documentationFileName(nameSpace)); addItem(nameSpace, manager->fileFromNamespace(nameSpace));
m_filesToRegister.clear(); m_filesToRegister.clear();
m_filesToUnregister.clear(); m_filesToUnregister.clear();
...@@ -103,11 +102,11 @@ void DocSettingsPage::addDocumentation() ...@@ -103,11 +102,11 @@ void DocSettingsPage::addDocumentation()
return; return;
m_recentDialogPath = QFileInfo(files.first()).canonicalPath(); m_recentDialogPath = QFileInfo(files.first()).canonicalPath();
const QHelpEngineCore &