Commit d3f43f5d authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Show the error message in a tooltip.

parent 30eba90d
......@@ -446,20 +446,24 @@ void ScriptEditor::updateDocumentNow()
QTextEdit::ExtraSelection sel;
foreach (const JavaScriptParser::DiagnosticMessage &d, parser.diagnosticMessages()) {
if (d.isWarning())
continue;
m_diagnosticMessages = parser.diagnosticMessages();
int line = d.line;
int column = d.column;
foreach (const JavaScriptParser::DiagnosticMessage &d, m_diagnosticMessages) {
int line = d.loc.startLine;
int column = d.loc.startColumn;
if (column == 0)
column = 1;
QTextCursor c(document()->findBlockByNumber(line - 1));
sel.cursor = c;
sel.cursor.setPosition(c.position() + column - 1);
sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
if (sel.cursor.atBlockEnd())
sel.cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
else
sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
sel.format = errorFormat;
selections.append(sel);
......
......@@ -32,6 +32,7 @@
#include <texteditor/basetexteditor.h>
#include <parser/javascriptast_p.h>
#include <parser/javascriptparser_p.h>
QT_BEGIN_NAMESPACE
class QComboBox;
......@@ -51,6 +52,8 @@ class ScriptEditor;
class ScriptEditorEditable : public TextEditor::BaseTextEditorEditable
{
Q_OBJECT
public:
ScriptEditorEditable(ScriptEditor *, const QList<int> &);
QList<int> context() const;
......@@ -94,6 +97,9 @@ public:
QList<Declaration> declarations() const;
QStringList words() const;
QList<JavaScriptParser::DiagnosticMessage> diagnosticMessages() const
{ return m_diagnosticMessages; }
public slots:
virtual void setFontSettings(const TextEditor::FontSettings &);
......@@ -126,6 +132,7 @@ private:
QList<Declaration> m_declarations;
QStringList m_words;
QMap<QString, QList<JavaScript::AST::SourceLocation> > m_ids; // ### use QMultiMap
QList<JavaScriptParser::DiagnosticMessage> m_diagnosticMessages;
};
} // namespace Internal
......
......@@ -19,13 +19,15 @@ duieditorplugin.h \
duihighlighter.h \
duieditoractionhandler.h \
duicodecompletion.h \
duieditorconstants.h
duieditorconstants.h \
duihoverhandler.h
SOURCES += duieditor.cpp \
duieditorfactory.cpp \
duieditorplugin.cpp \
duihighlighter.cpp \
duieditoractionhandler.cpp \
duicodecompletion.cpp
duicodecompletion.cpp \
duihoverhandler.cpp
RESOURCES += duieditor.qrc
......@@ -34,6 +34,7 @@
#include "duieditorconstants.h"
#include "duieditorfactory.h"
#include "duicodecompletion.h"
#include "duihoverhandler.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
......@@ -112,6 +113,8 @@ bool DuiEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
m_completion = new DuiCodeCompletion();
addAutoReleasedObject(m_completion);
addAutoReleasedObject(new DuiHoverHandler());
// Restore settings
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("CppTools")); // ### FIXME:
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#include "duihoverhandler.h"
#include "duieditor.h"
#include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h>
#include <debugger/debuggerconstants.h>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QSettings>
#include <QtGui/QToolTip>
#include <QtGui/QTextCursor>
#include <QtGui/QTextBlock>
#include <QtHelp/QHelpEngineCore>
using namespace DuiEditor::Internal;
using namespace Core;
DuiHoverHandler::DuiHoverHandler(QObject *parent)
: QObject(parent)
{
ICore *core = ICore::instance();
// Listen for editor opened events in order to connect to tooltip/helpid requests
connect(core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
this, SLOT(editorOpened(Core::IEditor *)));
}
void DuiHoverHandler::editorOpened(IEditor *editor)
{
ScriptEditorEditable *duiEditor = qobject_cast<ScriptEditorEditable *>(editor);
if (!duiEditor)
return;
qDebug() << "connected for editor:" << editor->file()->fileName();
connect(duiEditor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*, QPoint, int)),
this, SLOT(showToolTip(TextEditor::ITextEditor*, QPoint, int)));
connect(duiEditor, SIGNAL(contextHelpIdRequested(TextEditor::ITextEditor*, int)),
this, SLOT(updateContextHelpId(TextEditor::ITextEditor*, int)));
}
void DuiHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos)
{
if (! editor)
return;
ScriptEditor *ed = qobject_cast<ScriptEditor *>(editor->widget());
ICore *core = ICore::instance();
const int dbgcontext = core->uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_GDBDEBUGGER);
if (core->hasContext(dbgcontext))
return;
m_toolTip.clear();
QTextCursor tc = ed->textCursor();
tc.setPosition(pos);
const unsigned line = tc.block().blockNumber() + 1;
foreach (const JavaScriptParser::DiagnosticMessage &m, ed->diagnosticMessages()) {
if (m.loc.startLine == line) {
m_toolTip.append(m.message);
break;
}
}
if (m_toolTip.isEmpty())
QToolTip::hideText();
else {
const QPoint pnt = point - QPoint(0,
#ifdef Q_WS_WIN
24
#else
16
#endif
);
QToolTip::showText(pnt, m_toolTip);
}
}
void DuiHoverHandler::updateContextHelpId(TextEditor::ITextEditor *, int)
{
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#ifndef DUIHOVERHANDLER_H
#define DUIHOVERHANDLER_H
#include <QtCore/QObject>
QT_BEGIN_NAMESPACE
class QPoint;
QT_END_NAMESPACE
namespace Core {
class IEditor;
}
namespace TextEditor {
class ITextEditor;
}
namespace DuiEditor {
namespace Internal {
class DuiHoverHandler : public QObject
{
Q_OBJECT
public:
DuiHoverHandler(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:
QString m_toolTip;
};
} // namespace Internal
} // namespace DuiEditor
#endif // DUIHOVERHANDLER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment