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
@@ -864,14 +864,18 @@ bool PerforcePlugin::managesDirectoryFstat(const QString &directory)
|
|||||||
return managed;
|
return managed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PerforcePlugin::vcsOpen(const QString &workingDir, const QString &fileName)
|
bool PerforcePlugin::vcsOpen(const QString &workingDir, const QString &fileName, bool silently)
|
||||||
{
|
{
|
||||||
if (Perforce::Constants::debug)
|
if (Perforce::Constants::debug)
|
||||||
qDebug() << "PerforcePlugin::vcsOpen" << workingDir << fileName;
|
qDebug() << "PerforcePlugin::vcsOpen" << workingDir << fileName;
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << QLatin1String("edit") << QDir::toNativeSeparators(fileName);
|
args << QLatin1String("edit") << QDir::toNativeSeparators(fileName);
|
||||||
const PerforceResponse result = runP4Cmd(workingDir, args,
|
|
||||||
CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
|
int flags = CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow;
|
||||||
|
if (silently) {
|
||||||
|
flags |= SilentStdOut;
|
||||||
|
}
|
||||||
|
const PerforceResponse result = runP4Cmd(workingDir, args, flags);
|
||||||
return !result.error;
|
return !result.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1003,7 +1007,12 @@ PerforceResponse PerforcePlugin::synchronousProcess(const QString &workingDir,
|
|||||||
// connect stdout to the output window if desired
|
// connect stdout to the output window if desired
|
||||||
if (flags & StdOutToWindow) {
|
if (flags & StdOutToWindow) {
|
||||||
process.setStdOutBufferedSignalsEnabled(true);
|
process.setStdOutBufferedSignalsEnabled(true);
|
||||||
connect(&process, SIGNAL(stdOutBuffered(QString,bool)), outputWindow, SLOT(append(QString)));
|
if (flags & SilentStdOut) {
|
||||||
|
connect(&process, SIGNAL(stdOutBuffered(QString,bool)), outputWindow, SLOT(appendSilently(QString)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
connect(&process, SIGNAL(stdOutBuffered(QString,bool)), outputWindow, SLOT(append(QString)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Perforce::Constants::debug)
|
if (Perforce::Constants::debug)
|
||||||
qDebug() << "PerforcePlugin::run syncp actual args [" << process.workingDirectory() << ']' << args;
|
qDebug() << "PerforcePlugin::run syncp actual args [" << process.workingDirectory() << ']' << args;
|
||||||
@@ -1104,7 +1113,7 @@ PerforceResponse PerforcePlugin::fullySynchronousProcess(const QString &workingD
|
|||||||
if ((flags & StdErrToWindow) && !response.stdErr.isEmpty())
|
if ((flags & StdErrToWindow) && !response.stdErr.isEmpty())
|
||||||
outputWindow->appendError(response.stdErr);
|
outputWindow->appendError(response.stdErr);
|
||||||
if ((flags & StdOutToWindow) && !response.stdOut.isEmpty())
|
if ((flags & StdOutToWindow) && !response.stdOut.isEmpty())
|
||||||
outputWindow->append(response.stdOut);
|
outputWindow->append(response.stdOut, VcsBase::VcsBaseOutputWindow::None, flags & SilentStdOut);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
|
|
||||||
bool managesDirectory(const QString &directory, QString *topLevel = 0);
|
bool managesDirectory(const QString &directory, QString *topLevel = 0);
|
||||||
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
|
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
|
||||||
bool vcsOpen(const QString &workingDir, const QString &fileName);
|
bool vcsOpen(const QString &workingDir, const QString &fileName, bool silently = false);
|
||||||
bool vcsAdd(const QString &workingDir, const QString &fileName);
|
bool vcsAdd(const QString &workingDir, const QString &fileName);
|
||||||
bool vcsDelete(const QString &workingDir, const QString &filename);
|
bool vcsDelete(const QString &workingDir, const QString &filename);
|
||||||
bool vcsMove(const QString &workingDir, const QString &from, const QString &to);
|
bool vcsMove(const QString &workingDir, const QString &from, const QString &to);
|
||||||
@@ -158,7 +158,8 @@ private:
|
|||||||
RunFullySynchronous = 0x20,
|
RunFullySynchronous = 0x20,
|
||||||
IgnoreExitCode = 0x40,
|
IgnoreExitCode = 0x40,
|
||||||
ShowBusyCursor = 0x80,
|
ShowBusyCursor = 0x80,
|
||||||
LongTimeOut = 0x100
|
LongTimeOut = 0x100,
|
||||||
|
SilentStdOut = 0x200,
|
||||||
};
|
};
|
||||||
|
|
||||||
// args are passed as command line arguments
|
// args are passed as command line arguments
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ Core::IVersionControl::OpenSupportMode PerforceVersionControl::openSupportMode(c
|
|||||||
bool PerforceVersionControl::vcsOpen(const QString &fileName)
|
bool PerforceVersionControl::vcsOpen(const QString &fileName)
|
||||||
{
|
{
|
||||||
const QFileInfo fi(fileName);
|
const QFileInfo fi(fileName);
|
||||||
return m_plugin->vcsOpen(fi.absolutePath(), fi.fileName());
|
return m_plugin->vcsOpen(fi.absolutePath(), fi.fileName(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IVersionControl::SettingsFlags PerforceVersionControl::settingsFlags() const
|
Core::IVersionControl::SettingsFlags PerforceVersionControl::settingsFlags() const
|
||||||
|
|||||||
@@ -85,20 +85,14 @@ class OutputWindowPlainTextEdit : public QPlainTextEdit
|
|||||||
public:
|
public:
|
||||||
explicit OutputWindowPlainTextEdit(QWidget *parent = 0);
|
explicit OutputWindowPlainTextEdit(QWidget *parent = 0);
|
||||||
|
|
||||||
void appendLines(QString s, const QString &repository = QString());
|
void appendLines(QString const& s, const QString &repository = QString());
|
||||||
// Append red error text and pop up.
|
void appendLinesWithStyle(QString const& s, enum VcsBaseOutputWindow::MessageStyle style, const QString &repository = QString());
|
||||||
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);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void contextMenuEvent(QContextMenuEvent *event);
|
virtual void contextMenuEvent(QContextMenuEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setFormat(enum VcsBaseOutputWindow::MessageStyle style);
|
||||||
QString identifierUnderCursor(const QPoint &pos, QString *repository = 0) const;
|
QString identifierUnderCursor(const QPoint &pos, QString *repository = 0) const;
|
||||||
|
|
||||||
const QTextCharFormat m_defaultFormat;
|
const QTextCharFormat m_defaultFormat;
|
||||||
@@ -202,15 +196,23 @@ void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
delete menu;
|
delete menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindowPlainTextEdit::appendLines(QString s, const QString &repository)
|
void OutputWindowPlainTextEdit::appendLines(QString const& s, const QString &repository)
|
||||||
{
|
{
|
||||||
if (s.isEmpty())
|
if (s.isEmpty())
|
||||||
return;
|
return;
|
||||||
// Avoid additional new line character generated by appendPlainText
|
|
||||||
if (s.endsWith(QLatin1Char('\n')))
|
|
||||||
s.truncate(s.size() - 1);
|
|
||||||
const int previousLineCount = document()->lineCount();
|
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
|
// Scroll down
|
||||||
moveCursor(QTextCursor::End);
|
moveCursor(QTextCursor::End);
|
||||||
ensureCursorVisible();
|
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);
|
setFormat(style);
|
||||||
appendLines(text);
|
|
||||||
|
if (style == VcsBaseOutputWindow::Command) {
|
||||||
|
const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
|
||||||
|
appendLines(timeStamp + s, repository);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
appendLines(s, repository);
|
||||||
|
}
|
||||||
|
|
||||||
setCurrentCharFormat(m_defaultFormat);
|
setCurrentCharFormat(m_defaultFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindowPlainTextEdit::appendWarning(const QString &text)
|
void OutputWindowPlainTextEdit::setFormat(enum VcsBaseOutputWindow::MessageStyle style)
|
||||||
{
|
{
|
||||||
setCurrentCharFormat(m_warningFormat);
|
switch (style) {
|
||||||
appendLines(text);
|
case VcsBaseOutputWindow::Warning:
|
||||||
setCurrentCharFormat(m_defaultFormat);
|
setCurrentCharFormat(m_warningFormat);
|
||||||
}
|
break;
|
||||||
|
case VcsBaseOutputWindow::Error:
|
||||||
// Append command with new line and log time stamp
|
setCurrentCharFormat(m_errorFormat);
|
||||||
void OutputWindowPlainTextEdit::appendCommand(const QString &text)
|
break;
|
||||||
{
|
case VcsBaseOutputWindow::Message:
|
||||||
setCurrentCharFormat(m_commandFormat);
|
setCurrentCharFormat(m_messageFormat);
|
||||||
const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
|
break;
|
||||||
appendLines(timeStamp + text);
|
case VcsBaseOutputWindow::Command:
|
||||||
setCurrentCharFormat(m_defaultFormat);
|
setCurrentCharFormat(m_commandFormat);
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
void OutputWindowPlainTextEdit::appendMessage(const QString &text)
|
case VcsBaseOutputWindow::None:
|
||||||
{
|
setCurrentCharFormat(m_defaultFormat);
|
||||||
setCurrentCharFormat(m_messageFormat);
|
break;
|
||||||
appendLines(text);
|
}
|
||||||
setCurrentCharFormat(m_defaultFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -375,28 +384,25 @@ void VcsBaseOutputWindow::setData(const QByteArray &data)
|
|||||||
|
|
||||||
void VcsBaseOutputWindow::appendSilently(const QString &text)
|
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);
|
d->plainTextEdit()->appendLinesWithStyle(text, style, d->repository);
|
||||||
if (!d->plainTextEdit()->isVisible())
|
|
||||||
|
if (!silently && !d->plainTextEdit()->isVisible())
|
||||||
popup(Core::IOutputPane::NoModeSwitch);
|
popup(Core::IOutputPane::NoModeSwitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsBaseOutputWindow::appendError(const QString &text)
|
void VcsBaseOutputWindow::appendError(const QString &text)
|
||||||
{
|
{
|
||||||
d->plainTextEdit()->appendError(text);
|
append(text, Error, false);
|
||||||
if (!d->plainTextEdit()->isVisible())
|
|
||||||
popup(Core::IOutputPane::NoModeSwitch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsBaseOutputWindow::appendWarning(const QString &text)
|
void VcsBaseOutputWindow::appendWarning(const QString &text)
|
||||||
{
|
{
|
||||||
d->plainTextEdit()->appendWarning(text);
|
append(text, Warning, false);
|
||||||
if (!d->plainTextEdit()->isVisible())
|
|
||||||
popup(Core::IOutputPane::NoModeSwitch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to format arguments for log windows hiding common password
|
// 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)
|
void VcsBaseOutputWindow::appendCommand(const QString &text)
|
||||||
{
|
{
|
||||||
d->plainTextEdit()->appendCommand(text);
|
append(text, Command, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsBaseOutputWindow::appendCommand(const QString &workingDirectory,
|
void VcsBaseOutputWindow::appendCommand(const QString &workingDirectory,
|
||||||
@@ -448,7 +454,7 @@ void VcsBaseOutputWindow::appendCommand(const QString &workingDirectory,
|
|||||||
|
|
||||||
void VcsBaseOutputWindow::appendMessage(const QString &text)
|
void VcsBaseOutputWindow::appendMessage(const QString &text)
|
||||||
{
|
{
|
||||||
d->plainTextEdit()->appendMessage(text);
|
append(text, Message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
VcsBaseOutputWindow *VcsBaseOutputWindow::instance()
|
VcsBaseOutputWindow *VcsBaseOutputWindow::instance()
|
||||||
|
|||||||
@@ -76,6 +76,14 @@ public:
|
|||||||
const QString &executable,
|
const QString &executable,
|
||||||
const QStringList &arguments);
|
const QStringList &arguments);
|
||||||
|
|
||||||
|
enum MessageStyle {
|
||||||
|
None,
|
||||||
|
Error, // Red error text
|
||||||
|
Warning, // Dark yellow warning text
|
||||||
|
Command, // A bold command with timetamp "10:00 " + "Executing: vcs -diff"
|
||||||
|
Message, // A blue message text (e.g. "command has finished successfully")
|
||||||
|
};
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setRepository(const QString &);
|
void setRepository(const QString &);
|
||||||
void clearRepository();
|
void clearRepository();
|
||||||
@@ -85,8 +93,9 @@ public slots:
|
|||||||
// Set text from QProcess' output data using the Locale's converter.
|
// Set text from QProcess' output data using the Locale's converter.
|
||||||
void setData(const QByteArray &data);
|
void setData(const QByteArray &data);
|
||||||
|
|
||||||
// Append text and pop up.
|
// Append text with a certain style (none by default),
|
||||||
void append(const QString &text);
|
// and maybe pop up (silent by default)
|
||||||
|
void append(const QString &text, enum MessageStyle style = None, bool silently = false);
|
||||||
|
|
||||||
// Silently append text, do not pop up.
|
// Silently append text, do not pop up.
|
||||||
void appendSilently(const QString &text);
|
void appendSilently(const QString &text);
|
||||||
|
|||||||
Reference in New Issue
Block a user