2009-08-10 15:46:45 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2009-08-10 15:46:45 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-08-10 15:46:45 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2009-08-10 15:46:45 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-08-10 15:46:45 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "vcsbaseoutputwindow.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
2009-12-15 14:20:06 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
#include <QTextCharFormat>
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
|
#include <QTextBlock>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
#include <QTextBlockUserData>
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QTime>
|
|
|
|
|
#include <QPoint>
|
|
|
|
|
#include <QFileInfo>
|
2009-08-10 15:46:45 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
\brief Output window for Version Control System command and other output (Singleton).
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
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.
|
2012-01-07 03:35:54 +01:00
|
|
|
class OutputWindowPlainTextEdit : public QPlainTextEdit
|
|
|
|
|
{
|
2009-08-10 15:46:45 +02:00
|
|
|
public:
|
2010-02-12 14:41:19 +01:00
|
|
|
explicit OutputWindowPlainTextEdit(QWidget *parent = 0);
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2009-12-15 14:20:06 +01:00
|
|
|
void appendLines(QString s, const QString &repository = QString());
|
2009-08-10 15:46:45 +02:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void contextMenuEvent(QContextMenuEvent *event);
|
|
|
|
|
|
|
|
|
|
private:
|
2009-12-15 14:20:06 +01:00
|
|
|
QString identifierUnderCursor(const QPoint &pos, QString *repository = 0) const;
|
|
|
|
|
|
2009-08-10 15:46:45 +02:00
|
|
|
const QTextCharFormat m_defaultFormat;
|
|
|
|
|
QTextCharFormat m_errorFormat;
|
|
|
|
|
QTextCharFormat m_warningFormat;
|
|
|
|
|
QTextCharFormat m_commandFormat;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
|
|
|
|
|
QPlainTextEdit(parent),
|
|
|
|
|
m_defaultFormat(currentCharFormat()),
|
|
|
|
|
m_errorFormat(m_defaultFormat),
|
|
|
|
|
m_warningFormat(m_defaultFormat),
|
|
|
|
|
m_commandFormat(m_defaultFormat)
|
|
|
|
|
{
|
|
|
|
|
setReadOnly(true);
|
|
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
m_errorFormat.setForeground(Qt::red);
|
|
|
|
|
m_warningFormat.setForeground(Qt::darkYellow);
|
|
|
|
|
m_commandFormat.setFontWeight(QFont::Bold);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
QAction *openAction = 0;
|
|
|
|
|
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();
|
2012-01-07 12:31:48 +01:00
|
|
|
openAction = menu->addAction(VcsBaseOutputWindow::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();
|
2012-01-07 12:31:48 +01:00
|
|
|
QAction *clearAction = menu->addAction(VcsBaseOutputWindow::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();
|
2011-11-10 11:36:51 +01:00
|
|
|
Core::EditorManager::instance()->openEditor(fileName, Core::Id(), Core::EditorManager::ModeSwitch);
|
2009-12-15 14:20:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-10 15:46:45 +02:00
|
|
|
delete menu;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-15 14:20:06 +01:00
|
|
|
void OutputWindowPlainTextEdit::appendLines(QString s, const QString &repository)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
if (s.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
// Avoid additional new line character generated by appendPlainText
|
|
|
|
|
if (s.endsWith(QLatin1Char('\n')))
|
|
|
|
|
s.truncate(s.size() - 1);
|
2009-12-15 14:20:06 +01:00
|
|
|
const int previousLineCount = document()->lineCount();
|
2009-08-10 15:46:45 +02:00
|
|
|
appendPlainText(s);
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutputWindowPlainTextEdit::appendError(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
setCurrentCharFormat(m_errorFormat);
|
|
|
|
|
appendLines(text);
|
|
|
|
|
setCurrentCharFormat(m_defaultFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutputWindowPlainTextEdit::appendWarning(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
// ------------------- VcsBaseOutputWindowPrivate
|
|
|
|
|
struct VcsBaseOutputWindowPrivate
|
2012-01-07 03:35:54 +01:00
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
static VcsBaseOutputWindow *instance;
|
2010-02-12 14:41:19 +01:00
|
|
|
Internal::OutputWindowPlainTextEdit *plainTextEdit();
|
|
|
|
|
|
|
|
|
|
QPointer<Internal::OutputWindowPlainTextEdit> m_plainTextEdit;
|
2009-12-15 14:20:06 +01:00
|
|
|
QString repository;
|
2009-08-10 15:46:45 +02:00
|
|
|
};
|
|
|
|
|
|
2010-02-12 14:41:19 +01:00
|
|
|
// Create log editor on demand. Some errors might be logged
|
|
|
|
|
// before CorePlugin::extensionsInitialized() pulls up the windows.
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
Internal::OutputWindowPlainTextEdit *VcsBaseOutputWindowPrivate::plainTextEdit()
|
2010-02-12 14:41:19 +01:00
|
|
|
{
|
|
|
|
|
if (!m_plainTextEdit)
|
|
|
|
|
m_plainTextEdit = new Internal::OutputWindowPlainTextEdit();
|
|
|
|
|
return m_plainTextEdit;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseOutputWindow *VcsBaseOutputWindowPrivate::instance = 0;
|
2009-08-10 15:46:45 +02:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseOutputWindow::VcsBaseOutputWindow() :
|
|
|
|
|
d(new VcsBaseOutputWindowPrivate)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseOutputWindowPrivate::instance = this;
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseOutputWindow::~VcsBaseOutputWindow()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseOutputWindowPrivate::instance = 0;
|
2009-08-10 15:46:45 +02:00
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
QWidget *VcsBaseOutputWindow::outputWidget(QWidget *parent)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-02-12 14:41:19 +01:00
|
|
|
if (d->m_plainTextEdit) {
|
|
|
|
|
if (parent != d->m_plainTextEdit->parent())
|
|
|
|
|
d->m_plainTextEdit->setParent(parent);
|
|
|
|
|
} else {
|
|
|
|
|
d->m_plainTextEdit = new Internal::OutputWindowPlainTextEdit(parent);
|
|
|
|
|
}
|
|
|
|
|
return d->m_plainTextEdit;
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
QWidgetList VcsBaseOutputWindow::toolBarWidgets() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return QWidgetList();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
QString VcsBaseOutputWindow::displayName() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return tr("Version Control");
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
int VcsBaseOutputWindow::priorityInStatusBar() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::clearContents()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-02-12 14:41:19 +01:00
|
|
|
if (d->m_plainTextEdit)
|
|
|
|
|
d->m_plainTextEdit->clear();
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::visibilityChanged(bool visible)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-02-12 14:41:19 +01:00
|
|
|
if (visible && d->m_plainTextEdit)
|
|
|
|
|
d->m_plainTextEdit->setFocus();
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::setFocus()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool VcsBaseOutputWindow::hasFocus() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool VcsBaseOutputWindow::canFocus() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool VcsBaseOutputWindow::canNavigate() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool VcsBaseOutputWindow::canNext() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool VcsBaseOutputWindow::canPrevious() const
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::goToNext()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::goToPrev()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::setText(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-02-12 14:41:19 +01:00
|
|
|
d->plainTextEdit()->setPlainText(text);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::setData(const QByteArray &data)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
setText(QTextCodec::codecForLocale()->toUnicode(data));
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::appendSilently(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-02-12 14:41:19 +01:00
|
|
|
d->plainTextEdit()->appendLines(text, d->repository);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::append(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
appendSilently(text);
|
|
|
|
|
// Pop up without focus
|
2010-02-12 14:41:19 +01:00
|
|
|
if (!d->plainTextEdit()->isVisible())
|
2009-08-10 15:46:45 +02:00
|
|
|
popup(false);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::appendError(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-02-12 14:41:19 +01:00
|
|
|
d->plainTextEdit()->appendError(text);
|
|
|
|
|
if (!d->plainTextEdit()->isVisible())
|
2009-08-10 15:46:45 +02:00
|
|
|
popup(false); // Pop up without focus
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::appendWarning(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-02-12 14:41:19 +01:00
|
|
|
d->plainTextEdit()->appendWarning(text);
|
|
|
|
|
if (!d->plainTextEdit()->isVisible())
|
2009-08-10 15:46:45 +02:00
|
|
|
popup(false); // Pop up without focus
|
|
|
|
|
}
|
|
|
|
|
|
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++) {
|
|
|
|
|
const QString &arg = args.at(i);
|
|
|
|
|
if (i)
|
|
|
|
|
str << ' ';
|
|
|
|
|
str << arg;
|
|
|
|
|
if (arg == QLatin1String(passwordOptionC)) {
|
|
|
|
|
str << " ********";
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
QString VcsBaseOutputWindow::msgExecutionLogEntry(const QString &workingDir,
|
2010-05-21 17:46:00 +02:00
|
|
|
const QString &executable,
|
|
|
|
|
const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
const QString args = formatArguments(arguments);
|
2010-07-05 09:52:32 +02:00
|
|
|
const QString nativeExecutable = QDir::toNativeSeparators(executable);
|
2010-05-21 17:46:00 +02:00
|
|
|
if (workingDir.isEmpty())
|
2010-07-05 09:52:32 +02:00
|
|
|
return tr("Executing: %1 %2\n").arg(nativeExecutable, args);
|
2010-05-21 17:46:00 +02:00
|
|
|
return tr("Executing in %1: %2 %3\n").
|
2010-07-05 09:52:32 +02:00
|
|
|
arg(QDir::toNativeSeparators(workingDir), nativeExecutable, args);
|
2010-05-21 17:46:00 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::appendCommand(const QString &text)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-02-12 14:41:19 +01:00
|
|
|
d->plainTextEdit()->appendCommand(text);
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::appendCommand(const QString &workingDirectory,
|
2010-05-21 17:46:00 +02:00
|
|
|
const QString &binary,
|
|
|
|
|
const QStringList &args)
|
|
|
|
|
{
|
|
|
|
|
appendCommand(msgExecutionLogEntry(workingDirectory, binary, args));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::appendData(const QByteArray &data)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
|
|
|
|
appendDataSilently(data);
|
2010-02-12 14:41:19 +01:00
|
|
|
if (!d->plainTextEdit()->isVisible())
|
2009-08-10 15:46:45 +02:00
|
|
|
popup(false); // Pop up without focus
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::appendDataSilently(const QByteArray &data)
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2010-05-21 19:35:33 +02:00
|
|
|
appendSilently(QTextCodec::codecForLocale()->toUnicode(data));
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseOutputWindow *VcsBaseOutputWindow::instance()
|
2009-08-10 15:46:45 +02:00
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
if (!VcsBaseOutputWindowPrivate::instance) {
|
|
|
|
|
VcsBaseOutputWindow *w = new VcsBaseOutputWindow;
|
2009-08-10 15:46:45 +02:00
|
|
|
Q_UNUSED(w)
|
|
|
|
|
}
|
2012-01-07 12:31:48 +01:00
|
|
|
return VcsBaseOutputWindowPrivate::instance;
|
2009-08-10 15:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
QString VcsBaseOutputWindow::repository() const
|
2009-12-15 14:20:06 +01:00
|
|
|
{
|
|
|
|
|
return d->repository;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::setRepository(const QString &r)
|
2009-12-15 14:20:06 +01:00
|
|
|
{
|
|
|
|
|
d->repository = r;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsBaseOutputWindow::clearRepository()
|
2009-12-15 14:20:06 +01:00
|
|
|
{
|
|
|
|
|
d->repository.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|