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