2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-08-10 15:46:45 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-08-10 15:46:45 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-08-10 15:46:45 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-08-10 15:46:45 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
#include "vcsoutputwindow.h"
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2009-12-15 14:20:06 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2015-10-30 10:32:54 +02:00
|
|
|
#include <aggregation/aggregate.h>
|
|
|
|
|
#include <coreplugin/find/basetextfind.h>
|
2015-10-30 10:33:25 +02:00
|
|
|
#include <coreplugin/outputwindow.h>
|
2014-07-15 23:32:11 +03:00
|
|
|
#include <utils/fileutils.h>
|
2014-03-18 20:25:03 +02:00
|
|
|
#include <utils/outputformatter.h>
|
2017-05-15 09:00:56 +03:00
|
|
|
#include <utils/qtcprocess.h>
|
2015-03-30 10:28:19 +03:00
|
|
|
#include <utils/theme/theme.h>
|
2014-03-18 20:25:03 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
#include <QTextCharFormat>
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
|
#include <QTextBlock>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QTextBlockUserData>
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
#include <QDir>
|
2017-03-09 23:02:32 +01:00
|
|
|
#include <QRegExp>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QTime>
|
|
|
|
|
#include <QPoint>
|
|
|
|
|
#include <QFileInfo>
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2018-07-17 22:54:58 +03:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2011-03-28 14:19:17 +02:00
|
|
|
/*!
|
2012-01-07 12:31:48 +01:00
|
|
|
\class VcsBase::VcsBaseOutputWindow
|
2011-03-28 14:19:17 +02:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The VcsBaseOutputWindow class is an output window for Version Control
|
|
|
|
|
System commands and other output (Singleton).
|
2011-03-28 14:19:17 +02:00
|
|
|
|
|
|
|
|
Installed by the base plugin and accessible for the other plugins
|
|
|
|
|
via static instance()-accessor. Provides slots to append output with
|
|
|
|
|
special formatting.
|
|
|
|
|
|
|
|
|
|
It is possible to associate a repository with plain log text, enabling
|
|
|
|
|
an "Open" context menu action over relative file name tokens in the text
|
|
|
|
|
(absolute paths will also work). This can be used for "status" logs,
|
|
|
|
|
showing modified file names, allowing the user to open them.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace VcsBase {
|
2009-08-10 15:46:45 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-10-30 10:33:25 +02:00
|
|
|
const char C_VCS_OUTPUT_PANE[] = "Vcs.OutputPane";
|
|
|
|
|
|
2009-12-15 14:20:06 +01:00
|
|
|
// Store repository along with text blocks
|
2012-01-07 03:35:54 +01:00
|
|
|
class RepositoryUserData : public QTextBlockUserData
|
|
|
|
|
{
|
2009-12-15 14:20:06 +01:00
|
|
|
public:
|
|
|
|
|
explicit RepositoryUserData(const QString &repo) : m_repository(repo) {}
|
|
|
|
|
const QString &repository() const { return m_repository; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const QString m_repository;
|
|
|
|
|
};
|
|
|
|
|
|
2009-08-10 15:46:45 +02:00
|
|
|
// A plain text edit with a special context menu containing "Clear" and
|
|
|
|
|
// and functions to append specially formatted entries.
|
2015-10-30 10:33:25 +02:00
|
|
|
class OutputWindowPlainTextEdit : public Core::OutputWindow
|
2012-01-07 03:35:54 +01:00
|
|
|
{
|
2009-08-10 15:46:45 +02:00
|
|
|
public:
|
2018-09-20 01:32:36 +03:00
|
|
|
explicit OutputWindowPlainTextEdit(QWidget *parent = nullptr);
|
|
|
|
|
~OutputWindowPlainTextEdit() override;
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2014-02-11 19:57:24 -05:00
|
|
|
void appendLines(QString const& s, const QString &repository = QString());
|
2014-08-26 00:02:47 +02:00
|
|
|
void appendLinesWithStyle(QString const& s, enum VcsOutputWindow::MessageStyle style, const QString &repository = QString());
|
2009-08-10 15:46:45 +02:00
|
|
|
|
|
|
|
|
protected:
|
2018-07-11 07:31:38 +02:00
|
|
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
2009-08-10 15:46:45 +02:00
|
|
|
|
|
|
|
|
private:
|
2014-08-26 00:02:47 +02:00
|
|
|
void setFormat(enum VcsOutputWindow::MessageStyle style);
|
2018-09-20 01:32:36 +03:00
|
|
|
QString identifierUnderCursor(const QPoint &pos, QString *repository = nullptr) const;
|
2009-12-15 14:20:06 +01:00
|
|
|
|
2018-11-17 22:27:29 +02:00
|
|
|
Utils::OutputFormat m_format;
|
2009-08-10 15:46:45 +02:00
|
|
|
const QTextCharFormat m_defaultFormat;
|
|
|
|
|
QTextCharFormat m_errorFormat;
|
|
|
|
|
QTextCharFormat m_warningFormat;
|
|
|
|
|
QTextCharFormat m_commandFormat;
|
2013-08-11 22:36:21 +03:00
|
|
|
QTextCharFormat m_messageFormat;
|
2018-07-17 22:54:58 +03:00
|
|
|
OutputFormatter *m_formatter;
|
2009-08-10 15:46:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
|
2018-11-17 22:27:29 +02:00
|
|
|
Core::OutputWindow(Core::Context(C_VCS_OUTPUT_PANE), parent)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
setReadOnly(true);
|
2013-07-31 20:45:10 +03:00
|
|
|
setUndoRedoEnabled(false);
|
2009-08-10 15:46:45 +02:00
|
|
|
setFrameStyle(QFrame::NoFrame);
|
2018-07-17 22:54:58 +03:00
|
|
|
m_formatter = new OutputFormatter;
|
2018-11-23 12:33:42 +02:00
|
|
|
m_formatter->setBoldFontEnabled(false);
|
2014-03-18 20:25:03 +02:00
|
|
|
m_formatter->setPlainTextEdit(this);
|
2018-09-20 01:32:36 +03:00
|
|
|
auto agg = new Aggregation::Aggregate;
|
2016-02-07 12:09:55 +02:00
|
|
|
agg->add(this);
|
|
|
|
|
agg->add(new Core::BaseTextFind(this));
|
2014-03-18 20:25:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputWindowPlainTextEdit::~OutputWindowPlainTextEdit()
|
|
|
|
|
{
|
|
|
|
|
delete m_formatter;
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-12-15 14:20:06 +01:00
|
|
|
// Search back for beginning of word
|
|
|
|
|
static inline int firstWordCharacter(const QString &s, int startPos)
|
|
|
|
|
{
|
|
|
|
|
for ( ; startPos >= 0 ; startPos--) {
|
|
|
|
|
if (s.at(startPos).isSpace())
|
|
|
|
|
return startPos + 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString OutputWindowPlainTextEdit::identifierUnderCursor(const QPoint &widgetPos, QString *repository) const
|
|
|
|
|
{
|
|
|
|
|
if (repository)
|
|
|
|
|
repository->clear();
|
|
|
|
|
// Get the blank-delimited word under cursor. Note that
|
|
|
|
|
// using "SelectWordUnderCursor" does not work since it breaks
|
|
|
|
|
// at delimiters like '/'. Get the whole line
|
|
|
|
|
QTextCursor cursor = cursorForPosition(widgetPos);
|
|
|
|
|
const int cursorDocumentPos = cursor.position();
|
|
|
|
|
cursor.select(QTextCursor::BlockUnderCursor);
|
|
|
|
|
if (!cursor.hasSelection())
|
|
|
|
|
return QString();
|
|
|
|
|
QString block = cursor.selectedText();
|
|
|
|
|
// Determine cursor position within line and find blank-delimited word
|
|
|
|
|
const int cursorPos = cursorDocumentPos - cursor.block().position();
|
|
|
|
|
const int blockSize = block.size();
|
|
|
|
|
if (cursorPos < 0 || cursorPos >= blockSize || block.at(cursorPos).isSpace())
|
|
|
|
|
return QString();
|
|
|
|
|
// Retrieve repository if desired
|
|
|
|
|
if (repository)
|
|
|
|
|
if (QTextBlockUserData *data = cursor.block().userData())
|
|
|
|
|
*repository = static_cast<const RepositoryUserData*>(data)->repository();
|
|
|
|
|
// Find first non-space character of word and find first non-space character past
|
|
|
|
|
const int startPos = firstWordCharacter(block, cursorPos);
|
|
|
|
|
int endPos = cursorPos;
|
|
|
|
|
for ( ; endPos < blockSize && !block.at(endPos).isSpace(); endPos++) ;
|
|
|
|
|
return endPos > startPos ? block.mid(startPos, endPos - startPos) : QString();
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-10 15:46:45 +02:00
|
|
|
void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QMenu *menu = createStandardContextMenu();
|
2009-12-15 14:20:06 +01:00
|
|
|
// Add 'open file'
|
|
|
|
|
QString repository;
|
|
|
|
|
const QString token = identifierUnderCursor(event->pos(), &repository);
|
2018-09-20 01:32:36 +03:00
|
|
|
QAction *openAction = nullptr;
|
2009-12-15 14:20:06 +01:00
|
|
|
if (!token.isEmpty()) {
|
|
|
|
|
// Check for a file, expand via repository if relative
|
|
|
|
|
QFileInfo fi(token);
|
|
|
|
|
if (!repository.isEmpty() && !fi.isFile() && fi.isRelative())
|
|
|
|
|
fi = QFileInfo(repository + QLatin1Char('/') + token);
|
|
|
|
|
if (fi.isFile()) {
|
|
|
|
|
menu->addSeparator();
|
2014-08-26 00:02:47 +02:00
|
|
|
openAction = menu->addAction(VcsOutputWindow::tr("Open \"%1\"").
|
2010-07-05 09:52:32 +02:00
|
|
|
arg(QDir::toNativeSeparators(fi.fileName())));
|
2009-12-15 14:20:06 +01:00
|
|
|
openAction->setData(fi.absoluteFilePath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Add 'clear'
|
2009-08-10 15:46:45 +02:00
|
|
|
menu->addSeparator();
|
2014-08-26 00:02:47 +02:00
|
|
|
QAction *clearAction = menu->addAction(VcsOutputWindow::tr("Clear"));
|
2009-12-15 14:20:06 +01:00
|
|
|
|
|
|
|
|
// Run
|
|
|
|
|
QAction *action = menu->exec(event->globalPos());
|
|
|
|
|
if (action) {
|
|
|
|
|
if (action == clearAction) {
|
|
|
|
|
clear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (action == openAction) {
|
|
|
|
|
const QString fileName = action->data().toString();
|
2013-05-31 12:52:53 +02:00
|
|
|
Core::EditorManager::openEditor(fileName);
|
2009-12-15 14:20:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-10 15:46:45 +02:00
|
|
|
delete menu;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 19:57:24 -05:00
|
|
|
void OutputWindowPlainTextEdit::appendLines(QString const& s, const QString &repository)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
if (s.isEmpty())
|
|
|
|
|
return;
|
2014-02-11 19:57:24 -05:00
|
|
|
|
2009-12-15 14:20:06 +01:00
|
|
|
const int previousLineCount = document()->lineCount();
|
2014-02-11 19:57:24 -05:00
|
|
|
|
2014-03-18 20:25:03 +02:00
|
|
|
const QChar newLine(QLatin1Char('\n'));
|
|
|
|
|
const QChar lastChar = s.at(s.size() - 1);
|
|
|
|
|
const bool appendNewline = (lastChar != QLatin1Char('\r') && lastChar != newLine);
|
2018-11-17 22:27:29 +02:00
|
|
|
m_formatter->appendMessage(appendNewline ? s + newLine : s, m_format);
|
2014-02-11 19:57:24 -05:00
|
|
|
|
2009-08-10 15:46:45 +02:00
|
|
|
// Scroll down
|
|
|
|
|
moveCursor(QTextCursor::End);
|
|
|
|
|
ensureCursorVisible();
|
2009-12-15 14:20:06 +01:00
|
|
|
if (!repository.isEmpty()) {
|
|
|
|
|
// Associate repository with new data.
|
|
|
|
|
QTextBlock block = document()->findBlockByLineNumber(previousLineCount);
|
|
|
|
|
for ( ; block.isValid(); block = block.next())
|
|
|
|
|
block.setUserData(new RepositoryUserData(repository));
|
|
|
|
|
}
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void OutputWindowPlainTextEdit::appendLinesWithStyle(QString const& s, enum VcsOutputWindow::MessageStyle style, const QString &repository)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2014-02-11 19:57:24 -05:00
|
|
|
setFormat(style);
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
if (style == VcsOutputWindow::Command) {
|
2014-02-11 19:57:24 -05:00
|
|
|
const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
|
|
|
|
|
appendLines(timeStamp + s, repository);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
appendLines(s, repository);
|
|
|
|
|
}
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void OutputWindowPlainTextEdit::setFormat(enum VcsOutputWindow::MessageStyle style)
|
2014-02-11 19:57:24 -05:00
|
|
|
{
|
|
|
|
|
switch (style) {
|
2014-08-26 00:02:47 +02:00
|
|
|
case VcsOutputWindow::Warning:
|
2018-11-17 22:27:29 +02:00
|
|
|
m_format = LogMessageFormat;
|
2014-02-11 19:57:24 -05:00
|
|
|
break;
|
2014-08-26 00:02:47 +02:00
|
|
|
case VcsOutputWindow::Error:
|
2018-11-17 22:27:29 +02:00
|
|
|
m_format = ErrorMessageFormat;
|
2014-02-11 19:57:24 -05:00
|
|
|
break;
|
2014-08-26 00:02:47 +02:00
|
|
|
case VcsOutputWindow::Message:
|
2018-11-17 22:27:29 +02:00
|
|
|
m_format = NormalMessageFormat;
|
2014-02-11 19:57:24 -05:00
|
|
|
break;
|
2014-08-26 00:02:47 +02:00
|
|
|
case VcsOutputWindow::Command:
|
2018-11-17 22:27:29 +02:00
|
|
|
m_format = NormalMessageFormat;
|
2014-02-11 19:57:24 -05:00
|
|
|
break;
|
|
|
|
|
default:
|
2014-08-26 00:02:47 +02:00
|
|
|
case VcsOutputWindow::None:
|
2018-11-17 22:27:29 +02:00
|
|
|
m_format = OutputFormat::StdOutFormat;
|
2014-02-11 19:57:24 -05:00
|
|
|
break;
|
|
|
|
|
}
|
2013-08-11 22:36:21 +03:00
|
|
|
}
|
|
|
|
|
|
2009-08-10 15:46:45 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
// ------------------- VcsBaseOutputWindowPrivate
|
2014-08-26 00:02:47 +02:00
|
|
|
class VcsOutputWindowPrivate
|
2012-01-07 03:35:54 +01:00
|
|
|
{
|
2014-02-27 13:47:48 +01:00
|
|
|
public:
|
2016-08-01 09:27:42 +03:00
|
|
|
Internal::OutputWindowPlainTextEdit widget;
|
2009-12-15 14:20:06 +01:00
|
|
|
QString repository;
|
2014-02-27 13:48:33 +01:00
|
|
|
QRegExp passwordRegExp;
|
2009-08-10 15:46:45 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-20 01:32:36 +03:00
|
|
|
static VcsOutputWindow *m_instance = nullptr;
|
|
|
|
|
static VcsOutputWindowPrivate *d = nullptr;
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
VcsOutputWindow::VcsOutputWindow()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2014-08-26 00:02:47 +02:00
|
|
|
d = new VcsOutputWindowPrivate;
|
2014-02-27 13:48:33 +01:00
|
|
|
d->passwordRegExp = QRegExp(QLatin1String("://([^@:]+):([^@]+)@"));
|
|
|
|
|
Q_ASSERT(d->passwordRegExp.isValid());
|
2014-08-26 00:02:47 +02:00
|
|
|
m_instance = this;
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
static QString filterPasswordFromUrls(const QString &input)
|
2014-02-27 13:48:33 +01:00
|
|
|
{
|
|
|
|
|
int pos = 0;
|
|
|
|
|
QString result = input;
|
|
|
|
|
while ((pos = d->passwordRegExp.indexIn(result, pos)) >= 0) {
|
|
|
|
|
QString tmp = result.left(pos + 3) + d->passwordRegExp.cap(1) + QLatin1String(":***@");
|
|
|
|
|
int newStart = tmp.count();
|
|
|
|
|
tmp += result.mid(pos + d->passwordRegExp.matchedLength());
|
|
|
|
|
result = tmp;
|
|
|
|
|
pos = newStart;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
VcsOutputWindow::~VcsOutputWindow()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2018-09-20 01:32:36 +03:00
|
|
|
m_instance = nullptr;
|
2009-08-10 15:46:45 +02:00
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
QWidget *VcsOutputWindow::outputWidget(QWidget *parent)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2016-08-01 09:27:42 +03:00
|
|
|
if (parent != d->widget.parent())
|
|
|
|
|
d->widget.setParent(parent);
|
|
|
|
|
return &d->widget;
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-01 09:27:42 +03:00
|
|
|
QList<QWidget *> VcsOutputWindow::toolBarWidgets() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2016-08-01 09:27:42 +03:00
|
|
|
return {};
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
QString VcsOutputWindow::displayName() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return tr("Version Control");
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
int VcsOutputWindow::priorityInStatusBar() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::clearContents()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2016-08-01 09:27:42 +03:00
|
|
|
d->widget.clear();
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::visibilityChanged(bool visible)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2016-08-01 09:27:42 +03:00
|
|
|
if (visible)
|
|
|
|
|
d->widget.setFocus();
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::setFocus()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2018-11-18 23:00:41 +02:00
|
|
|
d->widget.setFocus();
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
bool VcsOutputWindow::hasFocus() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2018-11-18 23:00:41 +02:00
|
|
|
return d->widget.hasFocus();
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
bool VcsOutputWindow::canFocus() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2018-11-18 23:00:41 +02:00
|
|
|
return true;
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
bool VcsOutputWindow::canNavigate() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
bool VcsOutputWindow::canNext() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
bool VcsOutputWindow::canPrevious() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::goToNext()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::goToPrev()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::setText(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2016-08-01 09:27:42 +03:00
|
|
|
d->widget.setPlainText(text);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::setData(const QByteArray &data)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
setText(QTextCodec::codecForLocale()->toUnicode(data));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::appendSilently(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2014-02-11 19:57:24 -05:00
|
|
|
append(text, None, true);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::append(const QString &text, enum MessageStyle style, bool silently)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2016-08-01 09:27:42 +03:00
|
|
|
d->widget.appendLinesWithStyle(text, style, d->repository);
|
2014-02-11 19:57:24 -05:00
|
|
|
|
2016-08-01 09:27:42 +03:00
|
|
|
if (!silently && !d->widget.isVisible())
|
2014-08-26 00:02:47 +02:00
|
|
|
m_instance->popup(Core::IOutputPane::NoModeSwitch);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::appendError(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2014-02-11 19:57:24 -05:00
|
|
|
append(text, Error, false);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::appendWarning(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2014-02-11 19:57:24 -05:00
|
|
|
append(text, Warning, false);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2010-05-21 17:46:00 +02:00
|
|
|
// Helper to format arguments for log windows hiding common password
|
|
|
|
|
// options.
|
|
|
|
|
static inline QString formatArguments(const QStringList &args)
|
|
|
|
|
{
|
|
|
|
|
const char passwordOptionC[] = "--password";
|
|
|
|
|
|
|
|
|
|
QString rc;
|
|
|
|
|
QTextStream str(&rc);
|
|
|
|
|
const int size = args.size();
|
|
|
|
|
// Skip authentication options
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
2015-01-20 12:16:13 +01:00
|
|
|
const QString arg = filterPasswordFromUrls(args.at(i));
|
2010-05-21 17:46:00 +02:00
|
|
|
if (i)
|
|
|
|
|
str << ' ';
|
2015-01-20 12:16:13 +01:00
|
|
|
if (arg.startsWith(QString::fromLatin1(passwordOptionC) + QLatin1Char('='))) {
|
2018-07-17 22:54:58 +03:00
|
|
|
str << QtcProcess::quoteArg("--password=********");
|
2015-01-20 12:16:13 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2018-07-17 22:54:58 +03:00
|
|
|
str << QtcProcess::quoteArg(arg);
|
2010-05-21 17:46:00 +02:00
|
|
|
if (arg == QLatin1String(passwordOptionC)) {
|
2018-07-17 22:54:58 +03:00
|
|
|
str << ' ' << QtcProcess::quoteArg("********");
|
2010-05-21 17:46:00 +02:00
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
QString VcsOutputWindow::msgExecutionLogEntry(const QString &workingDir,
|
2018-07-17 22:54:58 +03:00
|
|
|
const FileName &executable,
|
|
|
|
|
const QStringList &arguments)
|
2010-05-21 17:46:00 +02:00
|
|
|
{
|
|
|
|
|
const QString args = formatArguments(arguments);
|
2018-07-17 22:54:58 +03:00
|
|
|
const QString nativeExecutable = QtcProcess::quoteArg(executable.toUserOutput());
|
2010-05-21 17:46:00 +02:00
|
|
|
if (workingDir.isEmpty())
|
2017-01-08 12:05:05 +01:00
|
|
|
return tr("Running: %1 %2").arg(nativeExecutable, args) + QLatin1Char('\n');
|
|
|
|
|
return tr("Running in %1: %2 %3").
|
2013-10-17 13:48:04 +02:00
|
|
|
arg(QDir::toNativeSeparators(workingDir), nativeExecutable, args) + QLatin1Char('\n');
|
2010-05-21 17:46:00 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-19 13:22:20 +01:00
|
|
|
void VcsOutputWindow::appendShellCommandLine(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2014-02-27 13:48:33 +01:00
|
|
|
append(filterPasswordFromUrls(text), Command, true);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::appendCommand(const QString &workingDirectory,
|
2018-07-17 22:54:58 +03:00
|
|
|
const FileName &binary,
|
2015-01-19 13:23:37 +01:00
|
|
|
const QStringList &args)
|
2010-05-21 17:46:00 +02:00
|
|
|
{
|
2015-01-19 13:22:20 +01:00
|
|
|
appendShellCommandLine(msgExecutionLogEntry(workingDirectory, binary, args));
|
2010-05-21 17:46:00 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::appendMessage(const QString &text)
|
2013-08-11 22:36:21 +03:00
|
|
|
{
|
2014-02-11 19:57:24 -05:00
|
|
|
append(text, Message, true);
|
2013-08-11 22:36:21 +03:00
|
|
|
}
|
|
|
|
|
|
2018-02-19 14:15:05 +01:00
|
|
|
void VcsOutputWindow::destroy()
|
|
|
|
|
{
|
|
|
|
|
delete m_instance;
|
|
|
|
|
m_instance = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
VcsOutputWindow *VcsOutputWindow::instance()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2014-08-26 00:02:47 +02:00
|
|
|
if (!m_instance)
|
|
|
|
|
(void) new VcsOutputWindow;
|
|
|
|
|
return m_instance;
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
QString VcsOutputWindow::repository() const
|
2009-12-15 14:20:06 +01:00
|
|
|
{
|
|
|
|
|
return d->repository;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::setRepository(const QString &r)
|
2009-12-15 14:20:06 +01:00
|
|
|
{
|
|
|
|
|
d->repository = r;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 00:02:47 +02:00
|
|
|
void VcsOutputWindow::clearRepository()
|
2009-12-15 14:20:06 +01:00
|
|
|
{
|
|
|
|
|
d->repository.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|