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     if ( it.current()->getDoc()->isModified() )
00463        it.current()->save();
00464 }
00465 
00466 void KateViewManager::slotDocumentClose ()
00467 {
00468   // no active view, do nothing
00469   if (!activeView()) return;
00470 
00471   // prevent close document if only one view alive and the document of
00472   // it is not modified and empty !!!
00473   if ( (m_viewList.count() == 1)
00474        && !activeView()->getDoc()->isModified()
00475        && activeView()->getDoc()->url().isEmpty()
00476        && (activeView()->getDoc()->length() == 0) )
00477   {
00478     activeView()->getDoc()->closeURL();
00479     return;
00480   }
00481 
00482   // close document
00483   m_docManager->closeDocument (activeView()->getDoc());
00484 
00485   // create new one, if none alive
00486   openNewIfEmpty();
00487 }
00488 
00489 void KateViewManager::slotDocumentCloseAll ()
00490 {
00491   if (m_docManager->documents () == 0) return;
00492 
00493   kdDebug(13001)<<"CLOSE ALL DOCUMENTS *****************"<<endl;
00494 
00495   m_blockViewCreationAndActivation=true;
00496   m_docManager->closeAllDocuments();
00497   m_blockViewCreationAndActivation=false;
00498 
00499   openNewIfEmpty();
00500 }
00501 
00502 uint KateViewManager::openURL (const KURL &url, const QString& encoding, bool activate)
00503 {
00504   uint id = 0;
00505   Kate::Document *doc = m_docManager->openURL (url, encoding, &id);
00506 
00507   if (!doc->url().isEmpty())
00508     m_mainWindow->fileOpenRecent->addURL( doc->url() );
00509 
00510   if (activate)
00511     activateView( id );
00512 
00513   return id;
00514 }
00515 
00516 void KateViewManager::openURL (const KURL &url)
00517 {
00518   openURL (url, QString::null);
00519 }
00520 
00521 void KateViewManager::splitViewSpace( KateViewSpace* vs,
00522                                       bool isHoriz,
00523                                       bool atTop)
00524 {
00525   kdDebug(13001)<<"splitViewSpace()"<<endl;
00526 
00527   if (!activeView()) return;
00528   if (!vs) vs = activeViewSpace();
00529 
00530   bool isFirstTime = vs->parentWidget() == this;
00531 
00532   QValueList<int> psizes;
00533   if ( ! isFirstTime )
00534     if ( QSplitter *ps = static_cast<QSplitter*>(vs->parentWidget()->qt_cast("QSplitter")) )
00535       psizes = ps->sizes();
00536 
00537   Qt::Orientation o = isHoriz ? Qt::Vertical : Qt::Horizontal;
00538   KateSplitter* s = new KateSplitter(o, vs->parentWidget());
00539   s->setOpaqueResize( useOpaqueResize );
00540 
00541   if (! isFirstTime) {
00542     // anders: make sure the split' viewspace is always
00543     // correctly positioned.
00544     // If viewSpace is the first child, the new splitter must be moveToFirst'd
00545     if ( !((KateSplitter*)vs->parentWidget())->isLastChild( vs ) )
00546        ((KateSplitter*)s->parentWidget())->moveToFirst( s );
00547   }
00548   vs->reparent( s, 0, QPoint(), true );
00549   KateViewSpace* vsNew = new KateViewSpace( this, s );
00550 
00551   if (atTop)
00552     s->moveToFirst( vsNew );
00553 
00554   if (isFirstTime)
00555     m_grid->addWidget(s, 0, 0);
00556   else if ( QSplitter *ps = static_cast<QSplitter*>(s->parentWidget()->qt_cast("QSplitter")) )
00557     ps->setSizes( psizes );
00558 
00559   s->show();
00560 
00561   QValueList<int> sizes;
00562   int space = 50;//isHoriz ? s->parentWidget()->height()/2 : s->parentWidget()->width()/2;
00563   sizes << space << space;
00564   s->setSizes( sizes );
00565 
00566   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 &)));
00567   m_viewSpaceList.append( vsNew );
00568   activeViewSpace()->setActive( false );
00569   vsNew->setActive( true, true );
00570   vsNew->show();
00571 
00572   createView (activeView()->getDoc());
00573 
00574   kdDebug(13001)<<"splitViewSpace() - DONE!"<<endl;
00575 }
00576 
00577 void KateViewManager::removeViewSpace (KateViewSpace *viewspace)
00578 {
00579   // abort if viewspace is 0
00580   if (!viewspace) return;
00581 
00582   // abort if this is the last viewspace
00583   if (m_viewSpaceList.count() < 2) return;
00584 
00585   KateSplitter* p = (KateSplitter*)viewspace->parentWidget();
00586 
00587   // find out if it is the first child for repositioning
00588   // see below
00589   bool pIsFirst = false;
00590 
00591   // save some size information
00592   KateSplitter* pp=0L;
00593   QValueList<int> ppsizes;
00594   if (m_viewSpaceList.count() > 2 && p->parentWidget() != this)
00595   {
00596     pp = (KateSplitter*)p->parentWidget();
00597     ppsizes = pp->sizes();
00598     pIsFirst = !pp->isLastChild( p ); // simple logic, right-
00599   }
00600 
00601   // Figure out where to put views that are still needed
00602   KateViewSpace* next;
00603   if (m_viewSpaceList.find(viewspace) == 0)
00604     next = m_viewSpaceList.next();
00605   else
00606     next = m_viewSpaceList.prev();
00607 
00608   // Reparent views in viewspace that are last views, delete the rest.
00609   int vsvc = viewspace->viewCount();
00610   while (vsvc > 0)
00611   {
00612     if (viewspace->currentView())
00613     {
00614       Kate::View* v = viewspace->currentView();
00615 
00616       if (v->isLastView())
00617       {
00618         viewspace->removeView(v);
00619         next->addView( v, false );
00620       }
00621       else
00622       {
00623         deleteView( v, false );
00624       }
00625     }
00626     vsvc = viewspace->viewCount();
00627   }
00628 
00629   m_viewSpaceList.remove( viewspace );
00630 
00631   // reparent the other sibling of the parent.
00632   while (p->children ())
00633   {
00634     QWidget* other = ((QWidget *)(( QPtrList<QObject>*)p->children())->first());
00635 
00636     other->reparent( p->parentWidget(), 0, QPoint(), true );
00637     // We also need to find the right viewspace to become active,
00638     // and if "other" is the last, we move it into the m_grid.
00639     if (pIsFirst)
00640        ((KateSplitter*)p->parentWidget())->moveToFirst( other );
00641     if ( other->isA("KateViewSpace") ) {
00642       setActiveSpace( (KateViewSpace*)other );
00643       if (m_viewSpaceList.count() == 1)
00644         m_grid->addWidget( other, 0, 0);
00645     }
00646     else {
00647       QObjectList* l = other->queryList( "KateViewSpace" );
00648       if ( l->first() != 0 ) { // I REALLY hope so!
00649         setActiveSpace( (KateViewSpace*)l->first() );
00650       }
00651       delete l;
00652     }
00653   }
00654 
00655   delete p;
00656 
00657   if (!ppsizes.isEmpty())
00658     pp->setSizes( ppsizes );
00659 
00660   // find the view that is now active.
00661   Kate::View* v = activeViewSpace()->currentView();
00662   if ( v )
00663     activateView( v );
00664 
00665   emit viewChanged();
00666   emit m_viewManager->viewChanged ();
00667 }
00668 
00669 void KateViewManager::slotCloseCurrentViewSpace()
00670 {
00671   removeViewSpace(activeViewSpace());
00672 }
00673 
00674 void KateViewManager::setShowFullPath( bool enable )
00675 {
00676   showFullPath = enable;
00677   statusMsg ();
00678   m_mainWindow->slotWindowActivated ();
00679 }
00680 
00685 void KateViewManager::saveViewConfiguration(KConfig *config,const QString& group)
00686 {
00687   bool weHaveSplittersAlive (viewSpaceCount() > 1);
00688 
00689   config->setGroup (group); //"View Configuration");
00690   config->writeEntry ("Splitters", weHaveSplittersAlive);
00691 
00692   // no splitters around
00693   if (!weHaveSplittersAlive)
00694   {
00695     config->writeEntry("Active Viewspace", 0);
00696     m_viewSpaceList.first()->saveConfig ( config, 0,group );
00697 
00698     return;
00699   }
00700 
00701   // I need the first splitter, the one which has this as parent.
00702   KateSplitter* s;
00703   QObjectList *l = queryList("KateSplitter", 0, false, false);
00704   QObjectListIt it( *l );
00705 
00706   if ( (s = (KateSplitter*)it.current()) != 0 )
00707     saveSplitterConfig( s, 0, config , group);
00708 
00709   delete l;
00710 }
00711 
00712 void KateViewManager::restoreViewConfiguration (KConfig *config, const QString& group)
00713 {
00714   config->setGroup(group);
00715   //config->setGroup ("View Configuration");
00716 
00717   // no splitters around, ohhh :()
00718   if (!config->readBoolEntry ("Splitters"))
00719   {
00720     // only add the new views needed, let the old stay, won't hurt if one around
00721     m_viewSpaceList.first ()->restoreConfig (this, config, QString(group+"-ViewSpace 0"));
00722   }
00723   else
00724   {
00725     // send all views + their gui to **** ;)
00726     for (uint i=0; i < m_viewList.count(); i++)
00727       m_mainWindow->guiFactory ()->removeClient (m_viewList.at(i));
00728 
00729     m_viewList.clear ();
00730 
00731     // cu viewspaces
00732     m_viewSpaceList.clear();
00733 
00734     // call restoreSplitter for Splitter 0
00735     restoreSplitter( config, QString(group+"-Splitter 0"), this,group );
00736   }
00737 
00738   // finally, make the correct view active.
00739   config->setGroup (group);
00740 /*
00741   KateViewSpace *vs = m_viewSpaceList.at( config->readNumEntry("Active ViewSpace") );
00742   if ( vs )
00743     activateSpace( vs->currentView() );
00744   */
00745 }
00746 
00747 
00748 void KateViewManager::saveSplitterConfig( KateSplitter* s, int idx, KConfig* config, const QString& viewConfGrp )
00749 {
00750   QString grp = QString(viewConfGrp+"-Splitter %1").arg(idx);
00751   config->setGroup(grp);
00752 
00753   // Save sizes, orient, children for this splitter
00754   config->writeEntry( "Sizes", s->sizes() );
00755   config->writeEntry( "Orientation", s->orientation() );
00756 
00757   QStringList childList;
00758   // a katesplitter has two children, of which one may be a KateSplitter.
00759   const QObjectList* l = s->children();
00760   QObjectListIt it( *l );
00761   QObject* obj;
00762   for (; it.current(); ++it) {
00763    obj = it.current();
00764    QString n;  // name for child list, see below
00765    // For KateViewSpaces, ask them to save the file list.
00766    if ( obj->isA("KateViewSpace") ) {
00767      n = QString(viewConfGrp+"-ViewSpace %1").arg( m_viewSpaceList.find((KateViewSpace*)obj) );
00768      ((KateViewSpace*)obj)->saveConfig ( config, m_viewSpaceList.find((KateViewSpace*)obj), viewConfGrp);
00769      // save active viewspace
00770      if ( ((KateViewSpace*)obj)->isActiveSpace() ) {
00771        config->setGroup(viewConfGrp);
00772        config->writeEntry("Active Viewspace", m_viewSpaceList.find((KateViewSpace*)obj) );
00773      }
00774    }
00775    // For KateSplitters, recurse
00776    else if ( obj->isA("KateSplitter") ) {
00777      idx++;
00778      saveSplitterConfig( (KateSplitter*)obj, idx, config,viewConfGrp);
00779      n = QString(viewConfGrp+"-Splitter %1").arg( idx );
00780    }
00781    // make sure list goes in right place!
00782    if (!n.isEmpty()) {
00783      if ( childList.count() > 0 && ! s->isLastChild( (QWidget*)obj ) )
00784        childList.prepend( n );
00785      else
00786        childList.append( n );
00787    }
00788   }
00789 
00790   // reset config group.
00791   config->setGroup(grp);
00792   config->writeEntry("Children", childList);
00793 }
00794 
00795 void KateViewManager::restoreSplitter( KConfig* config, const QString &group, QWidget* parent, const QString& viewConfGrp)
00796 {
00797   config->setGroup( group );
00798 
00799   KateSplitter* s = new KateSplitter((Qt::Orientation)config->readNumEntry("Orientation"), parent);
00800 
00801   if ( group.compare(viewConfGrp+"-Splitter 0") == 0 )
00802    m_grid->addWidget(s, 0, 0);
00803 
00804   QStringList children = config->readListEntry( "Children" );
00805   for (QStringList::Iterator it=children.begin(); it!=children.end(); ++it)
00806   {
00807     // for a viewspace, create it and open all documents therein.
00808     if ( (*it).startsWith(viewConfGrp+"-ViewSpace") )
00809     {
00810      KateViewSpace* vs = new KateViewSpace( this, s );
00811 
00812      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 &)));
00813 
00814      if (m_viewSpaceList.isEmpty())
00815        vs->setActive (true);
00816 
00817      m_viewSpaceList.append( vs );
00818 
00819      vs->show();
00820      setActiveSpace( vs );
00821 
00822      vs->restoreConfig (this, config, *it);
00823     }
00824     else
00825     {
00826       // for a splitter, recurse.
00827       restoreSplitter( config, QString(*it), s, viewConfGrp );
00828     }
00829   }
00830 
00831   // set sizes
00832   config->setGroup( group );
00833   s->setSizes( config->readIntListEntry("Sizes") );
00834   s->show();
00835 }
00836 
00837 KateMainWindow *KateViewManager::mainWindow() {
00838         return m_mainWindow;
00839 }
00840 
00841 // 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.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 11:21:45 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003