Commit 99c38093 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

VCS: Use OutputFormatter for output window



Change-Id: I62cdd8e5c73d21d837772be83087dc065698db30
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 0960127e
......@@ -62,12 +62,17 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
}
void OutputFormatter::appendMessage(const QString &text, OutputFormat format)
{
appendMessage(text, m_formats[format]);
}
void OutputFormatter::appendMessage(const QString &text, const QTextCharFormat &format)
{
QTextCursor cursor(m_plainTextEdit->document());
cursor.movePosition(QTextCursor::End);
foreach (const FormattedText &output,
m_escapeCodeHandler->parseText(FormattedText(text, m_formats[format]))) {
m_escapeCodeHandler->parseText(FormattedText(text, format))) {
int startPos = 0;
int crPos = -1;
while ((crPos = output.text.indexOf(QLatin1Char('\r'), startPos)) >= 0) {
......
......@@ -63,6 +63,7 @@ public:
void flush();
virtual void appendMessage(const QString &text, OutputFormat format);
virtual void appendMessage(const QString &text, const QTextCharFormat &format);
virtual void handleLink(const QString &href);
protected:
......
......@@ -31,6 +31,8 @@
#include <coreplugin/editormanager/editormanager.h>
#include <utils/outputformatter.h>
#include <QPlainTextEdit>
#include <QTextCharFormat>
#include <QContextMenuEvent>
......@@ -84,6 +86,7 @@ class OutputWindowPlainTextEdit : public QPlainTextEdit
{
public:
explicit OutputWindowPlainTextEdit(QWidget *parent = 0);
~OutputWindowPlainTextEdit();
void appendLines(QString const& s, const QString &repository = QString());
void appendLinesWithStyle(QString const& s, enum VcsBaseOutputWindow::MessageStyle style, const QString &repository = QString());
......@@ -100,6 +103,7 @@ private:
QTextCharFormat m_warningFormat;
QTextCharFormat m_commandFormat;
QTextCharFormat m_messageFormat;
Utils::OutputFormatter *m_formatter;
};
OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
......@@ -117,6 +121,13 @@ OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
m_warningFormat.setForeground(Qt::darkYellow);
m_commandFormat.setFontWeight(QFont::Bold);
m_messageFormat.setForeground(Qt::blue);
m_formatter = new Utils::OutputFormatter;
m_formatter->setPlainTextEdit(this);
}
OutputWindowPlainTextEdit::~OutputWindowPlainTextEdit()
{
delete m_formatter;
}
// Search back for beginning of word
......@@ -203,15 +214,10 @@ void OutputWindowPlainTextEdit::appendLines(QString const& s, const QString &rep
const int previousLineCount = document()->lineCount();
// Avoid additional new line character generated by appendPlainText
if (s.endsWith(QLatin1Char('\n'))) {
QString truncated(s);
truncated.truncate(s.size() - 1);
appendPlainText(truncated);
}
else {
appendPlainText(s);
}
const QChar newLine(QLatin1Char('\n'));
const QChar lastChar = s.at(s.size() - 1);
const bool appendNewline = (lastChar != QLatin1Char('\r') && lastChar != newLine);
m_formatter->appendMessage(appendNewline ? s + newLine : s, currentCharFormat());
// Scroll down
moveCursor(QTextCursor::End);
......
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