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

kate

katefilelist.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 "katefilelist.h"
00023 #include "katefilelist.moc"
00024 
00025 #include "katedocmanager.h"
00026 #include "kateviewmanager.h"
00027 #include "katemainwindow.h"
00028 
00029 #include <tqapplication.h>
00030 #include <tqpainter.h>
00031 #include <tqpopupmenu.h>
00032 #include <tqheader.h>
00033 #include <tqcolor.h>
00034 #include <tqcheckbox.h>
00035 #include <tqhbox.h>
00036 #include <tqlayout.h>
00037 #include <tqgroupbox.h>
00038 #include <tqlabel.h>
00039 #include <tqwhatsthis.h>
00040 
00041 #include <kiconloader.h>
00042 #include <tdeconfig.h>
00043 #include <tdelocale.h>
00044 #include <tdeglobalsettings.h>
00045 #include <kpassivepopup.h>
00046 #include <kdebug.h>
00047 #include <tdeapplication.h>
00048 #include <kstringhandler.h>
00049 #include <kcolorbutton.h>
00050 #include <kdialog.h>
00051 //END Includes
00052 
00053 //BEGIN ToolTip
00054 class ToolTip : public TQToolTip
00055 {
00056   public:
00057     ToolTip( TQWidget *parent, KateFileList *lv )
00058       : TQToolTip( parent ),
00059     m_listView( lv )
00060     {
00061     }
00062     virtual ~ToolTip() {};
00063 
00064     void maybeTip( const TQPoint &pos )
00065     {
00066       TQListViewItem *i = m_listView->itemAt( pos );
00067       if ( ! i ) return;
00068 
00069       KateFileListItem *item = ((KateFileListItem*)i);
00070       if ( ! item ) return;
00071 
00072       tip( m_listView->itemRect( i ), m_listView->tooltip( item, 0 ) );
00073 
00074     }
00075 
00076   private:
00077     KateFileList *m_listView;
00078 };
00079 
00080 //END ToolTip
00081 
00082 //BEGIN KateFileList
00083 KateFileList::KateFileList (KateMainWindow *main,
00084                             KateViewManager *_viewManager,
00085                             TQWidget * parent, const char * name )
00086     :  TDEListView (parent, name)
00087     , m_sort( KateFileList::sortByID )
00088 {
00089   m_main = main;
00090   m_tooltip = new ToolTip( viewport(), this );
00091 
00092   // default colors
00093   m_viewShade = TQColor( 51, 204, 255 );
00094   m_editShade = TQColor( 255, 102, 153 );
00095   m_enableBgShading = false;
00096 
00097   setFocusPolicy ( TQ_NoFocus  );
00098 
00099   viewManager = _viewManager;
00100 
00101   header()->hide();
00102   addColumn("Document Name");
00103 
00104   setSelectionMode( TQListView::Single );
00105   setSortType(KateFileList::sortByID);
00106   setShowToolTips( false );
00107 
00108   setupActions ();
00109 
00110   connect(this,TQT_SIGNAL(moved()),this,TQT_SLOT(updateFileListLocations()));
00111 
00112   for (uint i = 0; i < KateDocManager::self()->documents(); i++)
00113   {
00114     slotDocumentCreated (KateDocManager::self()->document(i));
00115     slotModChanged (KateDocManager::self()->document(i));
00116   }
00117 
00118   connect(KateDocManager::self(),TQT_SIGNAL(documentCreated(Kate::Document *)),
00119       this,TQT_SLOT(slotDocumentCreated(Kate::Document *)));
00120   connect(KateDocManager::self(),TQT_SIGNAL(documentDeleted(uint)),
00121       this,TQT_SLOT(slotDocumentDeleted(uint)));
00122 
00123   // don't Honour KDE single/double click setting, this files are already open,
00124   // no need for hassle of considering double-click
00125   connect(this,TQT_SIGNAL(selectionChanged(TQListViewItem *)),
00126       this,TQT_SLOT(slotActivateView(TQListViewItem *)));
00127   connect(viewManager,TQT_SIGNAL(viewChanged()), this,TQT_SLOT(slotViewChanged()));
00128   connect(this,TQT_SIGNAL(contextMenuRequested( TQListViewItem *, const TQPoint &, int )),
00129       this,TQT_SLOT(slotMenu ( TQListViewItem *, const TQPoint &, int )));
00130 }
00131 
00132 KateFileList::~KateFileList ()
00133 {
00134   delete m_tooltip;
00135 }
00136 
00137 void KateFileList::setupActions ()
00138 {
00139   windowNext = KStdAction::back(TQT_TQOBJECT(this), TQT_SLOT(slotPrevDocument()), m_main->actionCollection());
00140   windowPrev = KStdAction::forward(TQT_TQOBJECT(this), TQT_SLOT(slotNextDocument()), m_main->actionCollection());
00141   sortAction = new TDESelectAction( i18n("Sort &By"), 0,
00142       m_main->actionCollection(), "filelist_sortby"  );
00143   listMoveFileUp = new TDEAction( i18n("Move File Up"), 0, m_main->actionCollection(), "filelist_move_up" );
00144   //listMoveFileUp->setShortcut(TDEShortcut(CTRL + SHIFT + Key_Comma));
00145   listMoveFileDown = new TDEAction( i18n("Move File Down"), 0, m_main->actionCollection(), "filelist_move_down" );
00146   //listMoveFileDown->setShortcut(TDEShortcut(CTRL + SHIFT + Key_Period));
00147   connect( listMoveFileUp, TQT_SIGNAL(activated()), TQT_TQOBJECT(this), TQT_SLOT(moveFileUp()) );
00148   connect( listMoveFileDown, TQT_SIGNAL(activated()), TQT_TQOBJECT(this), TQT_SLOT(moveFileDown()) );
00149   TQStringList l;
00150   l << i18n("Opening Order") << i18n("Document Name") << i18n("URL") << i18n("Manual Placement");
00151   sortAction->setItems( l );
00152   connect( sortAction, TQT_SIGNAL(activated(int)), TQT_TQOBJECT(this), TQT_SLOT(setSortType(int)) );
00153 }
00154 
00155 void KateFileList::updateActions ()
00156 {
00157   windowNext->setEnabled(KateDocManager::self()->documents()  > 1);
00158   windowPrev->setEnabled(KateDocManager::self()->documents()  > 1);
00159 }
00160 
00161 void KateFileList::keyPressEvent(TQKeyEvent *e) {
00162   if ( ( e->key() == Key_Return ) || ( e->key() == Key_Enter ) )
00163   {
00164     e->accept();
00165     slotActivateView( currentItem() );
00166   }
00167   else
00168   {
00169     TDEListView::keyPressEvent(e);
00170   }
00171 }
00172 
00173 // Protect single mode selection: don't let them
00174 // leftclick outside items.
00175 // ### if we get to accept keyboard navigation, set focus before
00176 // returning
00177 void KateFileList::contentsMousePressEvent( TQMouseEvent *e )
00178 {
00179   m_lastMouseDownPos = e->pos();
00180 
00181   if ( ! itemAt( contentsToViewport( e->pos() ) ) )
00182   return;
00183 
00184   TDEListView::contentsMousePressEvent( e );
00185 }
00186 
00187 void KateFileList::resizeEvent( TQResizeEvent *e )
00188 {
00189   TDEListView::resizeEvent( e );
00190 
00191   // ### We may want to actually calculate the widest field,
00192   // since it's not automatically scrinked. If I add support for
00193   // tree or marks, the changes of the required width will vary
00194   // a lot with opening/closing of files and display changes for
00195   // the mark branches.
00196   int w = viewport()->width();
00197   if ( columnWidth( 0 ) < w )
00198     setColumnWidth( 0, w );
00199 }
00200 
00201 void KateFileList::slotNextDocument()
00202 {
00203   if ( ! currentItem() || childCount() == 0 )
00204     return;
00205 
00206   // ### more checking once more item types are added
00207 
00208   if ( currentItem()->nextSibling() )
00209     viewManager->activateView( ((KateFileListItem*)currentItem()->nextSibling())->documentNumber() );
00210   else
00211     viewManager->activateView( ((KateFileListItem *)firstChild())->documentNumber() );
00212 }
00213 
00214 void KateFileList::slotPrevDocument()
00215 {
00216   if ( ! currentItem() || childCount() == 0 )
00217     return;
00218 
00219   // ### more checking once more item types are added
00220 
00221   if ( currentItem()->itemAbove() )
00222     viewManager->activateView( ((KateFileListItem*)currentItem()->itemAbove())->documentNumber() );
00223   else
00224     viewManager->activateView( ((KateFileListItem *)lastItem())->documentNumber() );
00225 }
00226 
00227 void KateFileList::slotDocumentCreated (Kate::Document *doc)
00228 {
00229   new KateFileListItem( this, doc/*, doc->documentNumber()*/ );
00230   connect(doc,TQT_SIGNAL(modStateChanged(Kate::Document *)),this,TQT_SLOT(slotModChanged(Kate::Document *)));
00231   connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotNameChanged(Kate::Document *)));
00232   connect(doc,TQT_SIGNAL(modifiedOnDisc(Kate::Document *, bool, unsigned char)),this,TQT_SLOT(slotModifiedOnDisc(Kate::Document *, bool, unsigned char)));
00233 
00234   sort();
00235   updateFileListLocations();
00236   updateActions ();
00237 }
00238 
00239 void KateFileList::slotDocumentDeleted (uint documentNumber)
00240 {
00241   TQListViewItem * item = firstChild();
00242   while( item ) {
00243     if ( ((KateFileListItem *)item)->documentNumber() == documentNumber )
00244     {
00245 //       m_viewHistory.removeRef( (KateFileListItem *)item );
00246 //       m_editHistory.removeRef( (KateFileListItem *)item );
00247 
00248       removeItem( item );
00249 
00250       break;
00251     }
00252     item = item->nextSibling();
00253   }
00254 
00255   updateFileListLocations();
00256   updateActions ();
00257 }
00258 
00259 void KateFileList::slotActivateView( TQListViewItem *item )
00260 {
00261   if ( ! item || item->rtti() != RTTI_KateFileListItem )
00262     return;
00263 
00264   KateFileListItem *i = ((KateFileListItem*)item);
00265   const KateDocumentInfo *info = KateDocManager::self()->documentInfo(i->document());
00266 
00267   if (info && info->modifiedOnDisc) {
00268     // Simulate mouse button release, otherwise the paused DND operation
00269     // will reactivate as soon as the mouse re-enters the list view!
00270     TQMouseEvent e(TQEvent::MouseButtonRelease, m_lastMouseDownPos, Qt::LeftButton, 0);
00271     contentsMouseReleaseEvent(&e);
00272   }
00273 
00274   viewManager->activateView( i->documentNumber() );
00275 }
00276 
00277 void KateFileList::slotModChanged (Kate::Document *doc)
00278 {
00279   if (!doc) return;
00280 
00281   TQListViewItem * item = firstChild();
00282   while( item )
00283   {
00284     if ( ((KateFileListItem *)item)->documentNumber() == doc->documentNumber() )
00285       break;
00286 
00287     item = item->nextSibling();
00288   }
00289 
00290   if ( ((KateFileListItem *)item)->document()->isModified() )
00291   {
00292     m_editHistory.removeRef( (KateFileListItem *)item );
00293     m_editHistory.prepend( (KateFileListItem *)item );
00294 
00295     for ( uint i=0; i <  m_editHistory.count(); i++ )
00296     {
00297       m_editHistory.at( i )->setEditHistPos( i+1 );
00298       repaintItem(  m_editHistory.at( i ) );
00299     }
00300   }
00301   else
00302     repaintItem( item );
00303 }
00304 
00305 void KateFileList::slotModifiedOnDisc (Kate::Document *doc, bool, unsigned char)
00306 {
00307   slotModChanged( doc );
00308 }
00309 
00310 void KateFileList::slotNameChanged (Kate::Document *doc)
00311 {
00312   if (!doc) return;
00313 
00314   // ### using nextSibling to *only* look at toplevel items.
00315   // child items could be marks for example
00316   TQListViewItem * item = firstChild();
00317   while( item ) {
00318     if ( ((KateFileListItem*)item)->document() == doc )
00319     {
00320       item->setText( 0, doc->docName() );
00321       repaintItem( item );
00322       break;
00323     }
00324     item = item->nextSibling();
00325   }
00326   updateSort();
00327 }
00328 
00329 void KateFileList::slotViewChanged ()
00330 {
00331   if (!viewManager->activeView()) return;
00332 
00333   Kate::View *view = viewManager->activeView();
00334   uint dn = view->getDoc()->documentNumber();
00335 
00336   TQListViewItem * i = firstChild();
00337   while( i ) {
00338     if ( ((KateFileListItem *)i)->documentNumber() == dn )
00339     {
00340       break;
00341     }
00342     i = i->nextSibling();
00343   }
00344 
00345   if ( ! i )
00346     return;
00347 
00348   KateFileListItem *item = (KateFileListItem*)i;
00349   setCurrentItem( item );
00350 
00351   // ### During load of file lists, all the loaded views gets active.
00352   // Do something to avoid shading them -- maybe not creating views, just
00353   // open the documents???
00354 
00355 
00356 //   int p = 0;
00357 //   if (  m_viewHistory.count() )
00358 //   {
00359 //     int p =  m_viewHistory.findRef( item ); // only repaint items that needs it
00360 //   }
00361 
00362   m_viewHistory.removeRef( item );
00363   m_viewHistory.prepend( item );
00364 
00365   for ( uint i=0; i <  m_viewHistory.count(); i++ )
00366   {
00367     m_viewHistory.at( i )->setViewHistPos( i+1 );
00368     repaintItem(  m_viewHistory.at( i ) );
00369   }
00370 
00371   updateFileListLocations();
00372 }
00373 
00374 void KateFileList::updateFileListLocations()
00375 {
00376   TQListViewItem* item = firstChild();
00377   int i=0;
00378   while (item) {
00379     Kate::Document* itemDocument = ((KateFileListItem *)item)->document();
00380     if (m_sort == KateFileList::sortManual) {
00381       if (KateDocManager::self()->findDocument(itemDocument) >= 0) {
00382         itemDocument->setDocumentListPosition(i);
00383       }
00384     }
00385     else {
00386       if (KateDocManager::self()->findDocument(itemDocument) >= 0) {
00387         itemDocument->setDocumentListPosition(-1);
00388       }
00389     }
00390     item = item->itemBelow();
00391     i++;
00392   }
00393 }
00394 
00395 void KateFileList::slotMenu ( TQListViewItem *item, const TQPoint &p, int /*col*/ )
00396 {
00397   if (!item)
00398     return;
00399 
00400   m_clickedMenuItem = item;
00401   if (m_clickedMenuItem->itemAbove()) {
00402     listMoveFileUp->setEnabled(true);
00403   }
00404   else {
00405     listMoveFileUp->setEnabled(false);
00406   }
00407   if (m_clickedMenuItem->itemBelow()) {
00408     listMoveFileDown->setEnabled(true);
00409   }
00410   else {
00411     listMoveFileDown->setEnabled(false);
00412   }
00413 
00414   TQPopupMenu *menu = (TQPopupMenu*) ((viewManager->mainWindow())->factory()->container("filelist_popup", viewManager->mainWindow()));
00415 
00416   if (menu) {
00417     menu->exec(p);
00418   }
00419 }
00420 
00421 TQString KateFileList::tooltip( TQListViewItem *item, int )
00422 {
00423   KateFileListItem *i = ((KateFileListItem*)item);
00424   if ( ! i ) return TQString::null;
00425 
00426   TQString str;
00427   const KateDocumentInfo *info = KateDocManager::self()->documentInfo(i->document());
00428 
00429   if (info && info->modifiedOnDisc)
00430   {
00431     if (info->modifiedOnDiscReason == 1)
00432       str += i18n("<b>This file was changed (modified) on disk by another program.</b><br />");
00433     else if (info->modifiedOnDiscReason == 2)
00434       str += i18n("<b>This file was changed (created) on disk by another program.</b><br />");
00435     else if (info->modifiedOnDiscReason == 3)
00436       str += i18n("<b>This file was changed (deleted) on disk by another program.</b><br />");
00437   }
00438 
00439   str += i->document()->url().prettyURL();
00440   return str;
00441 }
00442 
00443 
00444 void KateFileList::setSortType (int s)
00445 {
00446   m_sort = s;
00447   if (m_sort == KateFileList::sortManual) {
00448     setSorting( -1, true );
00449     setDragEnabled(true);
00450     setAcceptDrops(true);
00451   }
00452   else {
00453     setSorting( 0, true );
00454     setDragEnabled(false);
00455     setAcceptDrops(false);
00456     updateSort ();
00457   }
00458 }
00459 
00460 void KateFileList::moveFileUp()
00461 {
00462   if (m_clickedMenuItem) {
00463     sortAction->setCurrentItem(KateFileList::sortManual);
00464     setSortType(KateFileList::sortManual);
00465     TQListViewItem* nitemabove = m_clickedMenuItem->itemAbove();
00466     if (nitemabove) {
00467       nitemabove = nitemabove->itemAbove();
00468       if (nitemabove) {
00469         m_clickedMenuItem->moveItem(nitemabove);
00470       }
00471       else {
00472         // Qt made this hard
00473         nitemabove = m_clickedMenuItem->itemAbove();
00474         nitemabove->moveItem(m_clickedMenuItem);
00475       }
00476     }
00477   }
00478   updateFileListLocations();
00479 }
00480 
00481 void KateFileList::moveFileDown()
00482 {
00483   if (m_clickedMenuItem) {
00484     sortAction->setCurrentItem(KateFileList::sortManual);
00485     setSortType(KateFileList::sortManual);
00486     TQListViewItem* nitemabove = m_clickedMenuItem->itemBelow();
00487     if (nitemabove) {
00488       m_clickedMenuItem->moveItem(nitemabove);
00489     }
00490   }
00491   updateFileListLocations();
00492 }
00493 
00494 void KateFileList::updateSort ()
00495 {
00496   sort ();
00497   updateFileListLocations();
00498 }
00499 
00500 void KateFileList::readConfig( TDEConfig *config, const TQString &group )
00501 {
00502   TQString oldgroup = config->group();
00503   config->setGroup( group );
00504 
00505   setSortType( config->readNumEntry( "Sort Type", sortByID ) );
00506   m_viewShade = config->readColorEntry( "View Shade", &m_viewShade );
00507   m_editShade = config->readColorEntry( "Edit Shade", &m_editShade );
00508   m_enableBgShading = config->readBoolEntry( "Shading Enabled", &m_enableBgShading );
00509 
00510   sortAction->setCurrentItem( sortType() );
00511 
00512   config->setGroup( oldgroup );
00513 }
00514 
00515 void KateFileList::writeConfig( TDEConfig *config, const TQString &group )
00516 {
00517   TQString oldgroup = config->group();
00518   config->setGroup( group );
00519 
00520   config->writeEntry( "Sort Type", m_sort );
00521   config->writeEntry( "View Shade", m_viewShade );
00522   config->writeEntry( "Edit Shade", m_editShade );
00523   config->writeEntry( "Shading Enabled", m_enableBgShading );
00524 
00525   config->setGroup( oldgroup );
00526 }
00527 
00528 void KateFileList::takeItem( TQListViewItem *item )
00529 {
00530   if ( item->rtti() == RTTI_KateFileListItem )
00531   {
00532     m_editHistory.removeRef( (KateFileListItem*)item );
00533     m_viewHistory.removeRef( (KateFileListItem*)item );
00534   }
00535   TQListView::takeItem( item );
00536 }
00537 //END KateFileList
00538 
00539 //BEGIN KateFileListItem
00540 KateFileListItem::KateFileListItem( TQListView* lv,
00541                     Kate::Document *_doc )
00542   : TQListViewItem( lv, _doc->docName() ),
00543     doc( _doc ),
00544     m_viewhistpos( 0 ),
00545     m_edithistpos( 0 ),
00546     m_docNumber( _doc->documentNumber() )
00547 {
00548   // Move this document to the end of the list where it belongs
00549   TQListViewItem* lastitem = lv->lastItem();
00550   if (lastitem) {
00551     moveItem(lastitem);
00552   }
00553 }
00554 
00555 KateFileListItem::~KateFileListItem()
00556 {
00557 }
00558 
00559 const TQPixmap *KateFileListItem::pixmap ( int column ) const
00560 {
00561   if ( column == 0) {
00562     static TQPixmap noPm = SmallIcon ("null");
00563     static TQPixmap modPm = SmallIcon("modified");
00564     static TQPixmap discPm = SmallIcon("modonhd");
00565     static TQPixmap modmodPm = SmallIcon("modmod");
00566 
00567     const KateDocumentInfo *info = KateDocManager::self()->documentInfo(doc);
00568 
00569     if (info && info->modifiedOnDisc)
00570       return doc->isModified() ? &modmodPm : &discPm;
00571     else
00572       return doc->isModified() ? &modPm : &noPm;
00573   }
00574 
00575   return 0;
00576 }
00577 
00578 void KateFileListItem::paintCell( TQPainter *painter, const TQColorGroup & cg, int column, int width, int align )
00579 {
00580   KateFileList *fl = (KateFileList*)listView();
00581   if ( ! fl ) return;
00582 
00583   if ( column == 0 )
00584   {
00585     TQColorGroup cgNew = cg;
00586 
00587     // replace the base color with a different shading if necessary...
00588     if ( fl->shadingEnabled() && m_viewhistpos > 1 )
00589     {
00590       TQColor b( cg.base() );
00591 
00592       TQColor shade = fl->viewShade();
00593       TQColor eshade = fl->editShade();
00594       int hc = fl->histCount();
00595       // If this file is in the edit history, blend in the eshade
00596       // color. The blend is weighted by the position in the editing history
00597       if ( fl->shadingEnabled() && m_edithistpos > 0 )
00598       {
00599         int ec = fl->editHistCount();
00600         int v = hc-m_viewhistpos;
00601         int e = ec-m_edithistpos+1;
00602         e = e*e;
00603         int n = TQMAX(v + e, 1);
00604         shade.setRgb(
00605             ((shade.red()*v) + (eshade.red()*e))/n,
00606             ((shade.green()*v) + (eshade.green()*e))/n,
00607             ((shade.blue()*v) + (eshade.blue()*e))/n
00608                     );
00609       }
00610       // blend in the shade color.
00611       // max transperancy < .5, latest is most colored.
00612       float t = (0.5/hc)*(hc-m_viewhistpos+1);
00613       b.setRgb(
00614           (int)((b.red()*(1-t)) + (shade.red()*t)),
00615           (int)((b.green()*(1-t)) + (shade.green()*t)),
00616           (int)((b.blue()*(1-t)) + (shade.blue()*t))
00617               );
00618 
00619       cgNew.setColor(TQColorGroup::Base, b);
00620     }
00621 
00622     TQListViewItem::paintCell( painter, cgNew, column, width, align );
00623   }
00624   else
00625     TQListViewItem::paintCell( painter, cg, column, width, align );
00626 }
00627 
00628 int KateFileListItem::compare ( TQListViewItem * i, int col, bool ascending ) const
00629 {
00630   if ( i->rtti() == RTTI_KateFileListItem )
00631   {
00632     switch( ((KateFileList*)listView())->sortType() )
00633     {
00634       case KateFileList::sortByID:
00635       {
00636 
00637         int d = (int)doc->documentNumber() - ((KateFileListItem*)i)->documentNumber();
00638         return ascending ? d : -d;
00639         break;
00640       }
00641       case KateFileList::sortByURL:
00642         return doc->url().prettyURL().compare( ((KateFileListItem*)i)->document()->url().prettyURL() );
00643         break;
00644       default:
00645         return TQListViewItem::compare( i, col, ascending );
00646     }
00647   }
00648   return 0;
00649 }
00650 //END KateFileListItem
00651 
00652 //BEGIN KFLConfigPage
00653 KFLConfigPage::KFLConfigPage( TQWidget* parent, const char *name, KateFileList *fl )
00654   :  Kate::ConfigPage( parent, name ),
00655     m_filelist( fl ),
00656     m_changed( false )
00657 {
00658   TQVBoxLayout *lo1 = new TQVBoxLayout( this );
00659   int spacing = KDialog::spacingHint();
00660   lo1->setSpacing( spacing );
00661 
00662   TQGroupBox *gb = new TQGroupBox( 1, Qt::Horizontal, i18n("Background Shading"), this );
00663   lo1->addWidget( gb );
00664 
00665   TQWidget *g = new TQWidget( gb );
00666   TQGridLayout *lo = new TQGridLayout( g, 2, 2 );
00667   lo->setSpacing( KDialog::spacingHint() );
00668   cbEnableShading = new TQCheckBox( i18n("&Enable background shading"), g );
00669   lo->addMultiCellWidget( cbEnableShading, 1, 1, 0, 1 );
00670 
00671   kcbViewShade = new KColorButton( g );
00672   lViewShade = new TQLabel( kcbViewShade, i18n("&Viewed documents' shade:"), g );
00673   lo->addWidget( lViewShade, 2, 0 );
00674   lo->addWidget( kcbViewShade, 2, 1 );
00675 
00676   kcbEditShade = new KColorButton( g );
00677   lEditShade = new TQLabel( kcbEditShade, i18n("&Modified documents' shade:"), g );
00678   lo->addWidget( lEditShade, 3, 0 );
00679   lo->addWidget( kcbEditShade, 3, 1 );
00680 
00681   // sorting
00682   TQHBox *hbSorting = new TQHBox( this );
00683   lo1->addWidget( hbSorting );
00684   lSort = new TQLabel( i18n("&Sort by:"), hbSorting );
00685   cmbSort = new TQComboBox( hbSorting );
00686   lSort->setBuddy( cmbSort );
00687   TQStringList l;
00688   l << i18n("Opening Order") << i18n("Document Name") << i18n("URL");
00689   cmbSort->insertStringList( l );
00690 
00691   lo1->insertStretch( -1, 10 );
00692 
00693   TQWhatsThis::add( cbEnableShading, i18n(
00694       "When background shading is enabled, documents that have been viewed "
00695       "or edited within the current session will have a shaded background. "
00696       "The most recent documents have the strongest shade.") );
00697   TQWhatsThis::add( kcbViewShade, i18n(
00698       "Set the color for shading viewed documents.") );
00699   TQWhatsThis::add( kcbEditShade, i18n(
00700       "Set the color for modified documents. This color is blended into "
00701       "the color for viewed files. The most recently edited documents get "
00702       "most of this color.") );
00703 
00704   TQWhatsThis::add( cmbSort, i18n(
00705       "Set the sorting method for the documents.") );
00706 
00707   reload();
00708 
00709   slotEnableChanged();
00710   connect( cbEnableShading, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotMyChanged()) );
00711   connect( cbEnableShading, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotEnableChanged()) );
00712   connect( kcbViewShade, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(slotMyChanged()) );
00713   connect( kcbEditShade, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(slotMyChanged()) );
00714   connect( cmbSort, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMyChanged()) );
00715 }
00716 
00717 void KFLConfigPage::apply()
00718 {
00719   if ( ! m_changed )
00720     return;
00721   m_changed = false;
00722 
00723   // Change settings in the filelist
00724   m_filelist->m_viewShade = kcbViewShade->color();
00725   m_filelist->m_editShade = kcbEditShade->color();
00726   m_filelist->m_enableBgShading = cbEnableShading->isChecked();
00727   m_filelist->setSortType( cmbSort->currentItem() );
00728   // repaint the affected items
00729   m_filelist->triggerUpdate();
00730 }
00731 
00732 void KFLConfigPage::reload()
00733 {
00734   // read in from config file
00735   TDEConfig *config = kapp->config();
00736   config->setGroup( "Filelist" );
00737   cbEnableShading->setChecked( config->readBoolEntry("Shading Enabled", &m_filelist->m_enableBgShading ) );
00738   kcbViewShade->setColor( config->readColorEntry("View Shade", &m_filelist->m_viewShade ) );
00739   kcbEditShade->setColor( config->readColorEntry("Edit Shade", &m_filelist->m_editShade ) );
00740   cmbSort->setCurrentItem( m_filelist->sortType() );
00741   m_changed = false;
00742 }
00743 
00744 void KFLConfigPage::slotEnableChanged()
00745 {
00746   kcbViewShade->setEnabled( cbEnableShading->isChecked() );
00747   kcbEditShade->setEnabled( cbEnableShading->isChecked() );
00748   lViewShade->setEnabled( cbEnableShading->isChecked() );
00749   lEditShade->setEnabled( cbEnableShading->isChecked() );
00750 }
00751 
00752 void KFLConfigPage::slotMyChanged()
00753 {
00754   m_changed = true;
00755   slotChanged();
00756 }
00757 
00758 //END KFLConfigPage
00759 
00760 
00761 // kate: space-indent on; indent-width 2; replace-tabs on;

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.7.6.1
This website is maintained by Timothy Pearson.