VCS: Use OutputFormatter for output window

Change-Id: I62cdd8e5c73d21d837772be83087dc065698db30
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2014-03-18 20:25:03 +02:00
committed by Orgad Shaneh
parent 0960127ece
commit 99c38093de
3 changed files with 22 additions and 10 deletions

View File

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