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:
Christian Kandeler
2020-03-19 16:00:37 +01:00
parent 7158e67612
commit 04a99c1de1
15 changed files with 314 additions and 85 deletions

View File

@@ -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(

View File

@@ -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;
};

View File

@@ -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));