2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-04-14 10:39:09 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2011-04-14 10:39:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-04-14 10:39:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-04-14 10:39:09 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-04-14 10:39:09 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
#include "appoutputpane.h"
|
|
|
|
|
#include "projectexplorer.h"
|
|
|
|
|
#include "projectexplorersettings.h"
|
|
|
|
|
#include "runconfiguration.h"
|
|
|
|
|
#include "session.h"
|
2015-01-19 10:44:30 +02:00
|
|
|
#include "windebuginterface.h"
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2011-04-14 10:39:09 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <coreplugin/outputwindow.h>
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <coreplugin/find/basetextfind.h>
|
2011-04-14 10:39:09 +02:00
|
|
|
#include <texteditor/fontsettings.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
2011-05-31 09:48:00 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
#include <extensionsystem/invoker.h>
|
2011-04-14 10:39:09 +02:00
|
|
|
|
2014-06-06 13:12:47 +02:00
|
|
|
#include <utils/algorithm.h>
|
2015-02-24 22:39:14 +02:00
|
|
|
#include <utils/outputformatter.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2011-04-14 10:39:09 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QTabWidget>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QTabBar>
|
|
|
|
|
#include <QMenu>
|
2011-04-14 10:39:09 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
enum { debug = 0 };
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
2014-10-28 08:26:25 +01:00
|
|
|
static QObject *debuggerPlugin()
|
2011-05-31 09:48:00 +02:00
|
|
|
{
|
2014-10-28 08:26:25 +01:00
|
|
|
return ExtensionSystem::PluginManager::getObjectByName(QLatin1String("DebuggerPlugin"));
|
2011-05-31 09:48:00 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-06 10:25:18 +02:00
|
|
|
static QString msgAttachDebuggerTooltip(const QString &handleDescription = QString())
|
|
|
|
|
{
|
|
|
|
|
return handleDescription.isEmpty() ?
|
|
|
|
|
AppOutputPane::tr("Attach debugger to this process") :
|
|
|
|
|
AppOutputPane::tr("Attach debugger to %1").arg(handleDescription);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 12:27:26 +02:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class TabWidget : public QTabWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
TabWidget(QWidget *parent = 0);
|
|
|
|
|
signals:
|
|
|
|
|
void contextMenuRequested(const QPoint &pos, const int index);
|
2014-08-11 12:35:45 +02:00
|
|
|
protected:
|
|
|
|
|
bool eventFilter(QObject *object, QEvent *event);
|
2011-08-05 12:27:26 +02:00
|
|
|
private slots:
|
|
|
|
|
void slotContextMenuRequested(const QPoint &pos);
|
2014-08-11 12:35:45 +02:00
|
|
|
private:
|
|
|
|
|
int m_tabIndexForMiddleClick;
|
2011-08-05 12:27:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TabWidget::TabWidget(QWidget *parent)
|
2014-08-11 12:35:45 +02:00
|
|
|
: QTabWidget(parent), m_tabIndexForMiddleClick(-1)
|
2011-08-05 12:27:26 +02:00
|
|
|
{
|
2014-08-11 12:35:45 +02:00
|
|
|
tabBar()->installEventFilter(this);
|
2011-08-05 12:27:26 +02:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
|
|
|
|
|
this, SLOT(slotContextMenuRequested(QPoint)));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-11 12:35:45 +02:00
|
|
|
bool TabWidget::eventFilter(QObject *object, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (object == tabBar()) {
|
|
|
|
|
if (event->type() == QEvent::MouseButtonPress) {
|
|
|
|
|
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
|
|
|
if (me->button() == Qt::MiddleButton) {
|
|
|
|
|
m_tabIndexForMiddleClick = tabBar()->tabAt(me->pos());
|
|
|
|
|
event->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
|
|
|
if (me->button() == Qt::MiddleButton) {
|
|
|
|
|
int tab = tabBar()->tabAt(me->pos());
|
|
|
|
|
if (tab != -1 && tab == m_tabIndexForMiddleClick)
|
|
|
|
|
emit tabCloseRequested(tab);
|
|
|
|
|
m_tabIndexForMiddleClick = -1;
|
|
|
|
|
event->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QTabWidget::eventFilter(object, event);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 12:27:26 +02:00
|
|
|
void TabWidget::slotContextMenuRequested(const QPoint &pos)
|
|
|
|
|
{
|
|
|
|
|
emit contextMenuRequested(pos, tabBar()->tabAt(pos));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-21 13:42:17 +02:00
|
|
|
AppOutputPane::RunControlTab::RunControlTab(RunControl *rc, Core::OutputWindow *w) :
|
2013-12-13 22:03:26 +01:00
|
|
|
runControl(rc), window(w), asyncClosing(false), behaviorOnOutput(Flash)
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppOutputPane::AppOutputPane() :
|
|
|
|
|
m_mainWidget(new QWidget),
|
2011-08-05 12:27:26 +02:00
|
|
|
m_tabWidget(new TabWidget),
|
2011-05-30 17:02:03 +02:00
|
|
|
m_stopAction(new QAction(tr("Stop"), this)),
|
2011-08-05 12:27:26 +02:00
|
|
|
m_closeCurrentTabAction(new QAction(tr("Close Tab"), this)),
|
|
|
|
|
m_closeAllTabsAction(new QAction(tr("Close All Tabs"), this)),
|
|
|
|
|
m_closeOtherTabsAction(new QAction(tr("Close Other Tabs"), this)),
|
2011-04-14 10:39:09 +02:00
|
|
|
m_reRunButton(new QToolButton),
|
2011-05-31 09:48:00 +02:00
|
|
|
m_stopButton(new QToolButton),
|
|
|
|
|
m_attachButton(new QToolButton)
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
2013-01-10 11:36:15 +01:00
|
|
|
setObjectName(QLatin1String("AppOutputPane")); // Used in valgrind engine
|
|
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
// Rerun
|
2014-10-13 22:37:28 +03:00
|
|
|
m_reRunButton->setIcon(QIcon(QLatin1String(Constants::ICON_RUN_SMALL)));
|
2011-04-14 10:39:09 +02:00
|
|
|
m_reRunButton->setToolTip(tr("Re-run this run-configuration"));
|
|
|
|
|
m_reRunButton->setAutoRaise(true);
|
|
|
|
|
m_reRunButton->setEnabled(false);
|
|
|
|
|
connect(m_reRunButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(reRunRunControl()));
|
|
|
|
|
|
|
|
|
|
// Stop
|
2011-05-30 17:02:03 +02:00
|
|
|
QIcon stopIcon = QIcon(QLatin1String(Constants::ICON_STOP));
|
|
|
|
|
stopIcon.addFile(QLatin1String(Constants::ICON_STOP_SMALL));
|
|
|
|
|
m_stopAction->setIcon(stopIcon);
|
2011-04-14 10:39:09 +02:00
|
|
|
m_stopAction->setToolTip(tr("Stop"));
|
|
|
|
|
m_stopAction->setEnabled(false);
|
|
|
|
|
|
2015-02-19 11:35:47 +01:00
|
|
|
Core::Command *cmd = Core::ActionManager::registerAction(m_stopAction, Constants::STOP);
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
m_stopButton->setDefaultAction(cmd->action());
|
|
|
|
|
m_stopButton->setAutoRaise(true);
|
|
|
|
|
|
|
|
|
|
connect(m_stopAction, SIGNAL(triggered()),
|
|
|
|
|
this, SLOT(stopRunControl()));
|
|
|
|
|
|
2011-05-31 09:48:00 +02:00
|
|
|
// Attach
|
2011-07-06 10:25:18 +02:00
|
|
|
m_attachButton->setToolTip(msgAttachDebuggerTooltip());
|
2011-05-31 09:48:00 +02:00
|
|
|
m_attachButton->setEnabled(false);
|
2014-10-13 22:37:28 +03:00
|
|
|
m_attachButton->setIcon(QIcon(QLatin1String(Constants::ICON_DEBUG_SMALL)));
|
2011-05-31 09:48:00 +02:00
|
|
|
m_attachButton->setAutoRaise(true);
|
|
|
|
|
|
|
|
|
|
connect(m_attachButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(attachToRunControl()));
|
|
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
// Spacer (?)
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
m_tabWidget->setDocumentMode(true);
|
|
|
|
|
m_tabWidget->setTabsClosable(true);
|
|
|
|
|
m_tabWidget->setMovable(true);
|
|
|
|
|
connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
|
|
|
|
|
layout->addWidget(m_tabWidget);
|
|
|
|
|
|
|
|
|
|
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
|
2011-08-05 12:27:26 +02:00
|
|
|
connect(m_tabWidget, SIGNAL(contextMenuRequested(QPoint,int)), this, SLOT(contextMenuRequested(QPoint,int)));
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
m_mainWidget->setLayout(layout);
|
|
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(SessionManager::instance(), SIGNAL(aboutToUnloadSession(QString)),
|
2011-04-14 10:39:09 +02:00
|
|
|
this, SLOT(aboutToUnloadSession()));
|
|
|
|
|
connect(ProjectExplorerPlugin::instance(), SIGNAL(settingsChanged()),
|
2011-04-29 09:36:04 +02:00
|
|
|
this, SLOT(updateFromSettings()));
|
2015-01-19 10:44:30 +02:00
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
connect(this, &AppOutputPane::allRunControlsFinished,
|
|
|
|
|
WinDebugInterface::instance(), &WinDebugInterface::stop);
|
|
|
|
|
#endif
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppOutputPane::~AppOutputPane()
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "OutputPane::~OutputPane: Entries left" << m_runControlTabs.size();
|
|
|
|
|
|
2011-04-26 11:33:37 +02:00
|
|
|
foreach (const RunControlTab &rt, m_runControlTabs)
|
2011-04-14 10:39:09 +02:00
|
|
|
delete rt.runControl;
|
|
|
|
|
delete m_mainWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AppOutputPane::currentIndex() const
|
|
|
|
|
{
|
|
|
|
|
if (const QWidget *w = m_tabWidget->currentWidget())
|
|
|
|
|
return indexOf(w);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RunControl *AppOutputPane::currentRunControl() const
|
|
|
|
|
{
|
|
|
|
|
const int index = currentIndex();
|
|
|
|
|
if (index != -1)
|
|
|
|
|
return m_runControlTabs.at(index).runControl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AppOutputPane::indexOf(const RunControl *rc) const
|
|
|
|
|
{
|
|
|
|
|
for (int i = m_runControlTabs.size() - 1; i >= 0; i--)
|
|
|
|
|
if (m_runControlTabs.at(i).runControl == rc)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AppOutputPane::indexOf(const QWidget *outputWindow) const
|
|
|
|
|
{
|
|
|
|
|
for (int i = m_runControlTabs.size() - 1; i >= 0; i--)
|
|
|
|
|
if (m_runControlTabs.at(i).window == outputWindow)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AppOutputPane::tabWidgetIndexOf(int runControlIndex) const
|
|
|
|
|
{
|
|
|
|
|
if (runControlIndex >= 0 && runControlIndex < m_runControlTabs.size())
|
|
|
|
|
return m_tabWidget->indexOf(m_runControlTabs.at(runControlIndex).window);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 12:27:26 +02:00
|
|
|
void AppOutputPane::updateCloseActions()
|
|
|
|
|
{
|
|
|
|
|
const int tabCount = m_tabWidget->count();
|
|
|
|
|
m_closeCurrentTabAction->setEnabled(tabCount > 0);
|
|
|
|
|
m_closeAllTabsAction->setEnabled(tabCount > 0);
|
|
|
|
|
m_closeOtherTabsAction->setEnabled(tabCount > 1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
bool AppOutputPane::aboutToClose() const
|
|
|
|
|
{
|
2014-06-06 13:12:47 +02:00
|
|
|
return Utils::allOf(m_runControlTabs, [](const RunControlTab &rt) {
|
|
|
|
|
return !rt.runControl->isRunning() || rt.runControl->promptToStop();
|
|
|
|
|
});
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::aboutToUnloadSession()
|
|
|
|
|
{
|
|
|
|
|
closeTabs(CloseTabWithPrompt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *AppOutputPane::outputWidget(QWidget *)
|
|
|
|
|
{
|
|
|
|
|
return m_mainWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QWidget*> AppOutputPane::toolBarWidgets() const
|
|
|
|
|
{
|
2011-05-31 09:48:00 +02:00
|
|
|
return QList<QWidget*>() << m_reRunButton << m_stopButton << m_attachButton;
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AppOutputPane::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return tr("Application Output");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AppOutputPane::priorityInStatusBar() const
|
|
|
|
|
{
|
|
|
|
|
return 60;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::clearContents()
|
|
|
|
|
{
|
2011-04-21 13:42:17 +02:00
|
|
|
Core::OutputWindow *currentWindow = qobject_cast<Core::OutputWindow *>(m_tabWidget->currentWidget());
|
2011-04-14 10:39:09 +02:00
|
|
|
if (currentWindow)
|
|
|
|
|
currentWindow->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::visibilityChanged(bool /* b */)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool AppOutputPane::hasFocus() const
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
2014-11-07 15:48:36 +01:00
|
|
|
QWidget *widget = m_tabWidget->currentWidget();
|
|
|
|
|
if (!widget)
|
|
|
|
|
return false;
|
|
|
|
|
return widget->window()->focusWidget() == widget;
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool AppOutputPane::canFocus() const
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
|
|
|
|
return m_tabWidget->currentWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::setFocus()
|
|
|
|
|
{
|
|
|
|
|
if (m_tabWidget->currentWidget())
|
|
|
|
|
m_tabWidget->currentWidget()->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::createNewOutputWindow(RunControl *rc)
|
|
|
|
|
{
|
|
|
|
|
connect(rc, SIGNAL(started()),
|
2011-10-20 12:59:13 +00:00
|
|
|
this, SLOT(slotRunControlStarted()));
|
2011-04-14 10:39:09 +02:00
|
|
|
connect(rc, SIGNAL(finished()),
|
2011-11-03 15:08:59 +01:00
|
|
|
this, SLOT(slotRunControlFinished()));
|
2011-07-06 10:25:18 +02:00
|
|
|
connect(rc, SIGNAL(applicationProcessHandleChanged()),
|
|
|
|
|
this, SLOT(enableButtons()));
|
2011-04-14 10:39:09 +02:00
|
|
|
connect(rc, SIGNAL(appendMessage(ProjectExplorer::RunControl*,QString,Utils::OutputFormat)),
|
|
|
|
|
this, SLOT(appendMessage(ProjectExplorer::RunControl*,QString,Utils::OutputFormat)));
|
|
|
|
|
|
|
|
|
|
Utils::OutputFormatter *formatter = rc->outputFormatter();
|
2013-09-19 17:59:27 +02:00
|
|
|
formatter->setFont(TextEditor::TextEditorSettings::fontSettings().font());
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
// First look if we can reuse a tab
|
|
|
|
|
const int size = m_runControlTabs.size();
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
|
RunControlTab &tab =m_runControlTabs[i];
|
|
|
|
|
if (tab.runControl->sameRunConfiguration(rc) && !tab.runControl->isRunning()) {
|
|
|
|
|
// Reuse this tab
|
|
|
|
|
delete tab.runControl;
|
|
|
|
|
tab.runControl = rc;
|
|
|
|
|
handleOldOutput(tab.window);
|
|
|
|
|
tab.window->scrollToBottom();
|
|
|
|
|
tab.window->setFormatter(formatter);
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "OutputPane::createNewOutputWindow: Reusing tab" << i << " for " << rc;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Create new
|
|
|
|
|
static uint counter = 0;
|
2013-01-28 10:37:19 +01:00
|
|
|
Core::Id contextId = Core::Id(Constants::C_APP_OUTPUT).withSuffix(counter++);
|
|
|
|
|
Core::Context context(contextId);
|
2011-04-21 13:42:17 +02:00
|
|
|
Core::OutputWindow *ow = new Core::OutputWindow(context, m_tabWidget);
|
2011-04-14 10:39:09 +02:00
|
|
|
ow->setWindowTitle(tr("Application Output Window"));
|
2011-05-20 19:48:44 +02:00
|
|
|
ow->setWindowIcon(QIcon(QLatin1String(Constants::ICON_WINDOW)));
|
2011-04-14 10:39:09 +02:00
|
|
|
ow->setFormatter(formatter);
|
2013-09-05 18:30:50 +02:00
|
|
|
ow->setWordWrapEnabled(ProjectExplorerPlugin::projectExplorerSettings().wrapAppOutput);
|
|
|
|
|
ow->setMaxLineCount(ProjectExplorerPlugin::projectExplorerSettings().maxAppOutputLines);
|
2011-04-14 10:39:09 +02:00
|
|
|
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
|
|
|
|
|
agg->add(ow);
|
2014-01-13 16:17:34 +01:00
|
|
|
agg->add(new Core::BaseTextFind(ow));
|
2011-04-14 10:39:09 +02:00
|
|
|
m_runControlTabs.push_back(RunControlTab(rc, ow));
|
|
|
|
|
m_tabWidget->addTab(ow, rc->displayName());
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "OutputPane::createNewOutputWindow: Adding tab for " << rc;
|
2011-08-05 12:27:26 +02:00
|
|
|
updateCloseActions();
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-21 13:42:17 +02:00
|
|
|
void AppOutputPane::handleOldOutput(Core::OutputWindow *window) const
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
2013-09-05 18:30:50 +02:00
|
|
|
if (ProjectExplorerPlugin::projectExplorerSettings().cleanOldAppOutput)
|
2011-04-14 10:39:09 +02:00
|
|
|
window->clear();
|
|
|
|
|
else
|
|
|
|
|
window->grayOutOldContent();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-29 09:36:04 +02:00
|
|
|
void AppOutputPane::updateFromSettings()
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
|
|
|
|
const int size = m_runControlTabs.size();
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
|
RunControlTab &tab =m_runControlTabs[i];
|
2013-09-05 18:30:50 +02:00
|
|
|
tab.window->setWordWrapEnabled(ProjectExplorerPlugin::projectExplorerSettings().wrapAppOutput);
|
|
|
|
|
tab.window->setMaxLineCount(ProjectExplorerPlugin::projectExplorerSettings().maxAppOutputLines);
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::appendMessage(RunControl *rc, const QString &out, Utils::OutputFormat format)
|
|
|
|
|
{
|
|
|
|
|
const int index = indexOf(rc);
|
2013-04-16 16:21:28 +02:00
|
|
|
if (index != -1) {
|
|
|
|
|
Core::OutputWindow *window = m_runControlTabs.at(index).window;
|
|
|
|
|
window->appendMessage(out, format);
|
|
|
|
|
if (format != Utils::NormalMessageFormat) {
|
2013-12-13 22:03:26 +01:00
|
|
|
if (m_runControlTabs.at(index).behaviorOnOutput == Flash)
|
2013-04-16 16:21:28 +02:00
|
|
|
flash();
|
|
|
|
|
else
|
|
|
|
|
popup(NoModeSwitch);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::showTabFor(RunControl *rc)
|
|
|
|
|
{
|
|
|
|
|
m_tabWidget->setCurrentIndex(tabWidgetIndexOf(indexOf(rc)));
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 22:03:26 +01:00
|
|
|
void AppOutputPane::setBehaviorOnOutput(RunControl *rc, AppOutputPane::BehaviorOnOutput mode)
|
2013-04-16 16:21:28 +02:00
|
|
|
{
|
|
|
|
|
const int index = indexOf(rc);
|
|
|
|
|
if (index != -1)
|
2013-12-13 22:03:26 +01:00
|
|
|
m_runControlTabs[index].behaviorOnOutput = mode;
|
2013-04-16 16:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
void AppOutputPane::reRunRunControl()
|
|
|
|
|
{
|
|
|
|
|
const int index = currentIndex();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(index != -1 && !m_runControlTabs.at(index).runControl->isRunning(), return);
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
RunControlTab &tab = m_runControlTabs[index];
|
|
|
|
|
|
|
|
|
|
handleOldOutput(tab.window);
|
|
|
|
|
tab.window->scrollToBottom();
|
|
|
|
|
tab.runControl->start();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 09:48:00 +02:00
|
|
|
void AppOutputPane::attachToRunControl()
|
|
|
|
|
{
|
|
|
|
|
const int index = currentIndex();
|
|
|
|
|
QTC_ASSERT(index != -1, return);
|
2014-10-13 22:37:28 +03:00
|
|
|
RunControl *rc = m_runControlTabs.at(index).runControl;
|
2011-05-31 09:48:00 +02:00
|
|
|
QTC_ASSERT(rc->isRunning(), return);
|
2014-10-28 08:26:25 +01:00
|
|
|
ExtensionSystem::Invoker<void>(debuggerPlugin(), "attachExternalApplication", rc);
|
2011-05-31 09:48:00 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
void AppOutputPane::stopRunControl()
|
|
|
|
|
{
|
|
|
|
|
const int index = currentIndex();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(index != -1 && m_runControlTabs.at(index).runControl->isRunning(), return);
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
RunControl *rc = m_runControlTabs.at(index).runControl;
|
|
|
|
|
if (rc->isRunning() && optionallyPromptToStop(rc))
|
|
|
|
|
rc->stop();
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "OutputPane::stopRunControl " << rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppOutputPane::closeTabs(CloseTabMode mode)
|
|
|
|
|
{
|
|
|
|
|
bool allClosed = true;
|
|
|
|
|
for (int t = m_tabWidget->count() - 1; t >= 0; t--)
|
|
|
|
|
if (!closeTab(t, mode))
|
|
|
|
|
allClosed = false;
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "OutputPane::closeTabs() returns " << allClosed;
|
|
|
|
|
return allClosed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppOutputPane::closeTab(int index)
|
|
|
|
|
{
|
|
|
|
|
return closeTab(index, CloseTabWithPrompt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppOutputPane::closeTab(int tabIndex, CloseTabMode closeTabMode)
|
|
|
|
|
{
|
2011-11-24 15:46:03 +01:00
|
|
|
int index = indexOf(m_tabWidget->widget(tabIndex));
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(index != -1, return true);
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
if (debug)
|
2014-09-19 17:44:13 +02:00
|
|
|
qDebug() << "OutputPane::closeTab tab " << tabIndex << m_runControlTabs[index].runControl
|
|
|
|
|
<< m_runControlTabs[index].window << m_runControlTabs[index].asyncClosing;
|
2011-04-14 10:39:09 +02:00
|
|
|
// Prompt user to stop
|
2014-09-19 17:44:13 +02:00
|
|
|
if (m_runControlTabs[index].runControl->isRunning()) {
|
2011-04-14 10:39:09 +02:00
|
|
|
switch (closeTabMode) {
|
|
|
|
|
case CloseTabNoPrompt:
|
|
|
|
|
break;
|
|
|
|
|
case CloseTabWithPrompt:
|
2011-11-24 15:46:03 +01:00
|
|
|
QWidget *tabWidget = m_tabWidget->widget(tabIndex);
|
2014-09-19 17:44:13 +02:00
|
|
|
if (!m_runControlTabs[index].runControl->promptToStop())
|
2011-04-14 10:39:09 +02:00
|
|
|
return false;
|
2011-11-24 15:46:03 +01:00
|
|
|
// The event loop has run, thus the ordering might have changed, a tab might
|
|
|
|
|
// have been closed, so do some strange things...
|
|
|
|
|
tabIndex = m_tabWidget->indexOf(tabWidget);
|
|
|
|
|
index = indexOf(tabWidget);
|
|
|
|
|
if (tabIndex == -1 || index == -1)
|
|
|
|
|
return false;
|
2011-04-14 10:39:09 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2014-09-19 17:44:13 +02:00
|
|
|
if (m_runControlTabs[index].runControl->isRunning()) { // yes it might have stopped already, then just close
|
2011-11-24 15:46:03 +01:00
|
|
|
QWidget *tabWidget = m_tabWidget->widget(tabIndex);
|
2014-09-19 17:44:13 +02:00
|
|
|
if (m_runControlTabs[index].runControl->stop() == RunControl::AsynchronousStop) {
|
|
|
|
|
m_runControlTabs[index].asyncClosing = true;
|
2011-11-24 15:46:03 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
tabIndex = m_tabWidget->indexOf(tabWidget);
|
|
|
|
|
index = indexOf(tabWidget);
|
|
|
|
|
if (tabIndex == -1 || index == -1)
|
|
|
|
|
return false;
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_tabWidget->removeTab(tabIndex);
|
2014-09-19 17:44:13 +02:00
|
|
|
delete m_runControlTabs[index].runControl;
|
|
|
|
|
delete m_runControlTabs[index].window;
|
2011-04-14 10:39:09 +02:00
|
|
|
m_runControlTabs.removeAt(index);
|
2011-08-05 12:27:26 +02:00
|
|
|
updateCloseActions();
|
2015-05-15 17:07:45 +02:00
|
|
|
|
|
|
|
|
if (m_runControlTabs.isEmpty())
|
|
|
|
|
hide();
|
|
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppOutputPane::optionallyPromptToStop(RunControl *runControl)
|
|
|
|
|
{
|
2013-09-05 18:30:50 +02:00
|
|
|
ProjectExplorerSettings settings = ProjectExplorerPlugin::projectExplorerSettings();
|
2011-04-14 10:39:09 +02:00
|
|
|
if (!runControl->promptToStop(&settings.prompToStopRunControl))
|
|
|
|
|
return false;
|
2013-09-05 18:30:50 +02:00
|
|
|
ProjectExplorerPlugin::setProjectExplorerSettings(settings);
|
2011-04-14 10:39:09 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::projectRemoved()
|
|
|
|
|
{
|
|
|
|
|
tabChanged(m_tabWidget->currentIndex());
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-06 10:25:18 +02:00
|
|
|
void AppOutputPane::enableButtons()
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
2011-07-06 10:25:18 +02:00
|
|
|
const RunControl *rc = currentRunControl();
|
|
|
|
|
const bool isRunning = rc && rc->isRunning();
|
|
|
|
|
enableButtons(rc, isRunning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::enableButtons(const RunControl *rc /* = 0 */, bool isRunning /* = false */)
|
|
|
|
|
{
|
|
|
|
|
if (rc) {
|
2015-03-02 13:54:11 +01:00
|
|
|
m_reRunButton->setEnabled(!isRunning && rc->supportsReRunning());
|
2014-05-27 18:50:55 +02:00
|
|
|
m_reRunButton->setIcon(QIcon(rc->icon()));
|
2011-07-06 10:25:18 +02:00
|
|
|
m_stopAction->setEnabled(isRunning);
|
2014-10-28 08:26:25 +01:00
|
|
|
if (isRunning && debuggerPlugin() && rc->applicationProcessHandle().isValid()) {
|
2011-07-06 10:25:18 +02:00
|
|
|
m_attachButton->setEnabled(true);
|
|
|
|
|
m_attachButton->setToolTip(msgAttachDebuggerTooltip(rc->applicationProcessHandle().toString()));
|
|
|
|
|
} else {
|
|
|
|
|
m_attachButton->setEnabled(false);
|
|
|
|
|
m_attachButton->setToolTip(msgAttachDebuggerTooltip());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2011-04-14 10:39:09 +02:00
|
|
|
m_reRunButton->setEnabled(false);
|
2014-10-13 22:37:28 +03:00
|
|
|
m_reRunButton->setIcon(QIcon(QLatin1String(Constants::ICON_RUN_SMALL)));
|
2011-05-31 09:48:00 +02:00
|
|
|
m_attachButton->setEnabled(false);
|
2011-07-06 10:25:18 +02:00
|
|
|
m_attachButton->setToolTip(msgAttachDebuggerTooltip());
|
|
|
|
|
m_stopAction->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-14 10:39:09 +02:00
|
|
|
|
2011-07-06 10:25:18 +02:00
|
|
|
void AppOutputPane::tabChanged(int i)
|
|
|
|
|
{
|
|
|
|
|
const int index = indexOf(m_tabWidget->widget(i));
|
|
|
|
|
if (i != -1) {
|
|
|
|
|
const RunControl *rc = m_runControlTabs.at(index).runControl;
|
|
|
|
|
enableButtons(rc, rc->isRunning());
|
|
|
|
|
} else {
|
|
|
|
|
enableButtons();
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 12:27:26 +02:00
|
|
|
void AppOutputPane::contextMenuRequested(const QPoint &pos, int index)
|
|
|
|
|
{
|
|
|
|
|
QList<QAction *> actions = QList<QAction *>() << m_closeCurrentTabAction << m_closeAllTabsAction << m_closeOtherTabsAction;
|
|
|
|
|
QAction *action = QMenu::exec(actions, m_tabWidget->mapToGlobal(pos), 0, m_tabWidget);
|
|
|
|
|
const int currentIdx = index != -1 ? index : currentIndex();
|
|
|
|
|
if (action == m_closeCurrentTabAction) {
|
|
|
|
|
if (currentIdx >= 0)
|
|
|
|
|
closeTab(currentIdx);
|
|
|
|
|
} else if (action == m_closeAllTabsAction) {
|
|
|
|
|
closeTabs(AppOutputPane::CloseTabWithPrompt);
|
|
|
|
|
} else if (action == m_closeOtherTabsAction) {
|
|
|
|
|
for (int t = m_tabWidget->count() - 1; t >= 0; t--)
|
|
|
|
|
if (t != currentIdx)
|
|
|
|
|
closeTab(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-20 12:59:13 +00:00
|
|
|
void AppOutputPane::slotRunControlStarted()
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
|
|
|
|
RunControl *current = currentRunControl();
|
2011-07-06 10:25:18 +02:00
|
|
|
if (current && current == sender())
|
|
|
|
|
enableButtons(current, true); // RunControl::isRunning() cannot be trusted in signal handler.
|
2011-10-20 12:59:13 +00:00
|
|
|
emit runControlStarted(current);
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-20 12:59:13 +00:00
|
|
|
void AppOutputPane::slotRunControlFinished()
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
2014-10-13 22:37:28 +03:00
|
|
|
RunControl *rc = qobject_cast<RunControl *>(sender());
|
2011-11-03 15:08:59 +01:00
|
|
|
QMetaObject::invokeMethod(this, "slotRunControlFinished2", Qt::QueuedConnection,
|
|
|
|
|
Q_ARG(ProjectExplorer::RunControl *, rc));
|
2013-09-03 06:47:17 +03:00
|
|
|
rc->outputFormatter()->flush();
|
2011-11-03 15:08:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::slotRunControlFinished2(RunControl *sender)
|
|
|
|
|
{
|
|
|
|
|
const int senderIndex = indexOf(sender);
|
2011-04-14 10:39:09 +02:00
|
|
|
|
2014-09-01 16:24:24 +02:00
|
|
|
// This slot is queued, so the stop() call in closeTab might lead to this slot, after closeTab already cleaned up
|
|
|
|
|
if (senderIndex == -1)
|
|
|
|
|
return;
|
2011-04-14 10:39:09 +02:00
|
|
|
|
|
|
|
|
// Enable buttons for current
|
|
|
|
|
RunControl *current = currentRunControl();
|
|
|
|
|
|
|
|
|
|
if (debug)
|
2011-11-03 15:08:59 +01:00
|
|
|
qDebug() << "OutputPane::runControlFinished" << sender << senderIndex
|
2011-04-14 10:39:09 +02:00
|
|
|
<< " current " << current << m_runControlTabs.size();
|
|
|
|
|
|
2011-11-03 15:08:59 +01:00
|
|
|
if (current && current == sender)
|
2011-07-06 10:25:18 +02:00
|
|
|
enableButtons(current, false); // RunControl::isRunning() cannot be trusted in signal handler.
|
|
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
// Check for asynchronous close. Close the tab.
|
|
|
|
|
if (m_runControlTabs.at(senderIndex).asyncClosing)
|
|
|
|
|
closeTab(tabWidgetIndexOf(senderIndex), CloseTabNoPrompt);
|
|
|
|
|
|
2011-11-03 15:08:59 +01:00
|
|
|
emit runControlFinished(sender);
|
2011-10-20 12:59:13 +00:00
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
if (!isRunning())
|
|
|
|
|
emit allRunControlsFinished();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppOutputPane::isRunning() const
|
|
|
|
|
{
|
2014-06-06 13:12:47 +02:00
|
|
|
return Utils::anyOf(m_runControlTabs, [](const RunControlTab &rt) {
|
|
|
|
|
return rt.runControl->isRunning();
|
|
|
|
|
});
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool AppOutputPane::canNext() const
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool AppOutputPane::canPrevious() const
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::goToNext()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppOutputPane::goToPrev()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool AppOutputPane::canNavigate() const
|
2011-04-14 10:39:09 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-04 14:09:27 +02:00
|
|
|
|
2011-08-05 12:27:26 +02:00
|
|
|
#include "appoutputpane.moc"
|
|
|
|
|
|