From ce1d728b9a412b69cb6bc4016533abf9300309aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Fri, 9 Jan 2009 11:06:36 +0100 Subject: [PATCH 1/2] Some code reorganization Changing nothing, just preventing next patch to be scrambled by it. --- src/plugins/projectexplorer/outputwindow.cpp | 231 +++++++++---------- src/plugins/projectexplorer/outputwindow.h | 8 +- 2 files changed, 119 insertions(+), 120 deletions(-) diff --git a/src/plugins/projectexplorer/outputwindow.cpp b/src/plugins/projectexplorer/outputwindow.cpp index a1a3b1dc969..7c30e935e94 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(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 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() << 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(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; icount(); ++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,6 +196,71 @@ void OutputPane::createNewOutputWindow(RunControl *rc) } } +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::insertLine() +{ + OutputWindow *currentWindow = qobject_cast(m_tabWidget->currentWidget()); + if (currentWindow) + currentWindow->clear(); +} + +void OutputPane::reRunRunControl() +{ + RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); + if (rc->runConfiguration()->project() != 0) + rc->start(); +} + +void OutputPane::stopRunControl() +{ + RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); + rc->stop(); +} + +void OutputPane::closeTab(int index) +{ + OutputWindow *ow = static_cast(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::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::runControlStarted() { RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); @@ -240,51 +279,11 @@ void OutputPane::runControlFinished() } } -QWidget *OutputPane::outputWidget(QWidget *) -{ - return m_mainWidget; -} - -QList OutputPane::toolBarWidgets(void) const -{ - return QList() << m_reRunButton << m_stopButton - ; // << m_insertLineButton; -} - -QString OutputPane::name() const -{ - return tr("Application Output"); -} - -void OutputPane::clearContents() -{ - OutputWindow *currentWindow = qobject_cast(m_tabWidget->currentWidget()); - if (currentWindow) - currentWindow->clear(); -} - -void OutputPane::visibilityChanged(bool /* b */) -{ - -} - -void OutputPane::insertLine() -{ - OutputWindow *currentWindow = qobject_cast(m_tabWidget->currentWidget()); - if (currentWindow) - currentWindow->clear(); -} - RunControl* OutputPane::runControlForTab(int index) const { return m_outputWindows.key(qobject_cast(m_tabWidget->widget(index))); } -int OutputPane::priorityInStatusBar() const -{ - return 60; -} - /*******************/ diff --git a/src/plugins/projectexplorer/outputwindow.h b/src/plugins/projectexplorer/outputwindow.h index 6e7431f2b62..cf298f6643a 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(); From 9b35e32e857c94dc01dab06a3de14a9fc676dc8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Fri, 9 Jan 2009 12:58:02 +0100 Subject: [PATCH 2/2] Register stop action globally Default shortcut is Ctrl+Shift+R now, but maybe there's something better or more widely accepted. No menu entry yet. --- src/plugins/projectexplorer/outputwindow.cpp | 37 +++++++++++++------ src/plugins/projectexplorer/outputwindow.h | 7 +++- .../projectexplorer/projectexplorer.cpp | 2 +- .../projectexplorerconstants.h | 6 +-- src/plugins/quickopen/quickopentoolwindow.cpp | 2 +- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/plugins/projectexplorer/outputwindow.cpp b/src/plugins/projectexplorer/outputwindow.cpp index 7c30e935e94..597a6daba6e 100644 --- a/src/plugins/projectexplorer/outputwindow.cpp +++ b/src/plugins/projectexplorer/outputwindow.cpp @@ -35,6 +35,9 @@ #include "projectexplorerconstants.h" #include "runconfiguration.h" +#include +#include +#include #include #include @@ -52,8 +55,8 @@ using namespace ProjectExplorer::Internal; using namespace ProjectExplorer; -OutputPane::OutputPane() - : m_mainWidget(new QWidget) +OutputPane::OutputPane(Core::ICore *core) + : m_mainWidget(new QWidget) { // m_insertLineButton = new QToolButton; // m_insertLineButton->setIcon(QIcon(ProjectExplorer::Constants::ICON_INSERT_LINE)); @@ -65,7 +68,7 @@ OutputPane::OutputPane() QIcon runIcon(Constants::ICON_RUN); runIcon.addFile(Constants::ICON_RUN_SMALL); - //Rerun + // Rerun m_reRunButton = new QToolButton; m_reRunButton->setIcon(runIcon); m_reRunButton->setToolTip(tr("Rerun this runconfiguration")); @@ -74,13 +77,23 @@ OutputPane::OutputPane() connect(m_reRunButton, SIGNAL(clicked()), this, SLOT(reRunRunControl())); - //Stop + // Stop + Core::ActionManagerInterface *am = core->actionManager(); + QList globalcontext; + globalcontext.append(Core::Constants::C_GLOBAL_ID); + + m_stopAction = new QAction(QIcon(Constants::ICON_STOP), tr("Stop"), this); + m_stopAction->setToolTip(tr("Stop")); + m_stopAction->setEnabled(false); + + Core::ICommand *cmd = am->registerAction(m_stopAction, Constants::STOP, globalcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+R"))); + m_stopButton = new QToolButton; - m_stopButton->setIcon(QIcon(Constants::ICON_STOP)); - m_stopButton->setToolTip(tr("Stop")); + m_stopButton->setDefaultAction(cmd->action()); m_stopButton->setAutoRaise(true); - m_stopButton->setEnabled(false); - connect(m_stopButton, SIGNAL(clicked()), + + connect(m_stopAction, SIGNAL(triggered()), this, SLOT(stopRunControl())); // Spacer (?) @@ -252,11 +265,11 @@ void OutputPane::projectRemoved() void OutputPane::tabChanged(int i) { if (i == -1) { - m_stopButton->setEnabled(false); + m_stopAction->setEnabled(false); m_reRunButton->setEnabled(false); } else { RunControl *rc = runControlForTab(i); - m_stopButton->setEnabled(rc->isRunning()); + m_stopAction->setEnabled(rc->isRunning()); m_reRunButton->setEnabled(!rc->isRunning() && rc->runConfiguration()->project()); } } @@ -266,7 +279,7 @@ void OutputPane::runControlStarted() RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); if (rc == qobject_cast(sender())) { m_reRunButton->setEnabled(false); - m_stopButton->setEnabled(true); + m_stopAction->setEnabled(true); } } @@ -275,7 +288,7 @@ void OutputPane::runControlFinished() RunControl *rc = runControlForTab(m_tabWidget->currentIndex()); if (rc == qobject_cast(sender())) { m_reRunButton->setEnabled(rc->runConfiguration()->project()); - m_stopButton->setEnabled(false); + m_stopAction->setEnabled(false); } } diff --git a/src/plugins/projectexplorer/outputwindow.h b/src/plugins/projectexplorer/outputwindow.h index cf298f6643a..3367909d804 100644 --- a/src/plugins/projectexplorer/outputwindow.h +++ b/src/plugins/projectexplorer/outputwindow.h @@ -48,6 +48,10 @@ QT_BEGIN_NAMESPACE class QTabWidget; QT_END_NAMESPACE +namespace Core { +class ICore; +} + namespace ProjectExplorer { class RunControl; @@ -61,7 +65,7 @@ class OutputPane : public Core::IOutputPane Q_OBJECT public: - OutputPane(); + OutputPane(Core::ICore *core); ~OutputPane(); QWidget *outputWidget(QWidget *); @@ -99,6 +103,7 @@ private: QWidget *m_mainWidget; QTabWidget *m_tabWidget; QHash m_outputWindows; + QAction *m_stopAction; // QToolButton *m_insertLineButton; QToolButton *m_reRunButton; QToolButton *m_stopButton; diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 385f7452b74..e4721457af4 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -200,7 +200,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList & /*arguments*/, QStrin addAutoReleasedObject(new CoreListenerCheckingForRunningBuild(m_buildManager)); - m_outputPane = new OutputPane(); + m_outputPane = new OutputPane(m_core); addAutoReleasedObject(m_outputPane); connect(m_session, SIGNAL(projectRemoved(ProjectExplorer::Project *)), m_outputPane, SLOT(projectRemoved())); diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index 3f937823ef2..5cc5f5c67e2 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -56,6 +56,8 @@ const char * const CLEANSESSION = "ProjectExplorer.CleanSession"; const char * const BUILDCONFIGURATIONMENU = "ProjectExplorer.BuildConfigurationMenu"; const char * const CANCELBUILD = "ProjectExplorer.CancelBuild"; const char * const RUNCONFIGURATIONMENU = "ProjectExplorer.RunConfigurationMenu"; +const char * const RUN = "ProjectExplorer.Run"; +const char * const STOP = "ProjectExplorer.Stop"; const char * const DEBUG = "ProjectExplorer.Debug"; const char * const DEPENDENCIES = "ProjectExplorer.Dependencies"; const char * const FINDINALLPROJECTS = "ProjectExplorer.FindInAllProjects"; @@ -67,7 +69,7 @@ const char * const OPENFILE = "ProjectExplorer.OpenFile"; const char * const REMOVEFILE = "ProjectExplorer.RemoveFile"; const char * const RENAMEFILE = "ProjectExplorer.RenameFile"; -//Run modes +// Run modes const char * const RUNMODE = "ProjectExplorer.RunMode"; const char * const DEBUGMODE = "ProjectExplorer.DebugMode"; @@ -76,8 +78,6 @@ const int P_ACTION_RUN = 100; const int P_ACTION_DEBUG = 90; const int P_ACTION_BUILDSESSION = 80; -const char * const RUN = "ProjectExplorer.Run"; - // context const char * const C_PROJECTEXPLORER = "Project Explorer"; diff --git a/src/plugins/quickopen/quickopentoolwindow.cpp b/src/plugins/quickopen/quickopentoolwindow.cpp index b3232147f37..c3f390f54b7 100644 --- a/src/plugins/quickopen/quickopentoolwindow.cpp +++ b/src/plugins/quickopen/quickopentoolwindow.cpp @@ -261,7 +261,7 @@ QuickOpenToolWindow::QuickOpenToolWindow(QuickOpenPlugin *qop) : m_configureAction(new QAction(tr("Configure..."), this)), m_fileLineEdit(new Core::Utils::FancyLineEdit) { - // Explcitly hide the completion list popup. + // Explicitly hide the completion list popup. m_completionList->hide(); setWindowTitle("Locate...");