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