From ccaeea481a005342e1e61b72dc03651268f31f7c Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sat, 29 Dec 2007 10:12:48 +0000 Subject: [PATCH] Fix bug where multiple Konsole KParts within one application would not work. Part::activeSession() was always returning the first session from the shared SessionManager. In the second KPart, activeSession()->isRunning() would always return true even when the session for that part was not actually running, so the session was never started. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=754194 --- src/Part.cpp | 22 +++++----------------- src/ViewManager.cpp | 13 ++++++++++++- src/ViewManager.h | 9 +++++++++ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Part.cpp b/src/Part.cpp index ee19a3b19..da557770a 100644 --- a/src/Part.cpp +++ b/src/Part.cpp @@ -118,27 +118,13 @@ void Part::newTab() } Session* Part::activeSession() const { - if ( _pluggedController ) - { - qDebug() << k_funcinfo << " - have plugged controller"; - - return _pluggedController->session(); - } - else - { - // for now, just return the first available session - QList list = SessionManager::instance()->sessions(); - - qDebug() << k_funcinfo << " - no plugged controller, selectin first from" << list.count() << "sessions"; - - Q_ASSERT( !list.isEmpty() ); - - return list.first(); - } + return _viewManager->activeViewController()->session(); } void Part::startProgram( const QString& program, const QStringList& arguments ) { + Q_ASSERT( activeSession() ); + if ( !activeSession()->isRunning() ) { if ( !program.isEmpty() && !arguments.isEmpty() ) @@ -152,6 +138,8 @@ void Part::startProgram( const QString& program, } void Part::showShellInDir( const QString& dir ) { + Q_ASSERT( activeSession() ); + if ( !activeSession()->isRunning() ) { if ( !dir.isEmpty() ) diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index b1e1741a4..adaa4bb0a 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -458,7 +458,7 @@ SessionController* ViewManager::createController(Session* session , TerminalDisp // create a new controller for the session, and ensure that this view manager // is notified when the view gains the focus SessionController* controller = new SessionController(session,view,this); - connect( controller , SIGNAL(focused(SessionController*)) , this , SIGNAL(activeViewChanged(SessionController*)) ); + connect( controller , SIGNAL(focused(SessionController*)) , this , SLOT(controllerChanged(SessionController*)) ); connect( session , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) ); connect( view , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) ); connect( controller , SIGNAL(sendInputToAll(bool)) , this , SLOT(sendInputToAll()) ); @@ -466,6 +466,17 @@ SessionController* ViewManager::createController(Session* session , TerminalDisp return controller; } +void ViewManager::controllerChanged(SessionController* controller) +{ + _pluggedController = controller; + emit activeViewChanged(controller); +} + +SessionController* ViewManager::activeViewController() const +{ + return _pluggedController; +} + void ViewManager::createView(Session* session) { // create the default container diff --git a/src/ViewManager.h b/src/ViewManager.h index a07b4c6ab..2777d5fe7 100644 --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -137,6 +137,12 @@ public: */ NavigationMethod navigationMethod() const; + /** + * Returns the controller for the active view. activeViewChanged() is + * emitted when this changes. + */ + SessionController* activeViewController() const; + signals: /** Emitted when the last view is removed from the view manager */ void empty(); @@ -232,6 +238,9 @@ private slots: // moves active view to the right void moveActiveViewRight(); + // called when a SessionController gains focus + void controllerChanged(SessionController* controller); + private: const ColorScheme* colorSchemeForProfile(const QString& key) const;