kate Library API Documentation

katefileselector.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 "katefileselector.h"
00023 #include "katefileselector.moc"
00024 
00025 #include "katemainwindow.h"
00026 #include "kateviewmanager.h"
00027 #include "kbookmarkhandler.h"
00028 
00029 #include "kactionselector.h"
00030 
00031 #include <qlayout.h>
00032 #include <qtoolbutton.h>
00033 #include <qhbox.h>
00034 #include <qvbox.h>
00035 #include <qlabel.h>
00036 #include <qstrlist.h>
00037 #include <qtooltip.h>
00038 #include <qwhatsthis.h>
00039 #include <qapplication.h>
00040 #include <qlistbox.h>
00041 #include <qscrollbar.h>
00042 #include <qspinbox.h>
00043 #include <qgroupbox.h>
00044 #include <qcheckbox.h>
00045 #include <qregexp.h>
00046 #include <qdockarea.h>
00047 #include <qtimer.h>
00048 #include <qdir.h>
00049 
00050 #include <kapplication.h>
00051 #include <kiconloader.h>
00052 #include <kurlcombobox.h>
00053 #include <kurlcompletion.h>
00054 #include <kprotocolinfo.h>
00055 #include <kdiroperator.h>
00056 #include <kconfig.h>
00057 #include <klocale.h>
00058 #include <kcombobox.h>
00059 #include <kaction.h>
00060 #include <kmessagebox.h>
00061 #include <ktoolbarbutton.h>
00062 #include <qtoolbar.h>
00063 #include <kpopupmenu.h>
00064 #include <kdialog.h>
00065 #include <kdebug.h>
00066 //END Includes
00067 
00068 //BEGIN Toolbar
00069  // from kfiledialog.cpp - avoid qt warning in STDERR (~/.xsessionerrors)
00070 static void silenceQToolBar(QtMsgType, const char *){}
00071 
00072 // helper classes to be able to have a toolbar without move handle
00073 KateFileSelectorToolBar::KateFileSelectorToolBar(QWidget *parent)
00074   : KToolBar( parent, "Kate FileSelector Toolbar", true )
00075 {
00076     setMinimumWidth(10);
00077 }
00078 
00079 KateFileSelectorToolBar::~KateFileSelectorToolBar(){}
00080 
00081 void KateFileSelectorToolBar::setMovingEnabled( bool)
00082 {
00083     KToolBar::setMovingEnabled(false);
00084 }
00085 
00086 
00087 KateFileSelectorToolBarParent::KateFileSelectorToolBarParent(QWidget *parent)
00088     :QFrame(parent),m_tb(0){}
00089 KateFileSelectorToolBarParent::~KateFileSelectorToolBarParent(){}
00090 void KateFileSelectorToolBarParent::setToolBar(KateFileSelectorToolBar *tb)
00091 {
00092     m_tb=tb;
00093 }
00094 
00095 void KateFileSelectorToolBarParent::resizeEvent ( QResizeEvent * )
00096 {
00097     if (m_tb)
00098     {
00099         setMinimumHeight(m_tb->sizeHint().height());
00100         m_tb->resize(width(),height());
00101     }
00102 }
00103 //END
00104 
00105 //BEGIN Constructor/destructor
00106 
00107 KateFileSelector::KateFileSelector( KateMainWindow *mainWindow,
00108                                     KateViewManager *viewManager,
00109                                     QWidget * parent, const char * name )
00110     : QWidget(parent, name),
00111       mainwin(mainWindow),
00112       viewmanager(viewManager)
00113 {
00114   mActionCollection = new KActionCollection( this );
00115 
00116   QVBoxLayout* lo = new QVBoxLayout(this);
00117 
00118   QtMsgHandler oldHandler = qInstallMsgHandler( silenceQToolBar );
00119 
00120   KateFileSelectorToolBarParent *tbp=new KateFileSelectorToolBarParent(this);
00121   toolbar = new KateFileSelectorToolBar(tbp);
00122   tbp->setToolBar(toolbar);
00123   lo->addWidget(tbp);
00124   toolbar->setMovingEnabled(false);
00125   toolbar->setFlat(true);
00126   qInstallMsgHandler( oldHandler );
00127 
00128   cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" );
00129   cmbPath->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
00130   KURLCompletion* cmpl = new KURLCompletion(KURLCompletion::DirCompletion);
00131   cmbPath->setCompletionObject( cmpl );
00132   cmbPath->setAutoDeleteCompletionObject( true );
00133   lo->addWidget(cmbPath);
00134   cmbPath->listBox()->installEventFilter( this );
00135 
00136   dir = new KDirOperator(KURL(), this, "operator");
00137   dir->setView(KFile::/* Simple */Detail);
00138   dir->view()->setSelectionMode(KFile::Multi);
00139 
00140   KActionCollection *coll = dir->actionCollection();
00141   // some shortcuts of diroperator that clashes with Kate
00142   coll->action( "delete" )->setShortcut( KShortcut( ALT + Key_Delete ) );
00143   coll->action( "reload" )->setShortcut( KShortcut( ALT + Key_F5 ) );
00144   coll->action( "back" )->setShortcut( KShortcut( ALT + SHIFT + Key_Left ) );
00145   coll->action( "forward" )->setShortcut( KShortcut( ALT + SHIFT + Key_Right ) );
00146   // some consistency - reset up for dir too
00147   coll->action( "up" )->setShortcut( KShortcut( ALT + SHIFT + Key_Up ) );
00148   coll->action( "home" )->setShortcut( KShortcut( CTRL + ALT + Key_Home ) );
00149 
00150   lo->addWidget(dir);
00151   lo->setStretchFactor(dir, 2);
00152 
00153   // bookmarks action!
00154   KActionMenu *acmBookmarks = new KActionMenu( i18n("Bookmarks"), "bookmark",
00155         mActionCollection, "bookmarks" );
00156   acmBookmarks->setDelayed( false );
00157   bookmarkHandler = new KBookmarkHandler( this, acmBookmarks->popupMenu() );
00158   QHBox* filterBox = new QHBox(this);
00159 
00160   btnFilter = new QToolButton( filterBox );
00161   btnFilter->setIconSet( SmallIconSet("filter" ) );
00162   btnFilter->setToggleButton( true );
00163   filter = new KHistoryCombo( true, filterBox, "filter");
00164   filter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
00165   filterBox->setStretchFactor(filter, 2);
00166   connect( btnFilter, SIGNAL( clicked() ), this, SLOT( btnFilterClick() ) );
00167   lo->addWidget(filterBox);
00168 
00169   connect( filter, SIGNAL( activated(const QString&) ),
00170                    SLOT( slotFilterChange(const QString&) ) );
00171   connect( filter, SIGNAL( returnPressed(const QString&) ),
00172            filter, SLOT( addToHistory(const QString&) ) );
00173 
00174   // kaction for the dir sync method
00175   acSyncDir = new KAction( i18n("Current Document Folder"), "curfiledir", 0,
00176         this, SLOT( setActiveDocumentDir() ), mActionCollection, "sync_dir" );
00177   toolbar->setIconText( KToolBar::IconOnly );
00178   toolbar->setIconSize( 16 );
00179   toolbar->setEnableContextMenu( false );
00180 
00181   connect( cmbPath, SIGNAL( urlActivated( const KURL&  )),
00182              this,  SLOT( cmbPathActivated( const KURL& ) ));
00183   connect( cmbPath, SIGNAL( returnPressed( const QString&  )),
00184              this,  SLOT( cmbPathReturnPressed( const QString& ) ));
00185   connect(dir, SIGNAL(urlEntered(const KURL&)),
00186              this, SLOT(dirUrlEntered(const KURL&)) );
00187 
00188   connect(dir, SIGNAL(finishedLoading()),
00189              this, SLOT(dirFinishedLoading()) );
00190 
00191   // enable dir sync button if current doc has a valid URL
00192   connect ( viewmanager, SIGNAL( viewChanged() ),
00193               this, SLOT( kateViewChanged() ) );
00194 
00195   // Connect the bookmark handler
00196   connect( bookmarkHandler, SIGNAL( openURL( const QString& )),
00197            this, SLOT( setDir( const QString& ) ) );
00198 
00199   waitingUrl = QString::null;
00200 
00201   // whatsthis help
00202   QWhatsThis::add( cmbPath,
00203        i18n("<p>Here you can enter a path for a folder to display."
00204             "<p>To go to a folder previously entered, press the arrow on "
00205             "the right and choose one. <p>The entry has folder "
00206             "completion. Right-click to choose how completion should behave.") );
00207   QWhatsThis::add( filter,
00208         i18n("<p>Here you can enter a name filter to limit which files are displayed."
00209              "<p>To clear the filter, toggle off the filter button to the left."
00210              "<p>To reapply the last filter used, toggle on the filter button." ) );
00211   QWhatsThis::add( btnFilter,
00212         i18n("<p>This button clears the name filter when toggled off, or "
00213              "reapplies the last filter used when toggled on.") );
00214 
00215 }
00216 
00217 KateFileSelector::~KateFileSelector()
00218 {
00219 }
00220 //END Constroctor/Destrctor
00221 
00222 //BEGIN Public Methods
00223 
00224 void KateFileSelector::readConfig(KConfig *config, const QString & name)
00225 {
00226   dir->setViewConfig( config, name + ":view" );
00227   dir->readConfig(config, name + ":dir");
00228   dir->setView( KFile::Default );
00229   dir->view()->setSelectionMode(KFile::Multi);
00230   config->setGroup( name );
00231 
00232   // set up the toolbar
00233   setupToolbar( config );
00234 
00235   cmbPath->setMaxItems( config->readNumEntry( "pathcombo history len", 9 ) );
00236   cmbPath->setURLs( config->readPathListEntry( "dir history" ) );
00237   // if we restore history
00238   if ( config->readBoolEntry( "restore location", true ) || kapp->isRestored() ) {
00239     QString loc( config->readPathEntry( "location" ) );
00240     if ( ! loc.isEmpty() ) {
00241 //       waitingDir = loc;
00242 //       QTimer::singleShot(0, this, SLOT(initialDirChangeHack()));
00243       setDir( loc );
00244     }
00245   }
00246 
00247   // else is automatic, as cmpPath->setURL is called when a location is entered.
00248 
00249   filter->setMaxCount( config->readNumEntry( "filter history len", 9 ) );
00250   filter->setHistoryItems( config->readListEntry("filter history"), true );
00251   lastFilter = config->readEntry( "last filter" );
00252   QString flt("");
00253   if ( config->readBoolEntry( "restore last filter", true ) || kapp->isRestored() )
00254     flt = config->readEntry("current filter");
00255   filter->lineEdit()->setText( flt );
00256   slotFilterChange( flt );
00257 
00258   autoSyncEvents = config->readNumEntry( "AutoSyncEvents", 0 );
00259 }
00260 
00261 void KateFileSelector::initialDirChangeHack()
00262 {
00263   setDir( waitingDir );
00264 }
00265 
00266 void KateFileSelector::setupToolbar( KConfig *config )
00267 {
00268   toolbar->clear();
00269   QStringList tbactions = config->readListEntry( "toolbar actions", ',' );
00270   if ( tbactions.isEmpty() ) {
00271     // reasonable collection for default toolbar
00272     tbactions << "up" << "back" << "forward" << "home" <<
00273                 "short view" << "detailed view" <<
00274                 "bookmarks" << "sync_dir";
00275   }
00276   KAction *ac;
00277   for ( QStringList::Iterator it=tbactions.begin(); it != tbactions.end(); ++it ) {
00278     if ( *it == "bookmarks" || *it == "sync_dir" )
00279       ac = mActionCollection->action( (*it).latin1() );
00280     else
00281       ac = dir->actionCollection()->action( (*it).latin1() );
00282     if ( ac )
00283       ac->plug( toolbar );
00284   }
00285 }
00286 
00287 void KateFileSelector::writeConfig(KConfig *config, const QString & name)
00288 {
00289   dir->writeConfig(config,name + ":dir");
00290 
00291   config->setGroup( name );
00292   config->writeEntry( "pathcombo history len", cmbPath->maxItems() );
00293   QStringList l;
00294   for (int i = 0; i < cmbPath->count(); i++) {
00295     l.append( cmbPath->text( i ) );
00296   }
00297   config->writePathEntry( "dir history", l );
00298   config->writePathEntry( "location", cmbPath->currentText() );
00299 
00300   config->writeEntry( "filter history len", filter->maxCount() );
00301   config->writeEntry( "filter history", filter->historyItems() );
00302   config->writeEntry( "current filter", filter->currentText() );
00303   config->writeEntry( "last filter", lastFilter );
00304   config->writeEntry( "AutoSyncEvents", autoSyncEvents );
00305 }
00306 
00307 void KateFileSelector::setView(KFile::FileView view)
00308 {
00309   dir->setView(view);
00310   dir->view()->setSelectionMode(KFile::Multi);
00311 }
00312 
00313 //END Public Methods
00314 
00315 //BEGIN Public Slots
00316 
00317 void KateFileSelector::slotFilterChange( const QString & nf )
00318 {
00319   QString f = nf.stripWhiteSpace();
00320   bool empty = f.isEmpty() || f == "*";
00321   QToolTip::remove( btnFilter );
00322   if ( empty ) {
00323     dir->clearFilter();
00324     filter->lineEdit()->setText( QString::null );
00325     QToolTip::add( btnFilter,
00326         QString( i18n("Apply last filter (\"%1\")") ).arg( lastFilter ) );
00327   }
00328   else {
00329     dir->setNameFilter( f );
00330     lastFilter = f;
00331     QToolTip::add( btnFilter, i18n("Clear filter") );
00332   }
00333   btnFilter->setOn( !empty );
00334   dir->updateDir();
00335   // this will be never true after the filter has been used;)
00336   btnFilter->setEnabled( !( empty && lastFilter.isEmpty() ) );
00337 
00338 }
00339 
00340 bool kateFileSelectorIsReadable ( const KURL& url )
00341 {
00342   if ( !url.isLocalFile() )
00343     return true; // what else can we say?
00344 
00345   QDir dir (url.path());
00346   return dir.exists ();
00347 }
00348 
00349 void KateFileSelector::setDir( KURL u )
00350 {
00351   KURL newurl;
00352 
00353   if ( !u.isValid() )
00354     newurl.setPath( QDir::homeDirPath() );
00355   else
00356     newurl = u;
00357 
00358   QString pathstr = newurl.path(+1);
00359   newurl.setPath(pathstr);
00360 
00361   if ( !kateFileSelectorIsReadable ( newurl ) )
00362     newurl.cd(QString::fromLatin1(".."));
00363 
00364   if ( !kateFileSelectorIsReadable (newurl) )
00365      newurl.setPath( QDir::homeDirPath() );
00366 
00367   dir->setURL(newurl, true);
00368 }
00369 
00370 //END Public Slots
00371 
00372 //BEGIN Private Slots
00373 
00374 void KateFileSelector::cmbPathActivated( const KURL& u )
00375 {
00376    cmbPathReturnPressed( u.url() );
00377 }
00378 
00379 void KateFileSelector::cmbPathReturnPressed( const QString& u )
00380 {
00381   KURL typedURL( u );
00382   if ( typedURL.hasPass() )
00383     typedURL.setPass( QString::null );
00384 
00385   QStringList urls = cmbPath->urls();
00386   urls.remove( typedURL.url() );
00387   urls.prepend( typedURL.url() );
00388   cmbPath->setURLs( urls, KURLComboBox::RemoveBottom );
00389   dir->setFocus();
00390   dir->setURL( KURL(u), true );
00391 }
00392 
00393 void KateFileSelector::dirUrlEntered( const KURL& u )
00394 {
00395   cmbPath->setURL( u );
00396 }
00397 
00398 void KateFileSelector::dirFinishedLoading()
00399 {
00400 }
00401 
00402 
00403 /*
00404    When the button in the filter box toggles:
00405    If off:
00406    If the name filer is anything but "" or "*", reset it.
00407    If on:
00408    Set last filter.
00409 */
00410 void KateFileSelector::btnFilterClick()
00411 {
00412   if ( !btnFilter->isOn() ) {
00413     slotFilterChange( QString::null );
00414   }
00415   else {
00416     filter->lineEdit()->setText( lastFilter );
00417     slotFilterChange( lastFilter );
00418   }
00419 }
00420 
00421 //FIXME crash on shutdown
00422 void KateFileSelector::setActiveDocumentDir()
00423 {
00424 //   kdDebug(13001)<<"KateFileSelector::setActiveDocumentDir()"<<endl;
00425   KURL u = mainwin->activeDocumentUrl();
00426 //   kdDebug(13001)<<"URL: "<<u.prettyURL()<<endl;
00427   if (!u.isEmpty())
00428     setDir( u.upURL() );
00429 //   kdDebug(13001)<<"... setActiveDocumentDir() DONE!"<<endl;
00430 }
00431 
00432 void KateFileSelector::kateViewChanged()
00433 {
00434   if ( autoSyncEvents & DocumentChanged )
00435   {
00436 //     kdDebug(13001)<<"KateFileSelector::do a sync ()"<<endl;
00437     // if visible, sync
00438     if ( isVisible() ) {
00439       setActiveDocumentDir();
00440       waitingUrl = QString::null;
00441     }
00442     // else set waiting url
00443     else {
00444       KURL u = mainwin->activeDocumentUrl();
00445       if (!u.isEmpty())
00446         waitingUrl = u.directory();
00447     }
00448   }
00449 
00450   // TODO: make sure the button is disabled if the directory is unreadable, eg
00451   //       the document URL has protocol http
00452   acSyncDir->setEnabled( ! mainwin->activeDocumentUrl().directory().isEmpty() );
00453 }
00454 
00455 //END Private Slots
00456 
00457 //BEGIN Protected
00458 
00459 void KateFileSelector::focusInEvent( QFocusEvent * )
00460 {
00461    dir->setFocus();
00462 }
00463 
00464 void KateFileSelector::showEvent( QShowEvent * )
00465 {
00466     // sync if we should
00467     if ( autoSyncEvents & GotVisible ) {
00468 //     kdDebug(13001)<<"syncing fs on show"<<endl;
00469       setActiveDocumentDir();
00470       waitingUrl = QString::null;
00471     }
00472     // else, if we have a waiting URL set it
00473     else if ( ! waitingUrl.isEmpty() ) {
00474       setDir( waitingUrl );
00475       waitingUrl = QString::null;
00476    }
00477 }
00478 
00479 bool KateFileSelector::eventFilter( QObject* o, QEvent *e )
00480 {
00481   /*
00482       This is rather unfortunate, but:
00483       QComboBox does not support setting the size of the listbox to something
00484       reasonable. Even using listbox->setVariableWidth() does not yield a
00485       satisfying result, something is wrong with the handling of the sizehint.
00486       And the popup is rather useless, if the paths are only partly visible.
00487   */
00488   QListBox *lb = cmbPath->listBox();
00489   if ( o == lb && e->type() == QEvent::Show ) {
00490     int add = lb->height() < lb->contentsHeight() ? lb->verticalScrollBar()->width() : 0;
00491     int w = QMIN( mainwin->width(), lb->contentsWidth() + add );
00492     lb->resize( w, lb->height() );
00493     // TODO - move the listbox to a suitable place if nessecary
00494     // TODO - decide if it is worth caching the size while untill the contents
00495     //        are changed.
00496   }
00497   // TODO - same thing for the completion popup?
00498   return QWidget::eventFilter( o, e );
00499 }
00500 
00501 //END Protected
00502 
00503 //BEGIN ACtionLBItem
00504 /*
00505    QListboxItem that can store and return a string,
00506    used for the toolbar action selector.
00507 */
00508 class ActionLBItem : public QListBoxPixmap {
00509   public:
00510   ActionLBItem( QListBox *lb=0,
00511                 const QPixmap &pm = QPixmap(),
00512                 const QString &text=QString::null,
00513                 const QString &str=QString::null ) :
00514     QListBoxPixmap( lb, pm, text ),
00515     _str(str) {};
00516   QString idstring() { return _str; };
00517   private:
00518     QString _str;
00519 };
00520 //END ActionLBItem
00521 
00522 //BEGIN KFSConfigPage
00524 // KFSConfigPage implementation
00526 KFSConfigPage::KFSConfigPage( QWidget *parent, const char *name, KateFileSelector *kfs )
00527   : Kate::ConfigPage( parent, name ),
00528     fileSelector( kfs ),
00529     m_changed( false )
00530 {
00531   QVBoxLayout *lo = new QVBoxLayout( this );
00532   int spacing = KDialog::spacingHint();
00533   lo->setSpacing( spacing );
00534 
00535   // Toolbar - a lot for a little...
00536   QGroupBox *gbToolbar = new QGroupBox( 1, Qt::Vertical, i18n("Toolbar"), this );
00537   acSel = new KActionSelector( gbToolbar );
00538   acSel->setAvailableLabel( i18n("A&vailable actions:") );
00539   acSel->setSelectedLabel( i18n("S&elected actions:") );
00540   lo->addWidget( gbToolbar );
00541   connect( acSel, SIGNAL( added( QListBoxItem * ) ), this, SLOT( slotMyChanged() ) );
00542   connect( acSel, SIGNAL( removed( QListBoxItem * ) ), this, SLOT( slotMyChanged() ) );
00543   connect( acSel, SIGNAL( movedUp( QListBoxItem * ) ), this, SLOT( slotMyChanged() ) );
00544   connect( acSel, SIGNAL( movedDown( QListBoxItem * ) ), this, SLOT( slotMyChanged() ) );
00545 
00546   // Sync
00547   QGroupBox *gbSync = new QGroupBox( 1, Qt::Horizontal, i18n("Auto Synchronization"), this );
00548   cbSyncActive = new QCheckBox( i18n("When a docu&ment becomes active"), gbSync );
00549   cbSyncShow = new QCheckBox( i18n("When the file selector becomes visible"), gbSync );
00550   lo->addWidget( gbSync );
00551   connect( cbSyncActive, SIGNAL( toggled( bool ) ), this, SLOT( slotMyChanged() ) );
00552   connect( cbSyncShow, SIGNAL( toggled( bool ) ), this, SLOT( slotMyChanged() ) );
00553 
00554   // Histories
00555   QHBox *hbPathHist = new QHBox ( this );
00556   QLabel *lbPathHist = new QLabel( i18n("Remember &locations:"), hbPathHist );
00557   sbPathHistLength = new QSpinBox( hbPathHist );
00558   lbPathHist->setBuddy( sbPathHistLength );
00559   lo->addWidget( hbPathHist );
00560   connect( sbPathHistLength, SIGNAL( valueChanged ( int ) ), this, SLOT( slotMyChanged() ) );
00561 
00562   QHBox *hbFilterHist = new QHBox ( this );
00563   QLabel *lbFilterHist = new QLabel( i18n("Remember &filters:"), hbFilterHist );
00564   sbFilterHistLength = new QSpinBox( hbFilterHist );
00565   lbFilterHist->setBuddy( sbFilterHistLength );
00566   lo->addWidget( hbFilterHist );
00567   connect( sbFilterHistLength, SIGNAL( valueChanged ( int ) ), this, SLOT( slotMyChanged() ) );
00568 
00569   // Session
00570   QGroupBox *gbSession = new QGroupBox( 1, Qt::Horizontal, i18n("Session"), this );
00571   cbSesLocation = new QCheckBox( i18n("Restore loca&tion"), gbSession );
00572   cbSesFilter = new QCheckBox( i18n("Restore last f&ilter"), gbSession );
00573   lo->addWidget( gbSession );
00574   connect( cbSesLocation, SIGNAL( toggled( bool ) ), this, SLOT( slotMyChanged() ) );
00575   connect( cbSesFilter, SIGNAL( toggled( bool ) ), this, SLOT( slotMyChanged() ) );
00576 
00577   // make it look nice
00578   lo->addStretch( 1 );
00579 
00580   // be helpfull
00581   /*
00582   QWhatsThis::add( lbAvailableActions, i18n(
00583         "<p>Available actions for the toolbar. To add an action, select it here "
00584         "and press the add (<strong>-&gt;</strong>) button" ) );
00585   QWhatsThis::add( lbUsedActions, i18n(
00586         "<p>Actions used in the toolbar. To remove an action, select it and "
00587         "press the remove (<strong>&lt;-</strong>) button."
00588         "<p>To change the order of the actions, use the Up and Down buttons to "
00589         "move the selected action.") );
00590   */
00591   QString lhwt( i18n(
00592         "<p>Decides how many locations to keep in the history of the location "
00593         "combo box.") );
00594   QWhatsThis::add( lbPathHist, lhwt );
00595   QWhatsThis::add( sbPathHistLength, lhwt );
00596   QString fhwt( i18n(
00597         "<p>Decides how many filters to keep in the history of the filter "
00598         "combo box.") );
00599   QWhatsThis::add( lbFilterHist, fhwt );
00600   QWhatsThis::add( sbFilterHistLength, fhwt );
00601   QString synwt( i18n(
00602         "<p>These options allow you to have the File Selector automatically "
00603         "change location to the folder of the active document on certain "
00604         "events."
00605         "<p>Auto synchronization is <em>lazy</em>, meaning it will not take "
00606         "effect until the file selector is visible."
00607         "<p>None of these are enabled by default, but you can always sync the "
00608         "location by pressing the sync button in the toolbar.") );
00609   QWhatsThis::add( gbSync, synwt );
00610   QWhatsThis::add( cbSesLocation, i18n(
00611         "<p>If this option is enabled (default), the location will be restored "
00612         "when you start Kate.<p><strong>Note</strong> that if the session is "
00613         "handled by the KDE session manager, the location is always restored.") );
00614   QWhatsThis::add( cbSesFilter, i18n(
00615         "<p>If this option is enabled (default), the current filter will be "
00616         "restored when you start Kate.<p><strong>Note</strong> that if the "
00617         "session is handled by the KDE session manager, the filter is always "
00618         "restored."
00619         "<p><strong>Note</strong> that some of the autosync settings may "
00620         "override the restored location if on.") );
00621 
00622   init();
00623 
00624 }
00625 
00626 void KFSConfigPage::apply()
00627 {
00628   if ( ! m_changed )
00629     return;
00630 
00631   m_changed = false;
00632 
00633   KConfig *config = kapp->config();
00634   config->setGroup( "fileselector" );
00635   // toolbar
00636   QStringList l;
00637   QListBoxItem *item = acSel->selectedListBox()->firstItem();
00638   ActionLBItem *aItem;
00639   while ( item )
00640   {
00641     aItem = (ActionLBItem*)item;
00642     if ( aItem )
00643     {
00644       l << aItem->idstring();
00645     }
00646     item = item->next();
00647   }
00648   config->writeEntry( "toolbar actions", l );
00649   fileSelector->setupToolbar( config );
00650   // sync
00651   int s = 0;
00652   if ( cbSyncActive->isChecked() )
00653     s |= KateFileSelector::DocumentChanged;
00654   if ( cbSyncShow->isChecked() )
00655     s |= KateFileSelector::GotVisible;
00656   fileSelector->autoSyncEvents = s;
00657 
00658   // histories
00659   fileSelector->cmbPath->setMaxItems( sbPathHistLength->value() );
00660   fileSelector->filter->setMaxCount( sbFilterHistLength->value() );
00661   // session - theese are read/written directly to the app config,
00662   //           as they are not needed during operation.
00663   config->writeEntry( "restore location", cbSesLocation->isChecked() );
00664   config->writeEntry( "restore last filter", cbSesFilter->isChecked() );
00665 }
00666 
00667 void KFSConfigPage::reload()
00668 {
00669   // hmm, what is this supposed to do, actually??
00670   init();
00671   m_changed = false;
00672 }
00673 void KFSConfigPage::init()
00674 {
00675   KConfig *config = kapp->config();
00676   config->setGroup( "fileselector" );
00677   // toolbar
00678   QStringList l = config->readListEntry( "toolbar actions", ',' );
00679   if ( l.isEmpty() ) // default toolbar
00680     l << "up" << "back" << "forward" << "home" <<
00681                 "short view" << "detailed view" <<
00682                 "bookmarks" << "sync_dir";
00683 
00684   // actions from diroperator + two of our own
00685   QStringList allActions;
00686   allActions << "up" << "back" << "forward" << "home" <<
00687                 "reload" << "mkdir" << "delete" <<
00688                 "short view" << "detailed view" /*<< "view menu" <<
00689                 "show hidden" << "properties"*/ <<
00690                 "bookmarks" << "sync_dir";
00691   QRegExp re("&(?=[^&])");
00692   KAction *ac;
00693   QListBox *lb;
00694   for ( QStringList::Iterator it=allActions.begin(); it != allActions.end(); ++it ) {
00695     lb = l.contains( *it ) ? acSel->selectedListBox() : acSel->availableListBox();
00696     if ( *it == "bookmarks" || *it == "sync_dir" )
00697       ac = fileSelector->actionCollection()->action( (*it).latin1() );
00698     else
00699       ac = fileSelector->dirOperator()->actionCollection()->action( (*it).latin1() );
00700     if ( ac )
00701       new ActionLBItem( lb, SmallIcon( ac->icon() ), ac->text().replace( re, "" ), *it );
00702   }
00703 
00704   // sync
00705   int s = fileSelector->autoSyncEvents;
00706   cbSyncActive->setChecked( s & KateFileSelector::DocumentChanged );
00707   cbSyncShow->setChecked( s & KateFileSelector::GotVisible );
00708   // histories
00709   sbPathHistLength->setValue( fileSelector->cmbPath->maxItems() );
00710   sbFilterHistLength->setValue( fileSelector->filter->maxCount() );
00711   // session
00712   cbSesLocation->setChecked( config->readBoolEntry( "restore location", true ) );
00713   cbSesFilter->setChecked( config->readBoolEntry( "restore last filter", true ) );
00714 }
00715 
00716 void KFSConfigPage::slotMyChanged()
00717 {
00718   m_changed = true;
00719   slotChanged();
00720 }
00721 //END KFSConfigPage
00722 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 6 02:40:57 2005 by doxygen 1.4.0 written by Dimitri van Heesch, © 1997-2003