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;
|
||||
}
|
||||
|
||||
bool PerforcePlugin::vcsOpen(const QString &workingDir, const QString &fileName)
|
||||
bool PerforcePlugin::vcsOpen(const QString &workingDir, const QString &fileName, bool silently)
|
||||
{
|
||||
if (Perforce::Constants::debug)
|
||||
qDebug() << "PerforcePlugin::vcsOpen" << workingDir << fileName;
|
||||
QStringList args;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1003,8 +1007,13 @@ PerforceResponse PerforcePlugin::synchronousProcess(const QString &workingDir,
|
||||
// connect stdout to the output window if desired
|
||||
if (flags & StdOutToWindow) {
|
||||
process.setStdOutBufferedSignalsEnabled(true);
|
||||
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)
|
||||
qDebug() << "PerforcePlugin::run syncp actual args [" << process.workingDirectory() << ']' << args;
|
||||
process.setTimeOutMessageBoxEnabled(true);
|
||||
@@ -1104,7 +1113,7 @@ PerforceResponse PerforcePlugin::fullySynchronousProcess(const QString &workingD
|
||||
if ((flags & StdErrToWindow) && !response.stdErr.isEmpty())
|
||||
outputWindow->appendError(response.stdErr);
|
||||
if ((flags & StdOutToWindow) && !response.stdOut.isEmpty())
|
||||
outputWindow->append(response.stdOut);
|
||||
outputWindow->append(response.stdOut, VcsBase::VcsBaseOutputWindow::None, flags & SilentStdOut);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
|
||||
bool managesDirectory(const QString &directory, QString *topLevel = 0);
|
||||
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 vcsDelete(const QString &workingDir, const QString &filename);
|
||||
bool vcsMove(const QString &workingDir, const QString &from, const QString &to);
|
||||
@@ -158,7 +158,8 @@ private:
|
||||
RunFullySynchronous = 0x20,
|
||||
IgnoreExitCode = 0x40,
|
||||
ShowBusyCursor = 0x80,
|
||||
LongTimeOut = 0x100
|
||||
LongTimeOut = 0x100,
|
||||
SilentStdOut = 0x200,
|
||||
};
|
||||
|
||||
// args are passed as command line arguments
|
||||
|
||||
@@ -91,7 +91,7 @@ Core::IVersionControl::OpenSupportMode PerforceVersionControl::openSupportMode(c
|
||||
bool PerforceVersionControl::vcsOpen(const QString &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
|
||||
|
||||
@@ -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();
|
||||
|
||||
// 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);
|
||||
setCurrentCharFormat(m_defaultFormat);
|
||||
}
|
||||
setFormat(style);
|
||||
|
||||
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);
|
||||
if (style == VcsBaseOutputWindow::Command) {
|
||||
const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
|
||||
appendLines(timeStamp + text);
|
||||
appendLines(timeStamp + s, repository);
|
||||
}
|
||||
else {
|
||||
appendLines(s, repository);
|
||||
}
|
||||
|
||||
setCurrentCharFormat(m_defaultFormat);
|
||||
}
|
||||
|
||||
void OutputWindowPlainTextEdit::appendMessage(const QString &text)
|
||||
void OutputWindowPlainTextEdit::setFormat(enum VcsBaseOutputWindow::MessageStyle style)
|
||||
{
|
||||
switch (style) {
|
||||
case VcsBaseOutputWindow::Warning:
|
||||
setCurrentCharFormat(m_warningFormat);
|
||||
break;
|
||||
case VcsBaseOutputWindow::Error:
|
||||
setCurrentCharFormat(m_errorFormat);
|
||||
break;
|
||||
case VcsBaseOutputWindow::Message:
|
||||
setCurrentCharFormat(m_messageFormat);
|
||||
appendLines(text);
|
||||
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()
|
||||
|
||||
@@ -76,6 +76,14 @@ public:
|
||||
const QString &executable,
|
||||
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:
|
||||
void setRepository(const QString &);
|
||||
void clearRepository();
|
||||
@@ -85,8 +93,9 @@ public slots:
|
||||
// Set text from QProcess' output data using the Locale's converter.
|
||||
void setData(const QByteArray &data);
|
||||
|
||||
// Append text and pop up.
|
||||
void append(const QString &text);
|
||||
// Append text with a certain style (none by default),
|
||||
// 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.
|
||||
void appendSilently(const QString &text);
|
||||
|
||||
Reference in New Issue
Block a user