forked from qt-creator/qt-creator
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.
This commit is contained in:
@@ -8,6 +8,7 @@ HEADERS += cppplugin.h \
|
||||
cppeditor.h \
|
||||
cppeditoractionhandler.h \
|
||||
cpphighlighter.h \
|
||||
cpphoverhandler.h \
|
||||
cppfilewizard.h \
|
||||
cppeditorconstants.h \
|
||||
cppeditorenums.h \
|
||||
@@ -17,6 +18,7 @@ SOURCES += cppplugin.cpp \
|
||||
cppeditoractionhandler.cpp \
|
||||
cppeditor.cpp \
|
||||
cpphighlighter.cpp \
|
||||
cpphoverhandler.cpp \
|
||||
cppfilewizard.cpp \
|
||||
cppclasswizard.cpp
|
||||
RESOURCES += cppeditor.qrc
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/cppeditor" >
|
||||
<file>images/f1.svg</file>
|
||||
<file>images/qt_cpp.png</file>
|
||||
<file>images/qt_h.png</file>
|
||||
<file>CppEditor.mimetypes.xml</file>
|
||||
|
||||
@@ -32,10 +32,13 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "cpphoverhandler.h"
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cppeditor.h"
|
||||
#include "cppplugin.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/uniqueidmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
#include <texteditor/itexteditor.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <debugger/debuggerconstants.h>
|
||||
@@ -57,12 +60,16 @@
|
||||
#include <QtHelp/QHelpEngineCore>
|
||||
#include <QtCore/QtCore>
|
||||
|
||||
using namespace CppTools::Internal;
|
||||
using namespace CppEditor::Internal;
|
||||
using namespace CPlusPlus;
|
||||
|
||||
CppHoverHandler::CppHoverHandler(CppModelManager *manager, QObject *parent)
|
||||
: QObject(parent), m_manager(manager), m_helpEngineNeedsSetup(false)
|
||||
CppHoverHandler::CppHoverHandler(QObject *parent)
|
||||
: 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());
|
||||
m_helpEngine = new QHelpEngineCore(fi.absolutePath()
|
||||
+ QLatin1String("/helpcollection.qhc"), this);
|
||||
@@ -70,6 +77,10 @@ CppHoverHandler::CppHoverHandler(CppModelManager *manager, QObject *parent)
|
||||
m_helpEngine->setupData();
|
||||
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(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
|
||||
this, SLOT(editorOpened(Core::IEditor *)));
|
||||
}
|
||||
|
||||
void CppHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int pos)
|
||||
@@ -77,15 +88,27 @@ void CppHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int p
|
||||
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()->
|
||||
uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_GDBDEBUGGER);
|
||||
|
||||
if (m_manager->core()->hasContext(dbgcontext))
|
||||
CPPEditorEditable *cppEditor = qobject_cast<CPPEditorEditable *>(editor);
|
||||
if (!cppEditor)
|
||||
return;
|
||||
|
||||
if (! editor)
|
||||
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)));
|
||||
}
|
||||
|
||||
void CppHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos)
|
||||
{
|
||||
if (!editor)
|
||||
return;
|
||||
|
||||
const int dbgcontext = m_core->uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_GDBDEBUGGER);
|
||||
|
||||
if (m_core->hasContext(dbgcontext))
|
||||
return;
|
||||
|
||||
updateHelpIdAndTooltip(editor, pos);
|
||||
@@ -158,6 +181,9 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
|
||||
m_helpId.clear();
|
||||
m_toolTip.clear();
|
||||
|
||||
if (!m_modelManager)
|
||||
return;
|
||||
|
||||
TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
|
||||
if (!edit)
|
||||
return;
|
||||
@@ -165,7 +191,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
|
||||
QTextCursor tc(edit->document());
|
||||
tc.setPosition(pos);
|
||||
|
||||
const Snapshot documents = m_manager->snapshot();
|
||||
const Snapshot documents = m_modelManager->snapshot();
|
||||
|
||||
const int lineNumber = tc.block().blockNumber() + 1;
|
||||
const QString fileName = editor->file()->fileName();
|
||||
@@ -261,7 +287,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
|
||||
|
||||
if (!m_helpId.isEmpty() && !m_helpEngine->linksForIdentifier(m_helpId).isEmpty()) {
|
||||
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));
|
||||
editor->setContextHelpId(m_helpId);
|
||||
} else if (!m_toolTip.isEmpty()) {
|
||||
@@ -35,36 +35,47 @@
|
||||
#define CPPHOVERHANDLER_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPoint>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QHelpEngineCore;
|
||||
class QPoint;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
class ICore;
|
||||
class IEditor;
|
||||
}
|
||||
|
||||
namespace CppTools {
|
||||
class CppModelManagerInterface;
|
||||
}
|
||||
|
||||
namespace TextEditor {
|
||||
class ITextEditor;
|
||||
}
|
||||
|
||||
namespace CppTools {
|
||||
namespace CppEditor {
|
||||
namespace Internal {
|
||||
|
||||
class CppModelManager;
|
||||
|
||||
class CppHoverHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CppHoverHandler(CppModelManager *manager, QObject *parent);
|
||||
CppHoverHandler(QObject *parent = 0);
|
||||
|
||||
public slots:
|
||||
void showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos);
|
||||
void updateContextHelpId(TextEditor::ITextEditor *editor, int pos);
|
||||
|
||||
private slots:
|
||||
void editorOpened(Core::IEditor *editor);
|
||||
|
||||
private:
|
||||
void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos);
|
||||
|
||||
CppModelManager *m_manager;
|
||||
Core::ICore *m_core;
|
||||
CppTools::CppModelManagerInterface *m_modelManager;
|
||||
QHelpEngineCore *m_helpEngine;
|
||||
QString m_helpId;
|
||||
QString m_toolTip;
|
||||
@@ -72,6 +83,6 @@ private:
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CppTools
|
||||
} // namespace CppEditor
|
||||
|
||||
#endif // CPPHOVERHANDLER_H
|
||||
@@ -32,12 +32,13 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "cppplugin.h"
|
||||
#include "cppclasswizard.h"
|
||||
#include "cppeditor.h"
|
||||
#include "cppeditoractionhandler.h"
|
||||
#include "cppeditorconstants.h"
|
||||
#include "cppeditorenums.h"
|
||||
#include "cppfilewizard.h"
|
||||
#include "cppclasswizard.h"
|
||||
#include "cppeditoractionhandler.h"
|
||||
#include "cpphoverhandler.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
@@ -171,6 +172,8 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
|
||||
m_factory = new CppPluginEditorFactory(this);
|
||||
addObject(m_factory);
|
||||
|
||||
addAutoReleasedObject(new CppHoverHandler);
|
||||
|
||||
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
|
||||
|
||||
wizardParameters.setCategory(QLatin1String("C++"));
|
||||
|
||||
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
@@ -34,7 +34,6 @@
|
||||
#include <cplusplus/pp.h>
|
||||
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cpphoverhandler.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
#include "cpptoolseditorsupport.h"
|
||||
|
||||
@@ -464,8 +463,6 @@ CppModelManager::CppModelManager(QObject *parent) :
|
||||
connect(this, SIGNAL(documentUpdated(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
|
||||
connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
|
||||
this, SLOT(editorOpened(Core::IEditor *)));
|
||||
@@ -633,14 +630,6 @@ void CppModelManager::editorOpened(Core::IEditor *editor)
|
||||
CppEditorSupport *editorSupport = new CppEditorSupport(this);
|
||||
editorSupport->setTextEditor(textEditor);
|
||||
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 {
|
||||
|
||||
class CppEditorSupport;
|
||||
class CppPreprocessor;
|
||||
class CppHoverHandler;
|
||||
|
||||
class CppModelManager : public CppModelManagerInterface
|
||||
{
|
||||
@@ -144,7 +143,6 @@ private:
|
||||
private:
|
||||
Core::ICore *m_core;
|
||||
ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer;
|
||||
CppHoverHandler *m_hoverHandler;
|
||||
CPlusPlus::Snapshot m_snapshot;
|
||||
|
||||
// cache
|
||||
|
||||
@@ -25,14 +25,11 @@ SOURCES += cppquickopenfilter.cpp \
|
||||
# Input
|
||||
SOURCES += cpptoolsplugin.cpp \
|
||||
cppmodelmanager.cpp \
|
||||
cppcodecompletion.cpp \
|
||||
cpphoverhandler.cpp
|
||||
cppcodecompletion.cpp
|
||||
HEADERS += cpptoolsplugin.h \
|
||||
cppmodelmanager.h \
|
||||
cppcodecompletion.h \
|
||||
cpphoverhandler.h \
|
||||
cppmodelmanagerinterface.h \
|
||||
cpptoolseditorsupport.h \
|
||||
cpptoolsconstants.h
|
||||
RESOURCES += cpptools.qrc
|
||||
FORMS += completionsettingspage.ui
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<RCC>
|
||||
<qresource prefix="/cpptools" >
|
||||
<file>images/f1.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -40,7 +40,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTimer;
|
||||
class QByteArray;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include "cppclassesfilter.h"
|
||||
#include "cppcodecompletion.h"
|
||||
#include "cppfunctionsfilter.h"
|
||||
#include "cpphoverhandler.h"
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
#include "cppquickopenfilter.h"
|
||||
|
||||
Reference in New Issue
Block a user