forked from qt-creator/qt-creator
VCS: Auto open for edit by Perforce no longer steals focus.
Refactoring appendLines to use MessageStyle enum. Task-number: QTCREATORBUG-8289 Change-Id: I3a023724e6616d1b60640cb4d70ce7dd8fe30338 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Tobias Hunger
parent
9310b652eb
commit
7f7b8f0ef7
@@ -85,20 +85,14 @@ class OutputWindowPlainTextEdit : public QPlainTextEdit
|
||||
public:
|
||||
explicit OutputWindowPlainTextEdit(QWidget *parent = 0);
|
||||
|
||||
void appendLines(QString s, const QString &repository = QString());
|
||||
// Append red error text and pop up.
|
||||
void appendError(const QString &text);
|
||||
// Append warning error text and pop up.
|
||||
void appendWarning(const QString &text);
|
||||
// Append a bold command "10:00 " + "Executing: vcs -diff"
|
||||
void appendCommand(const QString &text);
|
||||
// Append a message text (e.g. "command has finished successfully") and pop up.
|
||||
void appendMessage(const QString &text);
|
||||
void appendLines(QString const& s, const QString &repository = QString());
|
||||
void appendLinesWithStyle(QString const& s, enum VcsBaseOutputWindow::MessageStyle style, const QString &repository = QString());
|
||||
|
||||
protected:
|
||||
virtual void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
private:
|
||||
void setFormat(enum VcsBaseOutputWindow::MessageStyle style);
|
||||
QString identifierUnderCursor(const QPoint &pos, QString *repository = 0) const;
|
||||
|
||||
const QTextCharFormat m_defaultFormat;
|
||||
@@ -202,15 +196,23 @@ void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void OutputWindowPlainTextEdit::appendLines(QString s, const QString &repository)
|
||||
void OutputWindowPlainTextEdit::appendLines(QString const& s, const QString &repository)
|
||||
{
|
||||
if (s.isEmpty())
|
||||
return;
|
||||
// Avoid additional new line character generated by appendPlainText
|
||||
if (s.endsWith(QLatin1Char('\n')))
|
||||
s.truncate(s.size() - 1);
|
||||
|
||||
const int previousLineCount = document()->lineCount();
|
||||
appendPlainText(s);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Scroll down
|
||||
moveCursor(QTextCursor::End);
|
||||
ensureCursorVisible();
|
||||
@@ -222,34 +224,41 @@ void OutputWindowPlainTextEdit::appendLines(QString s, const QString &repository
|
||||
}
|
||||
}
|
||||
|
||||
void OutputWindowPlainTextEdit::appendError(const QString &text)
|
||||
void OutputWindowPlainTextEdit::appendLinesWithStyle(QString const& s, enum VcsBaseOutputWindow::MessageStyle style, const QString &repository)
|
||||
{
|
||||
setCurrentCharFormat(m_errorFormat);
|
||||
appendLines(text);
|
||||
setFormat(style);
|
||||
|
||||
if (style == VcsBaseOutputWindow::Command) {
|
||||
const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
|
||||
appendLines(timeStamp + s, repository);
|
||||
}
|
||||
else {
|
||||
appendLines(s, repository);
|
||||
}
|
||||
|
||||
setCurrentCharFormat(m_defaultFormat);
|
||||
}
|
||||
|
||||
void OutputWindowPlainTextEdit::appendWarning(const QString &text)
|
||||
void OutputWindowPlainTextEdit::setFormat(enum VcsBaseOutputWindow::MessageStyle style)
|
||||
{
|
||||
setCurrentCharFormat(m_warningFormat);
|
||||
appendLines(text);
|
||||
setCurrentCharFormat(m_defaultFormat);
|
||||
}
|
||||
|
||||
// Append command with new line and log time stamp
|
||||
void OutputWindowPlainTextEdit::appendCommand(const QString &text)
|
||||
{
|
||||
setCurrentCharFormat(m_commandFormat);
|
||||
const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
|
||||
appendLines(timeStamp + text);
|
||||
setCurrentCharFormat(m_defaultFormat);
|
||||
}
|
||||
|
||||
void OutputWindowPlainTextEdit::appendMessage(const QString &text)
|
||||
{
|
||||
setCurrentCharFormat(m_messageFormat);
|
||||
appendLines(text);
|
||||
setCurrentCharFormat(m_defaultFormat);
|
||||
switch (style) {
|
||||
case VcsBaseOutputWindow::Warning:
|
||||
setCurrentCharFormat(m_warningFormat);
|
||||
break;
|
||||
case VcsBaseOutputWindow::Error:
|
||||
setCurrentCharFormat(m_errorFormat);
|
||||
break;
|
||||
case VcsBaseOutputWindow::Message:
|
||||
setCurrentCharFormat(m_messageFormat);
|
||||
break;
|
||||
case VcsBaseOutputWindow::Command:
|
||||
setCurrentCharFormat(m_commandFormat);
|
||||
break;
|
||||
default:
|
||||
case VcsBaseOutputWindow::None:
|
||||
setCurrentCharFormat(m_defaultFormat);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
@@ -375,28 +384,25 @@ void VcsBaseOutputWindow::setData(const QByteArray &data)
|
||||
|
||||
void VcsBaseOutputWindow::appendSilently(const QString &text)
|
||||
{
|
||||
d->plainTextEdit()->appendLines(text, d->repository);
|
||||
append(text, None, true);
|
||||
}
|
||||
|
||||
void VcsBaseOutputWindow::append(const QString &text)
|
||||
void VcsBaseOutputWindow::append(const QString &text, enum MessageStyle style, bool silently)
|
||||
{
|
||||
appendSilently(text);
|
||||
if (!d->plainTextEdit()->isVisible())
|
||||
d->plainTextEdit()->appendLinesWithStyle(text, style, d->repository);
|
||||
|
||||
if (!silently && !d->plainTextEdit()->isVisible())
|
||||
popup(Core::IOutputPane::NoModeSwitch);
|
||||
}
|
||||
|
||||
void VcsBaseOutputWindow::appendError(const QString &text)
|
||||
{
|
||||
d->plainTextEdit()->appendError(text);
|
||||
if (!d->plainTextEdit()->isVisible())
|
||||
popup(Core::IOutputPane::NoModeSwitch);
|
||||
append(text, Error, false);
|
||||
}
|
||||
|
||||
void VcsBaseOutputWindow::appendWarning(const QString &text)
|
||||
{
|
||||
d->plainTextEdit()->appendWarning(text);
|
||||
if (!d->plainTextEdit()->isVisible())
|
||||
popup(Core::IOutputPane::NoModeSwitch);
|
||||
append(text, Warning, false);
|
||||
}
|
||||
|
||||
// Helper to format arguments for log windows hiding common password
|
||||
@@ -436,7 +442,7 @@ QString VcsBaseOutputWindow::msgExecutionLogEntry(const QString &workingDir,
|
||||
|
||||
void VcsBaseOutputWindow::appendCommand(const QString &text)
|
||||
{
|
||||
d->plainTextEdit()->appendCommand(text);
|
||||
append(text, Command, true);
|
||||
}
|
||||
|
||||
void VcsBaseOutputWindow::appendCommand(const QString &workingDirectory,
|
||||
@@ -448,7 +454,7 @@ void VcsBaseOutputWindow::appendCommand(const QString &workingDirectory,
|
||||
|
||||
void VcsBaseOutputWindow::appendMessage(const QString &text)
|
||||
{
|
||||
d->plainTextEdit()->appendMessage(text);
|
||||
append(text, Message, true);
|
||||
}
|
||||
|
||||
VcsBaseOutputWindow *VcsBaseOutputWindow::instance()
|
||||
|
||||
Reference in New Issue
Block a user