forked from qt-creator/qt-creator
TextEditor: Enable tooltips for textmarks
Adjust bookmark code, add tooltips for clang diagnostics. Change-Id: I489d499f5431fcb29f27611d4350298acb30baac Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -78,7 +78,7 @@ void Bookmark::updateFileName(const QString &fileName)
|
|||||||
|
|
||||||
void Bookmark::setNote(const QString ¬e)
|
void Bookmark::setNote(const QString ¬e)
|
||||||
{
|
{
|
||||||
m_note = note;
|
setToolTip(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bookmark::updateNote(const QString ¬e)
|
void Bookmark::updateNote(const QString ¬e)
|
||||||
@@ -94,5 +94,5 @@ QString Bookmark::lineText() const
|
|||||||
|
|
||||||
QString Bookmark::note() const
|
QString Bookmark::note() const
|
||||||
{
|
{
|
||||||
return m_note;
|
return toolTip();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,13 +37,14 @@ class Bookmark : public TextEditor::TextMark
|
|||||||
public:
|
public:
|
||||||
Bookmark(int lineNumber, BookmarkManager *manager);
|
Bookmark(int lineNumber, BookmarkManager *manager);
|
||||||
|
|
||||||
void updateLineNumber(int lineNumber);
|
void updateLineNumber(int lineNumber) override;
|
||||||
void move(int line);
|
void move(int line) override;
|
||||||
void updateBlock(const QTextBlock &block);
|
void updateBlock(const QTextBlock &block) override;
|
||||||
void updateFileName(const QString &fileName);
|
void updateFileName(const QString &fileName) override;
|
||||||
|
void removedFromEditor() override;
|
||||||
|
|
||||||
void setNote(const QString ¬e);
|
void setNote(const QString ¬e);
|
||||||
void updateNote(const QString ¬e);
|
void updateNote(const QString ¬e);
|
||||||
void removedFromEditor();
|
|
||||||
|
|
||||||
QString lineText() const;
|
QString lineText() const;
|
||||||
QString note() const;
|
QString note() const;
|
||||||
@@ -51,7 +52,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
BookmarkManager *m_manager;
|
BookmarkManager *m_manager;
|
||||||
QString m_lineText;
|
QString m_lineText;
|
||||||
QString m_note;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
#include <utils/icon.h>
|
#include <utils/icon.h>
|
||||||
#include <utils/tooltip/tooltip.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/checkablemessagebox.h>
|
#include <utils/checkablemessagebox.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
@@ -845,17 +844,6 @@ void BookmarkManager::saveBookmarks()
|
|||||||
SessionManager::setValue(QLatin1String("Bookmarks"), list);
|
SessionManager::setValue(QLatin1String("Bookmarks"), list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkManager::operateTooltip(QWidget *widget, const QPoint &pos, Bookmark *mark)
|
|
||||||
{
|
|
||||||
if (!mark)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (mark->note().isEmpty())
|
|
||||||
ToolTip::hide();
|
|
||||||
else
|
|
||||||
ToolTip::show(pos, mark->note(), widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Loads the bookmarks from the session settings. */
|
/* Loads the bookmarks from the session settings. */
|
||||||
void BookmarkManager::loadBookmarks()
|
void BookmarkManager::loadBookmarks()
|
||||||
{
|
{
|
||||||
@@ -867,12 +855,6 @@ void BookmarkManager::loadBookmarks()
|
|||||||
updateActionStatus();
|
updateActionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkManager::handleBookmarkTooltipRequest(IEditor *editor, const QPoint &pos, int line)
|
|
||||||
{
|
|
||||||
Bookmark *mark = findBookmark(editor->document()->filePath().toString(), line);
|
|
||||||
operateTooltip(editor->widget(), pos, mark);
|
|
||||||
}
|
|
||||||
|
|
||||||
// BookmarkViewFactory
|
// BookmarkViewFactory
|
||||||
|
|
||||||
BookmarkViewFactory::BookmarkViewFactory(BookmarkManager *bm)
|
BookmarkViewFactory::BookmarkViewFactory(BookmarkManager *bm)
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utils/itemviews.h>
|
#include <utils/itemviews.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
|
||||||
#include <coreplugin/inavigationwidgetfactory.h>
|
#include <coreplugin/inavigationwidgetfactory.h>
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
@@ -36,6 +35,8 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
namespace Core { class IContext; }
|
||||||
|
|
||||||
namespace Bookmarks {
|
namespace Bookmarks {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -87,8 +88,6 @@ public:
|
|||||||
Note = Qt::UserRole + 4
|
Note = Qt::UserRole + 4
|
||||||
};
|
};
|
||||||
|
|
||||||
void handleBookmarkTooltipRequest(Core::IEditor *editor, const QPoint &pos, int line);
|
|
||||||
|
|
||||||
void toggleBookmark(const QString &fileName, int lineNumber);
|
void toggleBookmark(const QString &fileName, int lineNumber);
|
||||||
void nextInDocument();
|
void nextInDocument();
|
||||||
void prevInDocument();
|
void prevInDocument();
|
||||||
@@ -117,7 +116,6 @@ private:
|
|||||||
bool removeBookmarkFromMap(Bookmark *bookmark, const QString &fileName = QString());
|
bool removeBookmarkFromMap(Bookmark *bookmark, const QString &fileName = QString());
|
||||||
static QString bookmarkToString(const Bookmark *b);
|
static QString bookmarkToString(const Bookmark *b);
|
||||||
void saveBookmarks();
|
void saveBookmarks();
|
||||||
void operateTooltip(QWidget *widget, const QPoint &pos, Bookmark *mark);
|
|
||||||
|
|
||||||
typedef QMultiMap<QString, Bookmark *> FileNameBookmarksMap;
|
typedef QMultiMap<QString, Bookmark *> FileNameBookmarksMap;
|
||||||
typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
|
typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
|
||||||
|
|||||||
@@ -170,13 +170,6 @@ void BookmarksPlugin::editorOpened(IEditor *editor)
|
|||||||
m_bookmarkManager->toggleBookmark(editor->document()->filePath().toString(), line);
|
m_bookmarkManager->toggleBookmark(editor->document()->filePath().toString(), line);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
connect(widget, &TextEditorWidget::markTooltipRequested, m_bookmarkManager,
|
|
||||||
[this, editor](TextEditorWidget *, const QPoint &pos, int line) {
|
|
||||||
if (editor->document())
|
|
||||||
m_bookmarkManager->handleBookmarkTooltipRequest(editor, pos, line);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(widget, &TextEditorWidget::markContextMenuRequested,
|
connect(widget, &TextEditorWidget::markContextMenuRequested,
|
||||||
this, &BookmarksPlugin::requestContextMenu);
|
this, &BookmarksPlugin::requestContextMenu);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,11 +243,23 @@ ClangDiagnosticManager::ClangDiagnosticManager(TextEditor::TextDocument *textDoc
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClangDiagnosticManager::~ClangDiagnosticManager()
|
||||||
|
{
|
||||||
|
cleanMarks();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangDiagnosticManager::cleanMarks()
|
||||||
|
{
|
||||||
|
for (ClangTextMark *textMark : m_clangTextMarks) {
|
||||||
|
m_textDocument->removeMark(textMark);
|
||||||
|
delete textMark;
|
||||||
|
}
|
||||||
|
m_clangTextMarks.clear();
|
||||||
|
}
|
||||||
void ClangDiagnosticManager::generateTextMarks()
|
void ClangDiagnosticManager::generateTextMarks()
|
||||||
{
|
{
|
||||||
m_clangTextMarks.clear();
|
cleanMarks();
|
||||||
m_clangTextMarks.reserve(m_warningDiagnostics.size() + m_errorDiagnostics.size());
|
m_clangTextMarks.reserve(m_warningDiagnostics.size() + m_errorDiagnostics.size());
|
||||||
|
|
||||||
addClangTextMarks(m_warningDiagnostics);
|
addClangTextMarks(m_warningDiagnostics);
|
||||||
addClangTextMarks(m_errorDiagnostics);
|
addClangTextMarks(m_errorDiagnostics);
|
||||||
}
|
}
|
||||||
@@ -332,18 +344,13 @@ ClangDiagnosticManager::diagnosticsWithFixIts() const
|
|||||||
void ClangDiagnosticManager::addClangTextMarks(
|
void ClangDiagnosticManager::addClangTextMarks(
|
||||||
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
|
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_clangTextMarks.size() + diagnostics.size() <= m_clangTextMarks.capacity(), return);
|
for (const ClangBackEnd::DiagnosticContainer &diagnostic : diagnostics) {
|
||||||
|
auto textMark = new ClangTextMark(filePath(),
|
||||||
for (auto &&diagnostic : diagnostics) {
|
diagnostic.location().line(),
|
||||||
m_clangTextMarks.emplace_back(filePath(),
|
diagnostic.severity());
|
||||||
diagnostic.location().line(),
|
textMark->setToolTip(diagnostic.text());
|
||||||
diagnostic.severity());
|
m_clangTextMarks.push_back(textMark);
|
||||||
|
m_textDocument->addMark(textMark);
|
||||||
ClangTextMark &textMark = m_clangTextMarks.back();
|
|
||||||
|
|
||||||
textMark.setBaseTextDocument(m_textDocument);
|
|
||||||
|
|
||||||
m_textDocument->addMark(&textMark);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class ClangDiagnosticManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClangDiagnosticManager(TextEditor::TextDocument *textDocument);
|
ClangDiagnosticManager(TextEditor::TextDocument *textDocument);
|
||||||
|
~ClangDiagnosticManager();
|
||||||
|
|
||||||
void processNewDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics);
|
void processNewDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics);
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ public:
|
|||||||
void clearDiagnosticsWithFixIts();
|
void clearDiagnosticsWithFixIts();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void cleanMarks();
|
||||||
QString filePath() const;
|
QString filePath() const;
|
||||||
void filterDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics);
|
void filterDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics);
|
||||||
void generateEditorSelections();
|
void generateEditorSelections();
|
||||||
@@ -77,7 +79,7 @@ private:
|
|||||||
QVector<ClangBackEnd::DiagnosticContainer> m_fixItdiagnostics;
|
QVector<ClangBackEnd::DiagnosticContainer> m_fixItdiagnostics;
|
||||||
QList<QTextEdit::ExtraSelection> m_extraSelections;
|
QList<QTextEdit::ExtraSelection> m_extraSelections;
|
||||||
TextEditor::RefactorMarkers m_fixItAvailableMarkers;
|
TextEditor::RefactorMarkers m_fixItAvailableMarkers;
|
||||||
std::vector<ClangTextMark> m_clangTextMarks;
|
std::vector<ClangTextMark *> m_clangTextMarks;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -79,10 +79,5 @@ void ClangTextMark::setIcon(ClangBackEnd::DiagnosticSeverity severity)
|
|||||||
TextMark::setIcon(errorIcon);
|
TextMark::setIcon(errorIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangTextMark::ClangTextMark(ClangTextMark &&other) Q_DECL_NOEXCEPT
|
|
||||||
: TextMark(std::move(other))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ClangCodeModel
|
} // namespace ClangCodeModel
|
||||||
|
|
||||||
|
|||||||
@@ -36,11 +36,6 @@ class ClangTextMark : public TextEditor::TextMark
|
|||||||
public:
|
public:
|
||||||
ClangTextMark(const QString &fileName, int lineNumber, ClangBackEnd::DiagnosticSeverity severity);
|
ClangTextMark(const QString &fileName, int lineNumber, ClangBackEnd::DiagnosticSeverity severity);
|
||||||
|
|
||||||
ClangTextMark(ClangTextMark &&other) Q_DECL_NOEXCEPT;
|
|
||||||
|
|
||||||
ClangTextMark(ClangTextMark &other) = delete;
|
|
||||||
ClangTextMark &operator=(ClangTextMark &other) = delete;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
|
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5105,10 +5105,18 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
|||||||
// Set whether the mouse cursor is a hand or normal arrow
|
// Set whether the mouse cursor is a hand or normal arrow
|
||||||
if (e->type() == QEvent::MouseMove) {
|
if (e->type() == QEvent::MouseMove) {
|
||||||
if (inMarkArea) {
|
if (inMarkArea) {
|
||||||
//Find line by cursor position
|
|
||||||
int line = cursor.blockNumber() + 1;
|
int line = cursor.blockNumber() + 1;
|
||||||
if (d->extraAreaPreviousMarkTooltipRequestedLine != line)
|
if (d->extraAreaPreviousMarkTooltipRequestedLine != line) {
|
||||||
emit markTooltipRequested(this, mapToGlobal(e->pos()), line);
|
if (auto data = static_cast<TextBlockUserData *>(cursor.block().userData())) {
|
||||||
|
QStringList toolTips;
|
||||||
|
foreach (TextMark *mark, data->marks()) {
|
||||||
|
QString toolTip = mark->toolTip();
|
||||||
|
if (!toolTip.isEmpty())
|
||||||
|
toolTips.append(toolTip);
|
||||||
|
}
|
||||||
|
ToolTip::show(mapToGlobal(e->pos()), toolTips.join('\n'), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
d->extraAreaPreviousMarkTooltipRequestedLine = line;
|
d->extraAreaPreviousMarkTooltipRequestedLine = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -583,8 +583,6 @@ signals:
|
|||||||
void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
|
void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
|
||||||
const QPoint &globalPos, int position, bool *handled);
|
const QPoint &globalPos, int position, bool *handled);
|
||||||
void tooltipRequested(const QPoint &globalPos, int position);
|
void tooltipRequested(const QPoint &globalPos, int position);
|
||||||
void markTooltipRequested(TextEditor::TextEditorWidget *widget,
|
|
||||||
const QPoint &globalPos, int line);
|
|
||||||
void activateEditor();
|
void activateEditor();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|||||||
@@ -60,20 +60,6 @@ TextMark::~TextMark()
|
|||||||
m_baseTextDocument = 0;
|
m_baseTextDocument = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextMark::TextMark(TextMark &&other) Q_DECL_NOEXCEPT
|
|
||||||
: m_baseTextDocument(std::move(other.m_baseTextDocument)),
|
|
||||||
m_fileName(std::move(other.m_fileName)),
|
|
||||||
m_lineNumber(std::move(other.m_lineNumber)),
|
|
||||||
m_priority(std::move(other.m_priority)),
|
|
||||||
m_visible(std::move(other.m_visible)),
|
|
||||||
m_icon(std::move(other.m_icon)),
|
|
||||||
m_color(std::move(other.m_color)),
|
|
||||||
m_category(std::move(other.m_category)),
|
|
||||||
m_widthFactor(std::move(other.m_widthFactor))
|
|
||||||
{
|
|
||||||
other.m_baseTextDocument = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TextMark::fileName() const
|
QString TextMark::fileName() const
|
||||||
{
|
{
|
||||||
return m_fileName;
|
return m_fileName;
|
||||||
@@ -212,6 +198,15 @@ void TextMark::setBaseTextDocument(TextDocument *baseTextDocument)
|
|||||||
m_baseTextDocument = baseTextDocument;
|
m_baseTextDocument = baseTextDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TextMark::toolTip() const
|
||||||
|
{
|
||||||
|
return m_toolTip;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextMark::setToolTip(const QString &toolTip)
|
||||||
|
{
|
||||||
|
m_toolTip = toolTip;
|
||||||
|
}
|
||||||
|
|
||||||
TextMarkRegistry::TextMarkRegistry(QObject *parent)
|
TextMarkRegistry::TextMarkRegistry(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ public:
|
|||||||
TextMark(const QString &fileName, int lineNumber, Core::Id category);
|
TextMark(const QString &fileName, int lineNumber, Core::Id category);
|
||||||
virtual ~TextMark();
|
virtual ~TextMark();
|
||||||
|
|
||||||
TextMark(TextMark &&other) Q_DECL_NOEXCEPT;
|
|
||||||
|
|
||||||
// determine order on markers on the same line.
|
// determine order on markers on the same line.
|
||||||
enum Priority
|
enum Priority
|
||||||
{
|
{
|
||||||
@@ -93,6 +91,9 @@ public:
|
|||||||
TextDocument *baseTextDocument() const;
|
TextDocument *baseTextDocument() const;
|
||||||
void setBaseTextDocument(TextDocument *baseTextDocument);
|
void setBaseTextDocument(TextDocument *baseTextDocument);
|
||||||
|
|
||||||
|
QString toolTip() const;
|
||||||
|
void setToolTip(const QString &toolTip);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(TextMark)
|
Q_DISABLE_COPY(TextMark)
|
||||||
friend class Internal::TextMarkRegistry;
|
friend class Internal::TextMarkRegistry;
|
||||||
@@ -106,6 +107,7 @@ private:
|
|||||||
QColor m_color;
|
QColor m_color;
|
||||||
Core::Id m_category;
|
Core::Id m_category;
|
||||||
double m_widthFactor;
|
double m_widthFactor;
|
||||||
|
QString m_toolTip;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|||||||
Reference in New Issue
Block a user