RunControl: Make sure to reset the outputformater

Make sure to reset the outputformater in the RunControl's Application
Output Tab when the runControl finishes.

Change-Id: I7014727580f56f3769f1308da53a1e37231fba22
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Tobias Hunger
2017-03-01 16:26:34 +01:00
parent cecaa6fbe7
commit 113134b3b6
3 changed files with 26 additions and 20 deletions

View File

@@ -196,7 +196,8 @@ OutputFormatter *OutputWindow::formatter() const
void OutputWindow::setFormatter(OutputFormatter *formatter) void OutputWindow::setFormatter(OutputFormatter *formatter)
{ {
d->formatter = formatter; d->formatter = formatter;
d->formatter->setPlainTextEdit(this); if (d->formatter)
d->formatter->setPlainTextEdit(this);
} }
void OutputWindow::showEvent(QShowEvent *e) void OutputWindow::showEvent(QShowEvent *e)
@@ -286,9 +287,8 @@ void OutputWindow::appendMessage(const QString &output, OutputFormat format)
const bool atBottom = isScrollbarAtBottom() || m_scrollTimer.isActive(); const bool atBottom = isScrollbarAtBottom() || m_scrollTimer.isActive();
if (format == ErrorMessageFormat || format == NormalMessageFormat) { if (format == ErrorMessageFormat || format == NormalMessageFormat) {
if (d->formatter)
d->formatter->appendMessage(doNewlineEnforcement(out), format); d->formatter->appendMessage(doNewlineEnforcement(out), format);
} else { } else {
bool sameLine = format == StdOutFormatSameLine bool sameLine = format == StdOutFormatSameLine
@@ -304,7 +304,7 @@ void OutputWindow::appendMessage(const QString &output, OutputFormat format)
if (!enforceNewline) { if (!enforceNewline) {
newline = out.indexOf(QLatin1Char('\n')); newline = out.indexOf(QLatin1Char('\n'));
moveCursor(QTextCursor::End); moveCursor(QTextCursor::End);
if (newline != -1) if (newline != -1 && d->formatter)
d->formatter->appendMessage(out.left(newline), format);// doesn't enforce new paragraph like appendPlainText d->formatter->appendMessage(out.left(newline), format);// doesn't enforce new paragraph like appendPlainText
} }
@@ -316,10 +316,12 @@ void OutputWindow::appendMessage(const QString &output, OutputFormat format)
d->enforceNewline = true; d->enforceNewline = true;
s.chop(1); s.chop(1);
} }
d->formatter->appendMessage(QLatin1Char('\n') + s, format); if (d->formatter)
d->formatter->appendMessage(QLatin1Char('\n') + s, format);
} }
} else { } else {
d->formatter->appendMessage(doNewlineEnforcement(out), format); if (d->formatter)
d->formatter->appendMessage(doNewlineEnforcement(out), format);
} }
} }

View File

@@ -259,8 +259,10 @@ AppOutputPane::~AppOutputPane()
if (debug) if (debug)
qDebug() << "OutputPane::~OutputPane: Entries left" << m_runControlTabs.size(); qDebug() << "OutputPane::~OutputPane: Entries left" << m_runControlTabs.size();
foreach (const RunControlTab &rt, m_runControlTabs) foreach (const RunControlTab &rt, m_runControlTabs) {
rt.window->setFormatter(nullptr);
delete rt.runControl; delete rt.runControl;
}
delete m_mainWidget; delete m_mainWidget;
} }
@@ -282,7 +284,7 @@ RunControl *AppOutputPane::currentRunControl() const
const int index = currentIndex(); const int index = currentIndex();
if (index != -1) if (index != -1)
return m_runControlTabs.at(index).runControl; return m_runControlTabs.at(index).runControl;
return 0; return nullptr;
} }
int AppOutputPane::indexOf(const RunControl *rc) const int AppOutputPane::indexOf(const RunControl *rc) const
@@ -404,8 +406,6 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
connect(rc, &RunControl::appendMessageRequested, connect(rc, &RunControl::appendMessageRequested,
this, &AppOutputPane::appendMessage); this, &AppOutputPane::appendMessage);
Utils::OutputFormatter *formatter = rc->outputFormatter();
// First look if we can reuse a tab // First look if we can reuse a tab
const int tabIndex = Utils::indexOf(m_runControlTabs, [rc](const RunControlTab &tab) { const int tabIndex = Utils::indexOf(m_runControlTabs, [rc](const RunControlTab &tab) {
return rc->canReUseOutputPane(tab.runControl); return rc->canReUseOutputPane(tab.runControl);
@@ -414,22 +414,22 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
RunControlTab &tab = m_runControlTabs[tabIndex]; RunControlTab &tab = m_runControlTabs[tabIndex];
// Reuse this tab // Reuse this tab
delete tab.runControl; delete tab.runControl;
tab.runControl = rc;
handleOldOutput(tab.window); handleOldOutput(tab.window);
tab.runControl = rc;
tab.window->setFormatter(nullptr);
tab.window->scrollToBottom(); tab.window->scrollToBottom();
tab.window->setFormatter(formatter);
if (debug) if (debug)
qDebug() << "OutputPane::createNewOutputWindow: Reusing tab" << tabIndex << " for " << rc; qDebug() << "OutputPane::createNewOutputWindow: Reusing tab" << tabIndex << " for " << rc;
return; return;
} }
// Create new // Create new
static uint counter = 0; static int counter = 0;
Core::Id contextId = Core::Id(Constants::C_APP_OUTPUT).withSuffix(counter++); Core::Id contextId = Core::Id(Constants::C_APP_OUTPUT).withSuffix(counter++);
Core::Context context(contextId); Core::Context context(contextId);
Core::OutputWindow *ow = new Core::OutputWindow(context, m_tabWidget); Core::OutputWindow *ow = new Core::OutputWindow(context, m_tabWidget);
ow->setWindowTitle(tr("Application Output Window")); ow->setWindowTitle(tr("Application Output Window"));
ow->setWindowIcon(Icons::WINDOW.icon()); ow->setWindowIcon(Icons::WINDOW.icon());
ow->setFormatter(formatter); ow->setFormatter(nullptr);
ow->setWordWrapEnabled(ProjectExplorerPlugin::projectExplorerSettings().wrapAppOutput); ow->setWordWrapEnabled(ProjectExplorerPlugin::projectExplorerSettings().wrapAppOutput);
ow->setMaxLineCount(ProjectExplorerPlugin::projectExplorerSettings().maxAppOutputLines); ow->setMaxLineCount(ProjectExplorerPlugin::projectExplorerSettings().maxAppOutputLines);
ow->setWheelZoomEnabled(TextEditor::TextEditorSettings::behaviorSettings().m_scrollWheelZooming); ow->setWheelZoomEnabled(TextEditor::TextEditorSettings::behaviorSettings().m_scrollWheelZooming);
@@ -586,6 +586,7 @@ bool AppOutputPane::closeTab(int tabIndex, CloseTabMode closeTabMode)
} }
m_tabWidget->removeTab(tabIndex); m_tabWidget->removeTab(tabIndex);
m_runControlTabs[index].window->setFormatter(nullptr);
delete m_runControlTabs[index].runControl; delete m_runControlTabs[index].runControl;
delete m_runControlTabs[index].window; delete m_runControlTabs[index].window;
m_runControlTabs.removeAt(index); m_runControlTabs.removeAt(index);
@@ -701,6 +702,10 @@ void AppOutputPane::contextMenuRequested(const QPoint &pos, int index)
void AppOutputPane::slotRunControlStarted() void AppOutputPane::slotRunControlStarted()
{ {
RunControl *current = currentRunControl(); RunControl *current = currentRunControl();
const int rcIndex = indexOf(current);
if (rcIndex >= 0 && m_runControlTabs.at(rcIndex).window)
m_runControlTabs.at(rcIndex).window->setFormatter(current->outputFormatter());
if (current && current == sender()) if (current && current == sender())
enableButtons(current, true); // RunControl::isRunning() cannot be trusted in signal handler. enableButtons(current, true); // RunControl::isRunning() cannot be trusted in signal handler.
emit runControlStarted(current); emit runControlStarted(current);
@@ -710,7 +715,8 @@ void AppOutputPane::slotRunControlFinished()
{ {
RunControl *rc = qobject_cast<RunControl *>(sender()); RunControl *rc = qobject_cast<RunControl *>(sender());
QTimer::singleShot(0, this, [this, rc]() { slotRunControlFinished2(rc); }); QTimer::singleShot(0, this, [this, rc]() { slotRunControlFinished2(rc); });
rc->outputFormatter()->flush(); if (rc->outputFormatter())
rc->outputFormatter()->flush();
} }
void AppOutputPane::slotRunControlFinished2(RunControl *sender) void AppOutputPane::slotRunControlFinished2(RunControl *sender)
@@ -731,6 +737,8 @@ void AppOutputPane::slotRunControlFinished2(RunControl *sender)
if (current && current == sender) if (current && current == sender)
enableButtons(current, false); // RunControl::isRunning() cannot be trusted in signal handler. enableButtons(current, false); // RunControl::isRunning() cannot be trusted in signal handler.
m_runControlTabs.at(senderIndex).window->setFormatter(nullptr); // Reset formater for this RC
// Check for asynchronous close. Close the tab. // Check for asynchronous close. Close the tab.
if (m_runControlTabs.at(senderIndex).asyncClosing) if (m_runControlTabs.at(senderIndex).asyncClosing)
closeTab(tabWidgetIndexOf(senderIndex), CloseTabNoPrompt); closeTab(tabWidgetIndexOf(senderIndex), CloseTabNoPrompt);

View File

@@ -511,10 +511,6 @@ public:
device = DeviceKitInformation::device(runConfiguration->target()->kit()); device = DeviceKitInformation::device(runConfiguration->target()->kit());
project = runConfiguration->target()->project(); project = runConfiguration->target()->project();
} }
// We need to ensure that there's always a OutputFormatter
if (!outputFormatter)
outputFormatter = new Utils::OutputFormatter();
} }
~RunControlPrivate() ~RunControlPrivate()