diff --git a/src/plugins/cppeditor/cppeditor.pro b/src/plugins/cppeditor/cppeditor.pro index cb71e9a8380b3f77bcec55753af60a609d53d8de..8ac3b334df35d93b640c1d9d478eb184dd3895e7 100644 --- a/src/plugins/cppeditor/cppeditor.pro +++ b/src/plugins/cppeditor/cppeditor.pro @@ -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 diff --git a/src/plugins/cppeditor/cppeditor.qrc b/src/plugins/cppeditor/cppeditor.qrc index 6ddcbac8bbb82f84d0d4dbb4e6192d7dabbbeaab..9a69ae6ab9d5bb0613029eaefb7711b3901b8e61 100644 --- a/src/plugins/cppeditor/cppeditor.qrc +++ b/src/plugins/cppeditor/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> diff --git a/src/plugins/cpptools/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp similarity index 85% rename from src/plugins/cpptools/cpphoverhandler.cpp rename to src/plugins/cppeditor/cpphoverhandler.cpp index 497ac78d743cffeae3fa73c184eda0abd5ebaf5b..439fc2ad96d5b140b5add85ec2fe538cfb44d6c0 100644 --- a/src/plugins/cpptools/cpphoverhandler.cpp +++ b/src/plugins/cppeditor/cpphoverhandler.cpp @@ -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); + CPPEditorEditable *cppEditor = qobject_cast<CPPEditorEditable *>(editor); + 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; - if (! editor) + 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()) { diff --git a/src/plugins/cpptools/cpphoverhandler.h b/src/plugins/cppeditor/cpphoverhandler.h similarity index 86% rename from src/plugins/cpptools/cpphoverhandler.h rename to src/plugins/cppeditor/cpphoverhandler.h index d1de5277b1241468b5dfdfbeff5d9ec14ea49927..d8bd48031c394b728e738f59bad64a9361d489b7 100644 --- a/src/plugins/cpptools/cpphoverhandler.h +++ b/src/plugins/cppeditor/cpphoverhandler.h @@ -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 diff --git a/src/plugins/cppeditor/cppplugin.cpp b/src/plugins/cppeditor/cppplugin.cpp index ac4a74b051819467bf5f5804497381a0c672b53c..4031f804398eb18d445149b6f2540abde7b286bd 100644 --- a/src/plugins/cppeditor/cppplugin.cpp +++ b/src/plugins/cppeditor/cppplugin.cpp @@ -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++")); diff --git a/src/plugins/cpptools/images/f1.svg b/src/plugins/cppeditor/images/f1.svg similarity index 100% rename from src/plugins/cpptools/images/f1.svg rename to src/plugins/cppeditor/images/f1.svg diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index a02656ee8c96943d5e774970c2727a0cb53126e0..bc5d72c097c18e276e113186e415494b4d87b440 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -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))); } } diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 25947056203929e7fac1e17096525b8f402dd64b..990d019ad757e87d621482713cde055d56e24621 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -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 diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index f86ca6bdd5e08b1048cb9826f4c98999d0c0c34e..ce71c2de71225859b1997a63ea20aef756ffd772 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -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 diff --git a/src/plugins/cpptools/cpptools.qrc b/src/plugins/cpptools/cpptools.qrc deleted file mode 100644 index a750578a4b00a3fde8fe87025ad2282fa2709049..0000000000000000000000000000000000000000 --- a/src/plugins/cpptools/cpptools.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/cpptools" > - <file>images/f1.svg</file> - </qresource> -</RCC> diff --git a/src/plugins/cpptools/cpptoolseditorsupport.h b/src/plugins/cpptools/cpptoolseditorsupport.h index 6cfb7dc20100512d8a9d9577607963e53fe2573c..4fb6c14071f8fdc0ac18670925a082195e6ef499 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.h +++ b/src/plugins/cpptools/cpptoolseditorsupport.h @@ -40,7 +40,6 @@ QT_BEGIN_NAMESPACE class QTimer; -class QByteArray; QT_END_NAMESPACE namespace TextEditor { diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index 0454a0b6fea1163609c806876a0e6fdbe7faa694..9d190162c82d0bc6a4a9432b99dbf24aa77ad8cc 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -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"