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