• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • app
katefileselector.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
4  Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 //BEGIN Includes
22 #include "katefileselector.h"
23 #include "katefileselector.moc"
24 
25 #include "katemainwindow.h"
26 #include "kateviewmanager.h"
27 #include "kbookmarkhandler.h"
28 
29 #include "tdeactionselector.h"
30 
31 #include <tqlayout.h>
32 #include <tqtoolbutton.h>
33 #include <tqhbox.h>
34 #include <tqvbox.h>
35 #include <tqlabel.h>
36 #include <tqstrlist.h>
37 #include <tqtooltip.h>
38 #include <tqwhatsthis.h>
39 #include <tqapplication.h>
40 #include <tqlistbox.h>
41 #include <tqscrollbar.h>
42 #include <tqspinbox.h>
43 #include <tqgroupbox.h>
44 #include <tqcheckbox.h>
45 #include <tqregexp.h>
46 #include <tqdockarea.h>
47 #include <tqtimer.h>
48 #include <tqdir.h>
49 
50 #include <tdeapplication.h>
51 #include <kiconloader.h>
52 #include <kurlcombobox.h>
53 #include <kurlcompletion.h>
54 #include <kprotocolinfo.h>
55 #include <tdediroperator.h>
56 #include <tdeconfig.h>
57 #include <tdelocale.h>
58 #include <kcombobox.h>
59 #include <tdeaction.h>
60 #include <tdemessagebox.h>
61 #include <tdetoolbarbutton.h>
62 #include <tqtoolbar.h>
63 #include <tdepopupmenu.h>
64 #include <kdialog.h>
65 #include <kdebug.h>
66 //END Includes
67 
68 //BEGIN Toolbar
69  // from tdefiledialog.cpp - avoid qt warning in STDERR (~/.xsessionerrors)
70 static void silenceQToolBar(TQtMsgType, const char *){}
71 
72 // helper classes to be able to have a toolbar without move handle
73 KateFileSelectorToolBar::KateFileSelectorToolBar(TQWidget *parent)
74  : TDEToolBar( parent, "Kate FileSelector Toolbar", true )
75 {
76  setMinimumWidth(10);
77 }
78 
79 KateFileSelectorToolBar::~KateFileSelectorToolBar(){}
80 
81 void KateFileSelectorToolBar::setMovingEnabled( bool)
82 {
83  TDEToolBar::setMovingEnabled(false);
84 }
85 
86 
87 KateFileSelectorToolBarParent::KateFileSelectorToolBarParent(TQWidget *parent)
88  :TQFrame(parent),m_tb(0){}
89 KateFileSelectorToolBarParent::~KateFileSelectorToolBarParent(){}
90 void KateFileSelectorToolBarParent::setToolBar(KateFileSelectorToolBar *tb)
91 {
92  m_tb=tb;
93 }
94 
95 void KateFileSelectorToolBarParent::resizeEvent ( TQResizeEvent * )
96 {
97  if (m_tb)
98  {
99  setMinimumHeight(m_tb->sizeHint().height());
100  m_tb->resize(width(),height());
101  }
102 }
103 //END
104 
105 //BEGIN Constructor/destructor
106 
107 KateFileSelector::KateFileSelector( KateMainWindow *mainWindow,
108  KateViewManager *viewManager,
109  TQWidget * parent, const char * name )
110  : TQVBox (parent, name),
111  mainwin(mainWindow),
112  viewmanager(viewManager)
113 {
114  mActionCollection = new TDEActionCollection( this );
115 
116  TQtMsgHandler oldHandler = tqInstallMsgHandler( silenceQToolBar );
117 
118  KateFileSelectorToolBarParent *tbp=new KateFileSelectorToolBarParent(this);
119  toolbar = new KateFileSelectorToolBar(tbp);
120  tbp->setToolBar(toolbar);
121  toolbar->setMovingEnabled(false);
122  toolbar->setFlat(true);
123  tqInstallMsgHandler( oldHandler );
124 
125  cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" );
126  cmbPath->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
127  KURLCompletion* cmpl = new KURLCompletion(KURLCompletion::DirCompletion);
128  cmbPath->setCompletionObject( cmpl );
129  cmbPath->setAutoDeleteCompletionObject( true );
130  cmbPath->listBox()->installEventFilter( this );
131 
132  dir = new KDirOperator(KURL(), this, "operator");
133  dir->setView(KFile::/* Simple */Detail);
134  dir->view()->setSelectionMode(KFile::Extended);
135  connect ( dir, TQT_SIGNAL( viewChanged(KFileView *) ),
136  this, TQT_SLOT( selectorViewChanged(KFileView *) ) );
137  setStretchFactor(dir, 2);
138 
139  TDEActionCollection *coll = dir->actionCollection();
140  // some shortcuts of diroperator that clashes with Kate
141  coll->action( "delete" )->setShortcut( TDEShortcut( ALT + Key_Delete ) );
142  coll->action( "reload" )->setShortcut( TDEShortcut( ALT + Key_F5 ) );
143  coll->action( "back" )->setShortcut( TDEShortcut( ALT + SHIFT + Key_Left ) );
144  coll->action( "forward" )->setShortcut( TDEShortcut( ALT + SHIFT + Key_Right ) );
145  // some consistency - reset up for dir too
146  coll->action( "up" )->setShortcut( TDEShortcut( ALT + SHIFT + Key_Up ) );
147  coll->action( "home" )->setShortcut( TDEShortcut( CTRL + ALT + Key_Home ) );
148 
149  // bookmarks action!
150  TDEActionMenu *acmBookmarks = new TDEActionMenu( i18n("Bookmarks"), "bookmark",
151  mActionCollection, "bookmarks" );
152  acmBookmarks->setDelayed( false );
153  bookmarkHandler = new KBookmarkHandler( this, acmBookmarks->popupMenu() );
154  TQHBox* filterBox = new TQHBox(this);
155 
156  btnFilter = new TQToolButton( filterBox );
157  btnFilter->setIconSet( SmallIconSet("filter" ) );
158  btnFilter->setToggleButton( true );
159  filter = new KHistoryCombo( true, filterBox, "filter");
160  filter->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
161  filterBox->setStretchFactor(filter, 2);
162  connect( btnFilter, TQT_SIGNAL( clicked() ), this, TQT_SLOT( btnFilterClick() ) );
163 
164  connect( filter, TQT_SIGNAL( activated(const TQString&) ),
165  TQT_SLOT( slotFilterChange(const TQString&) ) );
166  connect( filter, TQT_SIGNAL( returnPressed(const TQString&) ),
167  filter, TQT_SLOT( addToHistory(const TQString&) ) );
168 
169  // tdeaction for the dir sync method
170  acSyncDir = new TDEAction( i18n("Current Document Folder"), "curfiledir", 0,
171  TQT_TQOBJECT(this), TQT_SLOT( setActiveDocumentDir() ), mActionCollection, "sync_dir" );
172  toolbar->setIconText( TDEToolBar::IconOnly );
173  toolbar->setIconSize( 16 );
174  toolbar->setEnableContextMenu( false );
175 
176  connect( cmbPath, TQT_SIGNAL( urlActivated( const KURL& )),
177  this, TQT_SLOT( cmbPathActivated( const KURL& ) ));
178  connect( cmbPath, TQT_SIGNAL( returnPressed( const TQString& )),
179  this, TQT_SLOT( cmbPathReturnPressed( const TQString& ) ));
180  connect(dir, TQT_SIGNAL(urlEntered(const KURL&)),
181  this, TQT_SLOT(dirUrlEntered(const KURL&)) );
182 
183  connect(dir, TQT_SIGNAL(finishedLoading()),
184  this, TQT_SLOT(dirFinishedLoading()) );
185 
186  // enable dir sync button if current doc has a valid URL
187  connect ( viewmanager, TQT_SIGNAL( viewChanged() ),
188  this, TQT_SLOT( kateViewChanged() ) );
189 
190  // Connect the bookmark handler
191  connect( bookmarkHandler, TQT_SIGNAL( openURL( const TQString& )),
192  this, TQT_SLOT( setDir( const TQString& ) ) );
193 
194  waitingUrl = TQString::null;
195 
196  // whatsthis help
197  TQWhatsThis::add( cmbPath,
198  i18n("<p>Here you can enter a path for a folder to display."
199  "<p>To go to a folder previously entered, press the arrow on "
200  "the right and choose one. <p>The entry has folder "
201  "completion. Right-click to choose how completion should behave.") );
202  TQWhatsThis::add( filter,
203  i18n("<p>Here you can enter a name filter to limit which files are displayed."
204  "<p>To clear the filter, toggle off the filter button to the left."
205  "<p>To reapply the last filter used, toggle on the filter button." ) );
206  TQWhatsThis::add( btnFilter,
207  i18n("<p>This button clears the name filter when toggled off, or "
208  "reapplies the last filter used when toggled on.") );
209 
210 }
211 
212 KateFileSelector::~KateFileSelector()
213 {
214 }
215 //END Constroctor/Destrctor
216 
217 //BEGIN Public Methods
218 
219 void KateFileSelector::readConfig(TDEConfig *config, const TQString & name)
220 {
221  dir->setViewConfig( config, name + ":view" );
222  dir->readConfig(config, name + ":dir");
223  dir->setView( KFile::Default );
224  dir->view()->setSelectionMode(KFile::Extended);
225  config->setGroup( name );
226 
227  // set up the toolbar
228  setupToolbar( config );
229 
230  cmbPath->setMaxItems( config->readNumEntry( "pathcombo history len", 9 ) );
231  cmbPath->setURLs( config->readPathListEntry( "dir history" ) );
232  // if we restore history
233  if ( config->readBoolEntry( "restore location", true ) || kapp->isRestored() ) {
234  TQString loc( config->readPathEntry( "location" ) );
235  if ( ! loc.isEmpty() ) {
236 // waitingDir = loc;
237 // TQTimer::singleShot(0, this, TQT_SLOT(initialDirChangeHack()));
238  setDir( loc );
239  }
240  }
241 
242  // else is automatic, as cmpPath->setURL is called when a location is entered.
243 
244  filter->setMaxCount( config->readNumEntry( "filter history len", 9 ) );
245  filter->setHistoryItems( config->readListEntry("filter history"), true );
246  lastFilter = config->readEntry( "last filter" );
247  TQString flt("");
248  if ( config->readBoolEntry( "restore last filter", true ) || kapp->isRestored() )
249  flt = config->readEntry("current filter");
250  filter->lineEdit()->setText( flt );
251  slotFilterChange( flt );
252 
253  autoSyncEvents = config->readNumEntry( "AutoSyncEvents", 0 );
254 }
255 
256 void KateFileSelector::initialDirChangeHack()
257 {
258  setDir( waitingDir );
259 }
260 
261 void KateFileSelector::setupToolbar( TDEConfig *config )
262 {
263  toolbar->clear();
264  TQStringList tbactions = config->readListEntry( "toolbar actions", ',' );
265  if ( tbactions.isEmpty() ) {
266  // reasonable collection for default toolbar
267  tbactions << "up" << "back" << "forward" << "home" <<
268  "short view" << "detailed view" <<
269  "bookmarks" << "sync_dir";
270  }
271  TDEAction *ac;
272  for ( TQStringList::Iterator it=tbactions.begin(); it != tbactions.end(); ++it ) {
273  if ( *it == "bookmarks" || *it == "sync_dir" )
274  ac = mActionCollection->action( (*it).latin1() );
275  else
276  ac = dir->actionCollection()->action( (*it).latin1() );
277  if ( ac )
278  ac->plug( toolbar );
279  }
280 }
281 
282 void KateFileSelector::writeConfig(TDEConfig *config, const TQString & name)
283 {
284  dir->writeConfig(config,name + ":dir");
285 
286  config->setGroup( name );
287  config->writeEntry( "pathcombo history len", cmbPath->maxItems() );
288  TQStringList l;
289  for (int i = 0; i < cmbPath->count(); i++) {
290  l.append( cmbPath->text( i ) );
291  }
292  config->writePathEntry( "dir history", l );
293  config->writePathEntry( "location", cmbPath->currentText() );
294 
295  config->writeEntry( "filter history len", filter->maxCount() );
296  config->writeEntry( "filter history", filter->historyItems() );
297  config->writeEntry( "current filter", filter->currentText() );
298  config->writeEntry( "last filter", lastFilter );
299  config->writeEntry( "AutoSyncEvents", autoSyncEvents );
300 }
301 
302 void KateFileSelector::setView(KFile::FileView view)
303 {
304  dir->setView(view);
305  dir->view()->setSelectionMode(KFile::Extended);
306 }
307 
308 //END Public Methods
309 
310 //BEGIN Public Slots
311 
312 void KateFileSelector::slotFilterChange( const TQString & nf )
313 {
314  TQString f = nf.stripWhiteSpace();
315  bool empty = f.isEmpty() || f == "*";
316  TQToolTip::remove( btnFilter );
317  if ( empty ) {
318  dir->clearFilter();
319  filter->lineEdit()->setText( TQString::null );
320  TQToolTip::add( btnFilter,
321  TQString( i18n("Apply last filter (\"%1\")") ).arg( lastFilter ) );
322  }
323  else {
324  dir->setNameFilter( f );
325  lastFilter = f;
326  TQToolTip::add( btnFilter, i18n("Clear filter") );
327  }
328  btnFilter->setOn( !empty );
329  dir->updateDir();
330  // this will be never true after the filter has been used;)
331  btnFilter->setEnabled( !( empty && lastFilter.isEmpty() ) );
332 
333 }
334 
335 bool kateFileSelectorIsReadable ( const KURL& url )
336 {
337  if ( !url.isLocalFile() )
338  return true; // what else can we say?
339 
340  TQDir dir (url.path());
341  return dir.exists ();
342 }
343 
344 void KateFileSelector::setDir( KURL u )
345 {
346  KURL newurl;
347 
348  if ( !u.isValid() )
349  newurl.setPath( TQDir::homeDirPath() );
350  else
351  newurl = u;
352 
353  TQString pathstr = newurl.path(+1);
354  newurl.setPath(pathstr);
355 
356  if ( !kateFileSelectorIsReadable ( newurl ) )
357  newurl.cd(TQString::fromLatin1(".."));
358 
359  if ( !kateFileSelectorIsReadable (newurl) )
360  newurl.setPath( TQDir::homeDirPath() );
361 
362  dir->setURL(newurl, true);
363 }
364 
365 //END Public Slots
366 
367 //BEGIN Private Slots
368 
369 void KateFileSelector::cmbPathActivated( const KURL& u )
370 {
371  cmbPathReturnPressed( u.url() );
372 }
373 
374 void KateFileSelector::cmbPathReturnPressed( const TQString& u )
375 {
376  KURL typedURL( u );
377  if ( typedURL.hasPass() )
378  typedURL.setPass( TQString::null );
379 
380  TQStringList urls = cmbPath->urls();
381  urls.remove( typedURL.url() );
382  urls.prepend( typedURL.url() );
383  cmbPath->setURLs( urls, KURLComboBox::RemoveBottom );
384  dir->setFocus();
385  dir->setURL( KURL(u), true );
386 }
387 
388 void KateFileSelector::dirUrlEntered( const KURL& u )
389 {
390  cmbPath->setURL( u );
391 }
392 
393 void KateFileSelector::dirFinishedLoading()
394 {
395 }
396 
397 
398 /*
399  When the button in the filter box toggles:
400  If off:
401  If the name filer is anything but "" or "*", reset it.
402  If on:
403  Set last filter.
404 */
405 void KateFileSelector::btnFilterClick()
406 {
407  if ( !btnFilter->isOn() ) {
408  slotFilterChange( TQString::null );
409  }
410  else {
411  filter->lineEdit()->setText( lastFilter );
412  slotFilterChange( lastFilter );
413  }
414 }
415 
416 //FIXME crash on shutdown
417 void KateFileSelector::setActiveDocumentDir()
418 {
419 // kdDebug(13001)<<"KateFileSelector::setActiveDocumentDir()"<<endl;
420  KURL u = mainwin->activeDocumentUrl();
421 // kdDebug(13001)<<"URL: "<<u.prettyURL()<<endl;
422  if (!u.isEmpty())
423  setDir( u.upURL() );
424 // kdDebug(13001)<<"... setActiveDocumentDir() DONE!"<<endl;
425 }
426 
427 void KateFileSelector::kateViewChanged()
428 {
429  if ( autoSyncEvents & DocumentChanged )
430  {
431 // kdDebug(13001)<<"KateFileSelector::do a sync ()"<<endl;
432  // if visible, sync
433  if ( isVisible() ) {
434  setActiveDocumentDir();
435  waitingUrl = TQString::null;
436  }
437  // else set waiting url
438  else {
439  KURL u = mainwin->activeDocumentUrl();
440  if (!u.isEmpty())
441  waitingUrl = u.directory();
442  }
443  }
444 
445  // TODO: make sure the button is disabled if the directory is unreadable, eg
446  // the document URL has protocol http
447  acSyncDir->setEnabled( ! mainwin->activeDocumentUrl().directory().isEmpty() );
448 }
449 
450 void KateFileSelector::selectorViewChanged( KFileView * newView )
451 {
452  newView->setSelectionMode(KFile::Extended);
453 }
454 
455 //END Private Slots
456 
457 //BEGIN Protected
458 
459 void KateFileSelector::focusInEvent( TQFocusEvent * )
460 {
461  dir->setFocus();
462 }
463 
464 void KateFileSelector::showEvent( TQShowEvent * )
465 {
466  // sync if we should
467  if ( autoSyncEvents & GotVisible ) {
468 // kdDebug(13001)<<"syncing fs on show"<<endl;
469  setActiveDocumentDir();
470  waitingUrl = TQString::null;
471  }
472  // else, if we have a waiting URL set it
473  else if ( ! waitingUrl.isEmpty() ) {
474  setDir( waitingUrl );
475  waitingUrl = TQString::null;
476  }
477 }
478 
479 bool KateFileSelector::eventFilter( TQObject* o, TQEvent *e )
480 {
481  /*
482  This is rather unfortunate, but:
483  TQComboBox does not support setting the size of the listbox to something
484  reasonable. Even using listbox->setVariableWidth() does not yield a
485  satisfying result, something is wrong with the handling of the sizehint.
486  And the popup is rather useless, if the paths are only partly visible.
487  */
488  TQListBox *lb = cmbPath->listBox();
489  if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(lb) && e->type() == TQEvent::Show ) {
490  int add = lb->height() < lb->contentsHeight() ? lb->verticalScrollBar()->width() : 0;
491  int w = TQMIN( mainwin->width(), lb->contentsWidth() + add );
492  lb->resize( w, lb->height() );
493  // TODO - move the listbox to a suitable place if nessecary
494  // TODO - decide if it is worth caching the size while untill the contents
495  // are changed.
496  }
497  // TODO - same thing for the completion popup?
498  return TQWidget::eventFilter( o, e );
499 }
500 
501 //END Protected
502 
503 //BEGIN ACtionLBItem
504 /*
505  QListboxItem that can store and return a string,
506  used for the toolbar action selector.
507 */
508 class ActionLBItem : public TQListBoxPixmap {
509  public:
510  ActionLBItem( TQListBox *lb=0,
511  const TQPixmap &pm = TQPixmap(),
512  const TQString &text=TQString::null,
513  const TQString &str=TQString::null ) :
514  TQListBoxPixmap( lb, pm, text ),
515  _str(str) {};
516  TQString idstring() { return _str; };
517  private:
518  TQString _str;
519 };
520 //END ActionLBItem
521 
522 //BEGIN KFSConfigPage
524 // KFSConfigPage implementation
526 KFSConfigPage::KFSConfigPage( TQWidget *parent, const char *name, KateFileSelector *kfs )
527  : Kate::ConfigPage( parent, name ),
528  fileSelector( kfs ),
529  m_changed( false )
530 {
531  TQVBoxLayout *lo = new TQVBoxLayout( this );
532  int spacing = KDialog::spacingHint();
533  lo->setSpacing( spacing );
534 
535  // Toolbar - a lot for a little...
536  TQGroupBox *gbToolbar = new TQGroupBox( 1, Qt::Vertical, i18n("Toolbar"), this );
537  acSel = new TDEActionSelector( gbToolbar );
538  acSel->setAvailableLabel( i18n("A&vailable actions:") );
539  acSel->setSelectedLabel( i18n("S&elected actions:") );
540  lo->addWidget( gbToolbar );
541  connect( acSel, TQT_SIGNAL( added( TQListBoxItem * ) ), this, TQT_SLOT( slotMyChanged() ) );
542  connect( acSel, TQT_SIGNAL( removed( TQListBoxItem * ) ), this, TQT_SLOT( slotMyChanged() ) );
543  connect( acSel, TQT_SIGNAL( movedUp( TQListBoxItem * ) ), this, TQT_SLOT( slotMyChanged() ) );
544  connect( acSel, TQT_SIGNAL( movedDown( TQListBoxItem * ) ), this, TQT_SLOT( slotMyChanged() ) );
545 
546  // Sync
547  TQGroupBox *gbSync = new TQGroupBox( 1, Qt::Horizontal, i18n("Auto Synchronization"), this );
548  cbSyncActive = new TQCheckBox( i18n("When a docu&ment becomes active"), gbSync );
549  cbSyncShow = new TQCheckBox( i18n("When the file selector becomes visible"), gbSync );
550  lo->addWidget( gbSync );
551  connect( cbSyncActive, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotMyChanged() ) );
552  connect( cbSyncShow, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotMyChanged() ) );
553 
554  // Histories
555  TQHBox *hbPathHist = new TQHBox ( this );
556  TQLabel *lbPathHist = new TQLabel( i18n("Remember &locations:"), hbPathHist );
557  sbPathHistLength = new TQSpinBox( hbPathHist );
558  lbPathHist->setBuddy( sbPathHistLength );
559  lo->addWidget( hbPathHist );
560  connect( sbPathHistLength, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotMyChanged() ) );
561 
562  TQHBox *hbFilterHist = new TQHBox ( this );
563  TQLabel *lbFilterHist = new TQLabel( i18n("Remember &filters:"), hbFilterHist );
564  sbFilterHistLength = new TQSpinBox( hbFilterHist );
565  lbFilterHist->setBuddy( sbFilterHistLength );
566  lo->addWidget( hbFilterHist );
567  connect( sbFilterHistLength, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotMyChanged() ) );
568 
569  // Session
570  TQGroupBox *gbSession = new TQGroupBox( 1, Qt::Horizontal, i18n("Session"), this );
571  cbSesLocation = new TQCheckBox( i18n("Restore loca&tion"), gbSession );
572  cbSesFilter = new TQCheckBox( i18n("Restore last f&ilter"), gbSession );
573  lo->addWidget( gbSession );
574  connect( cbSesLocation, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotMyChanged() ) );
575  connect( cbSesFilter, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotMyChanged() ) );
576 
577  // make it look nice
578  lo->addStretch( 1 );
579 
580  // be helpfull
581  /*
582  TQWhatsThis::add( lbAvailableActions, i18n(
583  "<p>Available actions for the toolbar. To add an action, select it here "
584  "and press the add (<strong>-&gt;</strong>) button" ) );
585  TQWhatsThis::add( lbUsedActions, i18n(
586  "<p>Actions used in the toolbar. To remove an action, select it and "
587  "press the remove (<strong>&lt;-</strong>) button."
588  "<p>To change the order of the actions, use the Up and Down buttons to "
589  "move the selected action.") );
590  */
591  TQString lhwt( i18n(
592  "<p>Decides how many locations to keep in the history of the location "
593  "combo box.") );
594  TQWhatsThis::add( lbPathHist, lhwt );
595  TQWhatsThis::add( sbPathHistLength, lhwt );
596  TQString fhwt( i18n(
597  "<p>Decides how many filters to keep in the history of the filter "
598  "combo box.") );
599  TQWhatsThis::add( lbFilterHist, fhwt );
600  TQWhatsThis::add( sbFilterHistLength, fhwt );
601  TQString synwt( i18n(
602  "<p>These options allow you to have the File Selector automatically "
603  "change location to the folder of the active document on certain "
604  "events."
605  "<p>Auto synchronization is <em>lazy</em>, meaning it will not take "
606  "effect until the file selector is visible."
607  "<p>None of these are enabled by default, but you can always sync the "
608  "location by pressing the sync button in the toolbar.") );
609  TQWhatsThis::add( gbSync, synwt );
610  TQWhatsThis::add( cbSesLocation, i18n(
611  "<p>If this option is enabled (default), the location will be restored "
612  "when you start Kate.<p><strong>Note</strong> that if the session is "
613  "handled by the TDE session manager, the location is always restored.") );
614  TQWhatsThis::add( cbSesFilter, i18n(
615  "<p>If this option is enabled (default), the current filter will be "
616  "restored when you start Kate.<p><strong>Note</strong> that if the "
617  "session is handled by the TDE session manager, the filter is always "
618  "restored."
619  "<p><strong>Note</strong> that some of the autosync settings may "
620  "override the restored location if on.") );
621 
622  init();
623 
624 }
625 
626 void KFSConfigPage::apply()
627 {
628  if ( ! m_changed )
629  return;
630 
631  m_changed = false;
632 
633  TDEConfig *config = kapp->config();
634  config->setGroup( "fileselector" );
635  // toolbar
636  TQStringList l;
637  TQListBoxItem *item = acSel->selectedListBox()->firstItem();
638  ActionLBItem *aItem;
639  while ( item )
640  {
641  aItem = (ActionLBItem*)item;
642  if ( aItem )
643  {
644  l << aItem->idstring();
645  }
646  item = item->next();
647  }
648  config->writeEntry( "toolbar actions", l );
649  fileSelector->setupToolbar( config );
650  // sync
651  int s = 0;
652  if ( cbSyncActive->isChecked() )
653  s |= KateFileSelector::DocumentChanged;
654  if ( cbSyncShow->isChecked() )
655  s |= KateFileSelector::GotVisible;
656  fileSelector->autoSyncEvents = s;
657 
658  // histories
659  fileSelector->cmbPath->setMaxItems( sbPathHistLength->value() );
660  fileSelector->filter->setMaxCount( sbFilterHistLength->value() );
661  // session - theese are read/written directly to the app config,
662  // as they are not needed during operation.
663  config->writeEntry( "restore location", cbSesLocation->isChecked() );
664  config->writeEntry( "restore last filter", cbSesFilter->isChecked() );
665 }
666 
667 void KFSConfigPage::reload()
668 {
669  // hmm, what is this supposed to do, actually??
670  init();
671  m_changed = false;
672 }
673 void KFSConfigPage::init()
674 {
675  TDEConfig *config = kapp->config();
676  config->setGroup( "fileselector" );
677  // toolbar
678  TQStringList l = config->readListEntry( "toolbar actions", ',' );
679  if ( l.isEmpty() ) // default toolbar
680  l << "up" << "back" << "forward" << "home" <<
681  "short view" << "detailed view" <<
682  "bookmarks" << "sync_dir";
683 
684  // actions from diroperator + two of our own
685  TQStringList allActions;
686  allActions << "up" << "back" << "forward" << "home" <<
687  "reload" << "mkdir" << "delete" <<
688  "short view" << "detailed view" /*<< "view menu" <<
689  "show hidden" << "properties"*/ <<
690  "bookmarks" << "sync_dir";
691  TQRegExp re("&(?=[^&])");
692  TDEAction *ac;
693  TQListBox *lb;
694  for ( TQStringList::Iterator it=allActions.begin(); it != allActions.end(); ++it ) {
695  lb = l.contains( *it ) ? acSel->selectedListBox() : acSel->availableListBox();
696  if ( *it == "bookmarks" || *it == "sync_dir" )
697  ac = fileSelector->actionCollection()->action( (*it).latin1() );
698  else
699  ac = fileSelector->dirOperator()->actionCollection()->action( (*it).latin1() );
700  if ( ac )
701  new ActionLBItem( lb, SmallIcon( ac->icon() ), ac->text().replace( re, "" ), *it );
702  }
703 
704  // sync
705  int s = fileSelector->autoSyncEvents;
706  cbSyncActive->setChecked( s & KateFileSelector::DocumentChanged );
707  cbSyncShow->setChecked( s & KateFileSelector::GotVisible );
708  // histories
709  sbPathHistLength->setValue( fileSelector->cmbPath->maxItems() );
710  sbFilterHistLength->setValue( fileSelector->filter->maxCount() );
711  // session
712  cbSesLocation->setChecked( config->readBoolEntry( "restore location", true ) );
713  cbSesFilter->setChecked( config->readBoolEntry( "restore last filter", true ) );
714 }
715 
716 void KFSConfigPage::slotMyChanged()
717 {
718  m_changed = true;
719  slotChanged();
720 }
721 //END KFSConfigPage

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kate

Skip menu "kate"
  • kate
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.