[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    Where to commit changes?
From:       Anders Lund <anders () alweb ! dk>
Date:       2002-03-27 2:27:37
[Download RAW message or body]

Hi,

I have a patch for the kate file selector that does the following
- changes to use KToolbar. It looks better and saves some work in the class, 
as it enables just plugging the actions of the dir operator into the toolbar, 
rather than duplicating buttons for them. It adds also reload and view type 
actions.

- resets some shortcuts of the dir operator, which clasthe with Kate:
  reload -> SHIFT + F5
  back -> ALT + SHIFT + Back
  forward -> ALT + SHIFT + Forward

There is a screenshot of it here: http://alweb.dk/katefileselector.png

The question is where to commit - to HEAD?

I think it should go into 3.0.1, as it does not make any new i18n strings, 
even there is a few problems:
- I can't find a way to make it not movable (setting toolbar->enableMoving( 
false ) affects all of kate's toolbars)
- the toolbar geometry management with the popup does not work.

I enclose a patch made against HEAD.

-anders
["fileselector.diff" (text/x-diff)]

Index: katefileselector.cpp
===================================================================
RCS file: /home/kde/kdebase/kate/app/katefileselector.cpp,v
retrieving revision 1.5
diff -u -r1.5 katefileselector.cpp
--- katefileselector.cpp	2002/02/23 19:38:52	1.5
+++ katefileselector.cpp	2002/03/27 02:23:29
@@ -27,6 +27,8 @@
 #include <qlabel.h>
 #include <qstrlist.h>
 #include <qtooltip.h>
+#include <qapplication.h>
+#include <qevent.h>
 
 #include <kiconloader.h>
 #include <kurlcombobox.h>
@@ -36,9 +38,13 @@
 #include <kconfig.h>
 #include <klocale.h>
 #include <kcombobox.h>
-
+#include <ktoolbar.h>
+#include <kaction.h>
 #include <kmessagebox.h>
 
+#include <kdebug.h>
+
+
 KateFileSelector::KateFileSelector( KateMainWindow *mainWindow, KateViewManager \
*viewManager,  QWidget * parent, const char * name )
     : QWidget(parent, name),
@@ -47,31 +53,9 @@
 {
   QVBoxLayout* lo = new QVBoxLayout(this);
 
-  QHBox *hlow = new QHBox (this);
-  lo->addWidget(hlow);
+  toolbar = new KToolBar( mainwin, this, false, "KateFileSelector::Toolbar" );
+  lo->addWidget( toolbar );
 
-  home = new QToolButton( hlow );
-  home->setIconSet(SmallIconSet("gohome"));
-  QToolTip::add(home, i18n("Home directory"));
-  up = new QToolButton( hlow );
-  up->setIconSet(SmallIconSet("up"));
-  QToolTip::add(up, i18n("Up one level"));
-  back = new QToolButton( hlow );
-  back->setIconSet(SmallIconSet("back"));
-  QToolTip::add(back, i18n("Previous directory"));
-  forward = new QToolButton( hlow );
-  forward->setIconSet(SmallIconSet("forward"));
-  QToolTip::add(forward, i18n("Next Directory"));
-
-  // HACK
-  QWidget* spacer = new QWidget(hlow);
-  hlow->setStretchFactor(spacer, 1);
-  hlow->setMaximumHeight(up->height());
-
-  cfdir = new QToolButton( hlow );
-  cfdir->setIconSet(SmallIconSet("curfiledir"));
-  QToolTip::add(cfdir, i18n("Current Document Directory"));
-
   cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" );
   cmbPath->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed \
));  KURLCompletion* cmpl = new KURLCompletion(KURLCompletion::DirCompletion);
@@ -80,11 +64,28 @@
 
   dir = new KDirOperator(QString::null, this, "operator");
   dir->setView(KFile::/*Simple*/Detail);
-  dir->actionCollection()->action( "delete" )->setShortcut (KShortcut \
(ALT+Key_Delete)); +
+  KActionCollection *coll = dir->actionCollection();
+  // some shortcuts of diroperator that clashes with Kate
+  coll->action( "delete" )->setShortcut( KShortcut( ALT + Key_Delete ) );
+  coll->action( "reload" )->setShortcut( KShortcut( ALT + Key_F5 ) );
+  coll->action( "back" )->setShortcut( KShortcut( ALT + SHIFT + Key_Left ) );
+  coll->action( "forward" )->setShortcut( KShortcut( ALT + SHIFT + Key_Right ) );
+  // some consistency - reset up for dir too
+  coll->action( "up" )->setShortcut( KShortcut( ALT + SHIFT + Key_Up ) );
+  coll->action( "home" )->setShortcut( KShortcut( CTRL + ALT + Key_Home ) );
+
+  coll->action( "up" )->plug( toolbar );
+  coll->action( "back" )->plug( toolbar );
+  coll->action( "forward" )->plug( toolbar );
+  coll->action( "home" )->plug( toolbar );
+  coll->action( "reload" )->plug( toolbar );
+  coll->action( "short view" )->plug( toolbar );
+  coll->action( "detailed view" )->plug( toolbar );
+
   lo->addWidget(dir);
   lo->setStretchFactor(dir, 2);
 
-
   QHBox* filterBox = new QHBox(this);
   filterIcon = new QLabel(filterBox);
   filterIcon->setPixmap( BarIcon("filter") );
@@ -96,11 +97,15 @@
   connect( filter, SIGNAL( activated(const QString&) ), SLOT( slotFilterChange(const \
QString&) ) );  connect( filter, SIGNAL( returnPressed(const QString&) ),filter, \
SLOT( addToHistory(const QString&) ) );  
-  connect( home, SIGNAL( clicked() ), dir, SLOT( home() ) );
-  connect( up, SIGNAL( clicked() ), dir, SLOT( cdUp() ) );
-  connect( back, SIGNAL( clicked() ), dir, SLOT( back() ) );
-  connect( forward, SIGNAL( clicked() ), dir, SLOT( forward() ) );
-  connect( cfdir, SIGNAL( clicked() ), this, SLOT( setCurrentDocDir() ) );
+  // kaction for the dir sync method
+  acSyncDir = new KAction( i18n("Current Document Directory"), "curfiledir", 0, \
this, SLOT( setCurrentDocDir() ), this, "sync_dir" ); +  acSyncDir->plug( toolbar );
+
+  toolbar->setIconText( KToolBar::IconOnly );
+  // Does not work :-((
+  //((QDockWindow*)toolbar)->setMovingEnabled( false ); // from QDockWindow
+  toolbar->adjustSize();
+  toolbar->setIconSize( 16 );
 
   connect( cmbPath, SIGNAL( urlActivated( const KURL&  )),
              this,  SLOT( cmbPathActivated( const KURL& ) ));
@@ -121,6 +126,7 @@
 {
 }
 
+
 void KateFileSelector::readConfig(KConfig *config, const QString & name)
 {
   dir->readConfig(config, name + ":dir");
@@ -186,12 +192,6 @@
 
 void KateFileSelector::dirFinishedLoading()
 {
-   // HACK - enable the nav buttons
-   // have to wait for diroperator...
-   up->setEnabled( dir->actionCollection()->action( "up" )->isEnabled() );
-   back->setEnabled( dir->actionCollection()->action( "back" )->isEnabled() );
-   forward->setEnabled( dir->actionCollection()->action( "forward" )->isEnabled() );
-   home->setEnabled( dir->actionCollection()->action( "home" )->isEnabled() );
 }
 
 void KateFileSelector::focusInEvent(QFocusEvent*)
@@ -199,6 +199,14 @@
    dir->setFocus();
 }
 
+void KateFileSelector::resizeEvent( QResizeEvent * )
+{
+  QSize sz( parentWidget()->parentWidget()->width(), toolbar->height() );
+  kdDebug()<<"New width should be "<<sz.width()<<endl;
+  QResizeEvent me( sz, toolbar->size() );
+  QApplication::sendEvent( toolbar, &me );
+}
+
 void KateFileSelector::setDir( KURL u )
 {
   dir->setURL(u, true);
@@ -215,6 +223,7 @@
 {
   // TODO: make sure the button is disabled if the directory is unreadable, eg the \
document URL  //       has protocol http
-  cfdir->setEnabled( ! mainwin->currentDocUrl().directory().isEmpty() );
+  //cfdir->setEnabled( ! mainwin->currentDocUrl().directory().isEmpty() );
+  acSyncDir->setEnabled( ! mainwin->currentDocUrl().directory().isEmpty() );
 }
 
Index: katefileselector.h
===================================================================
RCS file: /home/kde/kdebase/kate/app/katefileselector.h,v
retrieving revision 1.5
diff -u -r1.5 katefileselector.h
--- katefileselector.h	2002/01/22 12:04:30	1.5
+++ katefileselector.h	2002/03/27 02:23:29
@@ -36,10 +36,10 @@
                       QWidget * parent = 0, const char * name = 0 );
     ~KateFileSelector();
 
-    void readConfig(KConfig *, const QString &);
-    void writeConfig(KConfig *, const QString &);
-    void setView(KFile::FileView);
-    KDirOperator * dirOperator(){return dir;}
+    void readConfig( KConfig *, const QString & );
+    void writeConfig( KConfig *, const QString & );
+    void setView( KFile::FileView );
+    KDirOperator * dirOperator(){ return dir; }
 
   public slots:
     void slotFilterChange(const QString&);
@@ -54,15 +54,16 @@
     void kateViewChanged();
 
   protected:
-    void focusInEvent(QFocusEvent*);
+    void focusInEvent( QFocusEvent* );
+    void resizeEvent( QResizeEvent * );
 
   private:
     KURLComboBox *cmbPath;
     KHistoryCombo * filter;
     QLabel* filterIcon;
     KDirOperator * dir;
-    class QToolButton *home, *up, *back, *forward, *cfdir;
-    
+    class KAction *acSyncDir;
+    class KToolBar *toolbar;
     KateMainWindow *mainwin;
     KateViewManager *viewmanager;
 };


_______________________________________________
kwrite-devel mailing list
kwrite-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kwrite-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic