diff --git a/src/plugins/projectexplorer/outputwindow.cpp b/src/plugins/projectexplorer/outputwindow.cpp index a1a3b1dc9692b5c47ca942fc331cef6865e27fbb..7c30e935e947e1158244a89da3b59afc005c08de 100644 --- a/src/plugins/projectexplorer/outputwindow.cpp +++ b/src/plugins/projectexplorer/outputwindow.cpp @@ -52,68 +52,6 @@ using namespace ProjectExplorer::Internal; using namespace ProjectExplorer; -bool OutputPane::hasFocus() -{ - return m_tabWidget->currentWidget() && m_tabWidget->currentWidget()->hasFocus(); -} - -bool OutputPane::canFocus() -{ - return m_tabWidget->currentWidget(); -} - -void OutputPane::setFocus() -{ - if (m_tabWidget->currentWidget()) - m_tabWidget->currentWidget()->setFocus(); -} - -void OutputPane::appendOutput(const QString &/*out*/) -{ - // This function is in the interface, since we can't do anything sensible here, we don't do anything here. -} - -void OutputPane::appendOutput(RunControl *rc, const QString &out) -{ - OutputWindow *ow = m_outputWindows.value(rc); - ow->appendOutput(out); -} - -void OutputPane::showTabFor(RunControl *rc) -{ - OutputWindow *ow = m_outputWindows.value(rc); - m_tabWidget->setCurrentWidget(ow); -} - -void OutputPane::stopRunControl() -{ - RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); - rc->stop(); -} - -void OutputPane::reRunRunControl() -{ - RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); - if (rc->runConfiguration()->project() != 0) - rc->start(); -} - -void OutputPane::closeTab(int index) -{ - OutputWindow *ow = static_cast<OutputWindow *>(m_tabWidget->widget(index)); - RunControl *rc = m_outputWindows.key(ow); - - if (rc->isRunning()) { - QString msg = tr("The application is still running. Close it first."); - QMessageBox::critical(0, tr("Unable to close"), msg); - return; - } - - m_tabWidget->removeTab(index); - delete ow; - delete rc; -} - OutputPane::OutputPane() : m_mainWidget(new QWidget) { @@ -173,21 +111,57 @@ OutputPane::~OutputPane() delete m_mainWidget; } -void OutputPane::projectRemoved() +QWidget *OutputPane::outputWidget(QWidget *) { - tabChanged(m_tabWidget->currentIndex()); + return m_mainWidget; } -void OutputPane::tabChanged(int i) +QList<QWidget*> OutputPane::toolBarWidgets(void) const { - if (i == -1) { - m_stopButton->setEnabled(false); - m_reRunButton->setEnabled(false); - } else { - RunControl *rc = runControlForTab(i); - m_stopButton->setEnabled(rc->isRunning()); - m_reRunButton->setEnabled(!rc->isRunning() && rc->runConfiguration()->project()); - } + return QList<QWidget*>() << m_reRunButton << m_stopButton + ; // << m_insertLineButton; +} + +QString OutputPane::name() const +{ + return tr("Application Output"); +} + +int OutputPane::priorityInStatusBar() const +{ + return 60; +} + +void OutputPane::clearContents() +{ + OutputWindow *currentWindow = qobject_cast<OutputWindow *>(m_tabWidget->currentWidget()); + if (currentWindow) + currentWindow->clear(); +} + +void OutputPane::visibilityChanged(bool /* b */) +{ +} + +bool OutputPane::hasFocus() +{ + return m_tabWidget->currentWidget() && m_tabWidget->currentWidget()->hasFocus(); +} + +bool OutputPane::canFocus() +{ + return m_tabWidget->currentWidget(); +} + +void OutputPane::setFocus() +{ + if (m_tabWidget->currentWidget()) + m_tabWidget->currentWidget()->setFocus(); +} + +void OutputPane::appendOutput(const QString &/*out*/) +{ + // This function is in the interface, since we can't do anything sensible here, we don't do anything here. } void OutputPane::createNewOutputWindow(RunControl *rc) @@ -195,11 +169,11 @@ void OutputPane::createNewOutputWindow(RunControl *rc) connect(rc, SIGNAL(started()), this, SLOT(runControlStarted())); connect(rc, SIGNAL(finished()), - this, SLOT(runControlFinished())); - + this, SLOT(runControlFinished())); + // First look if we can reuse a tab bool found = false; - for (int i=0; i<m_tabWidget->count(); ++i) { + for (int i = 0; i < m_tabWidget->count(); ++i) { RunControl *old = runControlForTab(i); if (old->runConfiguration() == rc->runConfiguration() && !old->isRunning()) { // Reuse this tab @@ -222,67 +196,92 @@ void OutputPane::createNewOutputWindow(RunControl *rc) } } -void OutputPane::runControlStarted() +void OutputPane::appendOutput(RunControl *rc, const QString &out) { - RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); - if (rc == qobject_cast<RunControl *>(sender())) { - m_reRunButton->setEnabled(false); - m_stopButton->setEnabled(true); - } + OutputWindow *ow = m_outputWindows.value(rc); + ow->appendOutput(out); } -void OutputPane::runControlFinished() +void OutputPane::showTabFor(RunControl *rc) { - RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); - if (rc == qobject_cast<RunControl *>(sender())) { - m_reRunButton->setEnabled(rc->runConfiguration()->project()); - m_stopButton->setEnabled(false); - } + OutputWindow *ow = m_outputWindows.value(rc); + m_tabWidget->setCurrentWidget(ow); } -QWidget *OutputPane::outputWidget(QWidget *) +void OutputPane::insertLine() { - return m_mainWidget; + OutputWindow *currentWindow = qobject_cast<OutputWindow *>(m_tabWidget->currentWidget()); + if (currentWindow) + currentWindow->clear(); } -QList<QWidget*> OutputPane::toolBarWidgets(void) const +void OutputPane::reRunRunControl() { - return QList<QWidget*>() << m_reRunButton << m_stopButton - ; // << m_insertLineButton; + RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); + if (rc->runConfiguration()->project() != 0) + rc->start(); } -QString OutputPane::name() const +void OutputPane::stopRunControl() { - return tr("Application Output"); + RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); + rc->stop(); } -void OutputPane::clearContents() +void OutputPane::closeTab(int index) { - OutputWindow *currentWindow = qobject_cast<OutputWindow *>(m_tabWidget->currentWidget()); - if (currentWindow) - currentWindow->clear(); + OutputWindow *ow = static_cast<OutputWindow *>(m_tabWidget->widget(index)); + RunControl *rc = m_outputWindows.key(ow); + + if (rc->isRunning()) { + QString msg = tr("The application is still running. Close it first."); + QMessageBox::critical(0, tr("Unable to close"), msg); + return; + } + + m_tabWidget->removeTab(index); + delete ow; + delete rc; } -void OutputPane::visibilityChanged(bool /* b */) +void OutputPane::projectRemoved() { + tabChanged(m_tabWidget->currentIndex()); +} +void OutputPane::tabChanged(int i) +{ + if (i == -1) { + m_stopButton->setEnabled(false); + m_reRunButton->setEnabled(false); + } else { + RunControl *rc = runControlForTab(i); + m_stopButton->setEnabled(rc->isRunning()); + m_reRunButton->setEnabled(!rc->isRunning() && rc->runConfiguration()->project()); + } } -void OutputPane::insertLine() +void OutputPane::runControlStarted() { - OutputWindow *currentWindow = qobject_cast<OutputWindow *>(m_tabWidget->currentWidget()); - if (currentWindow) - currentWindow->clear(); + RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); + if (rc == qobject_cast<RunControl *>(sender())) { + m_reRunButton->setEnabled(false); + m_stopButton->setEnabled(true); + } } -RunControl* OutputPane::runControlForTab(int index) const +void OutputPane::runControlFinished() { - return m_outputWindows.key(qobject_cast<OutputWindow *>(m_tabWidget->widget(index))); + RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); + if (rc == qobject_cast<RunControl *>(sender())) { + m_reRunButton->setEnabled(rc->runConfiguration()->project()); + m_stopButton->setEnabled(false); + } } -int OutputPane::priorityInStatusBar() const +RunControl* OutputPane::runControlForTab(int index) const { - return 60; + return m_outputWindows.key(qobject_cast<OutputWindow *>(m_tabWidget->widget(index))); } diff --git a/src/plugins/projectexplorer/outputwindow.h b/src/plugins/projectexplorer/outputwindow.h index 6e7431f2b62aea4dbcead39e4920468001f3beec..cf298f6643a27db5896ace05c607047464e433b7 100644 --- a/src/plugins/projectexplorer/outputwindow.h +++ b/src/plugins/projectexplorer/outputwindow.h @@ -77,9 +77,9 @@ public: void appendOutput(const QString &out); // ApplicationOutputspecifics - void createNewOutputWindow(RunControl *); - void appendOutput(RunControl *, const QString &out); - void showTabFor(RunControl *); + void createNewOutputWindow(RunControl *rc); + void appendOutput(RunControl *rc, const QString &out); + void showTabFor(RunControl *rc); public slots: void projectRemoved(); @@ -105,10 +105,10 @@ private: }; - class OutputWindow : public QPlainTextEdit { Q_OBJECT + public: OutputWindow(QWidget *parent = 0); ~OutputWindow();