forked from qt-creator/qt-creator
Core: Provide a default output formatter
This allows us to get rid of a bunch of checks and a parallel implementation. Change-Id: Icbd23150700d26d96f5163418e46bf83e374e98a Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -111,7 +111,7 @@ void MessageOutputWindow::visibilityChanged(bool /*b*/)
|
|||||||
|
|
||||||
void MessageOutputWindow::append(const QString &text)
|
void MessageOutputWindow::append(const QString &text)
|
||||||
{
|
{
|
||||||
m_widget->appendText(text);
|
m_widget->appendMessage(text, Utils::DebugFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MessageOutputWindow::priorityInStatusBar() const
|
int MessageOutputWindow::priorityInStatusBar() const
|
||||||
|
@@ -63,6 +63,7 @@ public:
|
|||||||
IContext *outputWindowContext = nullptr;
|
IContext *outputWindowContext = nullptr;
|
||||||
QPointer<Utils::OutputFormatter> formatter;
|
QPointer<Utils::OutputFormatter> formatter;
|
||||||
QString settingsKey;
|
QString settingsKey;
|
||||||
|
OutputFormatter defaultFormatter;
|
||||||
|
|
||||||
bool enforceNewline = false;
|
bool enforceNewline = false;
|
||||||
bool prependCarriageReturn = false;
|
bool prependCarriageReturn = false;
|
||||||
@@ -93,6 +94,7 @@ OutputWindow::OutputWindow(Context context, const QString &settingsKey, QWidget
|
|||||||
setFrameShape(QFrame::NoFrame);
|
setFrameShape(QFrame::NoFrame);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setUndoRedoEnabled(false);
|
setUndoRedoEnabled(false);
|
||||||
|
setFormatter(&d->defaultFormatter);
|
||||||
|
|
||||||
d->settingsKey = settingsKey;
|
d->settingsKey = settingsKey;
|
||||||
|
|
||||||
@@ -169,7 +171,6 @@ void OutputWindow::mouseReleaseEvent(QMouseEvent *e)
|
|||||||
{
|
{
|
||||||
if (d->linksActive && d->mouseButtonPressed == Qt::LeftButton) {
|
if (d->linksActive && d->mouseButtonPressed == Qt::LeftButton) {
|
||||||
const QString href = anchorAt(e->pos());
|
const QString href = anchorAt(e->pos());
|
||||||
if (d->formatter)
|
|
||||||
d->formatter->handleLink(href);
|
d->formatter->handleLink(href);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +220,8 @@ void OutputWindow::setFormatter(OutputFormatter *formatter)
|
|||||||
d->formatter = formatter;
|
d->formatter = formatter;
|
||||||
if (d->formatter)
|
if (d->formatter)
|
||||||
d->formatter->setPlainTextEdit(this);
|
d->formatter->setPlainTextEdit(this);
|
||||||
|
else
|
||||||
|
d->formatter = &d->defaultFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindow::showEvent(QShowEvent *e)
|
void OutputWindow::showEvent(QShowEvent *e)
|
||||||
@@ -424,7 +427,6 @@ void OutputWindow::appendMessage(const QString &output, OutputFormat format)
|
|||||||
const bool atBottom = isScrollbarAtBottom() || m_scrollTimer.isActive();
|
const bool atBottom = isScrollbarAtBottom() || m_scrollTimer.isActive();
|
||||||
|
|
||||||
if (format == ErrorMessageFormat || format == NormalMessageFormat) {
|
if (format == ErrorMessageFormat || format == NormalMessageFormat) {
|
||||||
if (d->formatter)
|
|
||||||
d->formatter->appendMessage(doNewlineEnforcement(out), format);
|
d->formatter->appendMessage(doNewlineEnforcement(out), format);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -443,7 +445,6 @@ void OutputWindow::appendMessage(const QString &output, OutputFormat format)
|
|||||||
const int newline = out.indexOf('\n');
|
const int newline = out.indexOf('\n');
|
||||||
moveCursor(QTextCursor::End);
|
moveCursor(QTextCursor::End);
|
||||||
if (newline != -1) {
|
if (newline != -1) {
|
||||||
if (d->formatter)
|
|
||||||
d->formatter->appendMessage(out.left(newline), format);// doesn't enforce new paragraph like appendPlainText
|
d->formatter->appendMessage(out.left(newline), format);// doesn't enforce new paragraph like appendPlainText
|
||||||
out = out.mid(newline);
|
out = out.mid(newline);
|
||||||
}
|
}
|
||||||
@@ -456,11 +457,9 @@ void OutputWindow::appendMessage(const QString &output, OutputFormat format)
|
|||||||
d->enforceNewline = true;
|
d->enforceNewline = true;
|
||||||
out.chop(1);
|
out.chop(1);
|
||||||
}
|
}
|
||||||
if (d->formatter)
|
|
||||||
d->formatter->appendMessage(out, format);
|
d->formatter->appendMessage(out, format);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (d->formatter)
|
|
||||||
d->formatter->appendMessage(doNewlineEnforcement(out), format);
|
d->formatter->appendMessage(doNewlineEnforcement(out), format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,31 +477,6 @@ void OutputWindow::appendMessage(const QString &output, OutputFormat format)
|
|||||||
enableUndoRedo();
|
enableUndoRedo();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO rename
|
|
||||||
void OutputWindow::appendText(const QString &textIn, const QTextCharFormat &format)
|
|
||||||
{
|
|
||||||
const QString text = SynchronousProcess::normalizeNewlines(textIn);
|
|
||||||
if (d->maxCharCount > 0 && document()->characterCount() >= d->maxCharCount)
|
|
||||||
return;
|
|
||||||
const bool atBottom = isScrollbarAtBottom();
|
|
||||||
if (!d->cursor.atEnd())
|
|
||||||
d->cursor.movePosition(QTextCursor::End);
|
|
||||||
d->cursor.beginEditBlock();
|
|
||||||
d->cursor.insertText(doNewlineEnforcement(text), format);
|
|
||||||
|
|
||||||
if (d->maxCharCount > 0 && document()->characterCount() >= d->maxCharCount) {
|
|
||||||
QTextCharFormat tmp;
|
|
||||||
tmp.setFontWeight(QFont::Bold);
|
|
||||||
d->cursor.insertText(doNewlineEnforcement(tr("Additional output omitted. You can increase "
|
|
||||||
"the limit in the \"Build & Run\" settings.")
|
|
||||||
+ '\n'), tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
d->cursor.endEditBlock();
|
|
||||||
if (atBottom)
|
|
||||||
scrollToBottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OutputWindow::isScrollbarAtBottom() const
|
bool OutputWindow::isScrollbarAtBottom() const
|
||||||
{
|
{
|
||||||
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
|
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
|
||||||
@@ -540,7 +514,6 @@ void OutputWindow::clear()
|
|||||||
d->enforceNewline = false;
|
d->enforceNewline = false;
|
||||||
d->prependCarriageReturn = false;
|
d->prependCarriageReturn = false;
|
||||||
QPlainTextEdit::clear();
|
QPlainTextEdit::clear();
|
||||||
if (d->formatter)
|
|
||||||
d->formatter->clear();
|
d->formatter->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,8 +59,6 @@ public:
|
|||||||
void setFormatter(Utils::OutputFormatter *formatter);
|
void setFormatter(Utils::OutputFormatter *formatter);
|
||||||
|
|
||||||
void appendMessage(const QString &out, Utils::OutputFormat format);
|
void appendMessage(const QString &out, Utils::OutputFormat format);
|
||||||
/// appends a \p text using \p format without using formater
|
|
||||||
void appendText(const QString &text, const QTextCharFormat &format = QTextCharFormat());
|
|
||||||
|
|
||||||
void grayOutOldContent();
|
void grayOutOldContent();
|
||||||
void clear();
|
void clear();
|
||||||
|
Reference in New Issue
Block a user