From 7aca63ec00a85720f5ce7731af55e00d710815c6 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sun, 1 Oct 2006 05:16:38 +0000 Subject: [PATCH] Allow views to be removed from a session. Better handling of terminal emulation size when a view is resized - Konsole looks through all of the visible views on a session and selects the largest number of lines and columns which can be displayed on all views. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=590854 --- konsole/SessionManager.cpp | 3 ++- konsole/SessionManager.h | 5 +++- konsole/TEWidget.cpp | 7 +++++- konsole/TEmulation.cpp | 3 ++- konsole/konsole.cpp | 8 ++++++- konsole/session.cpp | 49 ++++++++++++++++++++++++++++---------- konsole/session.h | 2 ++ 7 files changed, 59 insertions(+), 18 deletions(-) diff --git a/konsole/SessionManager.cpp b/konsole/SessionManager.cpp index 4a27bedf..72e99760 100644 --- a/konsole/SessionManager.cpp +++ b/konsole/SessionManager.cpp @@ -187,6 +187,7 @@ SessionManager::~SessionManager() void SessionManager::pushSessionSettings( const SessionInfo* info ) { addSetting( InitialWorkingDirectory , SessionConfig , info->defaultWorkingDirectory() ); + addSetting( ColorScheme , SessionConfig , info->colorScheme() ); } TESession* SessionManager::createSession(QString configPath ) @@ -208,7 +209,7 @@ TESession* SessionManager::createSession(QString configPath ) { //supply settings from session config pushSessionSettings( info ); - + //configuration information found, create a new session based on this session = new TESession(); diff --git a/konsole/SessionManager.h b/konsole/SessionManager.h index 6097afc6..90b5e1d1 100644 --- a/konsole/SessionManager.h +++ b/konsole/SessionManager.h @@ -138,7 +138,10 @@ public: enum Setting { Font = 0, - InitialWorkingDirectory = 1 + InitialWorkingDirectory = 1, + ColorScheme = 2, + HistoryEnabled = 3, + HistorySize = 4 // set to 0 for unlimited history ( stored in a file ) }; /** document me */ diff --git a/konsole/TEWidget.cpp b/konsole/TEWidget.cpp index 27bc0dda..27a33f48 100644 --- a/konsole/TEWidget.cpp +++ b/konsole/TEWidget.cpp @@ -1347,7 +1347,12 @@ void TEWidget::updateImageSize() // `emu' will call back via `setImage'. resizing = (oldlin!=lines) || (oldcol!=columns); - emit changedContentSizeSignal(contentHeight, contentWidth); // expose resizeEvent + + if ( resizing ) + { + emit changedContentSizeSignal(contentHeight, contentWidth); // expose resizeEvent + } + resizing = false; } diff --git a/konsole/TEmulation.cpp b/konsole/TEmulation.cpp index 05d03341..1db2adc5 100644 --- a/konsole/TEmulation.cpp +++ b/konsole/TEmulation.cpp @@ -529,8 +529,9 @@ void TEmulation::addView(TEWidget* widget) void TEmulation::removeView(TEWidget* widget) { - Q_ASSERT(0); // Not implemented yet _views.removeAll(widget); + + disconnect(widget); } void TEmulation::showBulk() diff --git a/konsole/konsole.cpp b/konsole/konsole.cpp index aefd8b1f..c3382fc1 100644 --- a/konsole/konsole.cpp +++ b/konsole/konsole.cpp @@ -2783,6 +2783,7 @@ void Konsole::slotNewSessionAction(QAction* action) // TODO: "type" isn't passed properly Konsole* konsole = new Konsole(objectName().toLatin1(), b_histEnabled, !menubar->isHidden(), n_tabbar != TabNone, b_framevis, n_scroll != TEWidget::SCRNONE, 0, false, 0); + konsole->setSessionManager( sessionManager() ); konsole->newSession(); konsole->enableFullScripting(b_fullScripting); konsole->enableFixedSize(b_fixedSize); @@ -3629,10 +3630,15 @@ void Konsole::detachSession(TESession* _se) { // TODO: "type" isn't passed properly Konsole* konsole = new Konsole( objectName().toLatin1(), b_histEnabled, !menubar->isHidden(), n_tabbar != TabNone, b_framevis, n_scroll != TEWidget::SCRNONE, 0, false, 0); + + konsole->setSessionManager(sessionManager()); + konsole->enableFullScripting(b_fullScripting); // TODO; Make this work: konsole->enableFixedSize(b_fixedSize); konsole->resize(size()); konsole->attachSession(_se); + _se->removeView( _se->primaryView() ); + konsole->activateSession(_se); konsole->changeTabTextColor( _se, se_tabtextcolor.rgb() );//restore prev color konsole->slotTabSetViewOptions(m_tabViewMode); @@ -3680,7 +3686,7 @@ void Konsole::attachSession(TESession* session) te->resize(se_widget->size()); te->setSize(se_widget->Columns(), se_widget->Lines()); initTEWidget(te, se_widget); - session->changeWidget(te); + session->addView(te); te->setFocus(); createSessionTab(te, SmallIconSet(session->IconName()), session->Title()); setSchema(session->schemaNo() , te); diff --git a/konsole/session.cpp b/konsole/session.cpp index a2ea78dd..3de48619 100644 --- a/konsole/session.cpp +++ b/konsole/session.cpp @@ -218,19 +218,13 @@ void TESession::addView(TEWidget* widget) if ( em != 0 ) em->addView(widget); - //temporary test - //if this is the first view then connect its resizing events - //to resizing of the emulation - if ( _views.count() == 1 ) - { - font_h = primaryView()-> fontHeight(); - font_w = primaryView()-> fontWidth(); - QObject::connect(primaryView(),SIGNAL(changedContentSizeSignal(int,int)), + font_h = primaryView()-> fontHeight(); + font_w = primaryView()-> fontWidth(); + + QObject::connect( widget ,SIGNAL(changedContentSizeSignal(int,int)), this,SLOT(onContentSizeChange(int,int))); - QObject::connect(primaryView(),SIGNAL(changedFontMetricSignal(int,int)), + QObject::connect( widget ,SIGNAL(changedFontMetricSignal(int,int)), this,SLOT(onFontMetricChange(int,int))); - - } } void TESession::removeView(TEWidget* widget) @@ -523,9 +517,13 @@ void TESession::notifySessionState(int state) void TESession::onContentSizeChange(int height, int width) { + kDebug() << __FUNCTION__ << endl; + + updateTerminalSize(); + //kDebug(1211)<<"TESession::onContentSizeChange " << height << " " << width << endl; - em->onImageSizeChange( height/font_h, width/font_w ); - sh->setSize( height/font_h, width/font_w ); +// em->onImageSizeChange( height/font_h, width/font_w ); +// sh->setSize( height/font_h, width/font_w ); } void TESession::onFontMetricChange(int height, int width) @@ -537,6 +535,31 @@ void TESession::onFontMetricChange(int height, int width) } } +void TESession::updateTerminalSize() +{ + QListIterator viewIter(_views); + + int minLines = -1; + int minColumns = -1; + + //select smallest number of lines and columns that will fit in all visible views + while ( viewIter.hasNext() ) + { + TEWidget* view = viewIter.next(); + if ( view->isHidden() == false ) + { + minLines = (minLines == -1) ? view->Lines() : qMin( minLines , view->Lines() ); + minColumns = (minColumns == -1) ? view->Columns() : qMin( minColumns , view->Columns() ); + } + } + + if ( minLines != -1 && minColumns != -1 ) + { + em->onImageSizeChange( minLines , minColumns ); + sh->setSize( minLines , minColumns ); + } +} + bool TESession::sendSignal(int signal) { return sh->kill(signal); diff --git a/konsole/session.h b/konsole/session.h index 914fcdd9..3e2b9a37 100644 --- a/konsole/session.h +++ b/konsole/session.h @@ -244,6 +244,8 @@ private Q_SLOTS: private: + void updateTerminalSize(); + TEPty* sh; TEWidget* te; TEmulation* em;