forked from qt-creator/qt-creator
Remove the limitation that output formatters have to be exclusive
Introduce an aggregating output formatter that forwards its input to a sub-formatter that feels responsible for it, or otherwise lets the base class handle it. Our output panes now use such an aggregating formatter. In particular, this means that in the future, we won't have to stuff all run control output formatting into the Qt output formatter anymore. Change-Id: I5498f200a61db10ccff3ec8974c6825da7f7072d Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -42,14 +42,17 @@ VcsOutputFormatter::VcsOutputFormatter() :
|
||||
{
|
||||
}
|
||||
|
||||
void VcsOutputFormatter::doAppendMessage(const QString &text, Utils::OutputFormat format)
|
||||
VcsOutputFormatter::Status VcsOutputFormatter::handleMessage(const QString &text,
|
||||
Utils::OutputFormat format)
|
||||
{
|
||||
QRegularExpressionMatchIterator it = m_regexp.globalMatch(text);
|
||||
if (!it.hasNext())
|
||||
return Status::NotHandled;
|
||||
int begin = 0;
|
||||
while (it.hasNext()) {
|
||||
const QRegularExpressionMatch match = it.next();
|
||||
const QTextCharFormat normalFormat = charFormat(format);
|
||||
OutputFormatter::doAppendMessage(text.mid(begin, match.capturedStart() - begin), format);
|
||||
appendMessageDefault(text.mid(begin, match.capturedStart() - begin), format);
|
||||
QTextCursor tc = plainTextEdit()->textCursor();
|
||||
QStringView url = match.capturedView();
|
||||
begin = match.capturedEnd();
|
||||
@@ -61,15 +64,17 @@ void VcsOutputFormatter::doAppendMessage(const QString &text, Utils::OutputForma
|
||||
tc.insertText(url.toString(), linkFormat(normalFormat, url.toString()));
|
||||
tc.movePosition(QTextCursor::End);
|
||||
}
|
||||
OutputFormatter::doAppendMessage(text.mid(begin), format);
|
||||
appendMessageDefault(text.mid(begin), format);
|
||||
return Status::Done;
|
||||
}
|
||||
|
||||
void VcsOutputFormatter::handleLink(const QString &href)
|
||||
bool VcsOutputFormatter::handleLink(const QString &href)
|
||||
{
|
||||
if (href.startsWith("http://") || href.startsWith("https://"))
|
||||
QDesktopServices::openUrl(QUrl(href));
|
||||
else if (!href.isEmpty())
|
||||
emit referenceClicked(href);
|
||||
return true;
|
||||
}
|
||||
|
||||
void VcsOutputFormatter::fillLinkContextMenu(
|
||||
|
||||
@@ -37,14 +37,15 @@ class VcsOutputFormatter : public Utils::OutputFormatter
|
||||
public:
|
||||
VcsOutputFormatter();
|
||||
~VcsOutputFormatter() override = default;
|
||||
void doAppendMessage(const QString &text, Utils::OutputFormat format) override;
|
||||
void handleLink(const QString &href) override;
|
||||
bool handleLink(const QString &href) override;
|
||||
void fillLinkContextMenu(QMenu *menu, const QString &workingDirectory, const QString &href);
|
||||
|
||||
signals:
|
||||
void referenceClicked(const QString &reference);
|
||||
|
||||
private:
|
||||
Status handleMessage(const QString &text, Utils::OutputFormat format) override;
|
||||
|
||||
const QRegularExpression m_regexp;
|
||||
};
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
m_formatter = new VcsOutputFormatter;
|
||||
m_formatter->setBoldFontEnabled(false);
|
||||
setFormatter(m_formatter);
|
||||
setFormatters({m_formatter});
|
||||
auto agg = new Aggregation::Aggregate;
|
||||
agg->add(this);
|
||||
agg->add(new Core::BaseTextFind(this));
|
||||
|
||||
Reference in New Issue
Block a user