forked from qt-creator/qt-creator
TextEditor: Simplify HoverHandler handling
The editor factories are already a central place to associate hover handlers with editors, no need to retrieve them later from the object pool again. This also allows for easy handling of more than one active handler per editor. Change-Id: Ie716b96f5ce6b526ee897468635e03e909d81538 Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -97,6 +97,8 @@ public:
|
|||||||
| TextEditorActionHandler::UnCollapseAll
|
| TextEditorActionHandler::UnCollapseAll
|
||||||
| TextEditorActionHandler::FollowSymbolUnderCursor);
|
| TextEditorActionHandler::FollowSymbolUnderCursor);
|
||||||
|
|
||||||
|
addHoverHandler(new CppHoverHandler);
|
||||||
|
|
||||||
if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) {
|
if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) {
|
||||||
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_cpp.png", Constants::CPP_SOURCE_MIMETYPE);
|
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_cpp.png", Constants::CPP_SOURCE_MIMETYPE);
|
||||||
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_c.png", Constants::C_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;
|
return false;
|
||||||
|
|
||||||
addAutoReleasedObject(new CppEditorFactory);
|
addAutoReleasedObject(new CppEditorFactory);
|
||||||
addAutoReleasedObject(new CppHoverHandler);
|
|
||||||
addAutoReleasedObject(new CppOutlineWidgetFactory);
|
addAutoReleasedObject(new CppOutlineWidgetFactory);
|
||||||
addAutoReleasedObject(new CppTypeHierarchyFactory);
|
addAutoReleasedObject(new CppTypeHierarchyFactory);
|
||||||
addAutoReleasedObject(new CppIncludeHierarchyFactory);
|
addAutoReleasedObject(new CppIncludeHierarchyFactory);
|
||||||
|
|||||||
@@ -49,14 +49,6 @@ namespace Internal {
|
|||||||
CppHoverHandler::CppHoverHandler()
|
CppHoverHandler::CppHoverHandler()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CppHoverHandler::~CppHoverHandler()
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool CppHoverHandler::acceptEditor(IEditor *editor)
|
|
||||||
{
|
|
||||||
return editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos)
|
void CppHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos)
|
||||||
{
|
{
|
||||||
if (!editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
if (!editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
||||||
|
|||||||
@@ -39,10 +39,8 @@ class CppHoverHandler : public TextEditor::BaseHoverHandler
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CppHoverHandler();
|
CppHoverHandler();
|
||||||
virtual ~CppHoverHandler();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool acceptEditor(Core::IEditor *editor);
|
|
||||||
virtual void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos);
|
virtual void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos);
|
||||||
virtual void decorateToolTip();
|
virtual void decorateToolTip();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "glsleditorconstants.h"
|
#include "glsleditorconstants.h"
|
||||||
#include "glsleditorplugin.h"
|
#include "glsleditorplugin.h"
|
||||||
#include "glslhighlighter.h"
|
#include "glslhighlighter.h"
|
||||||
|
#include "glslhoverhandler.h"
|
||||||
#include "glslautocompleter.h"
|
#include "glslautocompleter.h"
|
||||||
#include "glslcompletionassist.h"
|
#include "glslcompletionassist.h"
|
||||||
#include "glslindenter.h"
|
#include "glslindenter.h"
|
||||||
@@ -347,6 +348,7 @@ GlslEditorFactory::GlslEditorFactory()
|
|||||||
| TextEditorActionHandler::UnCommentSelection
|
| TextEditorActionHandler::UnCommentSelection
|
||||||
| TextEditorActionHandler::UnCollapseAll);
|
| TextEditorActionHandler::UnCollapseAll);
|
||||||
|
|
||||||
|
addHoverHandler(new GlslHoverHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
#include "glsleditorconstants.h"
|
#include "glsleditorconstants.h"
|
||||||
#include "glslfilewizard.h"
|
#include "glslfilewizard.h"
|
||||||
#include "glslhighlighter.h"
|
#include "glslhighlighter.h"
|
||||||
#include "glslhoverhandler.h"
|
|
||||||
|
|
||||||
#include <glsl/glslengine.h>
|
#include <glsl/glslengine.h>
|
||||||
#include <glsl/glslparser.h>
|
#include <glsl/glslparser.h>
|
||||||
@@ -128,7 +127,6 @@ bool GlslEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
|
|||||||
if (!MimeDatabase::addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage))
|
if (!MimeDatabase::addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
addAutoReleasedObject(new GlslHoverHandler(this));
|
|
||||||
addAutoReleasedObject(new GlslEditorFactory);
|
addAutoReleasedObject(new GlslEditorFactory);
|
||||||
addAutoReleasedObject(new GlslCompletionAssistProvider);
|
addAutoReleasedObject(new GlslCompletionAssistProvider);
|
||||||
|
|
||||||
|
|||||||
@@ -29,30 +29,10 @@
|
|||||||
|
|
||||||
#include "glslhoverhandler.h"
|
#include "glslhoverhandler.h"
|
||||||
#include "glsleditor.h"
|
#include "glsleditor.h"
|
||||||
#include "glsleditorconstants.h"
|
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <coreplugin/helpmanager.h>
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
|
||||||
#include <texteditor/texteditor.h>
|
|
||||||
|
|
||||||
using namespace Core;
|
|
||||||
|
|
||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
namespace Internal {
|
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)
|
void GlslHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos)
|
||||||
{
|
{
|
||||||
if (!editorWidget->extraSelectionTooltip(pos).isEmpty())
|
if (!editorWidget->extraSelectionTooltip(pos).isEmpty())
|
||||||
|
|||||||
@@ -32,24 +32,15 @@
|
|||||||
|
|
||||||
#include <texteditor/basehoverhandler.h>
|
#include <texteditor/basehoverhandler.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
|
||||||
|
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
|
||||||
|
|
||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class GlslHoverHandler : public TextEditor::BaseHoverHandler
|
class GlslHoverHandler : public TextEditor::BaseHoverHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
GlslHoverHandler(QObject *parent = 0);
|
GlslHoverHandler() {}
|
||||||
virtual ~GlslHoverHandler();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool acceptEditor(Core::IEditor *editor);
|
|
||||||
virtual void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos);
|
virtual void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos);
|
||||||
virtual void decorateToolTip();
|
virtual void decorateToolTip();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "profilecompletionassist.h"
|
#include "profilecompletionassist.h"
|
||||||
#include "profilehighlighter.h"
|
#include "profilehighlighter.h"
|
||||||
|
#include "profilehoverhandler.h"
|
||||||
#include "qmakeprojectmanager.h"
|
#include "qmakeprojectmanager.h"
|
||||||
#include "qmakeprojectmanagerconstants.h"
|
#include "qmakeprojectmanagerconstants.h"
|
||||||
#include "qmakeprojectmanagerconstants.h"
|
#include "qmakeprojectmanagerconstants.h"
|
||||||
@@ -215,6 +216,8 @@ ProFileEditorFactory::ProFileEditorFactory()
|
|||||||
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
||||||
| TextEditorActionHandler::JumpToFileUnderCursor);
|
| TextEditorActionHandler::JumpToFileUnderCursor);
|
||||||
|
|
||||||
|
addHoverHandler(new ProFileHoverHandler);
|
||||||
|
|
||||||
Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "pro");
|
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, "pri");
|
||||||
Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "prf");
|
Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "prf");
|
||||||
|
|||||||
@@ -53,11 +53,6 @@ ProFileHoverHandler::ProFileHoverHandler()
|
|||||||
m_keywords = TextEditor::Keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
|
m_keywords = TextEditor::Keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProFileHoverHandler::acceptEditor(IEditor *editor)
|
|
||||||
{
|
|
||||||
return editor->context().contains(Constants::PROFILE_EDITOR_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProFileHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos)
|
void ProFileHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos)
|
||||||
{
|
{
|
||||||
m_docFragment.clear();
|
m_docFragment.clear();
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ namespace Internal {
|
|||||||
class ProFileHoverHandler : public TextEditor::BaseHoverHandler
|
class ProFileHoverHandler : public TextEditor::BaseHoverHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ProFileHoverHandler();
|
ProFileHoverHandler();
|
||||||
|
|
||||||
@@ -49,8 +50,7 @@ signals:
|
|||||||
void creatorHelpRequested(const QUrl &url);
|
void creatorHelpRequested(const QUrl &url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool acceptEditor(Core::IEditor *editor);
|
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos);
|
||||||
virtual void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos);
|
|
||||||
void identifyQMakeKeyword(const QString &text, int pos);
|
void identifyQMakeKeyword(const QString &text, int pos);
|
||||||
|
|
||||||
enum ManualKind {
|
enum ManualKind {
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
#include "wizards/subdirsprojectwizard.h"
|
#include "wizards/subdirsprojectwizard.h"
|
||||||
#include "wizards/qtquickappwizard.h"
|
#include "wizards/qtquickappwizard.h"
|
||||||
#include "customwidgetwizard/customwidgetwizard.h"
|
#include "customwidgetwizard/customwidgetwizard.h"
|
||||||
#include "profilehoverhandler.h"
|
|
||||||
#include "qmakeprojectmanagerconstants.h"
|
#include "qmakeprojectmanagerconstants.h"
|
||||||
#include "qmakeproject.h"
|
#include "qmakeproject.h"
|
||||||
#include "externaleditors.h"
|
#include "externaleditors.h"
|
||||||
@@ -111,7 +110,6 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
|
|||||||
|
|
||||||
ProjectExplorer::KitManager::registerKitInformation(new QmakeKitInformation);
|
ProjectExplorer::KitManager::registerKitInformation(new QmakeKitInformation);
|
||||||
|
|
||||||
addAutoReleasedObject(new ProFileEditorFactory);
|
|
||||||
addAutoReleasedObject(new EmptyProjectWizard);
|
addAutoReleasedObject(new EmptyProjectWizard);
|
||||||
addAutoReleasedObject(new SubdirsProjectWizard);
|
addAutoReleasedObject(new SubdirsProjectWizard);
|
||||||
addAutoReleasedObject(new GuiAppWizard);
|
addAutoReleasedObject(new GuiAppWizard);
|
||||||
@@ -137,7 +135,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
|
|||||||
addAutoReleasedObject(new LinguistExternalEditor);
|
addAutoReleasedObject(new LinguistExternalEditor);
|
||||||
|
|
||||||
addAutoReleasedObject(new ProFileCompletionAssistProvider);
|
addAutoReleasedObject(new ProFileCompletionAssistProvider);
|
||||||
addAutoReleasedObject(new ProFileHoverHandler);
|
addAutoReleasedObject(new ProFileEditorFactory);
|
||||||
|
|
||||||
auto hf = new TextEditor::HighlighterFactory;
|
auto hf = new TextEditor::HighlighterFactory;
|
||||||
hf->setProductType<ProFileHighlighter>();
|
hf->setProductType<ProFileHighlighter>();
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include "qmljseditordocument.h"
|
#include "qmljseditordocument.h"
|
||||||
#include "qmljseditorplugin.h"
|
#include "qmljseditorplugin.h"
|
||||||
#include "qmljsfindreferences.h"
|
#include "qmljsfindreferences.h"
|
||||||
|
#include "qmljshoverhandler.h"
|
||||||
#include "qmljsquickfixassist.h"
|
#include "qmljsquickfixassist.h"
|
||||||
#include "qmloutlinemodel.h"
|
#include "qmloutlinemodel.h"
|
||||||
|
|
||||||
@@ -901,6 +902,8 @@ QmlJSEditorFactory::QmlJSEditorFactory()
|
|||||||
setAutoCompleterCreator([]() { return new AutoCompleter; });
|
setAutoCompleterCreator([]() { return new AutoCompleter; });
|
||||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
||||||
|
|
||||||
|
addHoverHandler(new QmlJSHoverHandler);
|
||||||
|
|
||||||
setEditorActionHandlers(TextEditorActionHandler::Format
|
setEditorActionHandlers(TextEditorActionHandler::Format
|
||||||
| TextEditorActionHandler::UnCommentSelection
|
| TextEditorActionHandler::UnCommentSelection
|
||||||
| TextEditorActionHandler::UnCollapseAll
|
| TextEditorActionHandler::UnCollapseAll
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
#include "qmljseditor.h"
|
#include "qmljseditor.h"
|
||||||
#include "qmljseditorconstants.h"
|
#include "qmljseditorconstants.h"
|
||||||
#include "qmljseditordocument.h"
|
#include "qmljseditordocument.h"
|
||||||
#include "qmljshoverhandler.h"
|
|
||||||
#include "qmlfilewizard.h"
|
#include "qmlfilewizard.h"
|
||||||
#include "jsfilewizard.h"
|
#include "jsfilewizard.h"
|
||||||
#include "qmljsoutline.h"
|
#include "qmljsoutline.h"
|
||||||
@@ -224,7 +223,6 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
m_quickFixAssistProvider = new QmlJSQuickFixAssistProvider;
|
m_quickFixAssistProvider = new QmlJSQuickFixAssistProvider;
|
||||||
addAutoReleasedObject(m_quickFixAssistProvider);
|
addAutoReleasedObject(m_quickFixAssistProvider);
|
||||||
addAutoReleasedObject(new QmlJSCompletionAssistProvider);
|
addAutoReleasedObject(new QmlJSCompletionAssistProvider);
|
||||||
addAutoReleasedObject(new QmlJSHoverHandler);
|
|
||||||
|
|
||||||
errorMessage->clear();
|
errorMessage->clear();
|
||||||
|
|
||||||
|
|||||||
@@ -92,16 +92,11 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlJSHoverHandler::QmlJSHoverHandler(QObject *parent) : BaseHoverHandler(parent), m_modelManager(0)
|
QmlJSHoverHandler::QmlJSHoverHandler() : m_modelManager(0)
|
||||||
{
|
{
|
||||||
m_modelManager = QmlJS::ModelManagerInterface::instance();
|
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,
|
static inline QString getModuleName(const ScopeChain &scopeChain, const Document::Ptr &qmlDocument,
|
||||||
const ObjectValue *value)
|
const ObjectValue *value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,10 +39,6 @@ QT_BEGIN_NAMESPACE
|
|||||||
template <class> class QList;
|
template <class> class QList;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
|
||||||
|
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
|
||||||
|
|
||||||
namespace QmlJS {
|
namespace QmlJS {
|
||||||
class ScopeChain;
|
class ScopeChain;
|
||||||
class Context;
|
class Context;
|
||||||
@@ -59,13 +55,13 @@ class QmlJSEditorWidget;
|
|||||||
class QmlJSHoverHandler : public TextEditor::BaseHoverHandler
|
class QmlJSHoverHandler : public TextEditor::BaseHoverHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QmlJSHoverHandler(QObject *parent = 0);
|
QmlJSHoverHandler();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
bool acceptEditor(Core::IEditor *editor);
|
|
||||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos);
|
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos);
|
||||||
void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point);
|
void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point);
|
||||||
|
|
||||||
|
|||||||
@@ -40,51 +40,31 @@ using namespace Core;
|
|||||||
|
|
||||||
namespace TextEditor {
|
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()
|
BaseHoverHandler::~BaseHoverHandler()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void BaseHoverHandler::editorOpened(Core::IEditor *editor)
|
void BaseHoverHandler::showToolTip(TextEditorWidget *widget, const QPoint &point, int pos)
|
||||||
{
|
{
|
||||||
if (acceptEditor(editor)) {
|
widget->setContextHelpId(QString());
|
||||||
BaseTextEditor *textEditor = qobject_cast<BaseTextEditor *>(editor);
|
|
||||||
if (textEditor) {
|
|
||||||
connect(textEditor, &BaseTextEditor::tooltipRequested,
|
|
||||||
this, &BaseHoverHandler::showToolTip);
|
|
||||||
|
|
||||||
connect(textEditor, &BaseTextEditor::contextHelpIdRequested,
|
process(widget, pos);
|
||||||
this, &BaseHoverHandler::updateContextHelpId);
|
operateTooltip(widget, point);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseHoverHandler::showToolTip(BaseTextEditor *editor, const QPoint &point, int pos)
|
QString BaseHoverHandler::contextHelpId(TextEditorWidget *widget, int pos)
|
||||||
{
|
|
||||||
TextEditorWidget *editorWidget = editor->editorWidget();
|
|
||||||
|
|
||||||
editor->setContextHelpId(QString());
|
|
||||||
|
|
||||||
process(editor, pos);
|
|
||||||
operateTooltip(editorWidget, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseHoverHandler::updateContextHelpId(BaseTextEditor *editor, int pos)
|
|
||||||
{
|
{
|
||||||
// If the tooltip is visible and there is a help match, this match is used to update
|
// 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.
|
// the help id. Otherwise, let the identification process happen.
|
||||||
if (!Utils::ToolTip::isVisible() || !lastHelpItemIdentified().isValid())
|
if (!Utils::ToolTip::isVisible() || !lastHelpItemIdentified().isValid())
|
||||||
process(editor, pos);
|
process(widget, pos);
|
||||||
|
|
||||||
if (lastHelpItemIdentified().isValid())
|
if (lastHelpItemIdentified().isValid())
|
||||||
editor->setContextHelpId(lastHelpItemIdentified().helpId());
|
return lastHelpItemIdentified().helpId();
|
||||||
else
|
return QString();
|
||||||
editor->setContextHelpId(QString()); // Make sure it's an empty string.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseHoverHandler::setToolTip(const QString &tooltip)
|
void BaseHoverHandler::setToolTip(const QString &tooltip)
|
||||||
@@ -136,10 +116,10 @@ void BaseHoverHandler::clear()
|
|||||||
m_lastHelpItemIdentified = HelpItem();
|
m_lastHelpItemIdentified = HelpItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseHoverHandler::process(BaseTextEditor *editor, int pos)
|
void BaseHoverHandler::process(TextEditorWidget *widget, int pos)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
identifyMatch(editor->editorWidget(), pos);
|
identifyMatch(widget, pos);
|
||||||
decorateToolTip();
|
decorateToolTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,9 +46,12 @@ class TEXTEDITOR_EXPORT BaseHoverHandler : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseHoverHandler(QObject *parent = 0);
|
BaseHoverHandler();
|
||||||
~BaseHoverHandler();
|
~BaseHoverHandler();
|
||||||
|
|
||||||
|
QString contextHelpId(TextEditorWidget *widget, int pos);
|
||||||
|
void showToolTip(TextEditorWidget *widget, const QPoint &point, int pos);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setToolTip(const QString &tooltip);
|
void setToolTip(const QString &tooltip);
|
||||||
void appendToolTip(const QString &extension);
|
void appendToolTip(const QString &extension);
|
||||||
@@ -63,14 +66,9 @@ protected:
|
|||||||
const HelpItem &lastHelpItemIdentified() const;
|
const HelpItem &lastHelpItemIdentified() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void editorOpened(Core::IEditor *editor);
|
|
||||||
void showToolTip(BaseTextEditor *editor, const QPoint &point, int pos);
|
|
||||||
void updateContextHelpId(BaseTextEditor *editor, int pos);
|
|
||||||
|
|
||||||
void clear();
|
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 identifyMatch(TextEditorWidget *editorWidget, int pos) = 0;
|
||||||
virtual void decorateToolTip();
|
virtual void decorateToolTip();
|
||||||
virtual void operateTooltip(TextEditorWidget *editorWidget, const QPoint &point);
|
virtual void operateTooltip(TextEditorWidget *editorWidget, const QPoint &point);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "texteditor_p.h"
|
#include "texteditor_p.h"
|
||||||
|
|
||||||
#include "autocompleter.h"
|
#include "autocompleter.h"
|
||||||
|
#include "basehoverhandler.h"
|
||||||
#include "behaviorsettings.h"
|
#include "behaviorsettings.h"
|
||||||
#include "circularclipboard.h"
|
#include "circularclipboard.h"
|
||||||
#include "circularclipboardassist.h"
|
#include "circularclipboardassist.h"
|
||||||
@@ -355,6 +356,7 @@ public:
|
|||||||
void snippetTabOrBacktab(bool forward);
|
void snippetTabOrBacktab(bool forward);
|
||||||
|
|
||||||
RefactorOverlay *m_refactorOverlay;
|
RefactorOverlay *m_refactorOverlay;
|
||||||
|
QString m_contextHelpId;
|
||||||
|
|
||||||
QBasicTimer foldedBlockTimer;
|
QBasicTimer foldedBlockTimer;
|
||||||
int visibleFoldedBlockNumber;
|
int visibleFoldedBlockNumber;
|
||||||
@@ -420,6 +422,7 @@ public:
|
|||||||
|
|
||||||
CodeAssistant m_codeAssistant;
|
CodeAssistant m_codeAssistant;
|
||||||
bool m_assistRelevantContentAdded;
|
bool m_assistRelevantContentAdded;
|
||||||
|
QList<BaseHoverHandler *> m_hoverHandlers; // Not owned
|
||||||
|
|
||||||
QPointer<TextEditorAnimator> m_animator;
|
QPointer<TextEditorAnimator> m_animator;
|
||||||
int m_cursorBlockNumber;
|
int m_cursorBlockNumber;
|
||||||
@@ -2965,8 +2968,13 @@ void TextEditorWidgetPrivate::processTooltipRequest(const QTextCursor &c)
|
|||||||
const QPoint toolTipPoint = q->toolTipPosition(c);
|
const QPoint toolTipPoint = q->toolTipPosition(c);
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
emit q->tooltipOverrideRequested(q, toolTipPoint, c.position(), &handled);
|
emit q->tooltipOverrideRequested(q, toolTipPoint, c.position(), &handled);
|
||||||
if (!handled)
|
if (handled)
|
||||||
emit q->tooltipRequested(toolTipPoint, c.position());
|
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)
|
bool TextEditorWidget::viewportEvent(QEvent *event)
|
||||||
@@ -6737,7 +6745,7 @@ void TextEditorWidgetPrivate::updateCursorPosition()
|
|||||||
.arg(q->textDocument()->tabSettings().columnAt(block.text(),
|
.arg(q->textDocument()->tabSettings().columnAt(block.text(),
|
||||||
column)+1),
|
column)+1),
|
||||||
tr("Line: 9999, Col: 999"));
|
tr("Line: 9999, Col: 999"));
|
||||||
q->clearContentsHelpId();
|
m_contextHelpId.clear();
|
||||||
|
|
||||||
if (!block.isVisible())
|
if (!block.isVisible())
|
||||||
q->ensureCursorVisible();
|
q->ensureCursorVisible();
|
||||||
@@ -6745,10 +6753,25 @@ void TextEditorWidgetPrivate::updateCursorPosition()
|
|||||||
|
|
||||||
QString BaseTextEditor::contextHelpId() const
|
QString BaseTextEditor::contextHelpId() const
|
||||||
{
|
{
|
||||||
if (m_contextHelpId.isEmpty())
|
return editorWidget()->contextHelpId();
|
||||||
emit const_cast<BaseTextEditor*>(this)->contextHelpIdRequested(const_cast<BaseTextEditor*>(this),
|
}
|
||||||
editorWidget()->textCursor().position());
|
|
||||||
return m_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
|
RefactorMarkers TextEditorWidget::refactorMarkers() const
|
||||||
@@ -7209,6 +7232,11 @@ TextEditorFactory::TextEditorFactory(QObject *parent)
|
|||||||
m_duplicatedSupported = true;
|
m_duplicatedSupported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextEditorFactory::~TextEditorFactory()
|
||||||
|
{
|
||||||
|
qDeleteAll(m_hoverHandlers);
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorFactory::setDocumentCreator(const DocumentCreator &creator)
|
void TextEditorFactory::setDocumentCreator(const DocumentCreator &creator)
|
||||||
{
|
{
|
||||||
m_documentCreator = creator;
|
m_documentCreator = creator;
|
||||||
@@ -7258,6 +7286,11 @@ void TextEditorFactory::setEditorActionHandlers(uint optionalActions)
|
|||||||
new TextEditorActionHandler(this, id(), optionalActions);
|
new TextEditorActionHandler(this, id(), optionalActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorFactory::addHoverHandler(BaseHoverHandler *handler)
|
||||||
|
{
|
||||||
|
m_hoverHandlers.append(handler);
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorFactory::setCommentStyle(CommentDefinition::Style style)
|
void TextEditorFactory::setCommentStyle(CommentDefinition::Style style)
|
||||||
{
|
{
|
||||||
m_commentStyle = style;
|
m_commentStyle = style;
|
||||||
@@ -7306,6 +7339,7 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc
|
|||||||
widget->setAutoCompleter(m_autoCompleterCreator());
|
widget->setAutoCompleter(m_autoCompleterCreator());
|
||||||
|
|
||||||
widget->setTextDocument(document);
|
widget->setTextDocument(document);
|
||||||
|
widget->d->m_hoverHandlers = m_hoverHandlers;
|
||||||
|
|
||||||
widget->d->m_codeAssistant.configure(widget);
|
widget->d->m_codeAssistant.configure(widget);
|
||||||
widget->d->m_commentDefinition.setStyle(m_commentStyle);
|
widget->d->m_commentDefinition.setStyle(m_commentStyle);
|
||||||
@@ -7320,11 +7354,6 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc
|
|||||||
editor->markContextMenuRequested(editor, line, menu);
|
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,
|
connect(widget, &TextEditorWidget::markTooltipRequested, editor,
|
||||||
[editor](const QPoint &globalPos, int line) {
|
[editor](const QPoint &globalPos, int line) {
|
||||||
editor->markTooltipRequested(editor, globalPos, line);
|
editor->markTooltipRequested(editor, globalPos, line);
|
||||||
@@ -7333,9 +7362,6 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc
|
|||||||
connect(widget, &TextEditorWidget::activateEditor,
|
connect(widget, &TextEditorWidget::activateEditor,
|
||||||
[editor]() { Core::EditorManager::activateEditor(editor); });
|
[editor]() { Core::EditorManager::activateEditor(editor); });
|
||||||
|
|
||||||
connect(widget, &TextEditorWidget::clearContentsHelpId,
|
|
||||||
[editor]() { editor->setContextHelpId(QString()); });
|
|
||||||
|
|
||||||
widget->finalizeInitialization();
|
widget->finalizeInitialization();
|
||||||
editor->finalizeInitialization();
|
editor->finalizeInitialization();
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ namespace Core { class MimeType; }
|
|||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
|
class BaseHoverHandler;
|
||||||
class TabSettings;
|
class TabSettings;
|
||||||
class RefactorOverlay;
|
class RefactorOverlay;
|
||||||
struct RefactorMarker;
|
struct RefactorMarker;
|
||||||
@@ -160,6 +161,7 @@ public:
|
|||||||
QWidget *toolBar();
|
QWidget *toolBar();
|
||||||
|
|
||||||
QString contextHelpId() const; // from IContext
|
QString contextHelpId() const; // from IContext
|
||||||
|
void setContextHelpId(const QString &id);
|
||||||
|
|
||||||
int currentLine() const;
|
int currentLine() const;
|
||||||
int currentColumn() const;
|
int currentColumn() const;
|
||||||
@@ -196,9 +198,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void markRequested(TextEditor::BaseTextEditor *editor, int line, TextEditor::BaseTextEditor::MarkRequestKind kind);
|
void markRequested(TextEditor::BaseTextEditor *editor, int line, TextEditor::BaseTextEditor::MarkRequestKind kind);
|
||||||
void markContextMenuRequested(TextEditor::BaseTextEditor *editor, int line, QMenu *menu);
|
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 markTooltipRequested(TextEditor::BaseTextEditor *editor, const QPoint &globalPos, int line);
|
||||||
void contextHelpIdRequested(TextEditor::BaseTextEditor *editor, int position);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class TextEditorFactory;
|
friend class TextEditorFactory;
|
||||||
@@ -569,6 +569,9 @@ public:
|
|||||||
QChar characterAt(int pos) const;
|
QChar characterAt(int pos) const;
|
||||||
QString textAt(int from, int to) const;
|
QString textAt(int from, int to) const;
|
||||||
|
|
||||||
|
QString contextHelpId();
|
||||||
|
void setContextHelpId(const QString &id);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*!
|
/*!
|
||||||
Reimplement this function to enable code navigation.
|
Reimplement this function to enable code navigation.
|
||||||
@@ -603,7 +606,6 @@ signals:
|
|||||||
void tooltipRequested(const QPoint &globalPos, int position);
|
void tooltipRequested(const QPoint &globalPos, int position);
|
||||||
void markTooltipRequested(const QPoint &globalPos, int line);
|
void markTooltipRequested(const QPoint &globalPos, int line);
|
||||||
void activateEditor();
|
void activateEditor();
|
||||||
void clearContentsHelpId();
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void slotCursorPositionChanged(); // Used in VcsBase
|
virtual void slotCursorPositionChanged(); // Used in VcsBase
|
||||||
@@ -626,6 +628,7 @@ class TEXTEDITOR_EXPORT TextEditorFactory : public Core::IEditorFactory
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
TextEditorFactory(QObject *parent = 0);
|
TextEditorFactory(QObject *parent = 0);
|
||||||
|
~TextEditorFactory();
|
||||||
|
|
||||||
typedef std::function<BaseTextEditor *()> EditorCreator;
|
typedef std::function<BaseTextEditor *()> EditorCreator;
|
||||||
typedef std::function<TextDocument *()> DocumentCreator;
|
typedef std::function<TextDocument *()> DocumentCreator;
|
||||||
@@ -645,6 +648,8 @@ public:
|
|||||||
void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
|
void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
|
||||||
void setEditorActionHandlers(uint optionalActions);
|
void setEditorActionHandlers(uint optionalActions);
|
||||||
|
|
||||||
|
void addHoverHandler(BaseHoverHandler *handler);
|
||||||
|
|
||||||
void setCommentStyle(Utils::CommentDefinition::Style style);
|
void setCommentStyle(Utils::CommentDefinition::Style style);
|
||||||
void setDuplicatedSupported(bool on);
|
void setDuplicatedSupported(bool on);
|
||||||
|
|
||||||
@@ -664,6 +669,7 @@ private:
|
|||||||
IndenterCreator m_indenterCreator;
|
IndenterCreator m_indenterCreator;
|
||||||
SyntaxHighLighterCreator m_syntaxHighlighterCreator;
|
SyntaxHighLighterCreator m_syntaxHighlighterCreator;
|
||||||
Utils::CommentDefinition::Style m_commentStyle;
|
Utils::CommentDefinition::Style m_commentStyle;
|
||||||
|
QList<BaseHoverHandler *> m_hoverHandlers; // owned
|
||||||
bool m_duplicatedSupported;
|
bool m_duplicatedSupported;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user