Commit 1efe7199 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Moved the CppHoverHandler to the CppEditor plugin

It used to be in CppTools, but since the hover handler only makes sense
in the context of the C++ editor, this is a better place.
parent 24e6d158
...@@ -8,6 +8,7 @@ HEADERS += cppplugin.h \ ...@@ -8,6 +8,7 @@ HEADERS += cppplugin.h \
cppeditor.h \ cppeditor.h \
cppeditoractionhandler.h \ cppeditoractionhandler.h \
cpphighlighter.h \ cpphighlighter.h \
cpphoverhandler.h \
cppfilewizard.h \ cppfilewizard.h \
cppeditorconstants.h \ cppeditorconstants.h \
cppeditorenums.h \ cppeditorenums.h \
...@@ -17,6 +18,7 @@ SOURCES += cppplugin.cpp \ ...@@ -17,6 +18,7 @@ SOURCES += cppplugin.cpp \
cppeditoractionhandler.cpp \ cppeditoractionhandler.cpp \
cppeditor.cpp \ cppeditor.cpp \
cpphighlighter.cpp \ cpphighlighter.cpp \
cpphoverhandler.cpp \
cppfilewizard.cpp \ cppfilewizard.cpp \
cppclasswizard.cpp cppclasswizard.cpp
RESOURCES += cppeditor.qrc RESOURCES += cppeditor.qrc
<RCC> <RCC>
<qresource prefix="/cppeditor" > <qresource prefix="/cppeditor" >
<file>images/f1.svg</file>
<file>images/qt_cpp.png</file> <file>images/qt_cpp.png</file>
<file>images/qt_h.png</file> <file>images/qt_h.png</file>
<file>CppEditor.mimetypes.xml</file> <file>CppEditor.mimetypes.xml</file>
......
...@@ -32,10 +32,13 @@ ...@@ -32,10 +32,13 @@
***************************************************************************/ ***************************************************************************/
#include "cpphoverhandler.h" #include "cpphoverhandler.h"
#include "cppmodelmanager.h" #include "cppeditor.h"
#include "cppplugin.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <texteditor/itexteditor.h> #include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <debugger/debuggerconstants.h> #include <debugger/debuggerconstants.h>
...@@ -57,12 +60,16 @@ ...@@ -57,12 +60,16 @@
#include <QtHelp/QHelpEngineCore> #include <QtHelp/QHelpEngineCore>
#include <QtCore/QtCore> #include <QtCore/QtCore>
using namespace CppTools::Internal; using namespace CppEditor::Internal;
using namespace CPlusPlus; using namespace CPlusPlus;
CppHoverHandler::CppHoverHandler(CppModelManager *manager, QObject *parent) CppHoverHandler::CppHoverHandler(QObject *parent)
: QObject(parent), m_manager(manager), m_helpEngineNeedsSetup(false) : QObject(parent)
, m_core(CppPlugin::core())
, m_helpEngineNeedsSetup(false)
{ {
m_modelManager = m_core->pluginManager()->getObject<CppTools::CppModelManagerInterface>();
QFileInfo fi(ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>()->settings()->fileName()); QFileInfo fi(ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>()->settings()->fileName());
m_helpEngine = new QHelpEngineCore(fi.absolutePath() m_helpEngine = new QHelpEngineCore(fi.absolutePath()
+ QLatin1String("/helpcollection.qhc"), this); + QLatin1String("/helpcollection.qhc"), this);
...@@ -70,6 +77,10 @@ CppHoverHandler::CppHoverHandler(CppModelManager *manager, QObject *parent) ...@@ -70,6 +77,10 @@ CppHoverHandler::CppHoverHandler(CppModelManager *manager, QObject *parent)
m_helpEngine->setupData(); m_helpEngine->setupData();
m_helpEngine->setCurrentFilter(tr("Unfiltered")); m_helpEngine->setCurrentFilter(tr("Unfiltered"));
m_helpEngineNeedsSetup = m_helpEngine->registeredDocumentations().count() == 0; m_helpEngineNeedsSetup = m_helpEngine->registeredDocumentations().count() == 0;
// Listen for editor opened events in order to connect to tooltip/helpid requests
connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
this, SLOT(editorOpened(Core::IEditor *)));
} }
void CppHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int pos) void CppHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int pos)
...@@ -77,15 +88,27 @@ void CppHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int p ...@@ -77,15 +88,27 @@ void CppHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int p
updateHelpIdAndTooltip(editor, pos); updateHelpIdAndTooltip(editor, pos);
} }
void CppHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos) void CppHoverHandler::editorOpened(Core::IEditor *editor)
{ {
const int dbgcontext = m_manager->core()-> CPPEditorEditable *cppEditor = qobject_cast<CPPEditorEditable *>(editor);
uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_GDBDEBUGGER); if (!cppEditor)
return;
connect(cppEditor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*, QPoint, int)),
this, SLOT(showToolTip(TextEditor::ITextEditor*, QPoint, int)));
connect(cppEditor, SIGNAL(contextHelpIdRequested(TextEditor::ITextEditor*, int)),
this, SLOT(updateContextHelpId(TextEditor::ITextEditor*, int)));
}
if (m_manager->core()->hasContext(dbgcontext)) void CppHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos)
{
if (!editor)
return; return;
if (! editor) const int dbgcontext = m_core->uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_GDBDEBUGGER);
if (m_core->hasContext(dbgcontext))
return; return;
updateHelpIdAndTooltip(editor, pos); updateHelpIdAndTooltip(editor, pos);
...@@ -158,6 +181,9 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -158,6 +181,9 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
m_helpId.clear(); m_helpId.clear();
m_toolTip.clear(); m_toolTip.clear();
if (!m_modelManager)
return;
TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget()); TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
if (!edit) if (!edit)
return; return;
...@@ -165,7 +191,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -165,7 +191,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
QTextCursor tc(edit->document()); QTextCursor tc(edit->document());
tc.setPosition(pos); tc.setPosition(pos);
const Snapshot documents = m_manager->snapshot(); const Snapshot documents = m_modelManager->snapshot();
const int lineNumber = tc.block().blockNumber() + 1; const int lineNumber = tc.block().blockNumber() + 1;
const QString fileName = editor->file()->fileName(); const QString fileName = editor->file()->fileName();
...@@ -261,7 +287,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -261,7 +287,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
if (!m_helpId.isEmpty() && !m_helpEngine->linksForIdentifier(m_helpId).isEmpty()) { if (!m_helpId.isEmpty() && !m_helpEngine->linksForIdentifier(m_helpId).isEmpty()) {
m_toolTip = QString(QLatin1String("<table><tr><td valign=middle><nobr>%1</td>" m_toolTip = QString(QLatin1String("<table><tr><td valign=middle><nobr>%1</td>"
"<td><img src=\":/cpptools/images/f1.svg\"></td></tr></table>")) "<td><img src=\":/cppeditor/images/f1.svg\"></td></tr></table>"))
.arg(Qt::escape(m_toolTip)); .arg(Qt::escape(m_toolTip));
editor->setContextHelpId(m_helpId); editor->setContextHelpId(m_helpId);
} else if (!m_toolTip.isEmpty()) { } else if (!m_toolTip.isEmpty()) {
......
...@@ -35,36 +35,47 @@ ...@@ -35,36 +35,47 @@
#define CPPHOVERHANDLER_H #define CPPHOVERHANDLER_H
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QPoint>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QHelpEngineCore; class QHelpEngineCore;
class QPoint;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core {
class ICore;
class IEditor;
}
namespace CppTools {
class CppModelManagerInterface;
}
namespace TextEditor { namespace TextEditor {
class ITextEditor; class ITextEditor;
} }
namespace CppTools { namespace CppEditor {
namespace Internal { namespace Internal {
class CppModelManager;
class CppHoverHandler : public QObject class CppHoverHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
CppHoverHandler(CppModelManager *manager, QObject *parent); CppHoverHandler(QObject *parent = 0);
public slots: public slots:
void showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos); void showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos);
void updateContextHelpId(TextEditor::ITextEditor *editor, int pos); void updateContextHelpId(TextEditor::ITextEditor *editor, int pos);
private slots:
void editorOpened(Core::IEditor *editor);
private: private:
void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos); void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos);
CppModelManager *m_manager; Core::ICore *m_core;
CppTools::CppModelManagerInterface *m_modelManager;
QHelpEngineCore *m_helpEngine; QHelpEngineCore *m_helpEngine;
QString m_helpId; QString m_helpId;
QString m_toolTip; QString m_toolTip;
...@@ -72,6 +83,6 @@ private: ...@@ -72,6 +83,6 @@ private:
}; };
} // namespace Internal } // namespace Internal
} // namespace CppTools } // namespace CppEditor
#endif // CPPHOVERHANDLER_H #endif // CPPHOVERHANDLER_H
...@@ -32,12 +32,13 @@ ...@@ -32,12 +32,13 @@
***************************************************************************/ ***************************************************************************/
#include "cppplugin.h" #include "cppplugin.h"
#include "cppclasswizard.h"
#include "cppeditor.h" #include "cppeditor.h"
#include "cppeditoractionhandler.h"
#include "cppeditorconstants.h" #include "cppeditorconstants.h"
#include "cppeditorenums.h" #include "cppeditorenums.h"
#include "cppfilewizard.h" #include "cppfilewizard.h"
#include "cppclasswizard.h" #include "cpphoverhandler.h"
#include "cppeditoractionhandler.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
...@@ -171,6 +172,8 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess ...@@ -171,6 +172,8 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
m_factory = new CppPluginEditorFactory(this); m_factory = new CppPluginEditorFactory(this);
addObject(m_factory); addObject(m_factory);
addAutoReleasedObject(new CppHoverHandler);
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard); CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
wizardParameters.setCategory(QLatin1String("C++")); wizardParameters.setCategory(QLatin1String("C++"));
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <cplusplus/pp.h> #include <cplusplus/pp.h>
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include "cpphoverhandler.h"
#include "cpptoolsconstants.h" #include "cpptoolsconstants.h"
#include "cpptoolseditorsupport.h" #include "cpptoolseditorsupport.h"
...@@ -464,8 +463,6 @@ CppModelManager::CppModelManager(QObject *parent) : ...@@ -464,8 +463,6 @@ CppModelManager::CppModelManager(QObject *parent) :
connect(this, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)), connect(this, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
this, SLOT(onDocumentUpdated(CPlusPlus::Document::Ptr))); this, SLOT(onDocumentUpdated(CPlusPlus::Document::Ptr)));
m_hoverHandler = new CppHoverHandler(this, this);
// Listen for editor closed and opened events so that we can keep track of changing files // Listen for editor closed and opened events so that we can keep track of changing files
connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)), connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
this, SLOT(editorOpened(Core::IEditor *))); this, SLOT(editorOpened(Core::IEditor *)));
...@@ -633,14 +630,6 @@ void CppModelManager::editorOpened(Core::IEditor *editor) ...@@ -633,14 +630,6 @@ void CppModelManager::editorOpened(Core::IEditor *editor)
CppEditorSupport *editorSupport = new CppEditorSupport(this); CppEditorSupport *editorSupport = new CppEditorSupport(this);
editorSupport->setTextEditor(textEditor); editorSupport->setTextEditor(textEditor);
m_editorSupport[textEditor] = editorSupport; m_editorSupport[textEditor] = editorSupport;
// ### move in CppEditorSupport
connect(editor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*, QPoint, int)),
m_hoverHandler, SLOT(showToolTip(TextEditor::ITextEditor*, QPoint, int)));
// ### move in CppEditorSupport
connect(editor, SIGNAL(contextHelpIdRequested(TextEditor::ITextEditor*, int)),
m_hoverHandler, SLOT(updateContextHelpId(TextEditor::ITextEditor*, int)));
} }
} }
......
...@@ -60,7 +60,6 @@ namespace Internal { ...@@ -60,7 +60,6 @@ namespace Internal {
class CppEditorSupport; class CppEditorSupport;
class CppPreprocessor; class CppPreprocessor;
class CppHoverHandler;
class CppModelManager : public CppModelManagerInterface class CppModelManager : public CppModelManagerInterface
{ {
...@@ -144,7 +143,6 @@ private: ...@@ -144,7 +143,6 @@ private:
private: private:
Core::ICore *m_core; Core::ICore *m_core;
ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer; ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer;
CppHoverHandler *m_hoverHandler;
CPlusPlus::Snapshot m_snapshot; CPlusPlus::Snapshot m_snapshot;
// cache // cache
......
...@@ -25,14 +25,11 @@ SOURCES += cppquickopenfilter.cpp \ ...@@ -25,14 +25,11 @@ SOURCES += cppquickopenfilter.cpp \
# Input # Input
SOURCES += cpptoolsplugin.cpp \ SOURCES += cpptoolsplugin.cpp \
cppmodelmanager.cpp \ cppmodelmanager.cpp \
cppcodecompletion.cpp \ cppcodecompletion.cpp
cpphoverhandler.cpp
HEADERS += cpptoolsplugin.h \ HEADERS += cpptoolsplugin.h \
cppmodelmanager.h \ cppmodelmanager.h \
cppcodecompletion.h \ cppcodecompletion.h \
cpphoverhandler.h \
cppmodelmanagerinterface.h \ cppmodelmanagerinterface.h \
cpptoolseditorsupport.h \ cpptoolseditorsupport.h \
cpptoolsconstants.h cpptoolsconstants.h
RESOURCES += cpptools.qrc
FORMS += completionsettingspage.ui FORMS += completionsettingspage.ui
<RCC>
<qresource prefix="/cpptools" >
<file>images/f1.svg</file>
</qresource>
</RCC>
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTimer; class QTimer;
class QByteArray;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace TextEditor { namespace TextEditor {
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "cppclassesfilter.h" #include "cppclassesfilter.h"
#include "cppcodecompletion.h" #include "cppcodecompletion.h"
#include "cppfunctionsfilter.h" #include "cppfunctionsfilter.h"
#include "cpphoverhandler.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include "cpptoolsconstants.h" #include "cpptoolsconstants.h"
#include "cppquickopenfilter.h" #include "cppquickopenfilter.h"
......
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