diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp index c634cc3bcf4d42473bc603dd2ace7fe14d52fe7a..fdbe0acc772adfb79a0e9d0a9ff0df045b2e5c2e 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -97,6 +97,8 @@ public: | TextEditorActionHandler::UnCollapseAll | TextEditorActionHandler::FollowSymbolUnderCursor); + addHoverHandler(new CppHoverHandler); + if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) { FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_cpp.png", Constants::CPP_SOURCE_MIMETYPE); FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_c.png", Constants::C_SOURCE_MIMETYPE); @@ -153,7 +155,6 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err return false; addAutoReleasedObject(new CppEditorFactory); - addAutoReleasedObject(new CppHoverHandler); addAutoReleasedObject(new CppOutlineWidgetFactory); addAutoReleasedObject(new CppTypeHierarchyFactory); addAutoReleasedObject(new CppIncludeHierarchyFactory); diff --git a/src/plugins/cppeditor/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp index c91b73795635bda11bbf1e207dc3feb06084556b..e0e2c78b5ee742454373a4a2c16192f0db3ae86d 100644 --- a/src/plugins/cppeditor/cpphoverhandler.cpp +++ b/src/plugins/cppeditor/cpphoverhandler.cpp @@ -49,14 +49,6 @@ namespace Internal { CppHoverHandler::CppHoverHandler() {} -CppHoverHandler::~CppHoverHandler() -{} - -bool CppHoverHandler::acceptEditor(IEditor *editor) -{ - return editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID; -} - void CppHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos) { if (!editorWidget->extraSelectionTooltip(pos).isEmpty()) { diff --git a/src/plugins/cppeditor/cpphoverhandler.h b/src/plugins/cppeditor/cpphoverhandler.h index dea4304db73f2838adce9cba0d1569e67ba74cee..b6276be0cddf5be08c173d2a5cb3917f625a649e 100644 --- a/src/plugins/cppeditor/cpphoverhandler.h +++ b/src/plugins/cppeditor/cpphoverhandler.h @@ -39,10 +39,8 @@ class CppHoverHandler : public TextEditor::BaseHoverHandler { public: CppHoverHandler(); - virtual ~CppHoverHandler(); private: - virtual bool acceptEditor(Core::IEditor *editor); virtual void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos); virtual void decorateToolTip(); }; diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 631c3f4dbcd7c0ca668f751854c984c7cc7d98f5..d15a16eb43cb97f97da17c02cdca13cd3bfd302d 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -31,6 +31,7 @@ #include "glsleditorconstants.h" #include "glsleditorplugin.h" #include "glslhighlighter.h" +#include "glslhoverhandler.h" #include "glslautocompleter.h" #include "glslcompletionassist.h" #include "glslindenter.h" @@ -347,6 +348,7 @@ GlslEditorFactory::GlslEditorFactory() | TextEditorActionHandler::UnCommentSelection | TextEditorActionHandler::UnCollapseAll); + addHoverHandler(new GlslHoverHandler); } } // namespace Internal diff --git a/src/plugins/glsleditor/glsleditorplugin.cpp b/src/plugins/glsleditor/glsleditorplugin.cpp index 3034bbaad0e84ee8a31ebb2a266a48a3dfccdca7..48485ef2ff9548eaea314984eb7b655f0545821e 100644 --- a/src/plugins/glsleditor/glsleditorplugin.cpp +++ b/src/plugins/glsleditor/glsleditorplugin.cpp @@ -33,7 +33,6 @@ #include "glsleditorconstants.h" #include "glslfilewizard.h" #include "glslhighlighter.h" -#include "glslhoverhandler.h" #include #include @@ -128,7 +127,6 @@ bool GlslEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er if (!MimeDatabase::addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage)) return false; - addAutoReleasedObject(new GlslHoverHandler(this)); addAutoReleasedObject(new GlslEditorFactory); addAutoReleasedObject(new GlslCompletionAssistProvider); diff --git a/src/plugins/glsleditor/glslhoverhandler.cpp b/src/plugins/glsleditor/glslhoverhandler.cpp index be76a9f2caa7dba76ba5943713cbd5e3defb84e9..d76289786c39843a39bf52f8271129a6bacf1ab0 100644 --- a/src/plugins/glsleditor/glslhoverhandler.cpp +++ b/src/plugins/glsleditor/glslhoverhandler.cpp @@ -29,30 +29,10 @@ #include "glslhoverhandler.h" #include "glsleditor.h" -#include "glsleditorconstants.h" - -#include -#include -#include -#include -#include - -using namespace Core; namespace GlslEditor { namespace Internal { -GlslHoverHandler::GlslHoverHandler(QObject *parent) : BaseHoverHandler(parent) -{} - -GlslHoverHandler::~GlslHoverHandler() -{} - -bool GlslHoverHandler::acceptEditor(IEditor *editor) -{ - return editor->context().contains(Constants::C_GLSLEDITOR_ID); -} - void GlslHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos) { if (!editorWidget->extraSelectionTooltip(pos).isEmpty()) diff --git a/src/plugins/glsleditor/glslhoverhandler.h b/src/plugins/glsleditor/glslhoverhandler.h index 9df874b63ae1d4e126fc1cb790ff541ca231b153..6aeb1fe50f8737a72df82cd469f0257b7e1cc25b 100644 --- a/src/plugins/glsleditor/glslhoverhandler.h +++ b/src/plugins/glsleditor/glslhoverhandler.h @@ -32,24 +32,15 @@ #include -#include - -namespace Core { class IEditor; } - -namespace TextEditor { class BaseTextEditor; } - namespace GlslEditor { namespace Internal { class GlslHoverHandler : public TextEditor::BaseHoverHandler { - Q_OBJECT public: - GlslHoverHandler(QObject *parent = 0); - virtual ~GlslHoverHandler(); + GlslHoverHandler() {} private: - virtual bool acceptEditor(Core::IEditor *editor); virtual void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos); virtual void decorateToolTip(); }; diff --git a/src/plugins/qmakeprojectmanager/profileeditor.cpp b/src/plugins/qmakeprojectmanager/profileeditor.cpp index d48e452f0ee7069b366e93f09f98ca5fd32d1462..0d02646d791121616fe88b3af359f2b2da154868 100644 --- a/src/plugins/qmakeprojectmanager/profileeditor.cpp +++ b/src/plugins/qmakeprojectmanager/profileeditor.cpp @@ -31,6 +31,7 @@ #include "profilecompletionassist.h" #include "profilehighlighter.h" +#include "profilehoverhandler.h" #include "qmakeprojectmanager.h" #include "qmakeprojectmanagerconstants.h" #include "qmakeprojectmanagerconstants.h" @@ -215,6 +216,8 @@ ProFileEditorFactory::ProFileEditorFactory() setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection | TextEditorActionHandler::JumpToFileUnderCursor); + addHoverHandler(new ProFileHoverHandler); + Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "pro"); Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "pri"); Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "prf"); diff --git a/src/plugins/qmakeprojectmanager/profilehoverhandler.cpp b/src/plugins/qmakeprojectmanager/profilehoverhandler.cpp index a48d33a3e9875ea0084a5199067866b1d6875c8d..acd4e3fcbf481a2d5f88320fea5864300255c4b2 100644 --- a/src/plugins/qmakeprojectmanager/profilehoverhandler.cpp +++ b/src/plugins/qmakeprojectmanager/profilehoverhandler.cpp @@ -53,11 +53,6 @@ ProFileHoverHandler::ProFileHoverHandler() m_keywords = TextEditor::Keywords(pcap->variables(), pcap->functions(), QMap()); } -bool ProFileHoverHandler::acceptEditor(IEditor *editor) -{ - return editor->context().contains(Constants::PROFILE_EDITOR_ID); -} - void ProFileHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos) { m_docFragment.clear(); diff --git a/src/plugins/qmakeprojectmanager/profilehoverhandler.h b/src/plugins/qmakeprojectmanager/profilehoverhandler.h index 0ec99fc2d087eea2445e08c39921ed6604294655..864604405b9fa187758b195696ca3189ff34e0f4 100644 --- a/src/plugins/qmakeprojectmanager/profilehoverhandler.h +++ b/src/plugins/qmakeprojectmanager/profilehoverhandler.h @@ -42,6 +42,7 @@ namespace Internal { class ProFileHoverHandler : public TextEditor::BaseHoverHandler { Q_OBJECT + public: ProFileHoverHandler(); @@ -49,8 +50,7 @@ signals: void creatorHelpRequested(const QUrl &url); private: - virtual bool acceptEditor(Core::IEditor *editor); - virtual void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos); + void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos); void identifyQMakeKeyword(const QString &text, int pos); enum ManualKind { diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp index c3dce8fedf784dd1341c8ae10b109e98727bac22..84682312bbdee041270e60887f04ad7b5f723246 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp @@ -44,7 +44,6 @@ #include "wizards/subdirsprojectwizard.h" #include "wizards/qtquickappwizard.h" #include "customwidgetwizard/customwidgetwizard.h" -#include "profilehoverhandler.h" #include "qmakeprojectmanagerconstants.h" #include "qmakeproject.h" #include "externaleditors.h" @@ -111,7 +110,6 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString ProjectExplorer::KitManager::registerKitInformation(new QmakeKitInformation); - addAutoReleasedObject(new ProFileEditorFactory); addAutoReleasedObject(new EmptyProjectWizard); addAutoReleasedObject(new SubdirsProjectWizard); addAutoReleasedObject(new GuiAppWizard); @@ -137,7 +135,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString addAutoReleasedObject(new LinguistExternalEditor); addAutoReleasedObject(new ProFileCompletionAssistProvider); - addAutoReleasedObject(new ProFileHoverHandler); + addAutoReleasedObject(new ProFileEditorFactory); auto hf = new TextEditor::HighlighterFactory; hf->setProductType(); diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index fce43670da226adbfbde5dc70cfe7b2f2ad8a537..3a2f88ef31a13a926d1771a2a80c7c8518ff84af 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -35,6 +35,7 @@ #include "qmljseditordocument.h" #include "qmljseditorplugin.h" #include "qmljsfindreferences.h" +#include "qmljshoverhandler.h" #include "qmljsquickfixassist.h" #include "qmloutlinemodel.h" @@ -901,6 +902,8 @@ QmlJSEditorFactory::QmlJSEditorFactory() setAutoCompleterCreator([]() { return new AutoCompleter; }); setCommentStyle(Utils::CommentDefinition::CppStyle); + addHoverHandler(new QmlJSHoverHandler); + setEditorActionHandlers(TextEditorActionHandler::Format | TextEditorActionHandler::UnCommentSelection | TextEditorActionHandler::UnCollapseAll diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 1ac7d4488d0398f7f733817fca277682d27cc988..88499e86b24e62f0b6998331f905a8c398f3f2d6 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -32,7 +32,6 @@ #include "qmljseditor.h" #include "qmljseditorconstants.h" #include "qmljseditordocument.h" -#include "qmljshoverhandler.h" #include "qmlfilewizard.h" #include "jsfilewizard.h" #include "qmljsoutline.h" @@ -224,7 +223,6 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e m_quickFixAssistProvider = new QmlJSQuickFixAssistProvider; addAutoReleasedObject(m_quickFixAssistProvider); addAutoReleasedObject(new QmlJSCompletionAssistProvider); - addAutoReleasedObject(new QmlJSHoverHandler); errorMessage->clear(); diff --git a/src/plugins/qmljseditor/qmljshoverhandler.cpp b/src/plugins/qmljseditor/qmljshoverhandler.cpp index 4a893f427bf77ae1530ff34ea73dc3ab40e9f385..e02961b746f429e60cc70d3b648e0459c8fa641f 100644 --- a/src/plugins/qmljseditor/qmljshoverhandler.cpp +++ b/src/plugins/qmljseditor/qmljshoverhandler.cpp @@ -92,16 +92,11 @@ namespace { } } -QmlJSHoverHandler::QmlJSHoverHandler(QObject *parent) : BaseHoverHandler(parent), m_modelManager(0) +QmlJSHoverHandler::QmlJSHoverHandler() : m_modelManager(0) { m_modelManager = QmlJS::ModelManagerInterface::instance(); } -bool QmlJSHoverHandler::acceptEditor(IEditor *editor) -{ - return editor->context().contains(Constants::C_QMLJSEDITOR_ID); -} - static inline QString getModuleName(const ScopeChain &scopeChain, const Document::Ptr &qmlDocument, const ObjectValue *value) { diff --git a/src/plugins/qmljseditor/qmljshoverhandler.h b/src/plugins/qmljseditor/qmljshoverhandler.h index 3d42ea8d3364ebabba04795597e74931fd5bf085..810dc44c10c677c3fb74c92fe6b66244e78f5435 100644 --- a/src/plugins/qmljseditor/qmljshoverhandler.h +++ b/src/plugins/qmljseditor/qmljshoverhandler.h @@ -39,10 +39,6 @@ QT_BEGIN_NAMESPACE template class QList; QT_END_NAMESPACE -namespace Core { class IEditor; } - -namespace TextEditor { class BaseTextEditor; } - namespace QmlJS { class ScopeChain; class Context; @@ -59,13 +55,13 @@ class QmlJSEditorWidget; class QmlJSHoverHandler : public TextEditor::BaseHoverHandler { Q_OBJECT + public: - QmlJSHoverHandler(QObject *parent = 0); + QmlJSHoverHandler(); private: void reset(); - bool acceptEditor(Core::IEditor *editor); void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos); void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point); diff --git a/src/plugins/texteditor/basehoverhandler.cpp b/src/plugins/texteditor/basehoverhandler.cpp index 82972ccd90af38905a8a4cbec9b29d21fcd22b3e..f5a137e0d11126ebf91d938346b817d6909b0458 100644 --- a/src/plugins/texteditor/basehoverhandler.cpp +++ b/src/plugins/texteditor/basehoverhandler.cpp @@ -40,51 +40,31 @@ using namespace Core; namespace TextEditor { -BaseHoverHandler::BaseHoverHandler(QObject *parent) : QObject(parent), m_diagnosticTooltip(false) +BaseHoverHandler::BaseHoverHandler() : m_diagnosticTooltip(false) { - // Listen for editor opened events in order to connect to tooltip/helpid requests - connect(EditorManager::instance(), &EditorManager::editorOpened, - this, &BaseHoverHandler::editorOpened); } BaseHoverHandler::~BaseHoverHandler() {} -void BaseHoverHandler::editorOpened(Core::IEditor *editor) +void BaseHoverHandler::showToolTip(TextEditorWidget *widget, const QPoint &point, int pos) { - if (acceptEditor(editor)) { - BaseTextEditor *textEditor = qobject_cast(editor); - if (textEditor) { - connect(textEditor, &BaseTextEditor::tooltipRequested, - this, &BaseHoverHandler::showToolTip); - - connect(textEditor, &BaseTextEditor::contextHelpIdRequested, - this, &BaseHoverHandler::updateContextHelpId); - } - } -} + widget->setContextHelpId(QString()); -void BaseHoverHandler::showToolTip(BaseTextEditor *editor, const QPoint &point, int pos) -{ - TextEditorWidget *editorWidget = editor->editorWidget(); - - editor->setContextHelpId(QString()); - - process(editor, pos); - operateTooltip(editorWidget, point); + process(widget, pos); + operateTooltip(widget, point); } -void BaseHoverHandler::updateContextHelpId(BaseTextEditor *editor, int pos) +QString BaseHoverHandler::contextHelpId(TextEditorWidget *widget, int pos) { // If the tooltip is visible and there is a help match, this match is used to update // the help id. Otherwise, let the identification process happen. if (!Utils::ToolTip::isVisible() || !lastHelpItemIdentified().isValid()) - process(editor, pos); + process(widget, pos); if (lastHelpItemIdentified().isValid()) - editor->setContextHelpId(lastHelpItemIdentified().helpId()); - else - editor->setContextHelpId(QString()); // Make sure it's an empty string. + return lastHelpItemIdentified().helpId(); + return QString(); } void BaseHoverHandler::setToolTip(const QString &tooltip) @@ -136,10 +116,10 @@ void BaseHoverHandler::clear() m_lastHelpItemIdentified = HelpItem(); } -void BaseHoverHandler::process(BaseTextEditor *editor, int pos) +void BaseHoverHandler::process(TextEditorWidget *widget, int pos) { clear(); - identifyMatch(editor->editorWidget(), pos); + identifyMatch(widget, pos); decorateToolTip(); } diff --git a/src/plugins/texteditor/basehoverhandler.h b/src/plugins/texteditor/basehoverhandler.h index adaa382d3e9dce7eb6b32bbeb1d2e8a400efdd50..7d78206934108c988eb3983f58362781495c4c7d 100644 --- a/src/plugins/texteditor/basehoverhandler.h +++ b/src/plugins/texteditor/basehoverhandler.h @@ -46,9 +46,12 @@ class TEXTEDITOR_EXPORT BaseHoverHandler : public QObject Q_OBJECT public: - BaseHoverHandler(QObject *parent = 0); + BaseHoverHandler(); ~BaseHoverHandler(); + QString contextHelpId(TextEditorWidget *widget, int pos); + void showToolTip(TextEditorWidget *widget, const QPoint &point, int pos); + protected: void setToolTip(const QString &tooltip); void appendToolTip(const QString &extension); @@ -63,14 +66,9 @@ protected: const HelpItem &lastHelpItemIdentified() const; private: - void editorOpened(Core::IEditor *editor); - void showToolTip(BaseTextEditor *editor, const QPoint &point, int pos); - void updateContextHelpId(BaseTextEditor *editor, int pos); - void clear(); - void process(BaseTextEditor *editor, int pos); + void process(TextEditorWidget *widget, int pos); - virtual bool acceptEditor(Core::IEditor *editor) = 0; virtual void identifyMatch(TextEditorWidget *editorWidget, int pos) = 0; virtual void decorateToolTip(); virtual void operateTooltip(TextEditorWidget *editorWidget, const QPoint &point); diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 5d1714672449be9c2db1506af4477d7820d42352..b7b9d26566bdccab92f3bd4ef4b992e75421c229 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -31,6 +31,7 @@ #include "texteditor_p.h" #include "autocompleter.h" +#include "basehoverhandler.h" #include "behaviorsettings.h" #include "circularclipboard.h" #include "circularclipboardassist.h" @@ -355,6 +356,7 @@ public: void snippetTabOrBacktab(bool forward); RefactorOverlay *m_refactorOverlay; + QString m_contextHelpId; QBasicTimer foldedBlockTimer; int visibleFoldedBlockNumber; @@ -420,6 +422,7 @@ public: CodeAssistant m_codeAssistant; bool m_assistRelevantContentAdded; + QList m_hoverHandlers; // Not owned QPointer m_animator; int m_cursorBlockNumber; @@ -2965,8 +2968,13 @@ void TextEditorWidgetPrivate::processTooltipRequest(const QTextCursor &c) const QPoint toolTipPoint = q->toolTipPosition(c); bool handled = false; emit q->tooltipOverrideRequested(q, toolTipPoint, c.position(), &handled); - if (!handled) - emit q->tooltipRequested(toolTipPoint, c.position()); + if (handled) + return; + if (!m_hoverHandlers.isEmpty()) { + m_hoverHandlers.first()->showToolTip(q, toolTipPoint, c.position()); + return; + } + emit q->tooltipRequested(toolTipPoint, c.position()); } bool TextEditorWidget::viewportEvent(QEvent *event) @@ -6737,7 +6745,7 @@ void TextEditorWidgetPrivate::updateCursorPosition() .arg(q->textDocument()->tabSettings().columnAt(block.text(), column)+1), tr("Line: 9999, Col: 999")); - q->clearContentsHelpId(); + m_contextHelpId.clear(); if (!block.isVisible()) q->ensureCursorVisible(); @@ -6745,10 +6753,25 @@ void TextEditorWidgetPrivate::updateCursorPosition() QString BaseTextEditor::contextHelpId() const { - if (m_contextHelpId.isEmpty()) - emit const_cast(this)->contextHelpIdRequested(const_cast(this), - editorWidget()->textCursor().position()); - return m_contextHelpId; + return editorWidget()->contextHelpId(); +} + +void BaseTextEditor::setContextHelpId(const QString &id) +{ + IEditor::setContextHelpId(id); + editorWidget()->setContextHelpId(id); +} + +QString TextEditorWidget::contextHelpId() +{ + if (d->m_contextHelpId.isEmpty() && !d->m_hoverHandlers.isEmpty()) + d->m_contextHelpId = d->m_hoverHandlers.first()->contextHelpId(this, textCursor().position()); + return d->m_contextHelpId; +} + +void TextEditorWidget::setContextHelpId(const QString &id) +{ + d->m_contextHelpId = id; } RefactorMarkers TextEditorWidget::refactorMarkers() const @@ -7209,6 +7232,11 @@ TextEditorFactory::TextEditorFactory(QObject *parent) m_duplicatedSupported = true; } +TextEditorFactory::~TextEditorFactory() +{ + qDeleteAll(m_hoverHandlers); +} + void TextEditorFactory::setDocumentCreator(const DocumentCreator &creator) { m_documentCreator = creator; @@ -7258,6 +7286,11 @@ void TextEditorFactory::setEditorActionHandlers(uint optionalActions) new TextEditorActionHandler(this, id(), optionalActions); } +void TextEditorFactory::addHoverHandler(BaseHoverHandler *handler) +{ + m_hoverHandlers.append(handler); +} + void TextEditorFactory::setCommentStyle(CommentDefinition::Style style) { m_commentStyle = style; @@ -7306,6 +7339,7 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc widget->setAutoCompleter(m_autoCompleterCreator()); widget->setTextDocument(document); + widget->d->m_hoverHandlers = m_hoverHandlers; widget->d->m_codeAssistant.configure(widget); widget->d->m_commentDefinition.setStyle(m_commentStyle); @@ -7320,11 +7354,6 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc editor->markContextMenuRequested(editor, line, menu); }); - connect(widget, &TextEditorWidget::tooltipRequested, editor, - [editor](const QPoint &globalPos, int position) { - editor->tooltipRequested(editor, globalPos, position); - }); - connect(widget, &TextEditorWidget::markTooltipRequested, editor, [editor](const QPoint &globalPos, int line) { editor->markTooltipRequested(editor, globalPos, line); @@ -7333,9 +7362,6 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc connect(widget, &TextEditorWidget::activateEditor, [editor]() { Core::EditorManager::activateEditor(editor); }); - connect(widget, &TextEditorWidget::clearContentsHelpId, - [editor]() { editor->setContextHelpId(QString()); }); - widget->finalizeInitialization(); editor->finalizeInitialization(); diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 2351ac6711eb168bc6d08e6bbae7013142f905f9..0622129bf8b08c85067b9e8b4223888ec708d5dd 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -61,6 +61,7 @@ namespace Core { class MimeType; } namespace TextEditor { +class BaseHoverHandler; class TabSettings; class RefactorOverlay; struct RefactorMarker; @@ -160,6 +161,7 @@ public: QWidget *toolBar(); QString contextHelpId() const; // from IContext + void setContextHelpId(const QString &id); int currentLine() const; int currentColumn() const; @@ -196,9 +198,7 @@ public: signals: void markRequested(TextEditor::BaseTextEditor *editor, int line, TextEditor::BaseTextEditor::MarkRequestKind kind); void markContextMenuRequested(TextEditor::BaseTextEditor *editor, int line, QMenu *menu); - void tooltipRequested(TextEditor::BaseTextEditor *editor, const QPoint &globalPos, int position); void markTooltipRequested(TextEditor::BaseTextEditor *editor, const QPoint &globalPos, int line); - void contextHelpIdRequested(TextEditor::BaseTextEditor *editor, int position); private: friend class TextEditorFactory; @@ -569,6 +569,9 @@ public: QChar characterAt(int pos) const; QString textAt(int from, int to) const; + QString contextHelpId(); + void setContextHelpId(const QString &id); + protected: /*! Reimplement this function to enable code navigation. @@ -603,7 +606,6 @@ signals: void tooltipRequested(const QPoint &globalPos, int position); void markTooltipRequested(const QPoint &globalPos, int line); void activateEditor(); - void clearContentsHelpId(); protected slots: virtual void slotCursorPositionChanged(); // Used in VcsBase @@ -626,6 +628,7 @@ class TEXTEDITOR_EXPORT TextEditorFactory : public Core::IEditorFactory public: TextEditorFactory(QObject *parent = 0); + ~TextEditorFactory(); typedef std::function EditorCreator; typedef std::function DocumentCreator; @@ -645,6 +648,8 @@ public: void setEditorActionHandlers(Core::Id contextId, uint optionalActions); void setEditorActionHandlers(uint optionalActions); + void addHoverHandler(BaseHoverHandler *handler); + void setCommentStyle(Utils::CommentDefinition::Style style); void setDuplicatedSupported(bool on); @@ -664,6 +669,7 @@ private: IndenterCreator m_indenterCreator; SyntaxHighLighterCreator m_syntaxHighlighterCreator; Utils::CommentDefinition::Style m_commentStyle; + QList m_hoverHandlers; // owned bool m_duplicatedSupported; };