forked from qt-creator/qt-creator
VcsOutputWindow: Cleanup and modernize
Change-Id: I3239fb232207fb661bbcdf460ee01fb297720353 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
committed by
André Hartmann
parent
f7625e82e9
commit
ea8a1c85c1
@@ -35,22 +35,21 @@
|
|||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
#include <QPlainTextEdit>
|
|
||||||
#include <QTextCharFormat>
|
|
||||||
#include <QContextMenuEvent>
|
|
||||||
#include <QTextBlock>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QTextBlockUserData>
|
#include <QContextMenuEvent>
|
||||||
|
|
||||||
#include <QPointer>
|
|
||||||
#include <QTextCodec>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QPlainTextEdit>
|
||||||
|
#include <QPoint>
|
||||||
|
#include <QPointer>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
#include <QTextBlock>
|
||||||
|
#include <QTextBlockUserData>
|
||||||
|
#include <QTextCharFormat>
|
||||||
|
#include <QTextCodec>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QPoint>
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -86,7 +85,7 @@ private:
|
|||||||
const QString m_repository;
|
const QString m_repository;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A plain text edit with a special context menu containing "Clear" and
|
// A plain text edit with a special context menu containing "Clear"
|
||||||
// and functions to append specially formatted entries.
|
// and functions to append specially formatted entries.
|
||||||
class OutputWindowPlainTextEdit : public Core::OutputWindow
|
class OutputWindowPlainTextEdit : public Core::OutputWindow
|
||||||
{
|
{
|
||||||
@@ -94,23 +93,19 @@ public:
|
|||||||
explicit OutputWindowPlainTextEdit(QWidget *parent = nullptr);
|
explicit OutputWindowPlainTextEdit(QWidget *parent = nullptr);
|
||||||
~OutputWindowPlainTextEdit() override;
|
~OutputWindowPlainTextEdit() override;
|
||||||
|
|
||||||
void appendLines(QString const& s, const QString &repository = QString());
|
void appendLines(const QString &s, const QString &repository = QString());
|
||||||
void appendLinesWithStyle(QString const& s, enum VcsOutputWindow::MessageStyle style, const QString &repository = QString());
|
void appendLinesWithStyle(const QString &s, VcsOutputWindow::MessageStyle style,
|
||||||
|
const QString &repository = QString());
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setFormat(enum VcsOutputWindow::MessageStyle style);
|
void setFormat(VcsOutputWindow::MessageStyle style);
|
||||||
QString identifierUnderCursor(const QPoint &pos, QString *repository = nullptr) const;
|
QString identifierUnderCursor(const QPoint &pos, QString *repository = nullptr) const;
|
||||||
|
|
||||||
Utils::OutputFormat m_format;
|
Utils::OutputFormat m_format;
|
||||||
const QTextCharFormat m_defaultFormat;
|
OutputFormatter *m_formatter = nullptr;
|
||||||
QTextCharFormat m_errorFormat;
|
|
||||||
QTextCharFormat m_warningFormat;
|
|
||||||
QTextCharFormat m_commandFormat;
|
|
||||||
QTextCharFormat m_messageFormat;
|
|
||||||
OutputFormatter *m_formatter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
|
OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
|
||||||
@@ -182,7 +177,7 @@ void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
// Check for a file, expand via repository if relative
|
// Check for a file, expand via repository if relative
|
||||||
QFileInfo fi(token);
|
QFileInfo fi(token);
|
||||||
if (!repository.isEmpty() && !fi.isFile() && fi.isRelative())
|
if (!repository.isEmpty() && !fi.isFile() && fi.isRelative())
|
||||||
fi = QFileInfo(repository + QLatin1Char('/') + token);
|
fi = QFileInfo(repository + '/' + token);
|
||||||
if (fi.isFile()) {
|
if (fi.isFile()) {
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
openAction = menu->addAction(VcsOutputWindow::tr("Open \"%1\"").
|
openAction = menu->addAction(VcsOutputWindow::tr("Open \"%1\"").
|
||||||
@@ -209,16 +204,16 @@ void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
delete menu;
|
delete menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindowPlainTextEdit::appendLines(QString const& s, const QString &repository)
|
void OutputWindowPlainTextEdit::appendLines(const QString &s, const QString &repository)
|
||||||
{
|
{
|
||||||
if (s.isEmpty())
|
if (s.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int previousLineCount = document()->lineCount();
|
const int previousLineCount = document()->lineCount();
|
||||||
|
|
||||||
const QChar newLine(QLatin1Char('\n'));
|
const QChar newLine('\n');
|
||||||
const QChar lastChar = s.at(s.size() - 1);
|
const QChar lastChar = s.at(s.size() - 1);
|
||||||
const bool appendNewline = (lastChar != QLatin1Char('\r') && lastChar != newLine);
|
const bool appendNewline = (lastChar != '\r' && lastChar != newLine);
|
||||||
m_formatter->appendMessage(appendNewline ? s + newLine : s, m_format);
|
m_formatter->appendMessage(appendNewline ? s + newLine : s, m_format);
|
||||||
|
|
||||||
// Scroll down
|
// Scroll down
|
||||||
@@ -232,20 +227,21 @@ void OutputWindowPlainTextEdit::appendLines(QString const& s, const QString &rep
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindowPlainTextEdit::appendLinesWithStyle(QString const& s, enum VcsOutputWindow::MessageStyle style, const QString &repository)
|
void OutputWindowPlainTextEdit::appendLinesWithStyle(const QString &s,
|
||||||
|
VcsOutputWindow::MessageStyle style,
|
||||||
|
const QString &repository)
|
||||||
{
|
{
|
||||||
setFormat(style);
|
setFormat(style);
|
||||||
|
|
||||||
if (style == VcsOutputWindow::Command) {
|
if (style == VcsOutputWindow::Command) {
|
||||||
const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
|
const QString timeStamp = QTime::currentTime().toString("\nHH:mm ");
|
||||||
appendLines(timeStamp + s, repository);
|
appendLines(timeStamp + s, repository);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
appendLines(s, repository);
|
appendLines(s, repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindowPlainTextEdit::setFormat(enum VcsOutputWindow::MessageStyle style)
|
void OutputWindowPlainTextEdit::setFormat(VcsOutputWindow::MessageStyle style)
|
||||||
{
|
{
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case VcsOutputWindow::Warning:
|
case VcsOutputWindow::Warning:
|
||||||
@@ -284,7 +280,7 @@ static VcsOutputWindowPrivate *d = nullptr;
|
|||||||
VcsOutputWindow::VcsOutputWindow()
|
VcsOutputWindow::VcsOutputWindow()
|
||||||
{
|
{
|
||||||
d = new VcsOutputWindowPrivate;
|
d = new VcsOutputWindowPrivate;
|
||||||
d->passwordRegExp = QRegExp(QLatin1String("://([^@:]+):([^@]+)@"));
|
d->passwordRegExp = QRegExp("://([^@:]+):([^@]+)@");
|
||||||
Q_ASSERT(d->passwordRegExp.isValid());
|
Q_ASSERT(d->passwordRegExp.isValid());
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
}
|
}
|
||||||
@@ -294,7 +290,7 @@ static QString filterPasswordFromUrls(const QString &input)
|
|||||||
int pos = 0;
|
int pos = 0;
|
||||||
QString result = input;
|
QString result = input;
|
||||||
while ((pos = d->passwordRegExp.indexIn(result, pos)) >= 0) {
|
while ((pos = d->passwordRegExp.indexIn(result, pos)) >= 0) {
|
||||||
QString tmp = result.left(pos + 3) + d->passwordRegExp.cap(1) + QLatin1String(":***@");
|
QString tmp = result.left(pos + 3) + d->passwordRegExp.cap(1) + ":***@";
|
||||||
int newStart = tmp.count();
|
int newStart = tmp.count();
|
||||||
tmp += result.midRef(pos + d->passwordRegExp.matchedLength());
|
tmp += result.midRef(pos + d->passwordRegExp.matchedLength());
|
||||||
result = tmp;
|
result = tmp;
|
||||||
@@ -395,7 +391,7 @@ void VcsOutputWindow::appendSilently(const QString &text)
|
|||||||
append(text, None, true);
|
append(text, None, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsOutputWindow::append(const QString &text, enum MessageStyle style, bool silently)
|
void VcsOutputWindow::append(const QString &text, MessageStyle style, bool silently)
|
||||||
{
|
{
|
||||||
d->widget.appendLinesWithStyle(text, style, d->repository);
|
d->widget.appendLinesWithStyle(text, style, d->repository);
|
||||||
|
|
||||||
@@ -413,8 +409,7 @@ void VcsOutputWindow::appendWarning(const QString &text)
|
|||||||
append(text, Warning, false);
|
append(text, Warning, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to format arguments for log windows hiding common password
|
// Helper to format arguments for log windows hiding common password options.
|
||||||
// options.
|
|
||||||
static inline QString formatArguments(const QStringList &args)
|
static inline QString formatArguments(const QStringList &args)
|
||||||
{
|
{
|
||||||
const char passwordOptionC[] = "--password";
|
const char passwordOptionC[] = "--password";
|
||||||
@@ -427,12 +422,12 @@ static inline QString formatArguments(const QStringList &args)
|
|||||||
const QString arg = filterPasswordFromUrls(args.at(i));
|
const QString arg = filterPasswordFromUrls(args.at(i));
|
||||||
if (i)
|
if (i)
|
||||||
str << ' ';
|
str << ' ';
|
||||||
if (arg.startsWith(QString::fromLatin1(passwordOptionC) + QLatin1Char('='))) {
|
if (arg.startsWith(QString::fromLatin1(passwordOptionC) + '=')) {
|
||||||
str << QtcProcess::quoteArg("--password=********");
|
str << QtcProcess::quoteArg("--password=********");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
str << QtcProcess::quoteArg(arg);
|
str << QtcProcess::quoteArg(arg);
|
||||||
if (arg == QLatin1String(passwordOptionC)) {
|
if (arg == passwordOptionC) {
|
||||||
str << ' ' << QtcProcess::quoteArg("********");
|
str << ' ' << QtcProcess::quoteArg("********");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -447,9 +442,9 @@ QString VcsOutputWindow::msgExecutionLogEntry(const QString &workingDir,
|
|||||||
const QString args = formatArguments(arguments);
|
const QString args = formatArguments(arguments);
|
||||||
const QString nativeExecutable = QtcProcess::quoteArg(executable.toUserOutput());
|
const QString nativeExecutable = QtcProcess::quoteArg(executable.toUserOutput());
|
||||||
if (workingDir.isEmpty())
|
if (workingDir.isEmpty())
|
||||||
return tr("Running: %1 %2").arg(nativeExecutable, args) + QLatin1Char('\n');
|
return tr("Running: %1 %2").arg(nativeExecutable, args) + '\n';
|
||||||
return tr("Running in %1: %2 %3").
|
return tr("Running in %1: %2 %3").
|
||||||
arg(QDir::toNativeSeparators(workingDir), nativeExecutable, args) + QLatin1Char('\n');
|
arg(QDir::toNativeSeparators(workingDir), nativeExecutable, args) + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsOutputWindow::appendShellCommandLine(const QString &text)
|
void VcsOutputWindow::appendShellCommandLine(const QString &text)
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public slots:
|
|||||||
|
|
||||||
// Append text with a certain style (none by default),
|
// Append text with a certain style (none by default),
|
||||||
// and maybe pop up (silent by default)
|
// and maybe pop up (silent by default)
|
||||||
static void append(const QString &text, enum MessageStyle style = None, bool silently = false);
|
static void append(const QString &text, MessageStyle style = None, bool silently = false);
|
||||||
|
|
||||||
// Silently append text, do not pop up.
|
// Silently append text, do not pop up.
|
||||||
static void appendSilently(const QString &text);
|
static void appendSilently(const QString &text);
|
||||||
|
|||||||
Reference in New Issue
Block a user