forked from qt-creator/qt-creator
Clang: Add tooltip action to copy to clipboard
...as selecting text in the tooltip was difficult and eventually got
disabled due to other problems - see
d58c0a9ac8.
This adds support for actions in TextMarks. They are displayed as
QToolButtons in a dedicated column in the tooltip.
Change-Id: I84ee3c3e4af573a80953786881d1333b00e4200c
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -474,9 +474,17 @@ QString ClangDiagnosticWidget::createText(
|
||||
const ClangDiagnosticWidget::Destination &destination)
|
||||
{
|
||||
const QString htmlText = WidgetFromDiagnostics(toHints(destination)).htmlText(diagnostics);
|
||||
|
||||
QTextDocument document;
|
||||
document.setHtml(htmlText);
|
||||
return document.toPlainText();
|
||||
QString text = document.toPlainText();
|
||||
|
||||
if (text.startsWith('\n'))
|
||||
text = text.mid(1);
|
||||
if (text.endsWith('\n'))
|
||||
text.chop(1);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
QWidget *ClangDiagnosticWidget::createWidget(
|
||||
|
||||
@@ -33,7 +33,9 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QLayout>
|
||||
#include <QString>
|
||||
|
||||
@@ -64,7 +66,6 @@ static Core::Id categoryForSeverity(ClangBackEnd::DiagnosticSeverity severity)
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
ClangTextMark::ClangTextMark(const FileName &fileName,
|
||||
const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
const RemovedFromEditorHandler &removedHandler,
|
||||
@@ -86,6 +87,16 @@ ClangTextMark::ClangTextMark(const FileName &fileName,
|
||||
setColor(warning ? ::Utils::Theme::CodeModel_Warning_TextMarkColor
|
||||
: ::Utils::Theme::CodeModel_Error_TextMarkColor);
|
||||
}
|
||||
|
||||
QAction *action = new QAction();
|
||||
action->setIcon(QIcon::fromTheme("edit-copy", ::Utils::Icons::COPY.icon()));
|
||||
QObject::connect(action, &QAction::triggered, [diagnostic]() {
|
||||
using namespace ClangCodeModel::Internal;
|
||||
const QString text = ClangDiagnosticWidget::createText({diagnostic},
|
||||
ClangDiagnosticWidget::InfoBar);
|
||||
QApplication::clipboard()->setText(text, QClipboard::Clipboard);
|
||||
});
|
||||
setActions({action});
|
||||
}
|
||||
|
||||
void ClangTextMark::updateIcon(bool valid)
|
||||
|
||||
Reference in New Issue
Block a user