Commit ef806894 authored by hjk's avatar hjk
Browse files

runcontrols: use ProjectExplorrer::OutputFormat for format selection

parent edf33c56
......@@ -52,6 +52,7 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/outputformat.h>
#include <projectexplorer/applicationrunconfiguration.h> // For LocalApplication*
#include <utils/synchronousprocess.h>
......@@ -443,12 +444,12 @@ void DebuggerRunControl::start()
d->m_engine->startDebugger(this);
if (d->m_running)
emit addToOutputWindow(this, tr("Debugging starts"), false, false);
emit appendMessage(this, tr("Debugging starts"), NormalMessageFormat);
}
void DebuggerRunControl::startFailed()
{
emit addToOutputWindow(this, tr("Debugging has failed"), false, false);
emit appendMessage(this, tr("Debugging has failed"), NormalMessageFormat);
d->m_running = false;
emit finished();
d->m_engine->handleStartFailed();
......@@ -456,7 +457,7 @@ void DebuggerRunControl::startFailed()
void DebuggerRunControl::handleFinished()
{
emit addToOutputWindow(this, tr("Debugging has finished"), false, false);
emit appendMessage(this, tr("Debugging has finished"), NormalMessageFormat);
if (d->m_engine)
d->m_engine->handleFinished();
debuggerCore()->runControlFinished(d->m_engine);
......@@ -466,13 +467,13 @@ void DebuggerRunControl::showMessage(const QString &msg, int channel)
{
switch (channel) {
case AppOutput:
emit addToOutputWindow(this, msg, false, true);
emit appendMessage(this, msg, StdOutFormatSameLine);
break;
case AppError:
emit addToOutputWindow(this, msg, true, true);
emit appendMessage(this, msg, StdErrFormatSameLine);
break;
case AppStuff:
emit appendMessage(this, msg, true);
emit appendMessage(this, msg, NormalMessageFormat);
break;
}
}
......
......@@ -35,6 +35,7 @@
#define APPLICATIONLAUNCHER_H
#include "projectexplorer_export.h"
#include "outputformat.h"
#include <QtCore/QProcess>
......@@ -68,8 +69,7 @@ public:
qint64 applicationPID() const;
signals:
void appendMessage(const QString &message, bool isError);
void appendOutput(const QString &line, bool onStdErr);
void appendMessage(const QString &message, ProjectExplorer::OutputFormat format);
void processExited(int exitCode);
void bringToForegroundRequested(qint64 pid);
......@@ -77,6 +77,7 @@ private slots:
void processStopped();
#ifdef Q_OS_WIN
void readWinDebugOutput(const QString &output, bool onStdErr);
void appendWinMessage(const QString &output, bool onStdErr);
void processFinished(int exitCode);
#else
void guiProcessError();
......
......@@ -51,12 +51,12 @@ ApplicationLauncher::ApplicationLauncher(QObject *parent)
: QObject(parent), d(new ApplicationLauncherPrivate)
{
connect(&d->m_consoleProcess, SIGNAL(processMessage(QString,bool)),
this, SIGNAL(appendMessage(QString,bool)));
this, SIGNAL(appendWinMessage(QString,bool)));
connect(&d->m_consoleProcess, SIGNAL(processStopped()),
this, SLOT(processStopped()));
connect(&d->m_winGuiProcess, SIGNAL(processMessage(QString, bool)),
this, SIGNAL(appendMessage(QString,bool)));
this, SIGNAL(appendWinMessage(QString,bool)));
connect(&d->m_winGuiProcess, SIGNAL(receivedDebugOutput(QString, bool)),
this, SLOT(readWinDebugOutput(QString, bool)));
connect(&d->m_winGuiProcess, SIGNAL(processFinished(int)),
......@@ -123,10 +123,16 @@ qint64 ApplicationLauncher::applicationPID() const
return result;
}
void ApplicationLauncher::appendWinMessage(const QString &output,
bool onStdErr)
{
emit appendMessage(output, onStdErr ? ErrorMessageFormat : NormalMessageFormat);
}
void ApplicationLauncher::readWinDebugOutput(const QString &output,
bool onStdErr)
{
emit appendOutput(output, onStdErr);
emit appendMessage(output, onStdErr ? StdErrFormat : StdOutFormat);
}
void ApplicationLauncher::processStopped()
......
......@@ -161,23 +161,24 @@ void ApplicationLauncher::guiProcessError()
default:
error = tr("Some error has occurred while running the program.");
}
emit appendMessage(error, true);
emit appendMessage(error, ErrorMessageFormat);
emit processExited(d->m_guiProcess.exitCode());
}
void ApplicationLauncher::readStandardOutput()
{
QByteArray data = d->m_guiProcess.readAllStandardOutput();
emit appendOutput(d->m_outputCodec->toUnicode(
data.constData(), data.length(), &d->m_outputCodecState),
false);
QString msg = d->m_outputCodec->toUnicode(
data.constData(), data.length(), &d->m_outputCodecState);
emit appendMessage(msg, StdOutFormatSameLine);
}
void ApplicationLauncher::readStandardError()
{
QByteArray data = d->m_guiProcess.readAllStandardError();
emit appendOutput(d->m_outputCodec->toUnicode(
data.constData(), data.length(), &d->m_errorCodecState),
true);
QString msg = d->m_outputCodec->toUnicode(
data.constData(), data.length(), &d->m_outputCodecState);
emit appendMessage(msg, StdErrFormatSameLine);
}
void ApplicationLauncher::processStopped()
......
......@@ -34,6 +34,7 @@
#include "localapplicationruncontrol.h"
#include "applicationrunconfiguration.h"
#include "projectexplorerconstants.h"
#include "outputformat.h"
#include <utils/qtcassert.h>
#include <utils/environment.h>
......@@ -89,10 +90,8 @@ LocalApplicationRunControl::LocalApplicationRunControl(LocalApplicationRunConfig
m_runMode = static_cast<ApplicationLauncher::Mode>(rc->runMode());
m_commandLineArguments = rc->commandLineArguments();
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,bool)),
this, SLOT(slotAppendMessage(QString,bool)));
connect(&m_applicationLauncher, SIGNAL(appendOutput(QString, bool)),
this, SLOT(slotAddToOutputWindow(QString, bool)));
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,ProcessExplorer::OutputFormat)),
this, SLOT(slotAppendMessage(QString,ProcessExplorer::OutputFormat)));
connect(&m_applicationLauncher, SIGNAL(processExited(int)),
this, SLOT(processExited(int)));
connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
......@@ -108,7 +107,8 @@ void LocalApplicationRunControl::start()
m_applicationLauncher.start(m_runMode, m_executable, m_commandLineArguments);
emit started();
emit appendMessage(this, tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable)), false);
QString msg = tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable));
emit appendMessage(this, msg, NormalMessageFormat);
}
LocalApplicationRunControl::StopResult LocalApplicationRunControl::stop()
......@@ -123,21 +123,16 @@ bool LocalApplicationRunControl::isRunning() const
}
void LocalApplicationRunControl::slotAppendMessage(const QString &err,
bool isError)
OutputFormat format)
{
emit appendMessage(this, err, isError);
emit finished();
}
void LocalApplicationRunControl::slotAddToOutputWindow(const QString &line,
bool isError)
{
emit addToOutputWindow(this, line, isError, true);
emit appendMessage(this, err, format);
}
void LocalApplicationRunControl::processExited(int exitCode)
{
emit appendMessage(this, tr("%1 exited with code %2").arg(QDir::toNativeSeparators(m_executable)).arg(exitCode), false);
QString msg = tr("%1 exited with code %2")
.arg(QDir::toNativeSeparators(m_executable)).arg(exitCode);
emit appendMessage(this, msg, ErrorMessageFormat);
emit finished();
}
......
......@@ -65,8 +65,7 @@ public:
virtual bool isRunning() const;
private slots:
void processExited(int exitCode);
void slotAddToOutputWindow(const QString &line, bool isError);
void slotAppendMessage(const QString &err, bool isError);
void slotAppendMessage(const QString &err, ProjectExplorer::OutputFormat isError);
private:
ProjectExplorer::ApplicationLauncher m_applicationLauncher;
QString m_executable;
......
......@@ -42,6 +42,8 @@ enum OutputFormat
ErrorMessageFormat,
StdOutFormat,
StdErrFormat,
StdOutFormatSameLine,
StdErrFormatSameLine,
NumberOfFormats // Keep this entry last.
};
......
......@@ -277,19 +277,11 @@ void OutputPane::createNewOutputWindow(RunControl *rc)
qDebug() << "OutputPane::createNewOutputWindow: Adding tab for " << rc;
}
void OutputPane::appendApplicationOutput(RunControl *rc, const QString &out,
bool onStdErr, bool sameLine)
void OutputPane::appendMessage(RunControl *rc, const QString &out, OutputFormat format)
{
const int index = indexOf(rc);
if (index != -1)
m_runControlTabs.at(index).window->appendApplicationOutput(out, onStdErr, sameLine);
}
void OutputPane::appendMessage(RunControl *rc, const QString &out, bool isError)
{
const int index = indexOf(rc);
if (index != -1)
m_runControlTabs.at(index).window->appendMessage(out, isError);
m_runControlTabs.at(index).window->appendMessage(out, format);
}
void OutputPane::showTabFor(RunControl *rc)
......@@ -616,39 +608,49 @@ QString OutputWindow::doNewlineEnfocement(const QString &out)
return s;
}
void OutputWindow::appendApplicationOutput(const QString &output, bool onStdErr, bool sameLine)
void OutputWindow::appendMessage(const QString &output, OutputFormat format)
{
QString out = output;
out.remove(QLatin1Char('\r'));
setMaximumBlockCount(MaxBlockCount);
const bool atBottom = isScrollbarAtBottom();
if (sameLine) {
m_scrollToBottom = true;
if (format == ErrorMessageFormat || format == NormalMessageFormat) {
int newline = -1;
bool enforceNewline = m_enforceNewline;
m_enforceNewline = false;
m_formatter->appendMessage(doNewlineEnfocement(out), format);
if (!enforceNewline) {
newline = out.indexOf(QLatin1Char('\n'));
moveCursor(QTextCursor::End);
if (newline != -1)
m_formatter->appendMessage(out.left(newline), onStdErr ? StdErrFormat : StdOutFormat); // doesn't enforce new paragraph like appendPlainText
}
} else {
QString s = out.mid(newline+1);
if (s.isEmpty()) {
m_enforceNewline = true;
} else {
if (s.endsWith(QLatin1Char('\n'))) {
bool sameLine = format == StdOutFormatSameLine
|| format == StdErrFormatSameLine;
if (sameLine) {
m_scrollToBottom = true;
int newline = -1;
bool enforceNewline = m_enforceNewline;
m_enforceNewline = false;
if (!enforceNewline) {
newline = out.indexOf(QLatin1Char('\n'));
moveCursor(QTextCursor::End);
if (newline != -1)
m_formatter->appendMessage(out.left(newline), format);// doesn't enforce new paragraph like appendPlainText
}
QString s = out.mid(newline+1);
if (s.isEmpty()) {
m_enforceNewline = true;
s.chop(1);
} else {
if (s.endsWith(QLatin1Char('\n'))) {
m_enforceNewline = true;
s.chop(1);
}
m_formatter->appendMessage(QLatin1Char('\n') + s, format);
}
m_formatter->appendMessage(QLatin1Char('\n') + s, onStdErr ? StdErrFormat : StdOutFormat);
} else {
m_formatter->appendMessage(doNewlineEnfocement(out), format);
}
} else {
m_formatter->appendMessage(doNewlineEnfocement(out), onStdErr ? StdErrFormat : StdOutFormat);
}
if (atBottom)
......@@ -656,18 +658,6 @@ void OutputWindow::appendApplicationOutput(const QString &output, bool onStdErr,
enableUndoRedo();
}
void OutputWindow::appendMessage(const QString &output, bool isError)
{
QString out = output;
out.remove(QLatin1Char('\r'));
setMaximumBlockCount(MaxBlockCount);
const bool atBottom = isScrollbarAtBottom();
m_formatter->appendMessage(doNewlineEnfocement(out), isError ? ErrorMessageFormat : NormalMessageFormat);
if (atBottom)
scrollToBottom();
enableUndoRedo();
}
// TODO rename
void OutputWindow::appendText(const QString &textIn, const QTextCharFormat &format, int maxLineCount)
{
......
......@@ -34,6 +34,7 @@
#ifndef OUTPUTWINDOW_H
#define OUTPUTWINDOW_H
#include "outputformat.h"
#include <coreplugin/ioutputpane.h>
#include <QtGui/QPlainTextEdit>
......@@ -101,9 +102,8 @@ public slots:
void createNewOutputWindow(RunControl *rc);
void projectRemoved();
void appendApplicationOutput(ProjectExplorer::RunControl *rc, const QString &out,
bool onStdErr, bool sameLine);
void appendMessage(ProjectExplorer::RunControl *rc, const QString &out, bool isError);
void appendMessage(ProjectExplorer::RunControl *rc, const QString &out,
ProjectExplorer::OutputFormat format);
private slots:
void reRunRunControl();
......@@ -155,8 +155,7 @@ public:
OutputFormatter* formatter() const;
void setFormatter(OutputFormatter *formatter);
void appendApplicationOutput(const QString &out, bool onStdErr, bool sameLine);
void appendMessage(const QString &out, bool isError);
void appendMessage(const QString &out, OutputFormat format);
/// appends a \p text using \p format without using formater
void appendText(const QString &text, const QTextCharFormat &format, int maxLineCount);
......
......@@ -1387,10 +1387,8 @@ void ProjectExplorerPlugin::startRunControl(RunControl *runControl, const QStrin
d->m_outputPane->popup(false);
d->m_outputPane->showTabFor(runControl);
connect(runControl, SIGNAL(addToOutputWindow(ProjectExplorer::RunControl*,QString,bool,bool)),
d->m_outputPane, SLOT(appendApplicationOutput(ProjectExplorer::RunControl*,QString, bool,bool)));
connect(runControl, SIGNAL(appendMessage(ProjectExplorer::RunControl*,QString,bool)),
d->m_outputPane, SLOT(appendMessage(ProjectExplorer::RunControl*,QString,bool)));
connect(runControl, SIGNAL(appendMessage(ProjectExplorer::RunControl*,QString,ProjectExplorer::OutputFormat)),
d->m_outputPane, SLOT(appendMessage(ProjectExplorer::RunControl*,QString,ProjectExplorer::OutputFormat)));
connect(runControl, SIGNAL(finished()),
this, SLOT(runControlFinished()));
......
......@@ -36,6 +36,7 @@
#include "projectconfiguration.h"
#include "projectexplorer_export.h"
#include "outputformat.h"
#include <QtCore/QMetaType>
#include <QtCore/QWeakPointer>
......@@ -201,8 +202,8 @@ public:
QString runMode() const;
signals:
void addToOutputWindow(ProjectExplorer::RunControl *, const QString &line, bool onStdErr, bool sameLine);
void appendMessage(ProjectExplorer::RunControl *, const QString &error, bool isError);
void appendMessage(ProjectExplorer::RunControl *, const QString &error,
ProjectExplorer::OutputFormat);
void started();
void finished();
......
......@@ -58,8 +58,7 @@
#include <QMessageBox>
#include <QPushButton>
using ProjectExplorer::RunConfiguration;
using ProjectExplorer::RunControl;
using namespace ProjectExplorer;
namespace QmlProjectManager {
namespace Internal {
......@@ -77,10 +76,8 @@ QmlRunControl::QmlRunControl(QmlProjectRunConfiguration *runConfiguration, QStri
}
m_commandLineArguments = runConfiguration->viewerArguments();
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,bool)),
this, SLOT(slotError(QString, bool)));
connect(&m_applicationLauncher, SIGNAL(appendOutput(QString, bool)),
this, SLOT(slotAddToOutputWindow(QString, bool)));
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,ProjectExplorer::OutputFormat)),
this, SLOT(slotAppendMessage(QString, ProjectExplorer::OutputFormat)));
connect(&m_applicationLauncher, SIGNAL(processExited(int)),
this, SLOT(processExited(int)));
connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
......@@ -94,12 +91,13 @@ QmlRunControl::~QmlRunControl()
void QmlRunControl::start()
{
m_applicationLauncher.start(ProjectExplorer::ApplicationLauncher::Gui, m_executable,
m_applicationLauncher.start(ApplicationLauncher::Gui, m_executable,
m_commandLineArguments);
emit started();
emit appendMessage(this, tr("Starting %1 %2").arg(QDir::toNativeSeparators(m_executable),
m_commandLineArguments), false);
QString msg = tr("Starting %1 %2")
.arg(QDir::toNativeSeparators(m_executable), m_commandLineArguments);
appendMessage(this, msg, NormalMessageFormat);
}
RunControl::StopResult QmlRunControl::stop()
......@@ -118,20 +116,16 @@ void QmlRunControl::slotBringApplicationToForeground(qint64 pid)
bringApplicationToForeground(pid);
}
void QmlRunControl::slotError(const QString &err, bool isError)
void QmlRunControl::slotAppendMessage(const QString &line, OutputFormat format)
{
emit appendMessage(this, err, isError);
emit finished();
}
void QmlRunControl::slotAddToOutputWindow(const QString &line, bool onStdErr)
{
emit addToOutputWindow(this, line, onStdErr, true);
emit appendMessage(this, line, format);
}
void QmlRunControl::processExited(int exitCode)
{
emit appendMessage(this, tr("%1 exited with code %2").arg(QDir::toNativeSeparators(m_executable)).arg(exitCode), exitCode != 0);
QString msg = tr("%1 exited with code %2")
.arg(QDir::toNativeSeparators(m_executable)).arg(exitCode);
emit appendMessage(this, msg, exitCode ? ErrorMessageFormat : NormalMessageFormat);
emit finished();
}
......@@ -195,7 +189,7 @@ QWidget *QmlRunControlFactory::createConfigurationWidget(RunConfiguration *runCo
return new QLabel("TODO add Configuration widget");
}
ProjectExplorer::RunControl *QmlRunControlFactory::createDebugRunControl(QmlProjectRunConfiguration *runConfig)
RunControl *QmlRunControlFactory::createDebugRunControl(QmlProjectRunConfiguration *runConfig)
{
Debugger::DebuggerStartParameters params;
params.startMode = Debugger::StartInternal;
......
......@@ -58,8 +58,7 @@ public:
private slots:
void processExited(int exitCode);
void slotBringApplicationToForeground(qint64 pid);
void slotAddToOutputWindow(const QString &line, bool onStdErr);
void slotError(const QString &error, bool isError);
void slotAppendMessage(const QString &line, ProjectExplorer::OutputFormat);
private:
ProjectExplorer::ApplicationLauncher m_applicationLauncher;
......
......@@ -45,6 +45,7 @@
#include <QtGui/QMessageBox>
using namespace Core;
using namespace ProjectExplorer;
namespace Qt4ProjectManager {
namespace Internal {
......@@ -85,7 +86,7 @@ void MaemoRunControl::start()
m_runner->start();
}
ProjectExplorer::RunControl::StopResult MaemoRunControl::stop()
RunControl::StopResult MaemoRunControl::stop()
{
m_runner->stop();
return StoppedSynchronously;
......@@ -99,7 +100,7 @@ void MaemoRunControl::handleSshError(const QString &error)
void MaemoRunControl::startExecution()
{
emit appendMessage(this, tr("Starting remote process ..."), false);
emit appendMessage(this, tr("Starting remote process ..."), NormalMessageFormat);
m_runner->startExecution(QString::fromLocal8Bit("%1 %2 %3 %4")
.arg(MaemoGlobal::remoteCommandPrefix(m_runner->remoteExecutable()))
.arg(MaemoGlobal::remoteEnvironment(m_runner->userEnvChanges()))
......@@ -112,29 +113,29 @@ void MaemoRunControl::handleRemoteProcessFinished(qint64 exitCode)
if (exitCode != MaemoSshRunner::InvalidExitCode) {
emit appendMessage(this,
tr("Finished running remote process. Exit code was %1.")
.arg(exitCode), false);
.arg(exitCode), NormalMessageFormat);
}
setFinished();
}
void MaemoRunControl::handleRemoteOutput(const QByteArray &output)
{
emit addToOutputWindow(this, QString::fromUtf8(output), false, true);
emit appendMessage(this, QString::fromUtf8(output), StdOutFormatSameLine);
}
void MaemoRunControl::handleRemoteErrorOutput(const QByteArray &output)
{
emit addToOutputWindow(this, QString::fromUtf8(output), true, true);
emit appendMessage(this, QString::fromUtf8(output), StdErrFormatSameLine);
}
void MaemoRunControl::handleProgressReport(const QString &progressString)
{
emit appendMessage(this, progressString, false);
emit appendMessage(this, progressString, NormalMessageFormat);
}
void MaemoRunControl::handleMountDebugOutput(const QString &output)
{
emit addToOutputWindow(this, output, true, true);
emit appendMessage(this, output, StdErrFormatSameLine);
}
bool MaemoRunControl::isRunning() const
......@@ -145,7 +146,7 @@ bool MaemoRunControl::isRunning() const
void MaemoRunControl::handleError(const QString &errString)
{
stop();
emit appendMessage(this, errString, true);
emit appendMessage(this, errString, ErrorMessageFormat);
QMessageBox::critical(0, tr("Remote Execution Failure"), errString);
}
......
......@@ -543,19 +543,21 @@ void S60DeviceRunControl::start()
emit started();
if (m_serialPortName.isEmpty()) {
m_launchProgress->reportCanceled();
appendMessage(this, tr("No device is connected. Please connect a device and try again."), true);
QString msg = tr("No device is connected. Please connect a device and try again.");
appendMessage(this, msg, NormalMessageFormat);
emit finished();
return;
}
emit appendMessage(this, tr("Executable file: %1").arg(msgListFile(m_executableFileName)), false);
emit appendMessage(this, tr("Executable file: %1").arg(msgListFile(m_executableFileName)),
NormalMessageFormat);
QString errorMessage;
QString settingsCategory;
QString settingsPage;
if (!checkConfiguration(&errorMessage, &settingsCategory, &settingsPage)) {
m_launchProgress->reportCanceled();
appendMessage(this, errorMessage, true);
appendMessage(this, errorMessage, ErrorMessageFormat);
emit finished();
Core::ICore::instance()->showWarningWithOptions(tr("Debugger for Symbian Platform"),
errorMessage, QString(),
......@@ -588,7 +590,7 @@ void S60DeviceRunControl::startLaunching()
m_launchProgress->setProgressValue(PROGRESS_MAX/2);
} else {
if (!errorMessage.isEmpty())
appendMessage(this, errorMessage, true);
appendMessage(this, errorMessage, ErrorMessageFormat);
stop();
emit finished();
}
......@@ -629,7 +631,8 @@ bool S60DeviceRunControl::setupLauncher(QString &errorMessage)