KDevelop API Documentation

parts/fileselector/fileselector_widget.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2003 Alexander Dymo <cloudtemple@mksat.net> 00003 Copyright (C) 2003 Roberto Raggi <roberto@kdevelop.org> 00004 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00005 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00006 Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License version 2 as published by the Free Software Foundation. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 Boston, MA 02111-1307, USA. 00021 */ 00022 00023 //BEGIN Includes 00024 #include "fileselector_part.h" 00025 #include "fileselector_widget.h" 00026 #include "kactionselector.h" 00027 #include "kbookmarkhandler.h" 00028 00029 #include <kdevcore.h> 00030 #include <kdevmainwindow.h> 00031 #include <kdevpartcontroller.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 00051 #include <ktexteditor/document.h> 00052 00053 #include <kmainwindow.h> 00054 #include <kapplication.h> 00055 #include <kiconloader.h> 00056 #include <kurlcombobox.h> 00057 #include <kurlcompletion.h> 00058 #include <kprotocolinfo.h> 00059 #include <kconfig.h> 00060 #include <klocale.h> 00061 #include <kcombobox.h> 00062 #include <kaction.h> 00063 #include <kmessagebox.h> 00064 #include <ktoolbarbutton.h> 00065 #include <qtoolbar.h> 00066 #include <kpopupmenu.h> 00067 #include <kdialog.h> 00068 #include <kio/netaccess.h> 00069 00070 #include <kdebug.h> 00071 //END Includes 00072 00073 // from kfiledialog.cpp - avoid qt warning in STDERR (~/.xsessionerrors) 00074 static void silenceQToolBar(QtMsgType, const char *) 00075 {} 00076 00077 00078 KDevFileSelectorToolBar::KDevFileSelectorToolBar(QWidget *parent) 00079 : KToolBar( parent, "KDev FileSelector Toolbar", true ) 00080 { 00081 setMinimumWidth(10); 00082 } 00083 00084 KDevFileSelectorToolBar::~KDevFileSelectorToolBar() 00085 {} 00086 00087 void KDevFileSelectorToolBar::setMovingEnabled( bool) 00088 { 00089 KToolBar::setMovingEnabled(false); 00090 } 00091 00092 00093 KDevFileSelectorToolBarParent::KDevFileSelectorToolBarParent(QWidget *parent) 00094 :QFrame(parent),m_tb(0) 00095 {} 00096 KDevFileSelectorToolBarParent::~KDevFileSelectorToolBarParent() 00097 {} 00098 void KDevFileSelectorToolBarParent::setToolBar(KDevFileSelectorToolBar *tb) 00099 { 00100 m_tb=tb; 00101 } 00102 00103 void KDevFileSelectorToolBarParent::resizeEvent ( QResizeEvent * ) 00104 { 00105 if (m_tb) 00106 { 00107 setMinimumHeight(m_tb->sizeHint().height()); 00108 m_tb->resize(width(),height()); 00109 } 00110 } 00111 00112 00113 //BEGIN Constructor/destructor 00114 00115 KDevFileSelector::KDevFileSelector( FileSelectorPart *part, KDevMainWindow *mainWindow, 00116 KDevPartController *partController, 00117 QWidget * parent, const char * name ) 00118 : QWidget(parent, name), 00119 m_part(part), 00120 mainwin(mainWindow), 00121 partController(partController) 00122 { 00123 mActionCollection = new KActionCollection( this ); 00124 00125 QVBoxLayout* lo = new QVBoxLayout(this); 00126 00127 QtMsgHandler oldHandler = qInstallMsgHandler( silenceQToolBar ); 00128 00129 KDevFileSelectorToolBarParent *tbp=new KDevFileSelectorToolBarParent(this); 00130 toolbar = new KDevFileSelectorToolBar(tbp); 00131 tbp->setToolBar(toolbar); 00132 lo->addWidget(tbp); 00133 toolbar->setMovingEnabled(false); 00134 toolbar->setFlat(true); 00135 qInstallMsgHandler( oldHandler ); 00136 00137 cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" ); 00138 cmbPath->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed )); 00139 KURLCompletion* cmpl = new KURLCompletion(KURLCompletion::DirCompletion); 00140 cmbPath->setCompletionObject( cmpl ); 00141 lo->addWidget(cmbPath); 00142 cmbPath->listBox()->installEventFilter( this ); 00143 00144 dir = new KDevDirOperator(m_part, QString::null, this, "operator"); 00145 dir->setView(KFile::/*Simple*/Detail); 00146 00147 KActionCollection *coll = dir->actionCollection(); 00148 // some shortcuts of diroperator that clashes with KDev 00149 coll->action( "delete" )->setShortcut( KShortcut( ALT + Key_Delete ) ); 00150 coll->action( "reload" )->setShortcut( KShortcut( ALT + Key_F5 ) ); 00151 coll->action( "back" )->setShortcut( KShortcut( ALT + SHIFT + Key_Left ) ); 00152 coll->action( "forward" )->setShortcut( KShortcut( ALT + SHIFT + Key_Right ) ); 00153 // some consistency - reset up for dir too 00154 coll->action( "up" )->setShortcut( KShortcut( ALT + SHIFT + Key_Up ) ); 00155 coll->action( "home" )->setShortcut( KShortcut( CTRL + ALT + Key_Home ) ); 00156 00157 lo->addWidget(dir); 00158 lo->setStretchFactor(dir, 2); 00159 00160 // bookmarks action! 00161 KActionMenu *acmBookmarks = new KActionMenu( i18n("Bookmarks"), "bookmark", 00162 mActionCollection, "bookmarks" ); 00163 acmBookmarks->setDelayed( false ); 00164 00165 bookmarkHandler = new KBookmarkHandler( this, acmBookmarks->popupMenu() ); 00166 00167 QHBox* filterBox = new QHBox(this); 00168 00169 btnFilter = new QToolButton( filterBox ); 00170 btnFilter->setIconSet( SmallIconSet("filter" ) ); 00171 btnFilter->setToggleButton( true ); 00172 filter = new KHistoryCombo( true, filterBox, "filter"); 00173 filter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed )); 00174 filterBox->setStretchFactor(filter, 2); 00175 connect( btnFilter, SIGNAL( clicked() ), this, SLOT( btnFilterClick() ) ); 00176 lo->addWidget(filterBox); 00177 00178 connect( filter, SIGNAL( activated(const QString&) ), 00179 SLOT( slotFilterChange(const QString&) ) ); 00180 connect( filter, SIGNAL( returnPressed(const QString&) ), 00181 filter, SLOT( addToHistory(const QString&) ) ); 00182 00183 // kaction for the dir sync method 00184 acSyncDir = new KAction( i18n("Current Document Directory"), "dirsynch", 0, 00185 this, SLOT( setActiveDocumentDir() ), mActionCollection, "sync_dir" ); 00186 toolbar->setIconText( KToolBar::IconOnly ); 00187 toolbar->setIconSize( 16 ); 00188 toolbar->setEnableContextMenu( false ); 00189 00190 connect( cmbPath, SIGNAL( urlActivated( const KURL& )), 00191 this, SLOT( cmbPathActivated( const KURL& ) )); 00192 connect( cmbPath, SIGNAL( returnPressed( const QString& )), 00193 this, SLOT( cmbPathReturnPressed( const QString& ) )); 00194 connect(dir, SIGNAL(urlEntered(const KURL&)), 00195 this, SLOT(dirUrlEntered(const KURL&)) ); 00196 00197 connect(dir, SIGNAL(finishedLoading()), 00198 this, SLOT(dirFinishedLoading()) ); 00199 00200 // enable dir sync button if current doc has a valid URL 00201 connect ( partController, SIGNAL(activePartChanged(KParts::Part*) ), 00202 this, SLOT(viewChanged() ) ); 00203 00204 // Connect the bookmark handler 00205 connect( bookmarkHandler, SIGNAL( openURL( const QString& )), 00206 this, SLOT( setDir( const QString& ) ) ); 00207 00208 waitingUrl = QString::null; 00209 00210 // whatsthis help 00211 QWhatsThis::add 00212 ( cmbPath, 00213 i18n("<p>Here you can enter a path for a directory to display." 00214 "<p>To go to a directory previously entered, press the arrow on " 00215 "the right and choose one. <p>The entry has directory " 00216 "completion. Right-click to choose how completion should behave.") ); 00217 QWhatsThis::add 00218 ( filter, 00219 i18n("<p>Here you can enter a name filter to limit which files are displayed." 00220 "<p>To clear the filter, toggle off the filter button to the left." 00221 "<p>To reapply the last filter used, toggle on the filter button." ) ); 00222 QWhatsThis::add 00223 ( btnFilter, 00224 i18n("<p>This button clears the name filter when toggled off, or " 00225 "reapplies the last filter used when toggled on.") ); 00226 } 00227 00228 KDevFileSelector::~KDevFileSelector() 00229 { 00230 writeConfig( m_part->instance()->config(), "fileselector" ); 00231 } 00232 //END Constroctor/Destrctor 00233 00234 //BEGIN Public Methods 00235 00236 void KDevFileSelector::readConfig(KConfig *config, const QString & name) 00237 { 00238 dir->readConfig(config, name + ":dir"); 00239 dir->setView( KFile::Default ); 00240 00241 config->setGroup( name ); 00242 00243 // set up the toolbar 00244 setupToolbar( config ); 00245 00246 cmbPath->setMaxItems( config->readNumEntry( "pathcombo history len", 9 ) ); 00247 cmbPath->setURLs( config->readListEntry("dir history") ); 00248 // if we restore history 00249 if ( config->readBoolEntry( "restore location", true ) || kapp->isRestored() ) 00250 { 00251 QString loc( config->readPathEntry( "location" ) ); 00252 if ( ! loc.isEmpty() ) 00253 { 00254 waitingDir = loc; 00255 QTimer::singleShot(0, this, SLOT(initialDirChangeHack())); 00256 } 00257 } 00258 00259 // else is automatic, as cmpPath->setURL is called when a location is entered. 00260 00261 filter->setMaxCount( config->readNumEntry( "filter history len", 9 ) ); 00262 filter->setHistoryItems( config->readListEntry("filter history"), true ); 00263 lastFilter = config->readEntry( "last filter" ); 00264 QString flt(""); 00265 if ( config->readBoolEntry( "restore last filter", true ) || kapp->isRestored() ) 00266 flt = config->readEntry("current filter"); 00267 filter->lineEdit()->setText( flt ); 00268 slotFilterChange( flt ); 00269 00270 autoSyncEvents = config->readNumEntry( "AutoSyncEvents", 0 ); 00271 // connect events as needed 00273 if ( autoSyncEvents & DocumentChanged ) 00274 connect( partController, SIGNAL( viewChanged() ), this, SLOT( autoSync() ) ); 00275 00276 if ( autoSyncEvents & DocumentOpened ) 00277 connect( partController, SIGNAL( partAdded(KParts::Part*) ), 00278 this, SLOT( autoSync(KParts::Part*) ) ); 00279 00280 } 00281 00282 void KDevFileSelector::initialDirChangeHack() 00283 { 00284 setDir( waitingDir ); 00285 } 00286 00287 void KDevFileSelector::setupToolbar( KConfig *config ) 00288 { 00289 toolbar->clear(); 00290 QStringList tbactions = config->readListEntry( "toolbar actions", ',' ); 00291 if ( tbactions.isEmpty() ) 00292 { 00293 // resonable collection for default toolbar 00294 tbactions << "up" << "back" << "forward" << "home" << 00295 "short view" << "detailed view" << 00296 "bookmarks" << "sync_dir"; 00297 } 00298 KAction *ac; 00299 for ( QStringList::Iterator it=tbactions.begin(); it != tbactions.end(); ++it ) 00300 { 00301 if ( *it == "bookmarks" || *it == "sync_dir" ) 00302 ac = mActionCollection->action( (*it).latin1() ); 00303 else 00304 ac = dir->actionCollection()->action( (*it).latin1() ); 00305 if ( ac ) 00306 ac->plug( toolbar ); 00307 } 00308 } 00309 00310 void KDevFileSelector::writeConfig(KConfig *config, const QString & name) 00311 { 00312 dir->writeConfig(config,name + ":dir"); 00313 00314 config->setGroup( name ); 00315 config->writeEntry( "pathcombo history len", cmbPath->maxItems() ); 00316 QStringList l; 00317 for (int i = 0; i < cmbPath->count(); i++) 00318 { 00319 l.append( cmbPath->text( i ) ); 00320 } 00321 config->writeEntry("dir history", l ); 00322 #if defined(KDE_IS_VERSION) 00323 # if KDE_IS_VERSION(3,1,3) 00324 # ifndef _KDE_3_1_3_ 00325 # define _KDE_3_1_3_ 00326 # endif 00327 # endif 00328 #endif 00329 #if defined(_KDE_3_1_3_) 00330 config->writePathEntry( "location", cmbPath->currentText() ); 00331 #else 00332 config->writeEntry( "location", cmbPath->currentText() ); 00333 #endif 00334 00335 config->writeEntry( "filter history len", filter->maxCount() ); 00336 config->writeEntry( "filter history", filter->historyItems() ); 00337 config->writeEntry( "current filter", filter->currentText() ); 00338 config->writeEntry( "last filter", lastFilter ); 00339 config->writeEntry( "AutoSyncEvents", autoSyncEvents ); 00340 } 00341 00342 void KDevFileSelector::setView(KFile::FileView view) 00343 { 00344 dir->setView(view); 00345 } 00346 00347 //END Public Methods 00348 00349 //BEGIN Public Slots 00350 00351 void KDevFileSelector::slotFilterChange( const QString & nf ) 00352 { 00353 QString f = nf.stripWhiteSpace(); 00354 QToolTip::remove(btnFilter); 00355 bool empty = f.isEmpty() || f == "*"; 00356 if ( empty ) 00357 { 00358 dir->clearFilter(); 00359 filter->lineEdit()->setText( QString::null ); 00360 QToolTip::add 00361 ( btnFilter, 00362 QString( i18n("Apply last filter (\"%1\")") ).arg( lastFilter ) ); 00363 } 00364 else 00365 { 00366 dir->setNameFilter( f ); 00367 lastFilter = f; 00368 QToolTip::add 00369 ( btnFilter, i18n("Clear filter") ); 00370 } 00371 btnFilter->setOn( !empty ); 00372 dir->updateDir(); 00373 // this will be never true after the filter has been used;) 00374 btnFilter->setEnabled( !( empty && lastFilter.isEmpty() ) ); 00375 00376 } 00377 void KDevFileSelector::setDir( KURL u ) 00378 { 00379 dir->setURL(u, true); 00380 } 00381 00382 //END Public Slots 00383 00384 //BEGIN Private Slots 00385 00386 void KDevFileSelector::cmbPathActivated( const KURL& u ) 00387 { 00388 cmbPathReturnPressed( u.url() ); 00389 } 00390 00391 void KDevFileSelector::cmbPathReturnPressed( const QString& u ) 00392 { 00393 QStringList urls = cmbPath->urls(); 00394 urls.remove( u ); 00395 urls.prepend( u ); 00396 cmbPath->setURLs( urls, KURLComboBox::RemoveBottom ); 00397 dir->setFocus(); 00398 dir->setURL( KURL(u), true ); 00399 } 00400 00401 void KDevFileSelector::dirUrlEntered( const KURL& u ) 00402 { 00403 cmbPath->setURL( u ); 00404 } 00405 00406 void KDevFileSelector::dirFinishedLoading() 00407 {} 00408 00409 00410 /* 00411 When the button in the filter box toggles: 00412 If off: 00413 If the name filer is anything but "" or "*", reset it. 00414 If on: 00415 Set last filter. 00416 */ 00417 void KDevFileSelector::btnFilterClick() 00418 { 00419 if ( !btnFilter->isOn() ) 00420 { 00421 slotFilterChange( QString::null ); 00422 } 00423 else 00424 { 00425 filter->lineEdit()->setText( lastFilter ); 00426 slotFilterChange( lastFilter ); 00427 } 00428 } 00429 00430 00431 void KDevFileSelector::autoSync() 00432 { 00433 kdDebug()<<"KDevFileSelector::autoSync()"<<endl; 00434 // if visible, sync 00435 if ( isVisible() ) 00436 { 00437 setActiveDocumentDir(); 00438 waitingUrl = QString::null; 00439 } 00440 // else set waiting url 00441 else 00442 { 00443 KURL u = activeDocumentUrl(); 00444 if (!u.isEmpty()) 00445 waitingUrl = u.directory(); 00446 } 00447 } 00448 00449 void KDevFileSelector::autoSync( KParts::Part *part ) 00450 { 00451 KTextEditor::Document* doc = dynamic_cast<KTextEditor::Document*>( part ); 00452 if( !doc ) 00453 return; 00454 00455 // as above, but using document url. 00456 kdDebug()<<"KDevFileSelector::autoSync( KTextEditor::Document )"<<endl; 00457 KURL u ( doc->url() ); 00458 if ( u.isEmpty() ) 00459 { 00460 waitingUrl = QString::null; 00461 return; 00462 } 00463 if ( isVisible() ) 00464 { 00465 setDir( u.directory() ); 00466 waitingUrl = QString::null; 00467 } 00468 else 00469 { 00470 waitingUrl = u.directory(); 00471 } 00472 } 00474 void KDevFileSelector::setActiveDocumentDir() 00475 { 00476 //kdDebug()<<"KDevFileSelector::setActiveDocumentDir()"<<endl; 00477 KURL u = activeDocumentUrl(); 00478 if (!u.isEmpty()) 00479 setDir( u.upURL() ); 00480 } 00481 00482 void KDevFileSelector::viewChanged() 00483 { 00486 acSyncDir->setEnabled( ! activeDocumentUrl().directory().isEmpty() ); 00487 } 00488 00489 //END Private Slots 00490 00491 //BEGIN Protected 00492 00493 void KDevFileSelector::focusInEvent( QFocusEvent * ) 00494 { 00495 dir->setFocus(); 00496 } 00497 00498 void KDevFileSelector::showEvent( QShowEvent * ) 00499 { 00500 // sync if we should 00501 if ( autoSyncEvents & GotVisible ) 00502 { 00503 kdDebug()<<"syncing fs on show"<<endl; 00504 setActiveDocumentDir(); 00505 waitingUrl = QString::null; 00506 } 00507 // else, if we have a waiting URL set it 00508 else if ( ! waitingUrl.isEmpty() ) 00509 { 00510 setDir( waitingUrl ); 00511 waitingUrl = QString::null; 00512 } 00513 } 00514 00515 bool KDevFileSelector::eventFilter( QObject* o, QEvent *e ) 00516 { 00517 /* 00518 This is rather unfortunate, but: 00519 QComboBox does not support setting the size of the listbox to something 00520 resonable. Even using listbox->setVariableWidth() does not yeld a 00521 satisfying result, something is wrong with the handling of the sizehint. 00522 And the popup is rather useless, if the paths are only partly visible. 00523 */ 00524 QListBox *lb = cmbPath->listBox(); 00525 if ( o == lb && e->type() == QEvent::Show ) 00526 { 00527 int add 00528 = lb->height() < lb->contentsHeight() ? lb->verticalScrollBar()->width() : 0; 00529 int w = QMIN( mainwin->main()->width(), lb->contentsWidth() + add ); 00530 lb->resize( w, lb->height() ); 00534 } 00536 return QWidget::eventFilter( o, e ); 00537 } 00538 00539 //END Protected 00540 00541 //BEGIN ACtionLBItem 00542 /* 00543 QListboxItem that can store and return a string, 00544 used for the toolbar action selector. 00545 */ 00546 class ActionLBItem : public QListBoxPixmap 00547 { 00548 public: 00549 ActionLBItem( QListBox *lb=0, 00550 const QPixmap &pm = QPixmap(), 00551 const QString &text=QString::null, 00552 const QString &str=QString::null ) : 00553 QListBoxPixmap( lb, pm, text ), 00554 _str(str) 00555 {} 00556 ; 00557 QString idstring() 00558 { 00559 return _str; 00560 }; 00561 private: 00562 QString _str; 00563 }; 00564 00565 KURL KDevFileSelector::activeDocumentUrl( ) 00566 { 00567 KTextEditor::Document* doc = dynamic_cast<KTextEditor::Document*>( partController->activePart() ); 00568 if( doc ) 00569 return doc->url(); 00570 00571 return KURL(); 00572 } 00573 //END ActionLBItem 00574 00575 //BEGIN KFSConfigPage 00577 // KFSConfigPage implementation 00579 KFSConfigPage::KFSConfigPage( QWidget *parent, const char *name, KDevFileSelector *kfs ) 00580 : QWidget( parent, name ), 00581 fileSelector( kfs ), 00582 bDirty( false ) 00583 { 00584 QVBoxLayout *lo = new QVBoxLayout( this ); 00585 int spacing = KDialog::spacingHint(); 00586 lo->setSpacing( spacing ); 00587 00588 // Toolbar - a lot for a little... 00589 QGroupBox *gbToolbar = new QGroupBox( 1, Qt::Vertical, i18n("Toolbar"), this ); 00590 acSel = new KActionSelector( gbToolbar ); 00591 acSel->setAvailableLabel( i18n("A&vailable actions:") ); 00592 acSel->setSelectedLabel( i18n("S&elected actions:") ); 00593 lo->addWidget( gbToolbar ); 00594 connect( acSel, SIGNAL( added( QListBoxItem * ) ), this, SLOT( slotChanged() ) ); 00595 connect( acSel, SIGNAL( removed( QListBoxItem * ) ), this, SLOT( slotChanged() ) ); 00596 connect( acSel, SIGNAL( movedUp( QListBoxItem * ) ), this, SLOT( slotChanged() ) ); 00597 connect( acSel, SIGNAL( movedDown( QListBoxItem * ) ), this, SLOT( slotChanged() ) ); 00598 00599 // Sync 00600 QGroupBox *gbSync = new QGroupBox( 1, Qt::Horizontal, i18n("Auto Synchronization"), this ); 00601 cbSyncActive = new QCheckBox( i18n("When a docu&ment becomes active"), gbSync ); 00602 cbSyncOpen = new QCheckBox( i18n("When a document is o&pened"), gbSync ); 00603 cbSyncShow = new QCheckBox( i18n("When the file selector becomes visible"), gbSync ); 00604 lo->addWidget( gbSync ); 00605 connect( cbSyncActive, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); 00606 connect( cbSyncOpen, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); 00607 connect( cbSyncShow, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); 00608 00609 // Histories 00610 QHBox *hbPathHist = new QHBox ( this ); 00611 QLabel *lbPathHist = new QLabel( i18n("Remember &locations:"), hbPathHist ); 00612 sbPathHistLength = new QSpinBox( hbPathHist ); 00613 lbPathHist->setBuddy( sbPathHistLength ); 00614 lo->addWidget( hbPathHist ); 00615 connect( sbPathHistLength, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) ); 00616 00617 QHBox *hbFilterHist = new QHBox ( this ); 00618 QLabel *lbFilterHist = new QLabel( i18n("Remember &filters:"), hbFilterHist ); 00619 sbFilterHistLength = new QSpinBox( hbFilterHist ); 00620 lbFilterHist->setBuddy( sbFilterHistLength ); 00621 lo->addWidget( hbFilterHist ); 00622 connect( sbFilterHistLength, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) ); 00623 00624 // Session 00625 QGroupBox *gbSession = new QGroupBox( 1, Qt::Horizontal, i18n("Session"), this ); 00626 cbSesLocation = new QCheckBox( i18n("Restore loca&tion"), gbSession ); 00627 cbSesFilter = new QCheckBox( i18n("Restore last f&ilter"), gbSession ); 00628 lo->addWidget( gbSession ); 00629 connect( cbSesLocation, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); 00630 connect( cbSesFilter, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); 00631 00632 // make it look nice 00633 lo->addStretch( 1 ); 00634 00635 // be helpfull 00636 /* 00637 QWhatsThis::add( lbAvailableActions, i18n( 00638 "<p>Available actions for the toolbar. To add an action, select it here " 00639 "and press the add (<strong>-&gt;</strong>) button" ) ); 00640 QWhatsThis::add( lbUsedActions, i18n( 00641 "<p>Actions used in the toolbar. To remove an action, select it and " 00642 "press the remove (<strong>&lt;-</strong>) button." 00643 "<p>To change the order of the actions, use the Up and Down buttons to " 00644 "move the selected action.") ); 00645 */ 00646 QString lhwt( i18n( 00647 "<p>Decides how many locations to keep in the history of the location " 00648 "combo box") ); 00649 QWhatsThis::add 00650 ( lbPathHist, lhwt ); 00651 QWhatsThis::add 00652 ( sbPathHistLength, lhwt ); 00653 QString fhwt( i18n( 00654 "<p>Decides how many filters to keep in the history of the filter " 00655 "combo box") ); 00656 QWhatsThis::add 00657 ( lbFilterHist, fhwt ); 00658 QWhatsThis::add 00659 ( sbFilterHistLength, fhwt ); 00660 QString synwt( i18n( 00661 "<p>These options allow you to have the File Selector automatically " 00662 "change location to the directory of the active document on certain " 00663 "events." 00664 "<p>Auto synchronization is <em>lazy</em>, meaning it will not take " 00665 "effect until the file selector is visible." 00666 "<p>None of these are enabled by default, but you can always sync the " 00667 "location by pressing the sync button in the toolbar.") ); 00668 QWhatsThis::add 00669 ( gbSync, synwt ); 00670 QWhatsThis::add 00671 ( cbSesLocation, i18n( 00672 "<p>If this option is enabled (default), the location will be restored " 00673 "when you start KDev.<p><strong>Note</strong> that if the session is " 00674 "handled by the KDE session manager, the location is always restored.") ); 00675 QWhatsThis::add 00676 ( cbSesFilter, i18n( 00677 "<p>If this option is enabled (default), the current filter will be " 00678 "restored when you start KDev.<p><strong>Note</strong> that if the " 00679 "session is handled by the KDE session manager, the filter is always " 00680 "restored." 00681 "<p><strong>Note</strong> that some of the autosync settings may " 00682 "override the restored location if on.") ); 00683 00684 init(); 00685 00686 } 00687 00688 void KFSConfigPage::apply() 00689 { 00690 KConfig *config = fileSelector->m_part->instance()->config(); 00691 config->setGroup( "fileselector" ); 00692 // toolbar 00693 QStringList l; 00694 QListBoxItem *item = acSel->selectedListBox()->firstItem(); 00695 ActionLBItem *aItem; 00696 while ( item ) 00697 { 00698 aItem = (ActionLBItem*)item; 00699 if ( aItem ) 00700 { 00701 l << aItem->idstring(); 00702 } 00703 item = item->next(); 00704 } 00705 config->writeEntry( "toolbar actions", l ); 00706 fileSelector->setupToolbar( config ); 00707 // sync 00708 int s = 0; 00709 if ( cbSyncActive->isChecked() ) 00710 s |= KDevFileSelector::DocumentChanged; 00711 if ( cbSyncOpen->isChecked() ) 00712 s |= KDevFileSelector::DocumentOpened; 00713 if ( cbSyncShow->isChecked() ) 00714 s |= KDevFileSelector::GotVisible; 00715 fileSelector->autoSyncEvents = s; 00716 // reset connections 00717 disconnect( fileSelector->partController, 0, fileSelector, SLOT( autoSync() ) ); 00718 disconnect( fileSelector->partController, 0, 00719 fileSelector, SLOT( autoSync( KParts::Part *) ) ); 00720 if ( s & KDevFileSelector::DocumentChanged ) 00721 connect( fileSelector->partController, SIGNAL( viewChanged() ), 00722 fileSelector, SLOT( autoSync() ) ); 00723 if ( s & KDevFileSelector::DocumentOpened ) 00724 connect( fileSelector->partController, 00725 SIGNAL( partAdded(KParts::Part *) ), 00726 fileSelector, SLOT( autoSync(KParts::Part *) ) ); 00727 00728 // histories 00729 fileSelector->cmbPath->setMaxItems( sbPathHistLength->value() ); 00730 fileSelector->filter->setMaxCount( sbFilterHistLength->value() ); 00731 // session - theese are read/written directly to the app config, 00732 // as they are not needed during operation. 00733 config->writeEntry( "restore location", cbSesLocation->isChecked() ); 00734 config->writeEntry( "restore last filter", cbSesFilter->isChecked() ); 00735 } 00736 00737 void KFSConfigPage::reload() 00738 { 00739 // hmm, what is this supposed to do, actually?? 00740 init(); 00741 } 00742 00743 void KFSConfigPage::init() 00744 { 00745 KConfig *config = fileSelector->m_part->instance()->config(); 00746 config->setGroup( "fileselector" ); 00747 // toolbar 00748 QStringList l = config->readListEntry( "toolbar actions", ',' ); 00749 if ( l.isEmpty() ) // default toolbar 00750 l << "up" << "back" << "forward" << "home" << 00751 "short view" << "detailed view" << 00752 "bookmarks" << "sync_dir"; 00753 00754 // actions from diroperator + two of our own 00755 QStringList allActions; 00756 allActions << "up" << "back" << "forward" << "home" << 00757 "reload" << "mkdir" << "delete" << 00758 "short view" << "detailed view" /*<< "view menu" << 00759 "show hidden" << "properties"*/ << 00760 "bookmarks" << "sync_dir"; 00761 QRegExp re("&(?=[^&])"); 00762 KAction *ac; 00763 QListBox *lb; 00764 for ( QStringList::Iterator it=allActions.begin(); it != allActions.end(); ++it ) 00765 { 00766 lb = l.contains( *it ) ? acSel->selectedListBox() : acSel->availableListBox(); 00767 if ( *it == "bookmarks" || *it == "sync_dir" ) 00768 ac = fileSelector->actionCollection()->action( (*it).latin1() ); 00769 else 00770 ac = fileSelector->dirOperator()->actionCollection()->action( (*it).latin1() ); 00771 if ( ac ) 00772 new ActionLBItem( lb, SmallIcon( ac->icon() ), ac->text().replace( re, "" ), *it ); 00773 } 00774 00775 // sync 00776 int s = fileSelector->autoSyncEvents; 00777 cbSyncActive->setChecked( s & KDevFileSelector::DocumentChanged ); 00778 cbSyncOpen->setChecked( s & KDevFileSelector::DocumentOpened ); 00779 cbSyncShow->setChecked( s & KDevFileSelector::GotVisible ); 00780 // histories 00781 sbPathHistLength->setValue( fileSelector->cmbPath->maxItems() ); 00782 sbFilterHistLength->setValue( fileSelector->filter->maxCount() ); 00783 // session 00784 cbSesLocation->setChecked( config->readBoolEntry( "restore location", true ) ); 00785 cbSesFilter->setChecked( config->readBoolEntry( "restore last filter", true ) ); 00786 } 00787 00788 void KFSConfigPage::slotChanged() 00789 { 00790 } 00791 00792 //END KFSConfigPage 00793 00794 00795 //BEGIN KDevDirOperator 00796 00797 void KDevDirOperator::activatedMenu( const KFileItem *fi, const QPoint & pos ) 00798 { 00799 setupMenu(); 00800 updateSelectionDependentActions(); 00801 00802 KActionMenu * am = dynamic_cast<KActionMenu*>(actionCollection()->action("popupMenu")); 00803 if (!am) 00804 return; 00805 KPopupMenu *popup = am->popupMenu(); 00806 00807 if (fi) 00808 { 00809 FileContext context( KURL::List(fi->url())); 00810 if ( (m_part) && (m_part->core())) 00811 m_part->core()->fillContextMenu(popup, &context); 00812 } 00813 00814 popup->popup(pos); 00815 } 00816 00817 //END KDevDirOperator 00818 00819 #include "fileselector_widget.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:51 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003