Commit c74da9b7 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Debugger: Reduce tooltip flicker.

Move tooltip-request handling from DebuggerPlugin into
DebuggerToolTipManager.

Request tooltip only if position changed and close
standard tooltip on success.
parent b8366705
......@@ -471,7 +471,7 @@ void CdbEngine::syncOperateByInstruction(bool operateByInstruction)
postCommand(m_operateByInstruction ? QByteArray("l-s") : QByteArray("l+s"), 0);
}
void CdbEngine::setToolTipExpression(const QPoint &mousePos,
bool CdbEngine::setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor *editor,
const DebuggerToolTipContext &contextIn)
{
......@@ -479,7 +479,7 @@ void CdbEngine::setToolTipExpression(const QPoint &mousePos,
qDebug() << Q_FUNC_INFO;
// Need a stopped debuggee and a cpp file in a valid frame
if (state() != InferiorStopOk || !isCppEditor(editor) || stackHandler()->currentIndex() < 0)
return;
return false;
// Determine expression and function
int line;
int column;
......@@ -487,20 +487,21 @@ void CdbEngine::setToolTipExpression(const QPoint &mousePos,
const QString exp = cppExpressionAt(editor, context.position, &line, &column, &context.function);
// Are we in the current stack frame
if (context.function.isEmpty() || exp.isEmpty() || context.function != stackHandler()->currentFrame().function)
return;
return false;
// No numerical or any other expressions [yet]
if (!(exp.at(0).isLetter() || exp.at(0) == QLatin1Char('_')))
return;
return false;
const QByteArray iname = QByteArray(localsPrefixC) + exp.toAscii();
const QModelIndex index = watchHandler()->itemIndex(iname);
if (index.isValid()) {
DebuggerTreeViewToolTipWidget *tw = new DebuggerTreeViewToolTipWidget;
tw->setContext(context);
tw->setDebuggerModel(LocalsWatch);
tw->setExpression(exp);
tw->acquireEngine(this);
DebuggerToolTipManager::instance()->add(mousePos, tw);
}
if (!index.isValid())
return false;
DebuggerTreeViewToolTipWidget *tw = new DebuggerTreeViewToolTipWidget;
tw->setContext(context);
tw->setDebuggerModel(LocalsWatch);
tw->setExpression(exp);
tw->acquireEngine(this);
DebuggerToolTipManager::instance()->add(mousePos, tw);
return true;
}
// Determine full path to the CDB extension library.
......
......@@ -85,7 +85,7 @@ public:
virtual ~CdbEngine();
// Factory function that returns 0 if the debug engine library cannot be found.
virtual void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor,
virtual bool setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor,
const DebuggerToolTipContext &ctx);
virtual void setupEngine();
virtual void setupInferior();
......
......@@ -1239,9 +1239,10 @@ DebuggerRunControl *DebuggerEngine::runControl() const
return d->runControl();
}
void DebuggerEngine::setToolTipExpression
bool DebuggerEngine::setToolTipExpression
(const QPoint &, TextEditor::ITextEditor *, const DebuggerToolTipContext &)
{
return false;
}
void DebuggerEngine::updateWatchData(const WatchData &, const WatchUpdateFlags &)
......
......@@ -137,7 +137,7 @@ public:
const DebuggerStartParameters &startParameters() const;
DebuggerStartParameters &startParameters();
virtual void setToolTipExpression(const QPoint & mousePos,
virtual bool setToolTipExpression(const QPoint & mousePos,
TextEditor::ITextEditor *editor, const Internal::DebuggerToolTipContext &);
virtual void updateWatchData(const Internal::WatchData &data,
......
......@@ -721,16 +721,6 @@ bool DebuggingHelperOptionPage::matches(const QString &s) const
//
///////////////////////////////////////////////////////////////////////
static bool isDebuggable(IEditor *editor)
{
// Only blacklist Qml. Whitelisting would fail on C++ code in files
// with strange names, more harm would be done this way.
// IFile *file = editor->file();
// return !(file && file->mimeType() == "application/x-qml");
// Nowadays, even Qml is debuggable.
return editor;
}
class ContextData
{
public:
......@@ -871,8 +861,6 @@ public slots:
void updateBreakMenuItem(Core::IEditor *editor);
void setBusyCursor(bool busy);
void requestMark(TextEditor::ITextEditor *editor, int lineNumber);
void showToolTip(TextEditor::ITextEditor *editor,
const QPoint &pnt, int pos, bool *handled);
void requestContextMenu(TextEditor::ITextEditor *editor,
int lineNumber, QMenu *menu);
......@@ -1776,7 +1764,7 @@ void DebuggerPluginPrivate::runScheduled()
void DebuggerPluginPrivate::editorOpened(IEditor *editor)
{
if (!isDebuggable(editor))
if (!isEditorDebuggable(editor))
return;
ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor);
if (!textEditor)
......@@ -1784,9 +1772,6 @@ void DebuggerPluginPrivate::editorOpened(IEditor *editor)
connect(textEditor,
SIGNAL(markRequested(TextEditor::ITextEditor*,int)),
SLOT(requestMark(TextEditor::ITextEditor*,int)));
connect(editor,
SIGNAL(tooltipOverrideRequested(TextEditor::ITextEditor*,QPoint,int,bool*)),
SLOT(showToolTip(TextEditor::ITextEditor*,QPoint,int,bool*)));
connect(textEditor,
SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)),
SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*)));
......@@ -1801,7 +1786,7 @@ void DebuggerPluginPrivate::updateBreakMenuItem(Core::IEditor *editor)
void DebuggerPluginPrivate::requestContextMenu(ITextEditor *editor,
int lineNumber, QMenu *menu)
{
if (!isDebuggable(editor))
if (!isEditorDebuggable(editor))
return;
ContextData args;
......@@ -1947,26 +1932,6 @@ void DebuggerPluginPrivate::requestMark(ITextEditor *editor, int lineNumber)
}
}
void DebuggerPluginPrivate::showToolTip(ITextEditor *editor,
const QPoint &point, int pos, bool *handled)
{
if (!isDebuggable(editor))
return;
if (!boolSetting(UseToolTipsInMainEditor))
return;
if (!currentEngine())
return;
if (!currentEngine()->canDisplayTooltip())
return;
QTC_ASSERT(handled, return);
const DebuggerToolTipContext context = DebuggerToolTipContext::fromEditor(editor, pos);
if (context.isValid()) {
*handled = true;
currentEngine()->setToolTipExpression(point, editor, context);
}
}
DebuggerRunControl *DebuggerPluginPrivate::createDebugger
(const DebuggerStartParameters &sp, RunConfiguration *rc)
{
......
......@@ -34,7 +34,9 @@
#include "debuggertooltipmanager.h"
#include "watchutils.h"
#include "debuggerengine.h"
#include "debuggeractions.h"
#include "watchhandler.h"
#include "watchutils.h"
#include "stackhandler.h"
#include "debuggercore.h"
......@@ -43,6 +45,7 @@
#include <coreplugin/imode.h>
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/itexteditor.h>
#include <texteditor/tooltip/tooltip.h>
#include <utils/qtcassert.h>
......@@ -128,28 +131,46 @@ static inline void debugMode(const QAbstractItemModel *model)
nospace << '#' << r << ' ' << model->data(model->index(r, 0)).toString() << '\n';
}
static inline QPlainTextEdit *plainTextEditor(Core::IEditor *ie, QString *fileName = 0)
namespace Debugger {
namespace Internal {
// A convenience struct to pass around all tooltip-relevant editor members
// (TextEditor, Widget, File, etc), constructing from a Core::IEditor.
struct DebuggerToolTipEditor
{
explicit DebuggerToolTipEditor(Core::IEditor *ie = 0);
inline bool isValid() const { return textEditor != 0 && plainTextEdit != 0 && file != 0; }
inline operator bool() const { return isValid(); }
QString fileName() const { return file ? file->fileName() : QString(); }
static DebuggerToolTipEditor currentToolTipEditor();
TextEditor::ITextEditor *textEditor;
QPlainTextEdit *plainTextEdit;
Core::IFile *file;
};
DebuggerToolTipEditor::DebuggerToolTipEditor(Core::IEditor *ie) :
textEditor(0), plainTextEdit(0), file(0)
{
if (const Core::IFile *file = ie->file())
if (qobject_cast<TextEditor::ITextEditor *>(ie))
if (ie && ie->file() && isEditorDebuggable(ie)) {
if (TextEditor::ITextEditor *te = qobject_cast<TextEditor::ITextEditor *>(ie)) {
if (QPlainTextEdit *pe = qobject_cast<QPlainTextEdit *>(ie->widget())) {
if (fileName)
*fileName = file->fileName();
return pe;
textEditor = te;
plainTextEdit = pe;
file = ie->file();
}
return 0;
}
}
}
static inline QPlainTextEdit *currentPlainTextEditor(QString *fileName = 0)
DebuggerToolTipEditor DebuggerToolTipEditor::currentToolTipEditor()
{
if (Core::IEditor *ie = Core::EditorManager::instance()->currentEditor())
return plainTextEditor(ie, fileName);
return 0;
return DebuggerToolTipEditor(ie);
return DebuggerToolTipEditor();
}
namespace Debugger {
namespace Internal {
/* Helper for building a QStandardItemModel of a tree form (see TreeModelVisitor).
* The recursion/building is based on the scheme: \code
<row><item1><item2>
......@@ -1005,7 +1026,8 @@ QString DebuggerTreeViewToolTipWidget::clipboardContents() const
DebuggerToolTipManager *DebuggerToolTipManager::m_instance = 0;
DebuggerToolTipManager::DebuggerToolTipManager(QObject *parent) :
QObject(parent), m_debugModeActive(false)
QObject(parent), m_debugModeActive(false),
m_lastToolTipPos(-1), m_lastToolTipEditor(0)
{
DebuggerToolTipManager::m_instance = this;
}
......@@ -1152,21 +1174,21 @@ void DebuggerToolTipManager::slotUpdateVisibleToolTips()
return;
}
QString fileName;
QPlainTextEdit *plainTextEdit = currentPlainTextEditor(&fileName);
DebuggerToolTipEditor toolTipEditor = DebuggerToolTipEditor::currentToolTipEditor();
if (debugToolTips)
qDebug() << "DebuggerToolTipManager::slotUpdateVisibleToolTips() " << fileName << sender();
qDebug() << "DebuggerToolTipManager::slotUpdateVisibleToolTips() " << sender();
if (fileName.isEmpty() || !plainTextEdit) {
if (!toolTipEditor.isValid() || toolTipEditor.fileName().isEmpty()) {
hide();
return;
}
// Reposition and show all tooltips of that file.
const QString fileName = toolTipEditor.fileName();
foreach (const QPointer<AbstractDebuggerToolTipWidget> &tw, m_tooltips) {
if (tw->fileName() == fileName) {
tw->positionShow(plainTextEdit);
tw->positionShow(toolTipEditor.plainTextEdit);
} else {
tw->hide();
}
......@@ -1250,9 +1272,12 @@ bool DebuggerToolTipManager::debug()
void DebuggerToolTipManager::slotEditorOpened(Core::IEditor *e)
{
// Move tooltip along when scrolled.
if (QPlainTextEdit *plainTextEdit = plainTextEditor(e)) {
connect(plainTextEdit->verticalScrollBar(), SIGNAL(valueChanged(int)),
if (DebuggerToolTipEditor toolTipEditor = DebuggerToolTipEditor(e)) {
connect(toolTipEditor.plainTextEdit->verticalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(slotUpdateVisibleToolTips()));
connect(toolTipEditor.textEditor,
SIGNAL(tooltipOverrideRequested(TextEditor::ITextEditor*,QPoint,int,bool*)),
SLOT(slotTooltipOverrideRequested(TextEditor::ITextEditor*,QPoint,int,bool*)));
}
}
......@@ -1288,16 +1313,65 @@ void DebuggerToolTipManager::leavingDebugMode()
if (m_debugModeActive) {
m_debugModeActive = false;
hide();
QWidget *topLevel = Core::ICore::instance()->mainWindow()->topLevelWidget();
topLevel->removeEventFilter(this);
Core::EditorManager *em = Core::EditorManager::instance();
foreach (Core::IEditor *e, em->openedEditors())
if (QPlainTextEdit *plainTextEdit = plainTextEditor(e))
plainTextEdit->verticalScrollBar()->disconnect(this);
em->disconnect(this);
if (QWidget *topLevel = Core::ICore::instance()->mainWindow()->topLevelWidget())
topLevel->removeEventFilter(this);
if (Core::EditorManager *em = Core::EditorManager::instance()) {
foreach (Core::IEditor *e, em->openedEditors()) {
if (DebuggerToolTipEditor toolTipEditor = DebuggerToolTipEditor(e)) {
toolTipEditor.plainTextEdit->verticalScrollBar()->disconnect(this);
toolTipEditor.textEditor->disconnect(this);
}
}
em->disconnect(this);
}
m_lastToolTipEditor = 0;
m_lastToolTipPos = -1;
}
}
void DebuggerToolTipManager::slotTooltipOverrideRequested(TextEditor::ITextEditor *editor,
const QPoint &point,
int pos, bool *handled)
{
QTC_ASSERT(handled, return);
if (debugToolTips)
qDebug() << ">slotTooltipOverrideRequested() " << editor << point << pos << *handled;
DebuggerEngine *currentEngine = 0;
do {
if (*handled || (m_lastToolTipEditor == editor && pos == m_lastToolTipPos))
break; // Avoid flicker.
DebuggerCore *core = debuggerCore();
if (!isEditorDebuggable(editor) || !core->boolSetting(UseToolTipsInMainEditor))
break;
currentEngine = core->currentEngine();
if (!currentEngine || !currentEngine->canDisplayTooltip())
break;
const DebuggerToolTipContext context = DebuggerToolTipContext::fromEditor(editor, pos);
if (context.isValid() && currentEngine->setToolTipExpression(point, editor, context)) {
if (TextEditor::ToolTip::instance()->isVisible())
TextEditor::ToolTip::instance()->hide();
*handled = true;
m_lastToolTipEditor = editor;
m_lastToolTipPos = pos;
}
} while (false);
// Other tooltip, close all in case mouse never entered the tooltip
// and no leave was triggered.
if (!*handled) {
m_lastToolTipEditor = 0;
m_lastToolTipPos = -1;
closeUnpinnedToolTips();
}
if (debugToolTips)
qDebug() << "<slotTooltipOverrideRequested() " << currentEngine << *handled;
}
QStringList DebuggerToolTipManager::treeWidgetExpressions(const QString &fileName,
const QString &engineType,
const QString &function) const
......
......@@ -62,6 +62,10 @@ class IEditor;
class IMode;
}
namespace TextEditor {
class ITextEditor;
}
namespace Debugger {
class DebuggerEngine;
......@@ -266,6 +270,8 @@ private slots:
void slotDebuggerStateChanged(Debugger::DebuggerState);
void slotStackFrameCompleted();
void slotEditorOpened(Core::IEditor *);
void slotTooltipOverrideRequested(TextEditor::ITextEditor *editor, const QPoint &point,
int pos, bool *handled);
private:
typedef QList<QPointer<AbstractDebuggerToolTipWidget> > DebuggerToolTipWidgetList;
......@@ -280,6 +286,8 @@ private:
DebuggerToolTipWidgetList m_tooltips;
bool m_debugModeActive;
int m_lastToolTipPos;
Core::IEditor *m_lastToolTipEditor;
};
} // namespace Internal
......
......@@ -3419,13 +3419,13 @@ void GdbEngine::clearToolTip()
m_toolTipContext.reset();
}
void GdbEngine::setToolTipExpression(const QPoint &mousePos,
bool GdbEngine::setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor *editor, const DebuggerToolTipContext &contextIn)
{
if (state() != InferiorStopOk || !isCppEditor(editor)) {
//qDebug() << "SUPPRESSING DEBUGGER TOOLTIP, INFERIOR NOT STOPPED "
// " OR NOT A CPPEDITOR";
return;
return false;
}
DebuggerToolTipContext context = contextIn;
......@@ -3434,7 +3434,7 @@ void GdbEngine::setToolTipExpression(const QPoint &mousePos,
if (DebuggerToolTipManager::debug())
qDebug() << "GdbEngine::setToolTipExpression1 " << exp << context;
if (exp.isEmpty())
return;
return false;
// Extract the first identifier, everything else is considered
// too dangerous.
......@@ -3455,10 +3455,10 @@ void GdbEngine::setToolTipExpression(const QPoint &mousePos,
exp = exp.mid(pos1, pos2 - pos1);
if (exp.isEmpty() || exp.startsWith(_c('#')) || !hasLetterOrNumber(exp) || isKeyWord(exp))
return;
return false;
if (exp.startsWith(_c('"')) && exp.endsWith(_c('"')))
return;
return false;
if (exp.startsWith(__("++")) || exp.startsWith(__("--")))
exp = exp.mid(2);
......@@ -3467,14 +3467,14 @@ void GdbEngine::setToolTipExpression(const QPoint &mousePos,
exp = exp.mid(2);
if (exp.startsWith(_c('<')) || exp.startsWith(_c('[')))
return;
return false;
if (hasSideEffects(exp) || exp.isEmpty())
return;
return false;
if (!m_toolTipContext.isNull() && m_toolTipContext->expression == exp) {
showToolTip();
return;
return true;
}
m_toolTipContext.reset(new GdbToolTipContext(context));
......@@ -3485,7 +3485,7 @@ void GdbEngine::setToolTipExpression(const QPoint &mousePos,
if (isSynchronous()) {
updateLocals(QVariant());
return;
return true;
}
WatchData toolTip;
......@@ -3494,6 +3494,7 @@ void GdbEngine::setToolTipExpression(const QPoint &mousePos,
toolTip.iname = tooltipIName(exp);
watchHandler()->removeData(toolTip.iname);
watchHandler()->insertData(toolTip);
return true;
}
......
......@@ -476,7 +476,7 @@ private: ////////// View & Data Stuff //////////
//
// Watch specific stuff
//
virtual void setToolTipExpression(const QPoint &mousePos,
virtual bool setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor *editor, const DebuggerToolTipContext &);
virtual void assignValueInDebugger(const WatchData *data,
const QString &expr, const QVariant &value);
......
......@@ -456,7 +456,7 @@ static WatchData m_toolTip;
static QPoint m_toolTipPos;
static QHash<QString, WatchData> m_toolTipCache;
void PdbEngine::setToolTipExpression(const QPoint &mousePos,
bool PdbEngine::setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor *editor, const DebuggerToolTipContext &ctx)
{
Q_UNUSED(mousePos)
......@@ -464,13 +464,13 @@ void PdbEngine::setToolTipExpression(const QPoint &mousePos,
if (state() != InferiorStopOk) {
//SDEBUG("SUPPRESSING DEBUGGER TOOLTIP, INFERIOR NOT STOPPED");
return;
return false;
}
// Check mime type and get expression (borrowing some C++ - functions)
const QString javaPythonMimeType =
QLatin1String("application/javascript");
if (!editor->file() || editor->file()->mimeType() != javaPythonMimeType)
return;
return false;
int line;
int column;
......@@ -488,17 +488,17 @@ void PdbEngine::setToolTipExpression(const QPoint &mousePos,
QToolTip::hideText();
if (exp.isEmpty() || exp.startsWith(QLatin1Char('#'))) {
QToolTip::hideText();
return;
return false;
}
if (!hasLetterOrNumber(exp)) {
QToolTip::showText(m_toolTipPos, tr("'%1' contains no identifier").arg(exp));
return;
return true;
}
if (exp.startsWith(QLatin1Char('"')) && exp.endsWith(QLatin1Char('"'))) {
QToolTip::showText(m_toolTipPos, tr("String literal %1").arg(exp));
return;
return true;
}
if (exp.startsWith(QLatin1String("++")) || exp.startsWith(QLatin1String("--")))
......@@ -508,13 +508,13 @@ void PdbEngine::setToolTipExpression(const QPoint &mousePos,
exp.remove(0, 2);
if (exp.startsWith(QLatin1Char('<')) || exp.startsWith(QLatin1Char('[')))
return;
return false;
if (hasSideEffects(exp)) {
QToolTip::showText(m_toolTipPos,
tr("Cowardly refusing to evaluate expression '%1' "
"with potential side effects").arg(exp));
return;
return true;
}
#if 0
......@@ -528,6 +528,7 @@ void PdbEngine::setToolTipExpression(const QPoint &mousePos,
m_toolTip.iname = tooltipIName;
insertData(m_toolTip);
#endif
return false;
}
......
......@@ -79,7 +79,7 @@ private:
void shutdownInferior();
void shutdownEngine();
void setToolTipExpression(const QPoint &mousePos,
bool setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor *editor, const DebuggerToolTipContext &);
void continueInferior();
......
......@@ -139,10 +139,10 @@ QmlCppEngine::~QmlCppEngine()
delete d->m_cppEngine;
}
void QmlCppEngine::setToolTipExpression(const QPoint & mousePos,
bool QmlCppEngine::setToolTipExpression(const QPoint & mousePos,
TextEditor::ITextEditor *editor, const DebuggerToolTipContext &ctx)
{
d->m_activeEngine->setToolTipExpression(mousePos, editor, ctx);
return d->m_activeEngine->setToolTipExpression(mousePos, editor, ctx);
}
void QmlCppEngine::updateWatchData(const WatchData &data,
......
......@@ -18,7 +18,7 @@ public:
explicit QmlCppEngine(const DebuggerStartParameters &sp);
~QmlCppEngine();
void setToolTipExpression(const QPoint &mousePos,
bool setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor * editor, const DebuggerToolTipContext &);
void updateWatchData(const WatchData &data,
const WatchUpdateFlags &flags);
......
......@@ -571,12 +571,13 @@ void QmlEngine::requestModuleSymbols(const QString &moduleName)
//
//////////////////////////////////////////////////////////////////////
void QmlEngine::setToolTipExpression(const QPoint &mousePos,
bool QmlEngine::setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor *editor, const DebuggerToolTipContext &ctx)
{
// This is processed by QML inspector, which has dependencies to
// the qml js editor. Makes life easier.
emit tooltipRequested(mousePos, editor, ctx.position);
return true;
}