kateviewspacecontainer.cpp
00001 /* This file is part of the KDE project 00002 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00003 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00004 Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 //BEGIN Includes 00022 #include "kateviewspacecontainer.h" 00023 #include "kateviewspacecontainer.moc" 00024 00025 #include "katetabwidget.h" 00026 #include "katemainwindow.h" 00027 #include "katedocmanager.h" 00028 #include "kateviewmanager.h" 00029 #include "kateviewspace.h" 00030 00031 #include <dcopclient.h> 00032 #include <kaction.h> 00033 #include <kcmdlineargs.h> 00034 #include <kdebug.h> 00035 #include <kdiroperator.h> 00036 #include <kdockwidget.h> 00037 #include <kencodingfiledialog.h> 00038 #include <kiconloader.h> 00039 #include <kglobal.h> 00040 #include <klocale.h> 00041 #include <ktoolbar.h> 00042 #include <kmessagebox.h> 00043 #include <ksimpleconfig.h> 00044 #include <kstdaction.h> 00045 #include <kstandarddirs.h> 00046 #include <kglobalsettings.h> 00047 #include <kstringhandler.h> 00048 00049 #include <ktexteditor/encodinginterface.h> 00050 00051 #include <tqlayout.h> 00052 #include <tqobjectlist.h> 00053 #include <tqstringlist.h> 00054 #include <tqvbox.h> 00055 #include <tqtimer.h> 00056 #include <tqfileinfo.h> 00057 00058 //END Includes 00059 00060 KateViewSpaceContainer::KateViewSpaceContainer (TQWidget *parent, KateViewManager *viewManager) 00061 : TQVBox (parent) 00062 , m_viewManager(viewManager) 00063 , m_blockViewCreationAndActivation (false) 00064 , m_activeViewRunning (false) 00065 , m_pendingViewCreation(false) 00066 { 00067 // no memleaks 00068 m_viewList.setAutoDelete(true); 00069 m_viewSpaceList.setAutoDelete(true); 00070 00071 KateViewSpace* vs = new KateViewSpace( this, this ); 00072 connect(this, TQT_SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const TQString&)), vs, TQT_SLOT(slotStatusChanged(Kate::View *, int, int, int, bool, int, const TQString&))); 00073 vs->setActive( true ); 00074 m_viewSpaceList.append(vs); 00075 connect( this, TQT_SIGNAL(viewChanged()), this, TQT_SLOT(slotViewChanged()) ); 00076 connect(KateDocManager::self(), TQT_SIGNAL(initialDocumentReplaced()), this, TQT_SIGNAL(viewChanged())); 00077 00078 connect(KateDocManager::self(),TQT_SIGNAL(documentCreated(Kate::Document *)),this,TQT_SLOT(documentCreated(Kate::Document *))); 00079 connect(KateDocManager::self(),TQT_SIGNAL(documentDeleted(uint)),this,TQT_SLOT(documentDeleted(uint))); 00080 } 00081 00082 KateViewSpaceContainer::~KateViewSpaceContainer () 00083 { 00084 m_viewList.setAutoDelete(false); 00085 m_viewSpaceList.setAutoDelete(false); 00086 } 00087 00088 void KateViewSpaceContainer::documentCreated (Kate::Document *doc) 00089 { 00090 if (m_blockViewCreationAndActivation) return; 00091 00092 if (!activeView()) 00093 activateView (doc->documentNumber()); 00094 } 00095 00096 void KateViewSpaceContainer::documentDeleted (uint) 00097 { 00098 if (m_blockViewCreationAndActivation) return; 00099 00100 // just for the case we close a document out of many and this was the active one 00101 // if all docs are closed, this will be handled by the documentCreated 00102 if (!activeView() && (KateDocManager::self()->documents() > 0)) 00103 createView (KateDocManager::self()->document(KateDocManager::self()->documents()-1)); 00104 } 00105 00106 bool KateViewSpaceContainer::createView ( Kate::Document *doc ) 00107 { 00108 if (m_blockViewCreationAndActivation) return false; 00109 00110 // create doc 00111 if (!doc) 00112 doc = KateDocManager::self()->createDoc (); 00113 00114 // create view 00115 Kate::View *view = (Kate::View *) doc->createView (this, 0L); 00116 00117 m_viewList.append (view); 00118 00119 // disable settings dialog action 00120 view->actionCollection()->remove (view->actionCollection()->action( "set_confdlg" )); 00121 00122 // popup menu 00123 view->installPopup ((TQPopupMenu*)(mainWindow()->factory()->container("ktexteditor_popup", mainWindow())) ); 00124 00125 connect(view->getDoc(),TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(statusMsg())); 00126 connect(view,TQT_SIGNAL(cursorPositionChanged()),this,TQT_SLOT(statusMsg())); 00127 connect(view,TQT_SIGNAL(newStatus()),this,TQT_SLOT(statusMsg())); 00128 connect(view->getDoc(), TQT_SIGNAL(undoChanged()), this, TQT_SLOT(statusMsg())); 00129 connect(view,TQT_SIGNAL(dropEventPass(TQDropEvent *)), mainWindow(),TQT_SLOT(slotDropEvent(TQDropEvent *))); 00130 connect(view,TQT_SIGNAL(gotFocus(Kate::View *)),this,TQT_SLOT(activateSpace(Kate::View *))); 00131 00132 activeViewSpace()->addView( view ); 00133 activateView( view ); 00134 connect( doc, TQT_SIGNAL(modifiedOnDisc(Kate::Document *, bool, unsigned char)), 00135 activeViewSpace(), TQT_SLOT(modifiedOnDisc(Kate::Document *, bool, unsigned char)) ); 00136 00137 return true; 00138 } 00139 00140 bool KateViewSpaceContainer::deleteView (Kate::View *view, bool delViewSpace) 00141 { 00142 if (!view) return true; 00143 00144 KateViewSpace *viewspace = (KateViewSpace *)view->parentWidget()->parentWidget(); 00145 00146 viewspace->removeView (view); 00147 00148 mainWindow()->guiFactory ()->removeClient (view); 00149 00150 // remove view from list and memory !! 00151 m_viewList.remove (view); 00152 00153 if (delViewSpace) 00154 if ( viewspace->viewCount() == 0 ) 00155 removeViewSpace( viewspace ); 00156 00157 return true; 00158 } 00159 00160 KateViewSpace* KateViewSpaceContainer::activeViewSpace () 00161 { 00162 TQPtrListIterator<KateViewSpace> it(m_viewSpaceList); 00163 00164 for (; it.current(); ++it) 00165 { 00166 if ( it.current()->isActiveSpace() ) 00167 return it.current(); 00168 } 00169 00170 if (m_viewSpaceList.count() > 0) 00171 { 00172 m_viewSpaceList.first()->setActive( true ); 00173 return m_viewSpaceList.first(); 00174 } 00175 00176 return 0L; 00177 } 00178 00179 Kate::View* KateViewSpaceContainer::activeView () 00180 { 00181 if (m_activeViewRunning) 00182 return 0L; 00183 00184 m_activeViewRunning = true; 00185 00186 for (TQPtrListIterator<Kate::View> it(m_viewList); it.current(); ++it) 00187 { 00188 if ( it.current()->isActive() ) 00189 { 00190 m_activeViewRunning = false; 00191 return it.current(); 00192 } 00193 } 00194 00195 // if we get to here, no view isActive() 00196 // first, try to get one from activeViewSpace() 00197 KateViewSpace* vs; 00198 if ( (vs = activeViewSpace()) ) 00199 { 00200 if ( vs->currentView() ) 00201 { 00202 activateView (vs->currentView()); 00203 00204 m_activeViewRunning = false; 00205 return vs->currentView(); 00206 } 00207 } 00208 00209 // last attempt: just pick first 00210 if (m_viewList.count() > 0) 00211 { 00212 activateView (m_viewList.first()); 00213 00214 m_activeViewRunning = false; 00215 return m_viewList.first(); 00216 } 00217 00218 m_activeViewRunning = false; 00219 00220 // no views exists! 00221 return 0L; 00222 } 00223 00224 void KateViewSpaceContainer::setActiveSpace ( KateViewSpace* vs ) 00225 { 00226 if (activeViewSpace()) 00227 activeViewSpace()->setActive( false ); 00228 00229 vs->setActive( true, viewSpaceCount() > 1 ); 00230 } 00231 00232 void KateViewSpaceContainer::setActiveView ( Kate::View* view ) 00233 { 00234 if (activeView()) 00235 activeView()->setActive( false ); 00236 00237 view->setActive( true ); 00238 } 00239 00240 void KateViewSpaceContainer::activateSpace (Kate::View* v) 00241 { 00242 if (!v) return; 00243 00244 KateViewSpace* vs = (KateViewSpace*)v->parentWidget()->parentWidget(); 00245 00246 if (!vs->isActiveSpace()) { 00247 setActiveSpace (vs); 00248 activateView(v); 00249 } 00250 } 00251 00252 void KateViewSpaceContainer::reactivateActiveView() { 00253 Kate::View *view=activeView(); 00254 if (view) { 00255 view->setActive(false); 00256 activateView(view); 00257 } else if (m_pendingViewCreation) { 00258 m_pendingViewCreation=false; 00259 disconnect(m_pendingDocument,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotPendingDocumentNameChanged())); 00260 createView(m_pendingDocument); 00261 } 00262 } 00263 00264 void KateViewSpaceContainer::activateView ( Kate::View *view ) 00265 { 00266 if (!view) return; 00267 00268 if (!view->isActive()) 00269 { 00270 if ( !activeViewSpace()->showView (view) ) 00271 { 00272 // since it wasn't found, give'em a new one 00273 createView ( view->getDoc() ); 00274 return; 00275 } 00276 00277 setActiveView (view); 00278 m_viewList.findRef (view); 00279 00280 mainWindow()->toolBar ()->setUpdatesEnabled (false); 00281 00282 if (m_viewManager->guiMergedView) 00283 mainWindow()->guiFactory()->removeClient (m_viewManager->guiMergedView ); 00284 00285 m_viewManager->guiMergedView = view; 00286 00287 if (!m_blockViewCreationAndActivation) 00288 mainWindow()->guiFactory ()->addClient( view ); 00289 00290 mainWindow()->toolBar ()->setUpdatesEnabled (true); 00291 00292 statusMsg(); 00293 00294 emit viewChanged (); 00295 } 00296 00297 KateDocManager::self()->setActiveDocument(view->getDoc()); 00298 } 00299 00300 void KateViewSpaceContainer::activateView( uint documentNumber ) 00301 { 00302 if ( activeViewSpace()->showView(documentNumber) ) { 00303 activateView( activeViewSpace()->currentView() ); 00304 } 00305 else 00306 { 00307 TQPtrListIterator<Kate::View> it(m_viewList); 00308 for ( ;it.current(); ++it) 00309 { 00310 if ( it.current()->getDoc()->documentNumber() == documentNumber ) 00311 { 00312 createView( it.current()->getDoc() ); 00313 return; 00314 } 00315 } 00316 00317 Kate::Document *d = (Kate::Document *)KateDocManager::self()->documentWithID(documentNumber); 00318 createView (d); 00319 } 00320 } 00321 00322 uint KateViewSpaceContainer::viewCount () 00323 { 00324 return m_viewList.count(); 00325 } 00326 00327 uint KateViewSpaceContainer::viewSpaceCount () 00328 { 00329 return m_viewSpaceList.count(); 00330 } 00331 00332 void KateViewSpaceContainer::slotViewChanged() 00333 { 00334 if ( activeView() && !activeView()->hasFocus()) 00335 activeView()->setFocus(); 00336 } 00337 00338 void KateViewSpaceContainer::activateNextView() 00339 { 00340 uint i = m_viewSpaceList.find (activeViewSpace())+1; 00341 00342 if (i >= m_viewSpaceList.count()) 00343 i=0; 00344 00345 setActiveSpace (m_viewSpaceList.at(i)); 00346 activateView(m_viewSpaceList.at(i)->currentView()); 00347 } 00348 00349 void KateViewSpaceContainer::activatePrevView() 00350 { 00351 int i = m_viewSpaceList.find (activeViewSpace())-1; 00352 00353 if (i < 0) 00354 i=m_viewSpaceList.count()-1; 00355 00356 setActiveSpace (m_viewSpaceList.at(i)); 00357 activateView(m_viewSpaceList.at(i)->currentView()); 00358 } 00359 00360 void KateViewSpaceContainer::closeViews(uint documentNumber) 00361 { 00362 TQPtrList<Kate::View> closeList; 00363 00364 for (uint z=0 ; z < m_viewList.count(); z++) 00365 { 00366 Kate::View* current = m_viewList.at(z); 00367 if ( current->getDoc()->documentNumber() == documentNumber ) 00368 { 00369 closeList.append (current); 00370 } 00371 } 00372 00373 while ( !closeList.isEmpty() ) 00374 { 00375 Kate::View *view = closeList.first(); 00376 deleteView (view, true); 00377 closeList.removeFirst(); 00378 } 00379 00380 if (m_blockViewCreationAndActivation) return; 00381 TQTimer::singleShot(0,this,TQT_SIGNAL(viewChanged())); 00382 //emit m_viewManager->viewChanged (); 00383 } 00384 00385 void KateViewSpaceContainer::slotPendingDocumentNameChanged() { 00386 TQString c; 00387 if (m_pendingDocument->url().isEmpty() || (!showFullPath)) 00388 { 00389 c = m_pendingDocument->docName(); 00390 } 00391 else 00392 { 00393 c = m_pendingDocument->url().prettyURL(); 00394 } 00395 setCaption(KStringHandler::lsqueeze(c,32)); 00396 } 00397 00398 void KateViewSpaceContainer::statusMsg () 00399 { 00400 if (!activeView()) return; 00401 00402 Kate::View* v = activeView(); 00403 00404 bool readOnly = !v->getDoc()->isReadWrite(); 00405 uint config = v->getDoc()->configFlags(); 00406 00407 int ovr = 0; 00408 if (readOnly) 00409 ovr = 0; 00410 else 00411 { 00412 if (config & Kate::Document::cfOvr) 00413 { 00414 ovr=1; 00415 } 00416 else 00417 { 00418 ovr=2; 00419 } 00420 } 00421 00422 int mod = (int)v->getDoc()->isModified(); 00423 bool block=v->getDoc()->blockSelectionMode(); 00424 00425 TQString c; 00426 if (v->getDoc()->url().isEmpty() || (!showFullPath)) 00427 { 00428 c = v->getDoc()->docName(); 00429 } 00430 else 00431 { 00432 c = v->getDoc()->url().prettyURL(); 00433 } 00434 00435 m_viewManager->mainWindow()->tabWidget()->changeTab (this, KStringHandler::lsqueeze(c,32)); 00436 emit statusChanged (v, v->cursorLine(), v->cursorColumn(), ovr,block, mod, KStringHandler::lsqueeze(c,64)); 00437 emit statChanged (); 00438 } 00439 00440 void KateViewSpaceContainer::splitViewSpace( KateViewSpace* vs, 00441 bool isHoriz, 00442 bool atTop) 00443 { 00444 // kdDebug(13001)<<"splitViewSpace()"<<endl; 00445 00446 if (!activeView()) return; 00447 if (!vs) vs = activeViewSpace(); 00448 00449 bool isFirstTime = vs->parentWidget() == this; 00450 00451 TQValueList<int> psizes; 00452 if ( ! isFirstTime ) 00453 if ( TQSplitter *ps = static_cast<TQSplitter*>(vs->parentWidget()->qt_cast(TQSPLITTER_OBJECT_NAME_STRING)) ) 00454 psizes = ps->sizes(); 00455 00456 Qt::Orientation o = isHoriz ? Qt::Vertical : Qt::Horizontal; 00457 KateMDI::Splitter* s = new KateMDI::Splitter(o, vs->parentWidget()); 00458 s->setOpaqueResize( KGlobalSettings::opaqueResize() ); 00459 00460 if (! isFirstTime) { 00461 // anders: make sure the split' viewspace is always 00462 // correctly positioned. 00463 // If viewSpace is the first child, the new splitter must be moveToFirst'd 00464 if ( !((KateMDI::Splitter*)vs->parentWidget())->isLastChild( vs ) ) 00465 ((KateMDI::Splitter*)s->parentWidget())->moveToFirst( s ); 00466 } 00467 vs->reparent( s, 0, TQPoint(), true ); 00468 KateViewSpace* vsNew = new KateViewSpace( this, s ); 00469 00470 if (atTop) 00471 s->moveToFirst( vsNew ); 00472 00473 if (!isFirstTime) 00474 if (TQSplitter *ps = static_cast<TQSplitter*>(s->parentWidget()->qt_cast(TQSPLITTER_OBJECT_NAME_STRING)) ) 00475 ps->setSizes( psizes ); 00476 00477 s->show(); 00478 00479 TQValueList<int> sizes; 00480 int space = 50;//isHoriz ? s->parentWidget()->height()/2 : s->parentWidget()->width()/2; 00481 sizes << space << space; 00482 s->setSizes( sizes ); 00483 00484 connect(this, TQT_SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const TQString &)), vsNew, TQT_SLOT(slotStatusChanged(Kate::View *, int, int,int, bool, int, const TQString &))); 00485 m_viewSpaceList.append( vsNew ); 00486 activeViewSpace()->setActive( false ); 00487 vsNew->setActive( true, true ); 00488 vsNew->show(); 00489 00490 createView (activeView()->getDoc()); 00491 00492 if (this == m_viewManager->activeContainer()) 00493 m_viewManager->updateViewSpaceActions (); 00494 00495 // kdDebug(13001)<<"splitViewSpace() - DONE!"<<endl; 00496 } 00497 00498 void KateViewSpaceContainer::removeViewSpace (KateViewSpace *viewspace) 00499 { 00500 // abort if viewspace is 0 00501 if (!viewspace) return; 00502 00503 // abort if this is the last viewspace 00504 if (m_viewSpaceList.count() < 2) return; 00505 00506 KateMDI::Splitter* p = (KateMDI::Splitter*)viewspace->parentWidget(); 00507 00508 // find out if it is the first child for repositioning 00509 // see below 00510 bool pIsFirst = false; 00511 00512 // save some size information 00513 KateMDI::Splitter* pp=0L; 00514 TQValueList<int> ppsizes; 00515 if (m_viewSpaceList.count() > 2 && p->parentWidget() != this) 00516 { 00517 pp = (KateMDI::Splitter*)p->parentWidget(); 00518 ppsizes = pp->sizes(); 00519 pIsFirst = !pp->isLastChild( p ); // simple logic, right- 00520 } 00521 00522 // Figure out where to put views that are still needed 00523 KateViewSpace* next; 00524 if (m_viewSpaceList.find(viewspace) == 0) 00525 next = m_viewSpaceList.next(); 00526 else 00527 next = m_viewSpaceList.prev(); 00528 00529 // Reparent views in viewspace that are last views, delete the rest. 00530 int vsvc = viewspace->viewCount(); 00531 while (vsvc > 0) 00532 { 00533 if (viewspace->currentView()) 00534 { 00535 Kate::View* v = viewspace->currentView(); 00536 00537 if (v->isLastView()) 00538 { 00539 viewspace->removeView(v); 00540 next->addView( v, false ); 00541 } 00542 else 00543 { 00544 deleteView( v, false ); 00545 } 00546 } 00547 vsvc = viewspace->viewCount(); 00548 } 00549 00550 m_viewSpaceList.remove( viewspace ); 00551 00552 // reparent the other sibling of the parent. 00553 while (!p->childrenListObject().isEmpty()) 00554 { 00555 TQWidget* other = ((TQWidget *)(( TQPtrList<TQObject>)p->childrenListObject()).first()); 00556 00557 other->reparent( p->parentWidget(), 0, TQPoint(), true ); 00558 // We also need to find the right viewspace to become active 00559 if (pIsFirst) 00560 ((KateMDI::Splitter*)p->parentWidget())->moveToFirst( other ); 00561 if ( other->isA("KateViewSpace") ) { 00562 setActiveSpace( (KateViewSpace*)other ); 00563 } 00564 else { 00565 TQObjectList* l = other->queryList( "KateViewSpace" ); 00566 if ( l->first() != 0 ) { // I REALLY hope so! 00567 setActiveSpace( (KateViewSpace*)l->first() ); 00568 } 00569 delete l; 00570 } 00571 } 00572 00573 delete p; 00574 00575 if (!ppsizes.isEmpty()) 00576 pp->setSizes( ppsizes ); 00577 00578 // find the view that is now active. 00579 Kate::View* v = activeViewSpace()->currentView(); 00580 if ( v ) 00581 activateView( v ); 00582 00583 if (this == m_viewManager->activeContainer()) 00584 m_viewManager->updateViewSpaceActions (); 00585 00586 emit viewChanged(); 00587 } 00588 00589 void KateViewSpaceContainer::slotCloseCurrentViewSpace() 00590 { 00591 removeViewSpace(activeViewSpace()); 00592 } 00593 00594 void KateViewSpaceContainer::setShowFullPath( bool enable ) 00595 { 00596 showFullPath = enable; 00597 statusMsg (); 00598 //m_mainWindow->slotWindowActivated (); 00599 } 00600 00605 void KateViewSpaceContainer::saveViewConfiguration(KConfig *config,const TQString& group) 00606 { 00607 bool weHaveSplittersAlive (viewSpaceCount() > 1); 00608 00609 config->setGroup (group); //"View Configuration"); 00610 config->writeEntry ("Splitters", weHaveSplittersAlive); 00611 00612 // no splitters around 00613 if (!weHaveSplittersAlive) 00614 { 00615 config->writeEntry("Active Viewspace", 0); 00616 m_viewSpaceList.first()->saveConfig ( config, 0,group ); 00617 00618 return; 00619 } 00620 00621 // I need the first splitter, the one which has this as parent. 00622 KateMDI::Splitter* s; 00623 TQObjectList *l = queryList("KateMDI::Splitter", 0, false, false); 00624 TQObjectListIt it( *l ); 00625 00626 if ( (s = (KateMDI::Splitter*)it.current()) != 0 ) 00627 saveSplitterConfig( s, 0, config , group); 00628 00629 delete l; 00630 } 00631 00632 void KateViewSpaceContainer::restoreViewConfiguration (KConfig *config, const TQString& group) 00633 { 00634 config->setGroup(group); 00635 //config->setGroup ("View Configuration"); 00636 00637 // no splitters around, ohhh :() 00638 if (!config->readBoolEntry ("Splitters")) 00639 { 00640 // only add the new views needed, let the old stay, won't hurt if one around 00641 m_viewSpaceList.first ()->restoreConfig (this, config, TQString(group+"-ViewSpace 0")); 00642 } 00643 else 00644 { 00645 // send all views + their gui to **** ;) 00646 for (uint i=0; i < m_viewList.count(); i++) 00647 mainWindow()->guiFactory ()->removeClient (m_viewList.at(i)); 00648 00649 m_viewList.clear (); 00650 00651 // cu viewspaces 00652 m_viewSpaceList.clear(); 00653 00654 // call restoreSplitter for Splitter 0 00655 restoreSplitter( config, TQString(group+"-Splitter 0"), this,group ); 00656 } 00657 00658 // finally, make the correct view active. 00659 config->setGroup (group); 00660 /* 00661 KateViewSpace *vs = m_viewSpaceList.at( config->readNumEntry("Active ViewSpace") ); 00662 if ( vs ) 00663 activateSpace( vs->currentView() ); 00664 */ 00665 } 00666 00667 00668 void KateViewSpaceContainer::saveSplitterConfig( KateMDI::Splitter* s, int idx, KConfig* config, const TQString& viewConfGrp ) 00669 { 00670 TQString grp = TQString(viewConfGrp+"-Splitter %1").arg(idx); 00671 config->setGroup(grp); 00672 00673 // Save sizes, orient, children for this splitter 00674 config->writeEntry( "Sizes", s->sizes() ); 00675 config->writeEntry( "Orientation", s->orientation() ); 00676 00677 TQStringList childList; 00678 // a katesplitter has two children, of which one may be a KateSplitter. 00679 const TQObjectList l = s->childrenListObject(); 00680 TQObjectListIt it( l ); 00681 TQObject* obj; 00682 for (; it.current(); ++it) { 00683 obj = it.current(); 00684 TQString n; // name for child list, see below 00685 // For KateViewSpaces, ask them to save the file list. 00686 if ( obj->isA("KateViewSpace") ) { 00687 n = TQString(viewConfGrp+"-ViewSpace %1").arg( m_viewSpaceList.find((KateViewSpace*)obj) ); 00688 ((KateViewSpace*)obj)->saveConfig ( config, m_viewSpaceList.find((KateViewSpace*)obj), viewConfGrp); 00689 // save active viewspace 00690 if ( ((KateViewSpace*)obj)->isActiveSpace() ) { 00691 config->setGroup(viewConfGrp); 00692 config->writeEntry("Active Viewspace", m_viewSpaceList.find((KateViewSpace*)obj) ); 00693 } 00694 } 00695 // For KateSplitters, recurse 00696 else if ( obj->isA("KateMDI::Splitter") ) { 00697 idx++; 00698 saveSplitterConfig( (KateMDI::Splitter*)obj, idx, config,viewConfGrp); 00699 n = TQString(viewConfGrp+"-Splitter %1").arg( idx ); 00700 } 00701 // make sure list goes in right place! 00702 if (!n.isEmpty()) { 00703 if ( childList.count() > 0 && ! s->isLastChild( (TQWidget*)obj ) ) 00704 childList.prepend( n ); 00705 else 00706 childList.append( n ); 00707 } 00708 } 00709 00710 // reset config group. 00711 config->setGroup(grp); 00712 config->writeEntry("Children", childList); 00713 } 00714 00715 void KateViewSpaceContainer::restoreSplitter( KConfig* config, const TQString &group, TQWidget* parent, const TQString& viewConfGrp) 00716 { 00717 config->setGroup( group ); 00718 00719 KateMDI::Splitter* s = new KateMDI::Splitter((Qt::Orientation)config->readNumEntry("Orientation"), parent); 00720 00721 TQStringList children = config->readListEntry( "Children" ); 00722 for (TQStringList::Iterator it=children.begin(); it!=children.end(); ++it) 00723 { 00724 // for a viewspace, create it and open all documents therein. 00725 if ( (*it).startsWith(viewConfGrp+"-ViewSpace") ) 00726 { 00727 KateViewSpace* vs = new KateViewSpace( this, s ); 00728 00729 connect(this, TQT_SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const TQString &)), vs, TQT_SLOT(slotStatusChanged(Kate::View *, int, int, int, bool, int, const TQString &))); 00730 00731 if (m_viewSpaceList.isEmpty()) 00732 vs->setActive (true); 00733 00734 m_viewSpaceList.append( vs ); 00735 00736 vs->show(); 00737 setActiveSpace( vs ); 00738 00739 vs->restoreConfig (this, config, *it); 00740 } 00741 else 00742 { 00743 // for a splitter, recurse. 00744 restoreSplitter( config, TQString(*it), s, viewConfGrp ); 00745 } 00746 } 00747 00748 // set sizes 00749 config->setGroup( group ); 00750 s->setSizes( config->readIntListEntry("Sizes") ); 00751 s->show(); 00752 } 00753 00754 KateMainWindow *KateViewSpaceContainer::mainWindow() { 00755 return m_viewManager->mainWindow(); 00756 } 00757 00758 // kate: space-indent on; indent-width 2; replace-tabs on;