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