kate Library API Documentation

kateviewmanager.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., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 //BEGIN Includes
00022 #include "kateviewmanager.h"
00023 #include "kateviewmanager.moc"
00024 
00025 #include "katemainwindow.h"
00026 #include "katedocmanager.h"
00027 #include "kateapp.h"
00028 
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 <qfileinfo.h>
00047 #include <kglobalsettings.h>
00048 
00049 #include <kio/netaccess.h>
00050 #include <ktexteditor/encodinginterface.h>
00051 
00052 #include <qlayout.h>
00053 #include <qobjectlist.h>
00054 #include <qstringlist.h>
00055 #include <qvbox.h>
00056 #include <qtimer.h>
00057 
00058 #include "katesplitter.h"
00059 //END Includes
00060 
00061 KateViewManager::KateViewManager (QWidget *parent, KateDocManager *m_docManager, KateMainWindow *mainWindow)
00062  : QWidget  (parent),
00063    m_activeViewRunning (false),m_mainWindow(mainWindow)
00064 {
00065   m_viewManager = new Kate::ViewManager (this);
00066 
00067   m_blockViewCreationAndActivation=false;
00068   
00069   useOpaqueResize = KGlobalSettings::opaqueResize();
00070 
00071   // no memleaks
00072   m_viewList.setAutoDelete(true);
00073   m_viewSpaceList.setAutoDelete(true);
00074 
00075   this->m_docManager = m_docManager;
00076 
00077   // sizemanagement
00078   m_grid = new QGridLayout( this, 1, 1 );
00079 
00080   KateViewSpace* vs = new KateViewSpace( this, this );
00081   connect(this, SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const QString&)), vs, SLOT(slotStatusChanged(Kate::View *, int, int, int, bool, int, const QString&)));
00082   vs->setActive( true );
00083   m_grid->addWidget( vs, 0, 0);
00084   m_viewSpaceList.append(vs);
00085   connect( this, SIGNAL(viewChanged()), this, SLOT(slotViewChanged()) );
00086   connect(m_docManager, SIGNAL(initialDocumentReplaced()), this, SIGNAL(viewChanged()));
00087 }
00088 
00089 KateViewManager::~KateViewManager ()
00090 {
00091   m_viewList.setAutoDelete(false);
00092   m_viewSpaceList.setAutoDelete(false);
00093 }
00094 
00095 bool KateViewManager::createView ( Kate::Document *doc )
00096 {
00097   if (m_blockViewCreationAndActivation) return false;
00098 
00099   // create doc
00100   if (!doc)
00101     doc = m_docManager->createDoc ();
00102 
00103   // create view
00104   Kate::View *view = (Kate::View *) doc->createView (this, 0L);
00105 
00106   m_viewList.append (view);
00107 
00108   // disable settings dialog action
00109   view->actionCollection()->remove (view->actionCollection()->action( "set_confdlg" ));
00110 
00111   // popup menu
00112   view->installPopup ((QPopupMenu*)(m_mainWindow->factory()->container("ktexteditor_popup", m_mainWindow)) );
00113 
00114   connect(view->getDoc(),SIGNAL(nameChanged(Kate::Document *)),this,SLOT(statusMsg()));
00115   connect(view,SIGNAL(cursorPositionChanged()),this,SLOT(statusMsg()));
00116   connect(view,SIGNAL(newStatus()),this,SLOT(statusMsg()));
00117   connect(view->getDoc(), SIGNAL(undoChanged()), this, SLOT(statusMsg()));
00118   connect(view,SIGNAL(dropEventPass(QDropEvent *)), m_mainWindow,SLOT(slotDropEvent(QDropEvent *)));
00119   connect(view,SIGNAL(gotFocus(Kate::View *)),this,SLOT(activateSpace(Kate::View *)));
00120 
00121   activeViewSpace()->addView( view );
00122   activateView( view );
00123   connect( doc, SIGNAL(modifiedOnDisc(Kate::Document *, bool, unsigned char)),
00124       activeViewSpace(), SLOT(modifiedOnDisc(Kate::Document *, bool, unsigned char)) );
00125 
00126   return true;
00127 }
00128 
00129 bool KateViewManager::deleteView (Kate::View *view, bool delViewSpace)
00130 {
00131   if (!view) return true;
00132 
00133   KateViewSpace *viewspace = (KateViewSpace *)view->parentWidget()->parentWidget();
00134 
00135   viewspace->removeView (view);
00136 
00137   m_mainWindow->guiFactory ()->removeClient (view);
00138 
00139   // remove view from list and memory !!
00140   m_viewList.remove (view);
00141 
00142   if (delViewSpace)
00143     if ( viewspace->viewCount() == 0 )
00144       removeViewSpace( viewspace );
00145 
00146   return true;
00147 }
00148 
00149 KateViewSpace* KateViewManager::activeViewSpace ()
00150 {
00151   QPtrListIterator<KateViewSpace> it(m_viewSpaceList);
00152 
00153   for (; it.current(); ++it)
00154   {
00155     if ( it.current()->isActiveSpace() )
00156       return it.current();
00157   }
00158 
00159   if (m_viewSpaceList.count() > 0)
00160   {
00161     m_viewSpaceList.first()->setActive( true );
00162     return m_viewSpaceList.first();
00163   }
00164 
00165   return 0L;
00166 }
00167 
00168 Kate::View* KateViewManager::activeView ()
00169 {
00170   if (m_activeViewRunning)
00171     return 0L;
00172 
00173   m_activeViewRunning = true;
00174 
00175   for (QPtrListIterator<Kate::View> it(m_viewList); it.current(); ++it)
00176   {
00177     if ( it.current()->isActive() )
00178     {
00179       m_activeViewRunning = false;
00180       return it.current();
00181     }
00182   }
00183 
00184   // if we get to here, no view isActive()
00185   // first, try to get one from activeViewSpace()
00186   KateViewSpace* vs;
00187   if ( (vs = activeViewSpace()) )
00188   {
00189     if ( vs->currentView() )
00190     {
00191       activateView (vs->currentView());
00192 
00193       m_activeViewRunning = false;
00194       return vs->currentView();
00195     }
00196   }
00197 
00198   // last attempt: just pick first
00199   if (m_viewList.count() > 0)
00200   {
00201     activateView (m_viewList.first());
00202 
00203     m_activeViewRunning = false;
00204     return m_viewList.first();
00205   }
00206 
00207   m_activeViewRunning = false;
00208 
00209   // no views exists!
00210   return 0L;
00211 }
00212 
00213 void KateViewManager::setActiveSpace ( KateViewSpace* vs )
00214 {
00215    if (activeViewSpace())
00216      activeViewSpace()->setActive( false );
00217 
00218    vs->setActive( true, viewSpaceCount() > 1 );
00219 }
00220 
00221 void KateViewManager::setActiveView ( Kate::View* view )
00222 {
00223   if (activeView())
00224     activeView()->setActive( false );
00225 
00226   view->setActive( true );
00227 }
00228 
00229 void KateViewManager::activateSpace (Kate::View* v)
00230 {
00231   if (!v) return;
00232 
00233   KateViewSpace* vs = (KateViewSpace*)v->parentWidget()->parentWidget();
00234 
00235   if (!vs->isActiveSpace()) {
00236     setActiveSpace (vs);
00237     activateView(v);
00238   }
00239 }
00240 
00241 void KateViewManager::activateView ( Kate::View *view )
00242 {
00243   if (!view) return;
00244 
00245   if (!view->isActive())
00246   {
00247     if ( !activeViewSpace()->showView (view) )
00248     {
00249       // since it wasn't found, give'em a new one
00250       createView ( view->getDoc() );
00251       return;
00252     }
00253 
00254     setActiveView (view);
00255     m_viewList.findRef (view);
00256 
00257    m_mainWindow->toolBar ()->setUpdatesEnabled (false);
00258 
00259     if (m_mainWindow->activeView)
00260       m_mainWindow->guiFactory()->removeClient (m_mainWindow->activeView );
00261 
00262     m_mainWindow->activeView = view;
00263 
00264     if (!m_blockViewCreationAndActivation)
00265       m_mainWindow->guiFactory ()->addClient( view );
00266 
00267     m_mainWindow->toolBar ()->setUpdatesEnabled (true);
00268 
00269     statusMsg();
00270 
00271     emit viewChanged ();
00272     emit m_viewManager->viewChanged ();
00273   }
00274 
00275   m_docManager->setActiveDocument(view->getDoc());
00276 }
00277 
00278 void KateViewManager::activateView( uint documentNumber )
00279 {
00280   if ( activeViewSpace()->showView(documentNumber) ) {
00281     activateView( activeViewSpace()->currentView() );
00282   }
00283   else
00284   {
00285     QPtrListIterator<Kate::View> it(m_viewList);
00286     for ( ;it.current(); ++it)
00287     {
00288       if ( it.current()->getDoc()->documentNumber() == documentNumber  )
00289       {
00290         createView( it.current()->getDoc() );
00291         return;
00292       }
00293     }
00294 
00295     Kate::Document *d = (Kate::Document *)m_docManager->documentWithID(documentNumber);
00296     createView (d);
00297   }
00298 }
00299 
00300 uint KateViewManager::viewCount ()
00301 {
00302   return m_viewList.count();
00303 }
00304 
00305 uint KateViewManager::viewSpaceCount ()
00306 {
00307   return m_viewSpaceList.count();
00308 }
00309 
00310 void KateViewManager::slotViewChanged()
00311 {
00312   if ( activeView() && !activeView()->hasFocus())
00313     activeView()->setFocus();
00314 }
00315 
00316 void KateViewManager::activateNextView()
00317 {
00318   uint i = m_viewSpaceList.find (activeViewSpace())+1;
00319 
00320   if (i >= m_viewSpaceList.count())
00321     i=0;
00322 
00323   setActiveSpace (m_viewSpaceList.at(i));
00324   activateView(m_viewSpaceList.at(i)->currentView());
00325 }
00326 
00327 void KateViewManager::activatePrevView()
00328 {
00329   int i = m_viewSpaceList.find (activeViewSpace())-1;
00330 
00331   if (i < 0)
00332     i=m_viewSpaceList.count()-1;
00333 
00334   setActiveSpace (m_viewSpaceList.at(i));
00335   activateView(m_viewSpaceList.at(i)->currentView());
00336 }
00337 
00338 void KateViewManager::deleteLastView ()
00339 {
00340   deleteView (activeView (), true);
00341 }
00342 
00343 void KateViewManager::closeViews(uint documentNumber)
00344 {
00345     QPtrList<Kate::View> closeList;
00346 
00347     for (uint z=0 ; z < m_viewList.count(); z++)
00348     {
00349       Kate::View* current = m_viewList.at(z);
00350       if ( current->getDoc()->documentNumber() == documentNumber )
00351       {
00352         closeList.append (current);
00353       }
00354     }
00355 
00356     while ( !closeList.isEmpty() )
00357     {
00358       Kate::View *view = closeList.first();
00359       deleteView (view, true);
00360       closeList.removeFirst();
00361     }
00362 
00363   if (m_blockViewCreationAndActivation) return;
00364   QTimer::singleShot(0,this,SIGNAL(viewChanged()));
00365   emit m_viewManager->viewChanged ();
00366 }
00367 
00368 
00369 void KateViewManager::openNewIfEmpty()
00370 {
00371   if (m_blockViewCreationAndActivation) return;
00372 
00373   for (uint i2=0; i2 < ((KateApp *)kapp)->mainWindows (); i2++ )
00374   {
00375     if (((KateApp *)kapp)->kateMainWindow(i2)->kateViewManager()->viewCount() == 0)
00376     {
00377       if ((m_viewList.count() < 1) && (m_docManager->documents() < 1) )
00378         ((KateApp *)kapp)->kateMainWindow(i2)->kateViewManager()->createView ();
00379       else if ((m_viewList.count() < 1) && (m_docManager->documents() > 0) )
00380         ((KateApp *)kapp)->kateMainWindow(i2)->kateViewManager()->createView (m_docManager->document(m_docManager->documents()-1));
00381     }
00382   }
00383 
00384   emit viewChanged ();
00385   emit m_viewManager->viewChanged ();
00386 }
00387 
00388 void KateViewManager::statusMsg ()
00389 {
00390   if (!activeView()) return;
00391 
00392   Kate::View* v = activeView();
00393 
00394   bool readOnly =  !v->getDoc()->isReadWrite();
00395   uint config =  v->getDoc()->configFlags();
00396 
00397   int ovr = 0;
00398   if (readOnly)
00399     ovr = 0;
00400   else
00401   {
00402     if (config & Kate::Document::cfOvr)
00403     {
00404       ovr=1;
00405     }
00406     else
00407     {
00408       ovr=2;
00409     }
00410   }
00411 
00412   int mod = (int)v->getDoc()->isModified();
00413   bool block=v->getDoc()->blockSelectionMode();
00414 
00415   QString c;
00416   if (v->getDoc()->url().isEmpty() || (!showFullPath))
00417   {
00418     c = v->getDoc()->docName();
00419 
00420     //File name shouldn't be too long - Maciek
00421     if (c.length() > 64)
00422       c = c.left(64) + "...";
00423   }
00424   else
00425   {
00426     c = v->getDoc()->url().prettyURL();
00427 
00428     //File name shouldn't be too long - Maciek
00429     if (c.length() > 64)
00430       c = "..." + c.right(64);
00431   }
00432 
00433   emit statusChanged (v, v->cursorLine(), v->cursorColumn(), ovr,block, mod, c);
00434   emit statChanged ();
00435 }
00436 
00437 void KateViewManager::slotDocumentNew ()
00438 {
00439   createView ();
00440 }
00441 
00442 void KateViewManager::slotDocumentOpen ()
00443 {
00444   Kate::View *cv = activeView();
00445 
00446   KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenURLsAndEncoding(
00447      (cv ? KTextEditor::encodingInterface(cv->document())->encoding() : Kate::Document::defaultEncoding()),
00448      (cv ? cv->document()->url().url() : QString::null),
00449      QString::null,this,i18n("Open File"));
00450 
00451   uint lastID = 0;
00452   for (KURL::List::Iterator i=r.URLs.begin(); i != r.URLs.end(); ++i)
00453     lastID = openURL( *i, r.encoding, false );
00454   
00455   if (lastID > 0)
00456     activateView (lastID);
00457 }
00458 
00459 void KateViewManager::slotDocumentSaveAll()
00460 {
00461   for( QPtrListIterator<Kate::View> it( m_viewList ); it.current(); ++it )
00462     it.current()->save();
00463 }
00464 
00465 void KateViewManager::slotDocumentClose ()
00466 {
00467   // no active view, do nothing
00468   if (!activeView()) return;
00469   
00470   // prevent close document if only one view alive and the document of
00471   // it is not modified and empty !!!
00472   if ( (m_viewList.count() == 1)
00473        && !activeView()->getDoc()->isModified()
00474        && activeView()->getDoc()->url().isEmpty()
00475        && (activeView()->getDoc()->length() == 0) )
00476   {
00477     activeView()->getDoc()->closeURL();
00478     return;
00479   }
00480 
00481   // close document
00482   m_docManager->closeDocument (activeView()->getDoc());
00483 
00484   // create new one, if none alive
00485   openNewIfEmpty();
00486 }
00487 
00488 void KateViewManager::slotDocumentCloseAll ()
00489 {
00490   if (m_docManager->documents () == 0) return;
00491 
00492   kdDebug(13001)<<"CLOSE ALL DOCUMENTS *****************"<<endl;
00493 
00494   m_blockViewCreationAndActivation=true;
00495   m_docManager->closeAllDocuments();
00496   m_blockViewCreationAndActivation=false;
00497 
00498   openNewIfEmpty();
00499 }
00500 
00501 uint KateViewManager::openURL (const KURL &url, const QString& encoding, bool activate)
00502 {
00503   uint id = 0;
00504   Kate::Document *doc = m_docManager->openURL (url, encoding, &id);
00505 
00506   if (!doc->url().isEmpty())
00507     m_mainWindow->fileOpenRecent->addURL( doc->url() );
00508 
00509   if (activate)
00510     activateView( id );
00511     
00512   return id;
00513 }
00514 
00515 void KateViewManager::openURL (const KURL &url)
00516 {
00517   openURL (url, QString::null);
00518 }
00519 
00520 void KateViewManager::splitViewSpace( KateViewSpace* vs,
00521                                       bool isHoriz,
00522                                       bool atTop)
00523 {
00524   kdDebug(13001)<<"splitViewSpace()"<<endl;
00525 
00526   if (!activeView()) return;
00527   if (!vs) vs = activeViewSpace();
00528 
00529   bool isFirstTime = vs->parentWidget() == this;
00530 
00531   QValueList<int> psizes;
00532   if ( ! isFirstTime )
00533     if ( QSplitter *ps = static_cast<QSplitter*>(vs->parentWidget()->qt_cast("QSplitter")) )
00534       psizes = ps->sizes();
00535 
00536   Qt::Orientation o = isHoriz ? Qt::Vertical : Qt::Horizontal;
00537   KateSplitter* s = new KateSplitter(o, vs->parentWidget());
00538   s->setOpaqueResize( useOpaqueResize );
00539 
00540   if (! isFirstTime) {
00541     // anders: make sure the split' viewspace is always
00542     // correctly positioned.
00543     // If viewSpace is the first child, the new splitter must be moveToFirst'd
00544     if ( !((KateSplitter*)vs->parentWidget())->isLastChild( vs ) )
00545        ((KateSplitter*)s->parentWidget())->moveToFirst( s );
00546   }
00547   vs->reparent( s, 0, QPoint(), true );
00548   KateViewSpace* vsNew = new KateViewSpace( this, s );
00549 
00550   if (atTop)
00551     s->moveToFirst( vsNew );
00552 
00553   if (isFirstTime)
00554     m_grid->addWidget(s, 0, 0);
00555   else if ( QSplitter *ps = static_cast<QSplitter*>(s->parentWidget()->qt_cast("QSplitter")) )
00556     ps->setSizes( psizes );
00557 
00558   s->show();
00559 
00560   QValueList<int> sizes;
00561   int space = 50;//isHoriz ? s->parentWidget()->height()/2 : s->parentWidget()->width()/2;
00562   sizes << space << space;
00563   s->setSizes( sizes );
00564 
00565   connect(this, SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const QString &)), vsNew, SLOT(slotStatusChanged(Kate::View *, int, int,int, bool, int, const QString &)));
00566   m_viewSpaceList.append( vsNew );
00567   activeViewSpace()->setActive( false );
00568   vsNew->setActive( true, true );
00569   vsNew->show();
00570 
00571   createView (activeView()->getDoc());
00572 
00573   kdDebug(13001)<<"splitViewSpace() - DONE!"<<endl;
00574 }
00575 
00576 void KateViewManager::removeViewSpace (KateViewSpace *viewspace)
00577 {
00578   // abort if viewspace is 0
00579   if (!viewspace) return;
00580 
00581   // abort if this is the last viewspace
00582   if (m_viewSpaceList.count() < 2) return;
00583 
00584   KateSplitter* p = (KateSplitter*)viewspace->parentWidget();
00585 
00586   // find out if it is the first child for repositioning
00587   // see below
00588   bool pIsFirst = false;
00589 
00590   // save some size information
00591   KateSplitter* pp=0L;
00592   QValueList<int> ppsizes;
00593   if (m_viewSpaceList.count() > 2 && p->parentWidget() != this)
00594   {
00595     pp = (KateSplitter*)p->parentWidget();
00596     ppsizes = pp->sizes();
00597     pIsFirst = !pp->isLastChild( p ); // simple logic, right-
00598   }
00599 
00600   // Figure out where to put views that are still needed
00601   KateViewSpace* next;
00602   if (m_viewSpaceList.find(viewspace) == 0)
00603     next = m_viewSpaceList.next();
00604   else
00605     next = m_viewSpaceList.prev();
00606 
00607   // Reparent views in viewspace that are last views, delete the rest.
00608   int vsvc = viewspace->viewCount();
00609   while (vsvc > 0)
00610   {
00611     if (viewspace->currentView())
00612     {
00613       Kate::View* v = viewspace->currentView();
00614 
00615       if (v->isLastView())
00616       {
00617         viewspace->removeView(v);
00618         next->addView( v, false );
00619       }
00620       else
00621       {
00622         deleteView( v, false );
00623       }
00624     }
00625     vsvc = viewspace->viewCount();
00626   }
00627 
00628   m_viewSpaceList.remove( viewspace );
00629 
00630   // reparent the other sibling of the parent.
00631   while (p->children ())
00632   {
00633     QWidget* other = ((QWidget *)(( QPtrList<QObject>*)p->children())->first());
00634 
00635     other->reparent( p->parentWidget(), 0, QPoint(), true );
00636     // We also need to find the right viewspace to become active,
00637     // and if "other" is the last, we move it into the m_grid.
00638     if (pIsFirst)
00639        ((KateSplitter*)p->parentWidget())->moveToFirst( other );
00640     if ( other->isA("KateViewSpace") ) {
00641       setActiveSpace( (KateViewSpace*)other );
00642       if (m_viewSpaceList.count() == 1)
00643         m_grid->addWidget( other, 0, 0);
00644     }
00645     else {
00646       QObjectList* l = other->queryList( "KateViewSpace" );
00647       if ( l->first() != 0 ) { // I REALLY hope so!
00648         setActiveSpace( (KateViewSpace*)l->first() );
00649       }
00650       delete l;
00651     }
00652   }
00653 
00654   delete p;
00655 
00656   if (!ppsizes.isEmpty())
00657     pp->setSizes( ppsizes );
00658 
00659   // find the view that is now active.
00660   Kate::View* v = activeViewSpace()->currentView();
00661   if ( v )
00662     activateView( v );
00663 
00664   emit viewChanged();
00665   emit m_viewManager->viewChanged ();
00666 }
00667 
00668 void KateViewManager::slotCloseCurrentViewSpace()
00669 {
00670   removeViewSpace(activeViewSpace());
00671 }
00672 
00673 void KateViewManager::setShowFullPath( bool enable )
00674 {
00675   showFullPath = enable;
00676   statusMsg ();
00677   m_mainWindow->slotWindowActivated ();
00678 }
00679 
00684 void KateViewManager::saveViewConfiguration(KConfig *config,const QString& group)
00685 {
00686   bool weHaveSplittersAlive (viewSpaceCount() > 1);
00687 
00688   config->setGroup (group); //"View Configuration");
00689   config->writeEntry ("Splitters", weHaveSplittersAlive);
00690 
00691   // no splitters around
00692   if (!weHaveSplittersAlive)
00693   {
00694     config->writeEntry("Active Viewspace", 0);
00695     m_viewSpaceList.first()->saveConfig ( config, 0,group );
00696 
00697     return;
00698   }
00699 
00700   // I need the first splitter, the one which has this as parent.
00701   KateSplitter* s;
00702   QObjectList *l = queryList("KateSplitter", 0, false, false);
00703   QObjectListIt it( *l );
00704 
00705   if ( (s = (KateSplitter*)it.current()) != 0 )
00706     saveSplitterConfig( s, 0, config , group);
00707 
00708   delete l;
00709 }
00710 
00711 void KateViewManager::restoreViewConfiguration (KConfig *config, const QString& group)
00712 {
00713   config->setGroup(group);
00714   //config->setGroup ("View Configuration");
00715 
00716   // no splitters around, ohhh :()
00717   if (!config->readBoolEntry ("Splitters"))
00718   {
00719     // only add the new views needed, let the old stay, won't hurt if one around
00720     m_viewSpaceList.first ()->restoreConfig (this, config, QString(group+"-ViewSpace 0"));
00721   }
00722   else
00723   {
00724     // send all views + their gui to **** ;)
00725     for (uint i=0; i < m_viewList.count(); i++)
00726       m_mainWindow->guiFactory ()->removeClient (m_viewList.at(i));
00727 
00728     m_viewList.clear ();
00729 
00730     // cu viewspaces
00731     m_viewSpaceList.clear();
00732 
00733     // call restoreSplitter for Splitter 0
00734     restoreSplitter( config, QString(group+"-Splitter 0"), this,group );
00735   }
00736 
00737   // finally, make the correct view active.
00738   config->setGroup (group);
00739 /*
00740   KateViewSpace *vs = m_viewSpaceList.at( config->readNumEntry("Active ViewSpace") );
00741   if ( vs )
00742     activateSpace( vs->currentView() );
00743   */
00744 }
00745 
00746 
00747 void KateViewManager::saveSplitterConfig( KateSplitter* s, int idx, KConfig* config, const QString& viewConfGrp )
00748 {
00749   QString grp = QString(viewConfGrp+"-Splitter %1").arg(idx);
00750   config->setGroup(grp);
00751 
00752   // Save sizes, orient, children for this splitter
00753   config->writeEntry( "Sizes", s->sizes() );
00754   config->writeEntry( "Orientation", s->orientation() );
00755 
00756   QStringList childList;
00757   // a katesplitter has two children, of which one may be a KateSplitter.
00758   const QObjectList* l = s->children();
00759   QObjectListIt it( *l );
00760   QObject* obj;
00761   for (; it.current(); ++it) {
00762    obj = it.current();
00763    QString n;  // name for child list, see below
00764    // For KateViewSpaces, ask them to save the file list.
00765    if ( obj->isA("KateViewSpace") ) {
00766      n = QString(viewConfGrp+"-ViewSpace %1").arg( m_viewSpaceList.find((KateViewSpace*)obj) );
00767      ((KateViewSpace*)obj)->saveConfig ( config, m_viewSpaceList.find((KateViewSpace*)obj), viewConfGrp);
00768      // save active viewspace
00769      if ( ((KateViewSpace*)obj)->isActiveSpace() ) {
00770        config->setGroup(viewConfGrp);
00771        config->writeEntry("Active Viewspace", m_viewSpaceList.find((KateViewSpace*)obj) );
00772      }
00773    }
00774    // For KateSplitters, recurse
00775    else if ( obj->isA("KateSplitter") ) {
00776      idx++;
00777      saveSplitterConfig( (KateSplitter*)obj, idx, config,viewConfGrp);
00778      n = QString(viewConfGrp+"-Splitter %1").arg( idx );
00779    }
00780    // make sure list goes in right place!
00781    if (!n.isEmpty()) {
00782      if ( childList.count() > 0 && ! s->isLastChild( (QWidget*)obj ) )
00783        childList.prepend( n );
00784      else
00785        childList.append( n );
00786    }
00787   }
00788 
00789   // reset config group.
00790   config->setGroup(grp);
00791   config->writeEntry("Children", childList);
00792 }
00793 
00794 void KateViewManager::restoreSplitter( KConfig* config, const QString &group, QWidget* parent, const QString& viewConfGrp)
00795 {
00796   config->setGroup( group );
00797 
00798   KateSplitter* s = new KateSplitter((Qt::Orientation)config->readNumEntry("Orientation"), parent);
00799 
00800   if ( group.compare(viewConfGrp+"-Splitter 0") == 0 )
00801    m_grid->addWidget(s, 0, 0);
00802 
00803   QStringList children = config->readListEntry( "Children" );
00804   for (QStringList::Iterator it=children.begin(); it!=children.end(); ++it)
00805   {
00806     // for a viewspace, create it and open all documents therein.
00807     if ( (*it).startsWith(viewConfGrp+"-ViewSpace") )
00808     {
00809      KateViewSpace* vs = new KateViewSpace( this, s );
00810 
00811      connect(this, SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const QString &)), vs, SLOT(slotStatusChanged(Kate::View *, int, int, int, bool, int, const QString &)));
00812 
00813      if (m_viewSpaceList.isEmpty())
00814        vs->setActive (true);
00815 
00816      m_viewSpaceList.append( vs );
00817 
00818      vs->show();
00819      setActiveSpace( vs );
00820 
00821      vs->restoreConfig (this, config, *it);
00822     }
00823     else
00824     {
00825       // for a splitter, recurse.
00826       restoreSplitter( config, QString(*it), s, viewConfGrp );
00827     }
00828   }
00829 
00830   // set sizes
00831   config->setGroup( group );
00832   s->setSizes( config->readIntListEntry("Sizes") );
00833   s->show();
00834 }
00835 
00836 KateMainWindow *KateViewManager::mainWindow() {
00837         return m_mainWindow;
00838 }
00839 
00840 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Sep 25 20:35:02 2004 by doxygen 1.3.8-20040913 written by Dimitri van Heesch, © 1997-2003