Commit f48de4f5 authored by hjk's avatar hjk
Browse files

projectexplorer: refactor OutputFormatter interface

parent 01d4c5a3
......@@ -53,8 +53,7 @@ OutputFormatter::OutputFormatter()
OutputFormatter::~OutputFormatter()
{
if (m_formats)
delete[] m_formats;
delete[] m_formats;
}
QPlainTextEdit *OutputFormatter::plainTextEdit() const
......@@ -68,21 +67,14 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
initFormats();
}
void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
void OutputFormatter::appendMessage(const QString &text, OutputFormat format)
{
QTextCursor cursor(m_plainTextEdit->document());
cursor.movePosition(QTextCursor::End);
cursor.insertText(text, format(onStdErr ? StdErrFormat : StdOutFormat));
cursor.insertText(text, m_formats[format]);
}
void OutputFormatter::appendMessage(const QString &text, bool isError)
{
QTextCursor cursor(m_plainTextEdit->document());
cursor.movePosition(QTextCursor::End);
cursor.insertText(text, format(isError ? ErrorMessageFormat : NormalMessageFormat));
}
QTextCharFormat OutputFormatter::format(Format format)
QTextCharFormat OutputFormatter::format(OutputFormat format) const
{
return m_formats[format];
}
......
......@@ -45,6 +45,15 @@ QT_FORWARD_DECLARE_CLASS(QColor)
namespace ProjectExplorer {
enum OutputFormat
{
NormalMessageFormat,
ErrorMessageFormat,
StdOutFormat,
StdErrFormat,
NumberOfFormats // Keep this entry last.
};
class PROJECTEXPLORER_EXPORT OutputFormatter: public QObject
{
Q_OBJECT
......@@ -56,24 +65,13 @@ public:
QPlainTextEdit *plainTextEdit() const;
void setPlainTextEdit(QPlainTextEdit *plainText);
virtual void appendApplicationOutput(const QString &text, bool onStdErr);
virtual void appendMessage(const QString &text, bool isError);
virtual void appendMessage(const QString &text, OutputFormat format);
virtual void handleLink(const QString &href);
protected:
enum Format {
NormalMessageFormat = 0,
ErrorMessageFormat = 1,
StdOutFormat = 2,
StdErrFormat = 3,
NumberOfFormats = 4
};
void initFormats();
void clearLastLine();
QTextCharFormat format(Format format);
QTextCharFormat format(OutputFormat format) const;
static QColor mixColors(const QColor &a, const QColor &b);
......
......@@ -631,7 +631,7 @@ void OutputWindow::appendApplicationOutput(const QString &output, bool onStdErr)
out.remove(QLatin1Char('\r'));
setMaximumBlockCount(MaxBlockCount);
const bool atBottom = isScrollbarAtBottom();
m_formatter->appendApplicationOutput(doNewlineEnfocement(out), onStdErr);
m_formatter->appendMessage(doNewlineEnfocement(out), onStdErr ? StdErrFormat : StdOutFormat);
if (atBottom)
scrollToBottom();
enableUndoRedo();
......@@ -653,7 +653,7 @@ void OutputWindow::appendApplicationOutputInline(const QString &output, bool onS
newline = out.indexOf(QLatin1Char('\n'));
moveCursor(QTextCursor::End);
if (newline != -1)
m_formatter->appendApplicationOutput(out.left(newline), onStdErr); // doesn't enforce new paragraph like appendPlainText
m_formatter->appendMessage(out.left(newline), onStdErr ? StdErrFormat : StdOutFormat); // doesn't enforce new paragraph like appendPlainText
}
QString s = out.mid(newline+1);
......@@ -664,7 +664,7 @@ void OutputWindow::appendApplicationOutputInline(const QString &output, bool onS
m_enforceNewline = true;
s.chop(1);
}
m_formatter->appendApplicationOutput(QLatin1Char('\n') + s, onStdErr);
m_formatter->appendMessage(QLatin1Char('\n') + s, onStdErr ? StdErrFormat : StdOutFormat);
}
if (atBottom)
......@@ -678,7 +678,7 @@ void OutputWindow::appendMessage(const QString &output, bool isError)
out.remove(QLatin1Char('\r'));
setMaximumBlockCount(MaxBlockCount);
const bool atBottom = isScrollbarAtBottom();
m_formatter->appendMessage(doNewlineEnfocement(out), isError);
m_formatter->appendMessage(doNewlineEnfocement(out), isError ? ErrorMessageFormat : NormalMessageFormat);
if (atBottom)
scrollToBottom();
enableUndoRedo();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment