forked from qt-creator/qt-creator
TextEditor: Move some hover handler operation from Editor to Widget
Change-Id: Ie54bf52d3f89c76f379d20c4807b1e252af51505 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -40,10 +40,13 @@
|
|||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
using namespace CppEditor::Internal;
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
using namespace TextEditor;
|
||||||
|
|
||||||
CppHoverHandler::CppHoverHandler(QObject *parent) : BaseHoverHandler(parent)
|
namespace CppEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
CppHoverHandler::CppHoverHandler()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CppHoverHandler::~CppHoverHandler()
|
CppHoverHandler::~CppHoverHandler()
|
||||||
@@ -54,19 +57,15 @@ bool CppHoverHandler::acceptEditor(IEditor *editor)
|
|||||||
return editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID;
|
return editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
|
void CppHoverHandler::identifyMatch(BaseTextEditorWidget *editorWidget, int pos)
|
||||||
{
|
{
|
||||||
using namespace TextEditor;
|
if (!editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
||||||
BaseTextEditorWidget *textEditor = qobject_cast<BaseTextEditorWidget *>(editor->widget());
|
setToolTip(editorWidget->extraSelectionTooltip(pos));
|
||||||
QTC_ASSERT(textEditor, return);
|
|
||||||
|
|
||||||
if (!textEditor->extraSelectionTooltip(pos).isEmpty()) {
|
|
||||||
setToolTip(textEditor->extraSelectionTooltip(pos));
|
|
||||||
} else {
|
} else {
|
||||||
QTextCursor tc(textEditor->document());
|
QTextCursor tc(editorWidget->document());
|
||||||
tc.setPosition(pos);
|
tc.setPosition(pos);
|
||||||
|
|
||||||
CppElementEvaluator evaluator(textEditor);
|
CppElementEvaluator evaluator(editorWidget);
|
||||||
evaluator.setTextCursor(tc);
|
evaluator.setTextCursor(tc);
|
||||||
evaluator.execute();
|
evaluator.execute();
|
||||||
if (evaluator.hasDiagnosis()) {
|
if (evaluator.hasDiagnosis()) {
|
||||||
@@ -83,9 +82,9 @@ void CppHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
|
|||||||
if (helpId.isEmpty())
|
if (helpId.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const QMap<QString, QUrl> helpLinks = Core::HelpManager::linksForIdentifier(helpId);
|
const QMap<QString, QUrl> helpLinks = HelpManager::linksForIdentifier(helpId);
|
||||||
if (!helpLinks.isEmpty()) {
|
if (!helpLinks.isEmpty()) {
|
||||||
setLastHelpItemIdentified(TextEditor::HelpItem(helpId,
|
setLastHelpItemIdentified(HelpItem(helpId,
|
||||||
cppElement->helpMark,
|
cppElement->helpMark,
|
||||||
cppElement->helpCategory,
|
cppElement->helpCategory,
|
||||||
helpLinks));
|
helpLinks));
|
||||||
@@ -104,29 +103,32 @@ void CppHoverHandler::decorateToolTip()
|
|||||||
if (isDiagnosticTooltip())
|
if (isDiagnosticTooltip())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const TextEditor::HelpItem &help = lastHelpItemIdentified();
|
const HelpItem &help = lastHelpItemIdentified();
|
||||||
if (help.isValid()) {
|
if (help.isValid()) {
|
||||||
// If Qt is built with a namespace, we still show the tip without it, as
|
// If Qt is built with a namespace, we still show the tip without it, as
|
||||||
// it is in the docs and for consistency with the doc extraction mechanism.
|
// it is in the docs and for consistency with the doc extraction mechanism.
|
||||||
const TextEditor::HelpItem::Category category = help.category();
|
const HelpItem::Category category = help.category();
|
||||||
const QString &contents = help.extractContent(false);
|
const QString &contents = help.extractContent(false);
|
||||||
if (!contents.isEmpty()) {
|
if (!contents.isEmpty()) {
|
||||||
if (category == TextEditor::HelpItem::ClassOrNamespace)
|
if (category == HelpItem::ClassOrNamespace)
|
||||||
setToolTip(help.helpId() + contents);
|
setToolTip(help.helpId() + contents);
|
||||||
else
|
else
|
||||||
setToolTip(contents);
|
setToolTip(contents);
|
||||||
} else if (category == TextEditor::HelpItem::Typedef ||
|
} else if (category == HelpItem::Typedef ||
|
||||||
category == TextEditor::HelpItem::Enum ||
|
category == HelpItem::Enum ||
|
||||||
category == TextEditor::HelpItem::ClassOrNamespace) {
|
category == HelpItem::ClassOrNamespace) {
|
||||||
// This approach is a bit limited since it cannot be used for functions
|
// This approach is a bit limited since it cannot be used for functions
|
||||||
// because the help id doesn't really help in that case.
|
// because the help id doesn't really help in that case.
|
||||||
QString prefix;
|
QString prefix;
|
||||||
if (category == TextEditor::HelpItem::Typedef)
|
if (category == HelpItem::Typedef)
|
||||||
prefix = QLatin1String("typedef ");
|
prefix = QLatin1String("typedef ");
|
||||||
else if (category == TextEditor::HelpItem::Enum)
|
else if (category == HelpItem::Enum)
|
||||||
prefix = QLatin1String("enum ");
|
prefix = QLatin1String("enum ");
|
||||||
setToolTip(prefix + help.helpId());
|
setToolTip(prefix + help.helpId());
|
||||||
}
|
}
|
||||||
addF1ToToolTip();
|
addF1ToToolTip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace CppEditor
|
||||||
|
|||||||
@@ -32,25 +32,18 @@
|
|||||||
|
|
||||||
#include <texteditor/basehoverhandler.h>
|
#include <texteditor/basehoverhandler.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
|
||||||
|
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CppHoverHandler : public TextEditor::BaseHoverHandler
|
class CppHoverHandler : public TextEditor::BaseHoverHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
CppHoverHandler(QObject *parent = 0);
|
CppHoverHandler();
|
||||||
virtual ~CppHoverHandler();
|
virtual ~CppHoverHandler();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool acceptEditor(Core::IEditor *editor);
|
virtual bool acceptEditor(Core::IEditor *editor);
|
||||||
virtual void identifyMatch(TextEditor::BaseTextEditor *editor, int pos);
|
virtual void identifyMatch(TextEditor::BaseTextEditorWidget *editorWidget, int pos);
|
||||||
virtual void decorateToolTip();
|
virtual void decorateToolTip();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ bool GlslHoverHandler::acceptEditor(IEditor *editor)
|
|||||||
return editor->context().contains(Constants::C_GLSLEDITOR_ID);
|
return editor->context().contains(Constants::C_GLSLEDITOR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlslHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
|
void GlslHoverHandler::identifyMatch(TextEditor::BaseTextEditorWidget *editorWidget, int pos)
|
||||||
{
|
{
|
||||||
if (!editor->editorWidget()->extraSelectionTooltip(pos).isEmpty())
|
if (!editorWidget->extraSelectionTooltip(pos).isEmpty())
|
||||||
setToolTip(editor->editorWidget()->extraSelectionTooltip(pos));
|
setToolTip(editorWidget->extraSelectionTooltip(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlslHoverHandler::decorateToolTip()
|
void GlslHoverHandler::decorateToolTip()
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool acceptEditor(Core::IEditor *editor);
|
virtual bool acceptEditor(Core::IEditor *editor);
|
||||||
virtual void identifyMatch(TextEditor::BaseTextEditor *editor, int pos);
|
virtual void identifyMatch(TextEditor::BaseTextEditorWidget *editorWidget, int pos);
|
||||||
virtual void decorateToolTip();
|
virtual void decorateToolTip();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,32 +45,27 @@ using namespace Core;
|
|||||||
namespace QmakeProjectManager {
|
namespace QmakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
ProFileHoverHandler::ProFileHoverHandler(QObject *parent)
|
ProFileHoverHandler::ProFileHoverHandler()
|
||||||
: BaseHoverHandler(parent),
|
: m_manualKind(UnknownManual)
|
||||||
m_manualKind(UnknownManual)
|
|
||||||
{
|
{
|
||||||
ProFileCompletionAssistProvider *pcap
|
ProFileCompletionAssistProvider *pcap
|
||||||
= ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>();
|
= ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>();
|
||||||
m_keywords = TextEditor::Keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
|
m_keywords = TextEditor::Keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
|
||||||
}
|
}
|
||||||
|
|
||||||
ProFileHoverHandler::~ProFileHoverHandler()
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool ProFileHoverHandler::acceptEditor(IEditor *editor)
|
bool ProFileHoverHandler::acceptEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
return editor->context().contains(Constants::PROFILE_EDITOR_ID);
|
return editor->context().contains(Constants::PROFILE_EDITOR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProFileHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
|
void ProFileHoverHandler::identifyMatch(TextEditor::BaseTextEditorWidget *editorWidget, int pos)
|
||||||
{
|
{
|
||||||
m_docFragment.clear();
|
m_docFragment.clear();
|
||||||
m_manualKind = UnknownManual;
|
m_manualKind = UnknownManual;
|
||||||
if (TextEditor::BaseTextEditorWidget *widget = editor->editorWidget()) {
|
if (!editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
||||||
if (!widget->extraSelectionTooltip(pos).isEmpty()) {
|
setToolTip(editorWidget->extraSelectionTooltip(pos));
|
||||||
setToolTip(widget->extraSelectionTooltip(pos));
|
|
||||||
} else {
|
} else {
|
||||||
QTextDocument *document = widget->document();
|
QTextDocument *document = editorWidget->document();
|
||||||
QTextBlock block = document->findBlock(pos);
|
QTextBlock block = document->findBlock(pos);
|
||||||
identifyQMakeKeyword(block.text(), pos - block.position());
|
identifyQMakeKeyword(block.text(), pos - block.position());
|
||||||
|
|
||||||
@@ -85,7 +80,6 @@ void ProFileHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int
|
|||||||
TextEditor::HelpItem::Unknown));
|
TextEditor::HelpItem::Unknown));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProFileHoverHandler::identifyQMakeKeyword(const QString &text, int pos)
|
void ProFileHoverHandler::identifyQMakeKeyword(const QString &text, int pos)
|
||||||
|
|||||||
@@ -31,18 +31,11 @@
|
|||||||
#define PROFILEHOVERHANDLER_H
|
#define PROFILEHOVERHANDLER_H
|
||||||
|
|
||||||
#include <texteditor/basehoverhandler.h>
|
#include <texteditor/basehoverhandler.h>
|
||||||
#include <texteditor/codeassist/keywordscompletionassist.h>
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QUrl;
|
class QUrl;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
|
||||||
|
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
namespace QmakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -50,15 +43,14 @@ class ProFileHoverHandler : public TextEditor::BaseHoverHandler
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ProFileHoverHandler(QObject *parent = 0);
|
ProFileHoverHandler();
|
||||||
virtual ~ProFileHoverHandler();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void creatorHelpRequested(const QUrl &url);
|
void creatorHelpRequested(const QUrl &url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool acceptEditor(Core::IEditor *editor);
|
virtual bool acceptEditor(Core::IEditor *editor);
|
||||||
virtual void identifyMatch(TextEditor::BaseTextEditor *editor, int pos);
|
virtual void identifyMatch(TextEditor::BaseTextEditorWidget *editorWidget, int pos);
|
||||||
void identifyQMakeKeyword(const QString &text, int pos);
|
void identifyQMakeKeyword(const QString &text, int pos);
|
||||||
|
|
||||||
enum ManualKind {
|
enum ManualKind {
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
|
|||||||
addAutoReleasedObject(new LinguistExternalEditor);
|
addAutoReleasedObject(new LinguistExternalEditor);
|
||||||
|
|
||||||
addAutoReleasedObject(new ProFileCompletionAssistProvider);
|
addAutoReleasedObject(new ProFileCompletionAssistProvider);
|
||||||
addAutoReleasedObject(new ProFileHoverHandler(this));
|
addAutoReleasedObject(new ProFileHoverHandler);
|
||||||
|
|
||||||
auto hf = new TextEditor::HighlighterFactory;
|
auto hf = new TextEditor::HighlighterFactory;
|
||||||
hf->setProductType<ProFileHighlighter>();
|
hf->setProductType<ProFileHighlighter>();
|
||||||
|
|||||||
@@ -226,8 +226,7 @@ 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);
|
||||||
addAutoReleasedObject(new HoverHandler);
|
|
||||||
|
|
||||||
errorMessage->clear();
|
errorMessage->clear();
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -91,12 +92,12 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HoverHandler::HoverHandler(QObject *parent) : BaseHoverHandler(parent), m_modelManager(0)
|
QmlJSHoverHandler::QmlJSHoverHandler(QObject *parent) : BaseHoverHandler(parent), m_modelManager(0)
|
||||||
{
|
{
|
||||||
m_modelManager = QmlJS::ModelManagerInterface::instance();
|
m_modelManager = QmlJS::ModelManagerInterface::instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HoverHandler::acceptEditor(IEditor *editor)
|
bool QmlJSHoverHandler::acceptEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
return editor->context().contains(Constants::C_QMLJSEDITOR_ID);
|
return editor->context().contains(Constants::C_QMLJSEDITOR_ID);
|
||||||
}
|
}
|
||||||
@@ -147,7 +148,7 @@ static inline QString getModuleName(const ScopeChain &scopeChain, const Document
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HoverHandler::setQmlTypeHelp(const ScopeChain &scopeChain, const Document::Ptr &qmlDocument,
|
bool QmlJSHoverHandler::setQmlTypeHelp(const ScopeChain &scopeChain, const Document::Ptr &qmlDocument,
|
||||||
const ObjectValue *value, const QStringList &qName)
|
const ObjectValue *value, const QStringList &qName)
|
||||||
{
|
{
|
||||||
QString moduleName = getModuleName(scopeChain, qmlDocument, value);
|
QString moduleName = getModuleName(scopeChain, qmlDocument, value);
|
||||||
@@ -175,21 +176,19 @@ bool HoverHandler::setQmlTypeHelp(const ScopeChain &scopeChain, const Document::
|
|||||||
break;
|
break;
|
||||||
return false;
|
return false;
|
||||||
} while (0);
|
} while (0);
|
||||||
setLastHelpItemIdentified(TextEditor::HelpItem(helpId, qName.join(QLatin1Char('.')),
|
setLastHelpItemIdentified(HelpItem(helpId, qName.join(QLatin1Char('.')), HelpItem::QmlComponent));
|
||||||
TextEditor::HelpItem::QmlComponent));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
|
void QmlJSHoverHandler::identifyMatch(BaseTextEditorWidget *editorWidget, int pos)
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
if (!m_modelManager)
|
if (!m_modelManager)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QmlJSEditorWidget *qmlEditor = qobject_cast<QmlJSEditorWidget *>(editor->widget());
|
QmlJSEditorWidget *qmlEditor = qobject_cast<QmlJSEditorWidget *>(editorWidget);
|
||||||
if (!qmlEditor)
|
QTC_ASSERT(qmlEditor, return);
|
||||||
return;
|
|
||||||
|
|
||||||
const QmlJSTools::SemanticInfo &semanticInfo = qmlEditor->qmlJsEditorDocument()->semanticInfo();
|
const QmlJSTools::SemanticInfo &semanticInfo = qmlEditor->qmlJsEditorDocument()->semanticInfo();
|
||||||
if (!semanticInfo.isValid() || qmlEditor->qmlJsEditorDocument()->isSemanticInfoOutdated())
|
if (!semanticInfo.isValid() || qmlEditor->qmlJsEditorDocument()->isSemanticInfoOutdated())
|
||||||
@@ -254,10 +253,10 @@ void HoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
|
|||||||
setQmlHelpItem(scopeChain, qmlDocument, node);
|
setQmlHelpItem(scopeChain, qmlDocument, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HoverHandler::matchDiagnosticMessage(QmlJSEditorWidget *qmlEditor, int pos)
|
bool QmlJSHoverHandler::matchDiagnosticMessage(QmlJSEditorWidget *qmlEditor, int pos)
|
||||||
{
|
{
|
||||||
foreach (const QTextEdit::ExtraSelection &sel,
|
foreach (const QTextEdit::ExtraSelection &sel,
|
||||||
qmlEditor->extraSelections(TextEditor::BaseTextEditorWidget::CodeWarningsSelection)) {
|
qmlEditor->extraSelections(BaseTextEditorWidget::CodeWarningsSelection)) {
|
||||||
if (pos >= sel.cursor.selectionStart() && pos <= sel.cursor.selectionEnd()) {
|
if (pos >= sel.cursor.selectionStart() && pos <= sel.cursor.selectionEnd()) {
|
||||||
setToolTip(sel.format.toolTip());
|
setToolTip(sel.format.toolTip());
|
||||||
return true;
|
return true;
|
||||||
@@ -273,7 +272,7 @@ bool HoverHandler::matchDiagnosticMessage(QmlJSEditorWidget *qmlEditor, int pos)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HoverHandler::matchColorItem(const ScopeChain &scopeChain,
|
bool QmlJSHoverHandler::matchColorItem(const ScopeChain &scopeChain,
|
||||||
const Document::Ptr &qmlDocument,
|
const Document::Ptr &qmlDocument,
|
||||||
const QList<AST::Node *> &astPath,
|
const QList<AST::Node *> &astPath,
|
||||||
unsigned pos)
|
unsigned pos)
|
||||||
@@ -331,7 +330,7 @@ bool HoverHandler::matchColorItem(const ScopeChain &scopeChain,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HoverHandler::handleOrdinaryMatch(const ScopeChain &scopeChain, AST::Node *node)
|
void QmlJSHoverHandler::handleOrdinaryMatch(const ScopeChain &scopeChain, AST::Node *node)
|
||||||
{
|
{
|
||||||
if (node && !(AST::cast<AST::StringLiteral *>(node) != 0 ||
|
if (node && !(AST::cast<AST::StringLiteral *>(node) != 0 ||
|
||||||
AST::cast<AST::NumericLiteral *>(node) != 0)) {
|
AST::cast<AST::NumericLiteral *>(node) != 0)) {
|
||||||
@@ -340,7 +339,7 @@ void HoverHandler::handleOrdinaryMatch(const ScopeChain &scopeChain, AST::Node *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HoverHandler::handleImport(const ScopeChain &scopeChain, AST::UiImport *node)
|
void QmlJSHoverHandler::handleImport(const ScopeChain &scopeChain, AST::UiImport *node)
|
||||||
{
|
{
|
||||||
const Imports *imports = scopeChain.context()->imports(scopeChain.document().data());
|
const Imports *imports = scopeChain.context()->imports(scopeChain.document().data());
|
||||||
if (!imports)
|
if (!imports)
|
||||||
@@ -368,22 +367,22 @@ void HoverHandler::handleImport(const ScopeChain &scopeChain, AST::UiImport *nod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HoverHandler::reset()
|
void QmlJSHoverHandler::reset()
|
||||||
{
|
{
|
||||||
m_colorTip = QColor();
|
m_colorTip = QColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HoverHandler::operateTooltip(TextEditor::BaseTextEditor *editor, const QPoint &point)
|
void QmlJSHoverHandler::operateTooltip(BaseTextEditorWidget *editorWidget, const QPoint &point)
|
||||||
{
|
{
|
||||||
if (toolTip().isEmpty())
|
if (toolTip().isEmpty())
|
||||||
Utils::ToolTip::hide();
|
Utils::ToolTip::hide();
|
||||||
else if (m_colorTip.isValid())
|
else if (m_colorTip.isValid())
|
||||||
Utils::ToolTip::show(point, Utils::ColorContent(m_colorTip), editor->widget());
|
Utils::ToolTip::show(point, Utils::ColorContent(m_colorTip), editorWidget);
|
||||||
else
|
else
|
||||||
Utils::ToolTip::show(point, Utils::TextContent(toolTip()), editor->widget());
|
Utils::ToolTip::show(point, Utils::TextContent(toolTip()), editorWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HoverHandler::prettyPrintTooltip(const QmlJS::Value *value,
|
void QmlJSHoverHandler::prettyPrintTooltip(const QmlJS::Value *value,
|
||||||
const QmlJS::ContextPtr &context)
|
const QmlJS::ContextPtr &context)
|
||||||
{
|
{
|
||||||
if (! value)
|
if (! value)
|
||||||
@@ -451,7 +450,7 @@ static const ObjectValue *isMember(const ScopeChain &scopeChain,
|
|||||||
return owningObject;
|
return owningObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HoverHandler::setQmlHelpItem(const ScopeChain &scopeChain,
|
bool QmlJSHoverHandler::setQmlHelpItem(const ScopeChain &scopeChain,
|
||||||
const Document::Ptr &qmlDocument,
|
const Document::Ptr &qmlDocument,
|
||||||
AST::Node *node)
|
AST::Node *node)
|
||||||
{
|
{
|
||||||
@@ -492,8 +491,7 @@ bool HoverHandler::setQmlHelpItem(const ScopeChain &scopeChain,
|
|||||||
helpId.clear();
|
helpId.clear();
|
||||||
} while (0);
|
} while (0);
|
||||||
if (!helpId.isEmpty()) {
|
if (!helpId.isEmpty()) {
|
||||||
setLastHelpItemIdentified(
|
setLastHelpItemIdentified(HelpItem(helpId, name, HelpItem::QmlProperty));
|
||||||
TextEditor::HelpItem(helpId, name, TextEditor::HelpItem::QmlProperty));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,23 +52,22 @@ class ObjectValue;
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class QmlJSEditorWidget;
|
class QmlJSEditorWidget;
|
||||||
|
|
||||||
class HoverHandler : public TextEditor::BaseHoverHandler
|
class QmlJSHoverHandler : public TextEditor::BaseHoverHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
HoverHandler(QObject *parent = 0);
|
QmlJSHoverHandler(QObject *parent = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
virtual bool acceptEditor(Core::IEditor *editor);
|
bool acceptEditor(Core::IEditor *editor);
|
||||||
virtual void identifyMatch(TextEditor::BaseTextEditor *editor, int pos);
|
void identifyMatch(TextEditor::BaseTextEditorWidget *editorWidget, int pos);
|
||||||
virtual void operateTooltip(TextEditor::BaseTextEditor *editor, const QPoint &point);
|
void operateTooltip(TextEditor::BaseTextEditorWidget *editorWidget, const QPoint &point);
|
||||||
|
|
||||||
bool matchDiagnosticMessage(QmlJSEditorWidget *qmlEditor, int pos);
|
bool matchDiagnosticMessage(QmlJSEditorWidget *qmlEditor, int pos);
|
||||||
bool matchColorItem(const QmlJS::ScopeChain &lookupContext,
|
bool matchColorItem(const QmlJS::ScopeChain &lookupContext,
|
||||||
|
|||||||
@@ -40,18 +40,11 @@ using namespace Core;
|
|||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
static BaseTextEditorWidget *baseTextEditor(BaseTextEditor *editor)
|
|
||||||
{
|
|
||||||
if (!editor)
|
|
||||||
return 0;
|
|
||||||
return qobject_cast<BaseTextEditorWidget *>(editor->widget());
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseHoverHandler::BaseHoverHandler(QObject *parent) : QObject(parent), m_diagnosticTooltip(false)
|
BaseHoverHandler::BaseHoverHandler(QObject *parent) : QObject(parent), m_diagnosticTooltip(false)
|
||||||
{
|
{
|
||||||
// Listen for editor opened events in order to connect to tooltip/helpid requests
|
// Listen for editor opened events in order to connect to tooltip/helpid requests
|
||||||
connect(Core::EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)),
|
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
||||||
this, SLOT(editorOpened(Core::IEditor*)));
|
this, &BaseHoverHandler::editorOpened);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseHoverHandler::~BaseHoverHandler()
|
BaseHoverHandler::~BaseHoverHandler()
|
||||||
@@ -62,33 +55,27 @@ void BaseHoverHandler::editorOpened(Core::IEditor *editor)
|
|||||||
if (acceptEditor(editor)) {
|
if (acceptEditor(editor)) {
|
||||||
BaseTextEditor *textEditor = qobject_cast<BaseTextEditor *>(editor);
|
BaseTextEditor *textEditor = qobject_cast<BaseTextEditor *>(editor);
|
||||||
if (textEditor) {
|
if (textEditor) {
|
||||||
connect(textEditor, SIGNAL(tooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)),
|
connect(textEditor, &BaseTextEditor::tooltipRequested,
|
||||||
this, SLOT(showToolTip(TextEditor::BaseTextEditor*,QPoint,int)));
|
this, &BaseHoverHandler::showToolTip);
|
||||||
|
|
||||||
connect(textEditor, SIGNAL(contextHelpIdRequested(TextEditor::BaseTextEditor*,int)),
|
connect(textEditor, &BaseTextEditor::contextHelpIdRequested,
|
||||||
this, SLOT(updateContextHelpId(TextEditor::BaseTextEditor*,int)));
|
this, &BaseHoverHandler::updateContextHelpId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseHoverHandler::showToolTip(TextEditor::BaseTextEditor *editor, const QPoint &point, int pos)
|
void BaseHoverHandler::showToolTip(BaseTextEditor *editor, const QPoint &point, int pos)
|
||||||
{
|
{
|
||||||
BaseTextEditorWidget *baseEditor = baseTextEditor(editor);
|
BaseTextEditorWidget *editorWidget = editor->editorWidget();
|
||||||
if (!baseEditor)
|
|
||||||
return;
|
|
||||||
|
|
||||||
editor->setContextHelpId(QString());
|
editor->setContextHelpId(QString());
|
||||||
|
|
||||||
process(editor, pos);
|
process(editor, pos);
|
||||||
operateTooltip(editor, point);
|
operateTooltip(editorWidget, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseHoverHandler::updateContextHelpId(TextEditor::BaseTextEditor *editor, int pos)
|
void BaseHoverHandler::updateContextHelpId(BaseTextEditor *editor, int pos)
|
||||||
{
|
{
|
||||||
BaseTextEditorWidget *baseEditor = baseTextEditor(editor);
|
|
||||||
if (!baseEditor)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 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())
|
||||||
@@ -152,7 +139,7 @@ void BaseHoverHandler::clear()
|
|||||||
void BaseHoverHandler::process(BaseTextEditor *editor, int pos)
|
void BaseHoverHandler::process(BaseTextEditor *editor, int pos)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
identifyMatch(editor, pos);
|
identifyMatch(editor->editorWidget(), pos);
|
||||||
decorateToolTip();
|
decorateToolTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,12 +158,12 @@ void BaseHoverHandler::decorateToolTip()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseHoverHandler::operateTooltip(BaseTextEditor *editor, const QPoint &point)
|
void BaseHoverHandler::operateTooltip(BaseTextEditorWidget *editorWidget, const QPoint &point)
|
||||||
{
|
{
|
||||||
if (m_toolTip.isEmpty())
|
if (m_toolTip.isEmpty())
|
||||||
Utils::ToolTip::hide();
|
Utils::ToolTip::hide();
|
||||||
else
|
else
|
||||||
Utils::ToolTip::show(point, Utils::TextContent(m_toolTip), editor->widget());
|
Utils::ToolTip::show(point, Utils::TextContent(m_toolTip), editorWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|||||||
@@ -32,13 +32,7 @@
|
|||||||
|
|
||||||
#include "texteditor_global.h"
|
#include "texteditor_global.h"
|
||||||
#include "helpitem.h"
|
#include "helpitem.h"
|
||||||
|
#include <texteditor/codeassist/keywordscompletionassist.h>
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QPoint;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
namespace Core { class IEditor; }
|
||||||
|
|
||||||
@@ -55,11 +49,6 @@ public:
|
|||||||
BaseHoverHandler(QObject *parent = 0);
|
BaseHoverHandler(QObject *parent = 0);
|
||||||
~BaseHoverHandler();
|
~BaseHoverHandler();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void editorOpened(Core::IEditor *editor);
|
|
||||||
void showToolTip(TextEditor::BaseTextEditor *editor, const QPoint &point, int pos);
|
|
||||||
void updateContextHelpId(TextEditor::BaseTextEditor *editor, int pos);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setToolTip(const QString &tooltip);
|
void setToolTip(const QString &tooltip);
|
||||||
void appendToolTip(const QString &extension);
|
void appendToolTip(const QString &extension);
|
||||||
@@ -74,13 +63,17 @@ 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(BaseTextEditor *editor, int pos);
|
||||||
|
|
||||||
virtual bool acceptEditor(Core::IEditor *editor) = 0;
|
virtual bool acceptEditor(Core::IEditor *editor) = 0;
|
||||||
virtual void identifyMatch(BaseTextEditor *editor, int pos) = 0;
|
virtual void identifyMatch(BaseTextEditorWidget *editorWidget, int pos) = 0;
|
||||||
virtual void decorateToolTip();
|
virtual void decorateToolTip();
|
||||||
virtual void operateTooltip(BaseTextEditor *editor, const QPoint &point);
|
virtual void operateTooltip(BaseTextEditorWidget *editorWidget, const QPoint &point);
|
||||||
|
|
||||||
bool m_diagnosticTooltip;
|
bool m_diagnosticTooltip;
|
||||||
QString m_toolTip;
|
QString m_toolTip;
|
||||||
|
|||||||
Reference in New Issue
Block a user