summaryrefslogtreecommitdiffstats
path: root/parts/fileselector
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /parts/fileselector
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'parts/fileselector')
-rw-r--r--parts/fileselector/Makefile.am18
-rw-r--r--parts/fileselector/README.dox13
-rw-r--r--parts/fileselector/fileselector_part.cpp108
-rw-r--r--parts/fileselector/fileselector_part.h40
-rw-r--r--parts/fileselector/fileselector_widget.cpp821
-rw-r--r--parts/fileselector/fileselector_widget.h203
-rw-r--r--parts/fileselector/kactionselector.cpp537
-rw-r--r--parts/fileselector/kactionselector.h399
-rw-r--r--parts/fileselector/kbookmarkhandler.cpp99
-rw-r--r--parts/fileselector/kbookmarkhandler.h70
-rw-r--r--parts/fileselector/kdevfileselector.desktop89
-rw-r--r--parts/fileselector/kdevpart_fileselector.rc8
12 files changed, 2405 insertions, 0 deletions
diff --git a/parts/fileselector/Makefile.am b/parts/fileselector/Makefile.am
new file mode 100644
index 00000000..f459fa79
--- /dev/null
+++ b/parts/fileselector/Makefile.am
@@ -0,0 +1,18 @@
+# Here resides the file selector part.
+
+INCLUDES = -I$(top_srcdir)/lib/interfaces -I$(top_srcdir)/lib/interfaces/extensions -I$(top_srcdir)/lib/util -I$(top_srcdir)/lib/sourceinfo $(all_includes)
+
+kde_module_LTLIBRARIES = libkdevfileselector.la
+libkdevfileselector_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN)
+libkdevfileselector_la_LIBADD = $(top_builddir)/lib/libkdevelop.la
+
+libkdevfileselector_la_SOURCES = fileselector_part.cpp fileselector_widget.cpp kactionselector.cpp kbookmarkhandler.cpp
+
+METASOURCES = AUTO
+
+servicedir = $(kde_servicesdir)
+service_DATA = kdevfileselector.desktop
+
+# not used currently
+#rcdir = $(kde_datadir)/kdevfileselector
+#rc_DATA = kdevfileselector.rc
diff --git a/parts/fileselector/README.dox b/parts/fileselector/README.dox
new file mode 100644
index 00000000..61a0047a
--- /dev/null
+++ b/parts/fileselector/README.dox
@@ -0,0 +1,13 @@
+/** \class FileSelectorPart
+Powerful network transparent file browser utility
+
+\authors <a href="mailto:anders.lund AT lund.tdcadsl.dk">Anders Lund</a> Copyright (C) 2001
+
+\maintainer <a href="mailto:jowenn AT kde.org">Joseph Wenninger</a> Copyright (C) 2001
+\maintainer <a href="mailto:cullmann AT kde.org">Christoph Cullmann</a> Copyright (C) 2001
+\maintainer <a href="mailto:roberto AT kdevelop.org">Roberto Raggi</a> Copyright (C) 2003
+\maintainer <a href="mailto:cloudtemple AT mksat.net">Alexander Dymo</a> Copyright (C) 2003
+
+\feature Powerful network transparent file browser utility
+
+*/
diff --git a/parts/fileselector/fileselector_part.cpp b/parts/fileselector/fileselector_part.cpp
new file mode 100644
index 00000000..20a3d27a
--- /dev/null
+++ b/parts/fileselector/fileselector_part.cpp
@@ -0,0 +1,108 @@
+#include "fileselector_part.h"
+
+#include <qwhatsthis.h>
+#include <qpushbutton.h>
+#include <qcheckbox.h>
+#include <qslider.h>
+#include <qvbox.h>
+
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kapplication.h>
+#include <kstandarddirs.h>
+#include <ktextbrowser.h>
+#include <kconfig.h>
+#include <kfileitem.h>
+#include <kdevgenericfactory.h>
+#include <kdiroperator.h>
+#include <kdialogbase.h>
+#include <kmessagebox.h>
+
+#include <kdevapi.h>
+#include <kdevcore.h>
+#include <kdevproject.h>
+#include <kdevmainwindow.h>
+#include <kdevpartcontroller.h>
+#include <kdevplugininfo.h>
+#include <kdevcreatefile.h>
+
+#include <ktip.h>
+
+#include "fileselector_widget.h"
+
+typedef KDevGenericFactory<FileSelectorPart> FileSelectorFactory;
+static const KDevPluginInfo data("kdevfileselector");
+K_EXPORT_COMPONENT_FACTORY( libkdevfileselector, FileSelectorFactory( data ) )
+
+FileSelectorPart::FileSelectorPart(QObject *parent, const char *name, const QStringList &)
+ : KDevPlugin(&data, parent, name ? name : "FileSelectorPart")
+{
+ setInstance(FileSelectorFactory::instance());
+
+ m_filetree = new KDevFileSelector( this, mainWindow(), partController(), 0, "fileselectorwidget" );
+
+ connect( m_filetree->dirOperator(), SIGNAL(fileSelected(const KFileItem*)),
+ this, SLOT(fileSelected(const KFileItem*)));
+ connect( core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) );
+
+ connect( core(), SIGNAL(configWidget(KDialogBase*)), this, SLOT(slotConfigWidget(KDialogBase*)) );
+
+ m_filetree->setCaption( i18n("File Selector") );
+ m_filetree->setIcon( SmallIcon( info()->icon() ) );
+ mainWindow()->embedSelectView( m_filetree, i18n("File Selector"), i18n("File selector") );
+ QWhatsThis::add(m_filetree, i18n("<b>File selector</b><p>This file selector lists directory contents and provides some file management functions."));
+
+ m_filetree->readConfig( instance()->config(), "fileselector" );
+
+ m_newFileAction = new KAction(i18n("New File..."), CTRL+ALT+SHIFT+Key_N, this, SLOT(newFile()), this);
+}
+
+FileSelectorPart::~FileSelectorPart()
+{
+ if (m_filetree){
+ mainWindow()->removeView( m_filetree );
+ }
+
+ delete (KDevFileSelector*) m_filetree;
+}
+
+void FileSelectorPart::fileSelected( const KFileItem * file )
+{
+ KURL u(file->url());
+
+ partController()->editDocument( u );
+}
+
+void FileSelectorPart::slotProjectOpened()
+{
+ KURL u;
+ u.setPath( project()->projectDirectory() );
+ m_filetree->setDir( u );
+}
+
+void FileSelectorPart::slotConfigWidget( KDialogBase * dlg )
+{
+ QVBox* vbox = dlg->addVBoxPage( i18n("File Selector"), i18n("File Selector"), BarIcon( info()->icon(), KIcon::SizeMedium) );
+ KFSConfigPage* page = new KFSConfigPage( vbox, 0, m_filetree );
+ connect( dlg, SIGNAL( okClicked( ) ), page, SLOT( apply( ) ) );
+ // ### implement reload
+}
+
+void FileSelectorPart::newFile()
+{
+ KDevCreateFile *creator = extension<KDevCreateFile>("KDevelop/CreateFile");
+ if (creator)
+ {
+ KDevCreateFile::CreatedFile file = creator->createNewFile("",
+ m_filetree->dirOperator()->url().path());
+ if (file.status == KDevCreateFile::CreatedFile::STATUS_NOTCREATED)
+ KMessageBox::error(0, i18n("Cannot create file. Check whether the directory and filename are valid."));
+ else if (file.status != KDevCreateFile::CreatedFile::STATUS_CANCELED)
+ {
+ partController()->editDocument(KURL::fromPathOrURL(
+ file.dir + "/" + file.filename));
+ }
+ }
+}
+
+#include "fileselector_part.moc"
diff --git a/parts/fileselector/fileselector_part.h b/parts/fileselector/fileselector_part.h
new file mode 100644
index 00000000..d12befb2
--- /dev/null
+++ b/parts/fileselector/fileselector_part.h
@@ -0,0 +1,40 @@
+#ifndef __KDEVPART_FILESELECTOR_H__
+#define __KDEVPART_FILESELECTOR_H__
+
+#include <kdevplugin.h>
+
+#include <kdialogbase.h>
+#include <kfileitem.h>
+
+#include <qguardedptr.h>
+
+class KDevFileSelector;
+class KDialogBase;
+
+class FileSelectorPart : public KDevPlugin
+{
+ Q_OBJECT
+public:
+ FileSelectorPart(QObject *parent, const char *name, const QStringList &);
+ virtual ~FileSelectorPart();
+
+ KAction *newFileAction() const { return m_newFileAction; }
+
+public slots:
+// void showTip();
+// void showOnStart();
+// void refresh();
+ void newFile();
+ void fileSelected(const KFileItem *file);
+
+private slots:
+ void slotProjectOpened();
+ void slotConfigWidget( KDialogBase * );
+
+private:
+ QGuardedPtr<KDevFileSelector> m_filetree;
+ KAction *m_newFileAction;
+};
+
+
+#endif
diff --git a/parts/fileselector/fileselector_widget.cpp b/parts/fileselector/fileselector_widget.cpp
new file mode 100644
index 00000000..41fab166
--- /dev/null
+++ b/parts/fileselector/fileselector_widget.cpp
@@ -0,0 +1,821 @@
+/* This file is part of the KDE project
+ Copyright (C) 2003 Alexander Dymo <cloudtemple@mksat.net>
+ Copyright (C) 2003 Roberto Raggi <roberto@kdevelop.org>
+ Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
+ Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
+ Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+//BEGIN Includes
+#include "fileselector_part.h"
+#include "fileselector_widget.h"
+#include "kactionselector.h"
+#include "kbookmarkhandler.h"
+
+#include <kdevcore.h>
+#include <kdevmainwindow.h>
+#include <kdevpartcontroller.h>
+
+#include <qlayout.h>
+#include <qtoolbutton.h>
+#include <qhbox.h>
+#include <qvbox.h>
+#include <qlabel.h>
+#include <qstrlist.h>
+#include <qtooltip.h>
+#include <qwhatsthis.h>
+#include <qapplication.h>
+#include <qlistbox.h>
+#include <qscrollbar.h>
+#include <qspinbox.h>
+#include <qgroupbox.h>
+#include <qcheckbox.h>
+#include <qregexp.h>
+#include <qdockarea.h>
+#include <qtimer.h>
+
+#include <ktexteditor/document.h>
+
+#include <kmainwindow.h>
+#include <kapplication.h>
+#include <kiconloader.h>
+#include <kurlcombobox.h>
+#include <kurlcompletion.h>
+#include <kprotocolinfo.h>
+#include <kconfig.h>
+#include <klocale.h>
+#include <kcombobox.h>
+#include <kaction.h>
+#include <kmessagebox.h>
+#include <ktoolbarbutton.h>
+#include <qtoolbar.h>
+#include <kpopupmenu.h>
+#include <kdialog.h>
+#include <kio/netaccess.h>
+
+#include <kdebug.h>
+//END Includes
+
+
+// from kfiledialog.cpp - avoid qt warning in STDERR (~/.xsessionerrors)
+static void silenceQToolBar(QtMsgType, const char *)
+{}
+
+
+KDevFileSelectorToolBar::KDevFileSelectorToolBar(QWidget *parent)
+ : KToolBar( parent, "KDev FileSelector Toolbar", true )
+{
+ setMinimumWidth(10);
+}
+
+KDevFileSelectorToolBar::~KDevFileSelectorToolBar()
+{}
+
+void KDevFileSelectorToolBar::setMovingEnabled( bool)
+{
+ KToolBar::setMovingEnabled(false);
+}
+
+
+KDevFileSelectorToolBarParent::KDevFileSelectorToolBarParent(QWidget *parent)
+ :QFrame(parent),m_tb(0)
+{}
+KDevFileSelectorToolBarParent::~KDevFileSelectorToolBarParent()
+{}
+void KDevFileSelectorToolBarParent::setToolBar(KDevFileSelectorToolBar *tb)
+{
+ m_tb=tb;
+}
+
+void KDevFileSelectorToolBarParent::resizeEvent ( QResizeEvent * )
+{
+ if (m_tb)
+ {
+ setMinimumHeight(m_tb->sizeHint().height());
+ m_tb->resize(width(),height());
+ }
+}
+
+
+//BEGIN Constructor/destructor
+
+KDevFileSelector::KDevFileSelector( FileSelectorPart *part, KDevMainWindow *mainWindow,
+ KDevPartController *partController,
+ QWidget * parent, const char * name )
+ : QWidget(parent, name),
+ m_part(part),
+ mainwin(mainWindow),
+ partController(partController)
+{
+ mActionCollection = new KActionCollection( this );
+
+ QVBoxLayout* lo = new QVBoxLayout(this);
+
+ QtMsgHandler oldHandler = qInstallMsgHandler( silenceQToolBar );
+
+ KDevFileSelectorToolBarParent *tbp=new KDevFileSelectorToolBarParent(this);
+ toolbar = new KDevFileSelectorToolBar(tbp);
+ tbp->setToolBar(toolbar);
+ lo->addWidget(tbp);
+ toolbar->setMovingEnabled(false);
+ toolbar->setFlat(true);
+ qInstallMsgHandler( oldHandler );
+
+ cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" );
+ cmbPath->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
+ KURLCompletion* cmpl = new KURLCompletion(KURLCompletion::DirCompletion);
+ cmbPath->setCompletionObject( cmpl );
+ lo->addWidget(cmbPath);
+ cmbPath->listBox()->installEventFilter( this );
+
+ dir = new KDevDirOperator(m_part, KURL(), this, "operator");
+ dir->setView(KFile::/*Simple*/Detail);
+
+ KActionCollection *coll = dir->actionCollection();
+ // some shortcuts of diroperator that clashes with KDev
+ 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 ) );
+
+ lo->addWidget(dir);
+ lo->setStretchFactor(dir, 2);
+
+ // bookmarks action!
+ KActionMenu *acmBookmarks = new KActionMenu( i18n("Bookmarks"), "bookmark",
+ mActionCollection, "bookmarks" );
+ acmBookmarks->setDelayed( false );
+
+ bookmarkHandler = new KBookmarkHandler( this, acmBookmarks->popupMenu() );
+
+ QHBox* filterBox = new QHBox(this);
+
+ btnFilter = new QToolButton( filterBox );
+ btnFilter->setIconSet( SmallIconSet("filter" ) );
+ btnFilter->setToggleButton( true );
+ filter = new KHistoryCombo( true, filterBox, "filter");
+ filter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
+ filterBox->setStretchFactor(filter, 2);
+ connect( btnFilter, SIGNAL( clicked() ), this, SLOT( btnFilterClick() ) );
+ lo->addWidget(filterBox);
+
+ connect( filter, SIGNAL( activated(const QString&) ),
+ SLOT( slotFilterChange(const QString&) ) );
+
+ connect( filter, SIGNAL( textChanged(const QString&) ),
+ SLOT( slotFilterChange(const QString&) ) );
+ connect( filter, SIGNAL( returnPressed(const QString&) ),
+ filter, SLOT( addToHistory(const QString&) ) );
+
+ // kaction for the dir sync method
+ acSyncDir = new KAction( i18n("Current Document Directory"), "dirsynch", 0,
+ this, SLOT( setActiveDocumentDir() ), mActionCollection, "sync_dir" );
+ toolbar->setIconText( KToolBar::IconOnly );
+ toolbar->setIconSize( 16 );
+ toolbar->setEnableContextMenu( false );
+
+ connect( cmbPath, SIGNAL( urlActivated( const KURL& )),
+ this, SLOT( cmbPathActivated( const KURL& ) ));
+ connect( cmbPath, SIGNAL( returnPressed( const QString& )),
+ this, SLOT( cmbPathReturnPressed( const QString& ) ));
+ connect(dir, SIGNAL(urlEntered(const KURL&)),
+ this, SLOT(dirUrlEntered(const KURL&)) );
+
+ connect(dir, SIGNAL(finishedLoading()),
+ this, SLOT(dirFinishedLoading()) );
+
+ // enable dir sync button if current doc has a valid URL
+ connect ( partController, SIGNAL(activePartChanged(KParts::Part*) ),
+ this, SLOT(viewChanged() ) );
+
+ // Connect the bookmark handler
+ connect( bookmarkHandler, SIGNAL( openURL( const QString& )),
+ this, SLOT( setDir( const QString& ) ) );
+
+ waitingUrl = QString::null;
+
+ // whatsthis help
+ QWhatsThis::add
+ ( cmbPath,
+ i18n("<p>Here you can enter a path for a directory to display."
+ "<p>To go to a directory previously entered, press the arrow on "
+ "the right and choose one. <p>The entry has directory "
+ "completion. Right-click to choose how completion should behave.") );
+ QWhatsThis::add
+ ( filter,
+ i18n("<p>Here you can enter a name filter to limit which files are displayed."
+ "<p>To clear the filter, toggle off the filter button to the left."
+ "<p>To reapply the last filter used, toggle on the filter button." ) );
+ QWhatsThis::add
+ ( btnFilter,
+ i18n("<p>This button clears the name filter when toggled off, or "
+ "reapplies the last filter used when toggled on.") );
+}
+
+KDevFileSelector::~KDevFileSelector()
+{
+ writeConfig( m_part->instance()->config(), "fileselector" );
+}
+//END Constroctor/Destrctor
+
+//BEGIN Public Methods
+
+void KDevFileSelector::readConfig(KConfig *config, const QString & name)
+{
+ dir->readConfig(config, name + ":dir");
+ dir->setView( KFile::Default );
+
+ config->setGroup( name );
+
+ // set up the toolbar
+ setupToolbar( config );
+
+ cmbPath->setMaxItems( config->readNumEntry( "pathcombo history len", 9 ) );
+ cmbPath->setURLs( config->readPathListEntry("dir history") );
+ // if we restore history
+ if ( config->readBoolEntry( "restore location", true ) || kapp->isRestored() )
+ {
+ QString loc( config->readPathEntry( "location" ) );
+ if ( ! loc.isEmpty() )
+ {
+ waitingDir = loc;
+ QTimer::singleShot(0, this, SLOT(initialDirChangeHack()));
+ }
+ }
+
+ // else is automatic, as cmpPath->setURL is called when a location is entered.
+
+ filter->setMaxCount( config->readNumEntry( "filter history len", 9 ) );
+ filter->setHistoryItems( config->readListEntry("filter history"), true );
+ lastFilter = config->readEntry( "last filter" );
+ QString flt("");
+ if ( config->readBoolEntry( "restore last filter", true ) || kapp->isRestored() )
+ flt = config->readEntry("current filter");
+ filter->lineEdit()->setText( flt );
+ slotFilterChange( flt );
+
+ autoSyncEvents = config->readNumEntry( "AutoSyncEvents", 0 );
+ // connect events as needed
+ /// @todo - solve startup problem: no need to set location for each doc opened!
+ if ( autoSyncEvents & DocumentChanged )
+ connect( partController, SIGNAL( viewChanged() ), this, SLOT( autoSync() ) );
+
+ if ( autoSyncEvents & DocumentOpened )
+ connect( partController, SIGNAL( partAdded(KParts::Part*) ),
+ this, SLOT( autoSync(KParts::Part*) ) );
+
+}
+
+void KDevFileSelector::initialDirChangeHack()
+{
+ setDir( waitingDir );
+}
+
+void KDevFileSelector::setupToolbar( KConfig *config )
+{
+ toolbar->clear();
+ QStringList tbactions = config->readListEntry( "toolbar actions", ',' );
+ if ( tbactions.isEmpty() )
+ {
+ // resonable collection for default toolbar
+ tbactions << "up" << "back" << "forward" << "home" <<
+ "short view" << "detailed view" <<
+ "bookmarks" << "sync_dir";
+ }
+ KAction *ac;
+ for ( QStringList::Iterator it=tbactions.begin(); it != tbactions.end(); ++it )
+ {
+ if ( *it == "bookmarks" || *it == "sync_dir" )
+ ac = mActionCollection->action( (*it).latin1() );
+ else
+ ac = dir->actionCollection()->action( (*it).latin1() );
+ if ( ac )
+ ac->plug( toolbar );
+ }
+}
+
+void KDevFileSelector::writeConfig(KConfig *config, const QString & name)
+{
+ dir->writeConfig(config,name + ":dir");
+
+ config->setGroup( name );
+ config->writeEntry( "pathcombo history len", cmbPath->maxItems() );
+ QStringList l;
+ for (int i = 0; i < cmbPath->count(); i++)
+ {
+ l.append( cmbPath->text( i ) );
+ }
+ config->writePathEntry( "dir history", l );
+ config->writePathEntry( "location", cmbPath->currentText() );
+
+ config->writeEntry( "filter history len", filter->maxCount() );
+ config->writeEntry( "filter history", filter->historyItems() );
+ config->writeEntry( "current filter", filter->currentText() );
+ config->writeEntry( "last filter", lastFilter );
+ config->writeEntry( "AutoSyncEvents", autoSyncEvents );
+}
+
+void KDevFileSelector::setView(KFile::FileView view)
+{
+ dir->setView(view);
+}
+
+//END Public Methods
+
+//BEGIN Public Slots
+
+void KDevFileSelector::slotFilterChange( const QString & nf )
+{
+ QToolTip::remove( btnFilter );
+ QString f = nf.stripWhiteSpace();
+ bool empty = f.isEmpty() || f == "*";
+ if ( empty )
+ {
+ dir->clearFilter();
+ filter->lineEdit()->setText( QString::null );
+ QToolTip::add
+ ( btnFilter,
+ QString( i18n("Apply last filter (\"%1\")") ).arg( lastFilter ) );
+ }
+ else
+ {
+ if ( !f.startsWith( "*" ) )
+ f.prepend( '*' );
+ if ( !f.endsWith( "*" ) )
+ f.append( '*' );
+ dir->setNameFilter( f );
+ lastFilter = f;
+ QToolTip::add
+ ( btnFilter, i18n("Clear filter") );
+ }
+ btnFilter->setOn( !empty );
+ dir->updateDir();
+ // this will be never true after the filter has been used;)
+ btnFilter->setEnabled( !( empty && lastFilter.isEmpty() ) );
+
+}
+void KDevFileSelector::setDir( KURL u )
+{
+ dir->setURL(u, true);
+}
+
+//END Public Slots
+
+//BEGIN Private Slots
+
+void KDevFileSelector::cmbPathActivated( const KURL& u )
+{
+ cmbPathReturnPressed( u.url() );
+}
+
+void KDevFileSelector::cmbPathReturnPressed( const QString& u )
+{
+ QStringList urls = cmbPath->urls();
+ urls.remove( u );
+ urls.prepend( u );
+ cmbPath->setURLs( urls, KURLComboBox::RemoveBottom );
+ dir->setFocus();
+ dir->setURL( KURL(u), true );
+}
+
+void KDevFileSelector::dirUrlEntered( const KURL& u )
+{
+ cmbPath->setURL( u );
+}
+
+void KDevFileSelector::dirFinishedLoading()
+{}
+
+
+/*
+ When the button in the filter box toggles:
+ If off:
+ If the name filer is anything but "" or "*", reset it.
+ If on:
+ Set last filter.
+*/
+void KDevFileSelector::btnFilterClick()
+{
+ if ( !btnFilter->isOn() )
+ {
+ slotFilterChange( QString::null );
+ }
+ else
+ {
+ filter->lineEdit()->setText( lastFilter );
+ slotFilterChange( lastFilter );
+ }
+}
+
+
+void KDevFileSelector::autoSync()
+{
+ kdDebug()<<"KDevFileSelector::autoSync()"<<endl;
+ // if visible, sync
+ if ( isVisible() )
+ {
+ setActiveDocumentDir();
+ waitingUrl = QString::null;
+ }
+ // else set waiting url
+ else
+ {
+ KURL u = activeDocumentUrl();
+ if (!u.isEmpty())
+ waitingUrl = u.directory();
+ }
+}
+
+void KDevFileSelector::autoSync( KParts::Part *part )
+{
+ KTextEditor::Document* doc = dynamic_cast<KTextEditor::Document*>( part );
+ if( !doc )
+ return;
+
+ // as above, but using document url.
+ kdDebug()<<"KDevFileSelector::autoSync( KTextEditor::Document )"<<endl;
+ KURL u ( doc->url() );
+ if ( u.isEmpty() )
+ {
+ waitingUrl = QString::null;
+ return;
+ }
+ if ( isVisible() )
+ {
+ setDir( u.directory() );
+ waitingUrl = QString::null;
+ }
+ else
+ {
+ waitingUrl = u.directory();
+ }
+}
+/// \FIXME crash on shutdown
+void KDevFileSelector::setActiveDocumentDir()
+{
+ //kdDebug()<<"KDevFileSelector::setActiveDocumentDir()"<<endl;
+ KURL u = activeDocumentUrl();
+ if (!u.isEmpty())
+ setDir( u.upURL() );
+}
+
+void KDevFileSelector::viewChanged()
+{
+ /// @todo make sure the button is disabled if the directory is unreadable, eg
+ /// the document URL has protocol http
+ acSyncDir->setEnabled( ! activeDocumentUrl().directory().isEmpty() );
+}
+
+//END Private Slots
+
+//BEGIN Protected
+
+void KDevFileSelector::focusInEvent( QFocusEvent * )
+{
+ dir->setFocus();
+}
+
+void KDevFileSelector::showEvent( QShowEvent * )
+{
+ // sync if we should
+ if ( autoSyncEvents & GotVisible )
+ {
+ kdDebug()<<"syncing fs on show"<<endl;
+ setActiveDocumentDir();
+ waitingUrl = QString::null;
+ }
+ // else, if we have a waiting URL set it
+ else if ( ! waitingUrl.isEmpty() )
+ {
+ setDir( waitingUrl );
+ waitingUrl = QString::null;
+ }
+}
+
+bool KDevFileSelector::eventFilter( QObject* o, QEvent *e )
+{
+ /*
+ This is rather unfortunate, but:
+ QComboBox does not support setting the size of the listbox to something
+ resonable. Even using listbox->setVariableWidth() does not yeld a
+ satisfying result, something is wrong with the handling of the sizehint.
+ And the popup is rather useless, if the paths are only partly visible.
+ */
+ QListBox *lb = cmbPath->listBox();
+ if ( o == lb && e->type() == QEvent::Show )
+ {
+ int add
+ = lb->height() < lb->contentsHeight() ? lb->verticalScrollBar()->width() : 0;
+ int w = QMIN( mainwin->main()->width(), lb->contentsWidth() + add );
+ lb->resize( w, lb->height() );
+ /// @todo - move the listbox to a suitable place if nessecary
+ /// @todo - decide if it is worth caching the size while untill the contents
+ /// are changed.
+ }
+ /// @todo - same thing for the completion popup?
+ return QWidget::eventFilter( o, e );
+}
+
+//END Protected
+
+//BEGIN ACtionLBItem
+/*
+ QListboxItem that can store and return a string,
+ used for the toolbar action selector.
+*/
+class ActionLBItem : public QListBoxPixmap
+{
+public:
+ ActionLBItem( QListBox *lb=0,
+ const QPixmap &pm = QPixmap(),
+ const QString &text=QString::null,
+ const QString &str=QString::null ) :
+ QListBoxPixmap( lb, pm, text ),
+ _str(str)
+ {}
+ ;
+ QString idstring()
+ {
+ return _str;
+ };
+private:
+ QString _str;
+};
+
+KURL KDevFileSelector::activeDocumentUrl( )
+{
+ KParts::ReadOnlyPart * part = dynamic_cast<KParts::ReadOnlyPart*>( partController->activePart() );
+ if ( part )
+ {
+ return part->url();
+ }
+
+ return KURL();
+}
+//END ActionLBItem
+
+//BEGIN KFSConfigPage
+////////////////////////////////////////////////////////////////////////////////
+// KFSConfigPage implementation
+////////////////////////////////////////////////////////////////////////////////
+KFSConfigPage::KFSConfigPage( QWidget *parent, const char *name, KDevFileSelector *kfs )
+ : QWidget( parent, name ),
+ fileSelector( kfs ),
+ bDirty( false )
+{
+ QVBoxLayout *lo = new QVBoxLayout( this );
+ int spacing = KDialog::spacingHint();
+ lo->setSpacing( spacing );
+
+ // Toolbar - a lot for a little...
+ QGroupBox *gbToolbar = new QGroupBox( 1, Qt::Vertical, i18n("Toolbar"), this );
+ acSel = new KActionSelector( gbToolbar );
+ acSel->setAvailableLabel( i18n("A&vailable actions:") );
+ acSel->setSelectedLabel( i18n("S&elected actions:") );
+ lo->addWidget( gbToolbar );
+ connect( acSel, SIGNAL( added( QListBoxItem * ) ), this, SLOT( slotChanged() ) );
+ connect( acSel, SIGNAL( removed( QListBoxItem * ) ), this, SLOT( slotChanged() ) );
+ connect( acSel, SIGNAL( movedUp( QListBoxItem * ) ), this, SLOT( slotChanged() ) );
+ connect( acSel, SIGNAL( movedDown( QListBoxItem * ) ), this, SLOT( slotChanged() ) );
+
+ // Sync
+ QGroupBox *gbSync = new QGroupBox( 1, Qt::Horizontal, i18n("Auto Synchronization"), this );
+ cbSyncActive = new QCheckBox( i18n("When a docu&ment becomes active"), gbSync );
+ cbSyncOpen = new QCheckBox( i18n("When a document is o&pened"), gbSync );
+ cbSyncShow = new QCheckBox( i18n("When the file selector becomes visible"), gbSync );
+ lo->addWidget( gbSync );
+ connect( cbSyncActive, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
+ connect( cbSyncOpen, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
+ connect( cbSyncShow, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
+
+ // Histories
+ QHBox *hbPathHist = new QHBox ( this );
+ QLabel *lbPathHist = new QLabel( i18n("Remember &locations:"), hbPathHist );
+ sbPathHistLength = new QSpinBox( hbPathHist );
+ lbPathHist->setBuddy( sbPathHistLength );
+ lo->addWidget( hbPathHist );
+ connect( sbPathHistLength, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
+
+ QHBox *hbFilterHist = new QHBox ( this );
+ QLabel *lbFilterHist = new QLabel( i18n("Remember &filters:"), hbFilterHist );
+ sbFilterHistLength = new QSpinBox( hbFilterHist );
+ lbFilterHist->setBuddy( sbFilterHistLength );
+ lo->addWidget( hbFilterHist );
+ connect( sbFilterHistLength, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
+
+ // Session
+ QGroupBox *gbSession = new QGroupBox( 1, Qt::Horizontal, i18n("Session"), this );
+ cbSesLocation = new QCheckBox( i18n("Restore loca&tion"), gbSession );
+ cbSesFilter = new QCheckBox( i18n("Restore last f&ilter"), gbSession );
+ lo->addWidget( gbSession );
+ connect( cbSesLocation, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
+ connect( cbSesFilter, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
+
+ // make it look nice
+ lo->addStretch( 1 );
+
+ // be helpfull
+ /*
+ QWhatsThis::add( lbAvailableActions, i18n(
+ "<p>Available actions for the toolbar. To add an action, select it here "
+ "and press the add (<strong>-&gt;</strong>) button" ) );
+ QWhatsThis::add( lbUsedActions, i18n(
+ "<p>Actions used in the toolbar. To remove an action, select it and "
+ "press the remove (<strong>&lt;-</strong>) button."
+ "<p>To change the order of the actions, use the Up and Down buttons to "
+ "move the selected action.") );
+ */
+ QString lhwt( i18n(
+ "<p>Decides how many locations to keep in the history of the location "
+ "combo box") );
+ QWhatsThis::add
+ ( lbPathHist, lhwt );
+ QWhatsThis::add
+ ( sbPathHistLength, lhwt );
+ QString fhwt( i18n(
+ "<p>Decides how many filters to keep in the history of the filter "
+ "combo box") );
+ QWhatsThis::add
+ ( lbFilterHist, fhwt );
+ QWhatsThis::add
+ ( sbFilterHistLength, fhwt );
+ QString synwt( i18n(
+ "<p>These options allow you to have the File Selector automatically "
+ "change location to the directory of the active document on certain "
+ "events."
+ "<p>Auto synchronization is <em>lazy</em>, meaning it will not take "
+ "effect until the file selector is visible."
+ "<p>None of these are enabled by default, but you can always sync the "
+ "location by pressing the sync button in the toolbar.") );
+ QWhatsThis::add
+ ( gbSync, synwt );
+ QWhatsThis::add
+ ( cbSesLocation, i18n(
+ "<p>If this option is enabled (default), the location will be restored "
+ "when you start KDev.<p><strong>Note</strong> that if the session is "
+ "handled by the KDE session manager, the location is always restored.") );
+ QWhatsThis::add
+ ( cbSesFilter, i18n(
+ "<p>If this option is enabled (default), the current filter will be "
+ "restored when you start KDev.<p><strong>Note</strong> that if the "
+ "session is handled by the KDE session manager, the filter is always "
+ "restored."
+ "<p><strong>Note</strong> that some of the autosync settings may "
+ "override the restored location if on.") );
+
+ init();
+
+}
+
+void KFSConfigPage::apply()
+{
+ KConfig *config = fileSelector->m_part->instance()->config();
+ config->setGroup( "fileselector" );
+ // toolbar
+ QStringList l;
+ QListBoxItem *item = acSel->selectedListBox()->firstItem();
+ ActionLBItem *aItem;
+ while ( item )
+ {
+ aItem = (ActionLBItem*)item;
+ if ( aItem )
+ {
+ l << aItem->idstring();
+ }
+ item = item->next();
+ }
+ config->writeEntry( "toolbar actions", l );
+ fileSelector->setupToolbar( config );
+ // sync
+ int s = 0;
+ if ( cbSyncActive->isChecked() )
+ s |= KDevFileSelector::DocumentChanged;
+ if ( cbSyncOpen->isChecked() )
+ s |= KDevFileSelector::DocumentOpened;
+ if ( cbSyncShow->isChecked() )
+ s |= KDevFileSelector::GotVisible;
+ fileSelector->autoSyncEvents = s;
+ // reset connections
+ disconnect( fileSelector->partController, 0, fileSelector, SLOT( autoSync() ) );
+ disconnect( fileSelector->partController, 0,
+ fileSelector, SLOT( autoSync( KParts::Part *) ) );
+ if ( s & KDevFileSelector::DocumentChanged )
+ connect( fileSelector->partController, SIGNAL( viewChanged() ),
+ fileSelector, SLOT( autoSync() ) );
+ if ( s & KDevFileSelector::DocumentOpened )
+ connect( fileSelector->partController,
+ SIGNAL( partAdded(KParts::Part *) ),
+ fileSelector, SLOT( autoSync(KParts::Part *) ) );
+
+ // histories
+ fileSelector->cmbPath->setMaxItems( sbPathHistLength->value() );
+ fileSelector->filter->setMaxCount( sbFilterHistLength->value() );
+ // session - theese are read/written directly to the app config,
+ // as they are not needed during operation.
+ config->writeEntry( "restore location", cbSesLocation->isChecked() );
+ config->writeEntry( "restore last filter", cbSesFilter->isChecked() );
+}
+
+void KFSConfigPage::reload()
+{
+ // hmm, what is this supposed to do, actually??
+ init();
+}
+
+void KFSConfigPage::init()
+{
+ KConfig *config = fileSelector->m_part->instance()->config();
+ config->setGroup( "fileselector" );
+ // toolbar
+ QStringList l = config->readListEntry( "toolbar actions", ',' );
+ if ( l.isEmpty() ) // default toolbar
+ l << "up" << "back" << "forward" << "home" <<
+ "short view" << "detailed view" <<
+ "bookmarks" << "sync_dir";
+
+ // actions from diroperator + two of our own
+ QStringList allActions;
+ allActions << "up" << "back" << "forward" << "home" <<
+ "reload" << "mkdir" << "delete" <<
+ "short view" << "detailed view" /*<< "view menu" <<
+ "show hidden" << "properties"*/ <<
+ "bookmarks" << "sync_dir";
+ QRegExp re("&(?=[^&])");
+ KAction *ac;
+ QListBox *lb;
+ for ( QStringList::Iterator it=allActions.begin(); it != allActions.end(); ++it )
+ {
+ lb = l.contains( *it ) ? acSel->selectedListBox() : acSel->availableListBox();
+ if ( *it == "bookmarks" || *it == "sync_dir" )
+ ac = fileSelector->actionCollection()->action( (*it).latin1() );
+ else
+ ac = fileSelector->dirOperator()->actionCollection()->action( (*it).latin1() );
+ if ( ac )
+ new ActionLBItem( lb, SmallIcon( ac->icon() ), ac->text().replace( re, "" ), *it );
+ }
+
+ // sync
+ int s = fileSelector->autoSyncEvents;
+ cbSyncActive->setChecked( s & KDevFileSelector::DocumentChanged );
+ cbSyncOpen->setChecked( s & KDevFileSelector::DocumentOpened );
+ cbSyncShow->setChecked( s & KDevFileSelector::GotVisible );
+ // histories
+ sbPathHistLength->setValue( fileSelector->cmbPath->maxItems() );
+ sbFilterHistLength->setValue( fileSelector->filter->maxCount() );
+ // session
+ cbSesLocation->setChecked( config->readBoolEntry( "restore location", true ) );
+ cbSesFilter->setChecked( config->readBoolEntry( "restore last filter", true ) );
+}
+
+void KFSConfigPage::slotChanged()
+{
+}
+
+//END KFSConfigPage
+
+
+//BEGIN KDevDirOperator
+
+void KDevDirOperator::activatedMenu( const KFileItem *fi, const QPoint & pos )
+{
+ setupMenu();
+ updateSelectionDependentActions();
+
+ KActionMenu * am = dynamic_cast<KActionMenu*>(actionCollection()->action("popupMenu"));
+ if (!am)
+ return;
+ KPopupMenu *popup = am->popupMenu();
+
+ popup->insertSeparator();
+ m_part->newFileAction()->plug(popup);
+
+ if (fi)
+ {
+ FileContext context( KURL::List(fi->url()));
+ if ( (m_part) && (m_part->core()))
+ m_part->core()->fillContextMenu(popup, &context);
+ }
+
+ popup->popup(pos);
+}
+
+//END KDevDirOperator
+
+#include "fileselector_widget.moc"
diff --git a/parts/fileselector/fileselector_widget.h b/parts/fileselector/fileselector_widget.h
new file mode 100644
index 00000000..cb194760
--- /dev/null
+++ b/parts/fileselector/fileselector_widget.h
@@ -0,0 +1,203 @@
+/* This file is part of the KDE project
+ Copyright (C) 2003 Roberto Raggi <roberto@kdevelop.org>
+ Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
+ Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
+ Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef FILESELECTOR_WIDGET_H
+#define FILESELECTOR_WIDGET_H
+
+#include <qwidget.h>
+#include <kfile.h>
+#include <kurl.h>
+#include <ktoolbar.h>
+#include <qframe.h>
+#include <kdiroperator.h>
+
+class KDevMainWindow;
+class KDevPartController;
+class FileSelectorPart;
+class KActionCollection;
+class KActionSelector;
+class KDirOperator;
+class KURLComboBox;
+class KHistoryCombo;
+
+namespace KParts
+{
+ class Part;
+}
+
+namespace KTextEditor
+{
+ class Document;
+}
+
+/*
+ The KDev file selector presents a directory view, in which the default action is
+ to open the activated file.
+ Additinally, a toolbar for managing the kdiroperator widget + sync that to
+ the directory of the current file is available, as well as a filter widget
+ allowing to filter the displayed files using a name filter.
+*/
+
+/* I think this fix for not moving toolbars is better */
+class KDevFileSelectorToolBar: public KToolBar
+{
+ Q_OBJECT
+public:
+ KDevFileSelectorToolBar(QWidget *parent);
+ virtual ~KDevFileSelectorToolBar();
+
+ virtual void setMovingEnabled( bool b );
+};
+
+class KDevFileSelectorToolBarParent: public QFrame
+{
+ Q_OBJECT
+public:
+ KDevFileSelectorToolBarParent(QWidget *parent);
+ ~KDevFileSelectorToolBarParent();
+ void setToolBar(KDevFileSelectorToolBar *tb);
+
+private:
+ KDevFileSelectorToolBar *m_tb;
+
+protected:
+ virtual void resizeEvent ( QResizeEvent * );
+};
+
+class KDevDirOperator: public KDirOperator
+{
+ Q_OBJECT
+public:
+ KDevDirOperator(FileSelectorPart *part, const KURL &urlName=KURL(), QWidget *parent=0, const char *name=0)
+ :KDirOperator(urlName, parent, name), m_part(part)
+ {
+ }
+
+protected slots:
+ virtual void activatedMenu (const KFileItem *fi, const QPoint &pos);
+
+private:
+ FileSelectorPart *m_part;
+};
+
+class KDevFileSelector : public QWidget
+{
+ Q_OBJECT
+
+ friend class KFSConfigPage;
+
+public:
+ /* When to sync to current document directory */
+ enum AutoSyncEvent { DocumentChanged=1, DocumentOpened=2, GotVisible=4 };
+
+ KDevFileSelector( FileSelectorPart *part, KDevMainWindow *mainWindow=0, KDevPartController *partController=0,
+ QWidget * parent = 0, const char * name = 0 );
+ ~KDevFileSelector();
+
+ void readConfig( KConfig *, const QString & );
+ void writeConfig( KConfig *, const QString & );
+ void setupToolbar( KConfig * );
+ void setView( KFile::FileView );
+ KDevDirOperator *dirOperator(){ return dir; }
+ KActionCollection *actionCollection() { return mActionCollection; };
+
+public slots:
+ void slotFilterChange(const QString&);
+ void setDir(KURL);
+ void setDir( const QString& url ) { setDir( KURL( url ) ); };
+
+private slots:
+ void cmbPathActivated( const KURL& u );
+ void cmbPathReturnPressed( const QString& u );
+ void dirUrlEntered( const KURL& u );
+ void dirFinishedLoading();
+ void setActiveDocumentDir();
+ void viewChanged();
+ void btnFilterClick();
+ void autoSync();
+ void autoSync( KParts::Part * );
+ void initialDirChangeHack();
+protected:
+ void focusInEvent( QFocusEvent * );
+ void showEvent( QShowEvent * );
+ bool eventFilter( QObject *, QEvent * );
+ KURL activeDocumentUrl();
+
+private:
+ class KDevFileSelectorToolBar *toolbar;
+ KActionCollection *mActionCollection;
+ class KBookmarkHandler *bookmarkHandler;
+ KURLComboBox *cmbPath;
+ KDevDirOperator * dir;
+ class KAction *acSyncDir;
+ KHistoryCombo * filter;
+ class QToolButton *btnFilter;
+
+ FileSelectorPart *m_part;
+ KDevMainWindow *mainwin;
+ KDevPartController *partController;
+
+ QString lastFilter;
+ int autoSyncEvents; // enabled autosync events
+ QString waitingUrl; // maybe display when we gets visible
+ QString waitingDir;
+};
+
+/* @todo anders
+ KFSFilterHelper
+ A popup widget presenting a listbox with checkable items
+ representing the mime types available in the current directory, and
+ providing a name filter based on those.
+*/
+
+/*
+ Config page for file selector.
+ Allows for configuring the toolbar, the history length
+ of the path and file filter combos, and how to handle
+ user closed session.
+*/
+class KFSConfigPage : public QWidget
+{
+ Q_OBJECT
+public:
+ KFSConfigPage( QWidget* parent=0, const char *name=0, KDevFileSelector *kfs=0);
+ virtual ~KFSConfigPage() {};
+
+public slots:
+ virtual void apply();
+ virtual void reload();
+ virtual void slotChanged();
+
+private:
+ void init();
+
+ KDevFileSelector *fileSelector;
+ bool bDirty;
+ //class QListBox *lbAvailableActions, *lbUsedActions;
+ KActionSelector *acSel;
+ class QSpinBox *sbPathHistLength, *sbFilterHistLength;
+ class QCheckBox *cbSyncOpen, *cbSyncActive, *cbSyncShow;
+ class QCheckBox *cbSesLocation, *cbSesFilter;
+};
+
+
+#endif
+
diff --git a/parts/fileselector/kactionselector.cpp b/parts/fileselector/kactionselector.cpp
new file mode 100644
index 00000000..5bf234a8
--- /dev/null
+++ b/parts/fileselector/kactionselector.cpp
@@ -0,0 +1,537 @@
+/* This file is part of the KDE project
+ Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+
+#include "kactionselector.h"
+
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kdialog.h> // for spacingHint()
+#include <kdebug.h>
+#include <qapplication.h>
+
+#include <qlistbox.h>
+#include <qtoolbutton.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qevent.h>
+#include <qwhatsthis.h>
+
+class KActionSelectorPrivate {
+ public:
+ QListBox *availableListBox, *selectedListBox;
+ QToolButton *btnAdd, *btnRemove, *btnUp, *btnDown;
+ QLabel *lAvailable, *lSelected;
+ bool moveOnDoubleClick, keyboardEnabled;
+ KActionSelector::ButtonIconSize iconSize;
+ QString addIcon, removeIcon, upIcon, downIcon;
+ KActionSelector::InsertionPolicy availableInsertionPolicy, selectedInsertionPolicy;
+ bool showUpDownButtons;
+};
+
+//BEGIN Constructor/destructor
+
+KActionSelector::KActionSelector( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ d = new KActionSelectorPrivate();
+ d->moveOnDoubleClick = true;
+ d->keyboardEnabled = true;
+ d->iconSize = SmallIcon;
+ d->addIcon = QApplication::reverseLayout() ? "back" : "forward";
+ d->removeIcon = QApplication::reverseLayout() ? "forward" : "back";
+ d->upIcon = "up";
+ d->downIcon = "down";
+ d->availableInsertionPolicy = Sorted;
+ d->selectedInsertionPolicy = BelowCurrent;
+ d->showUpDownButtons = true;
+
+ //int isz = IconSize( KIcon::Small );
+
+ QHBoxLayout *lo = new QHBoxLayout( this );
+ lo->setSpacing( KDialog::spacingHint() );
+
+ QVBoxLayout *loAv = new QVBoxLayout( lo );
+ d->lAvailable = new QLabel( i18n("&Available:"), this );
+ loAv->addWidget( d->lAvailable );
+ d->availableListBox = new QListBox( this );
+ loAv->addWidget( d->availableListBox );
+ d->lAvailable->setBuddy( d->availableListBox );
+
+ QVBoxLayout *loHBtns = new QVBoxLayout( lo );
+ loHBtns->addStretch( 1 );
+ d->btnAdd = new QToolButton( this );
+ loHBtns->addWidget( d->btnAdd );
+ d->btnRemove = new QToolButton( this );
+ loHBtns->addWidget( d->btnRemove );
+ loHBtns->addStretch( 1 );
+
+ QVBoxLayout *loS = new QVBoxLayout( lo );
+ d->lSelected = new QLabel( i18n("&Selected:"), this );
+ loS->addWidget( d->lSelected );
+ d->selectedListBox = new QListBox( this );
+ loS->addWidget( d->selectedListBox );
+ d->lSelected->setBuddy( d->selectedListBox );
+
+ QVBoxLayout *loVBtns = new QVBoxLayout( lo );
+ loVBtns->addStretch( 1 );
+ d->btnUp = new QToolButton( this );
+ loVBtns->addWidget( d->btnUp );
+ d->btnDown = new QToolButton( this );
+ loVBtns->addWidget( d->btnDown );
+ loVBtns->addStretch( 1 );
+
+ loadIcons();
+
+ connect( d->btnAdd, SIGNAL(clicked()), this, SLOT(buttonAddClicked()) );
+ connect( d->btnRemove, SIGNAL(clicked()), this, SLOT(buttonRemoveClicked()) );
+ connect( d->btnUp, SIGNAL(clicked()), this, SLOT(buttonUpClicked()) );
+ connect( d->btnDown, SIGNAL(clicked()), this, SLOT(buttonDownClicked()) );
+ connect( d->availableListBox, SIGNAL(doubleClicked(QListBoxItem*)),
+ this, SLOT(itemDoubleClicked(QListBoxItem*)) );
+ connect( d->selectedListBox, SIGNAL(doubleClicked(QListBoxItem*)),
+ this, SLOT(itemDoubleClicked(QListBoxItem*)) );
+ connect( d->availableListBox, SIGNAL(currentChanged(QListBoxItem*)),
+ this, SLOT(slotCurrentChanged(QListBoxItem *)) );
+ connect( d->selectedListBox, SIGNAL(currentChanged(QListBoxItem*)),
+ this, SLOT(slotCurrentChanged(QListBoxItem *)) );
+
+ d->availableListBox->installEventFilter( this );
+ d->selectedListBox->installEventFilter( this );
+}
+
+KActionSelector::~KActionSelector()
+{
+ delete d;
+}
+
+//END Constructor/destroctor
+
+//BEGIN Public Methods
+
+QListBox *KActionSelector::availableListBox()
+{
+ return d->availableListBox;
+}
+
+QListBox *KActionSelector::selectedListBox()
+{
+ return d->selectedListBox;
+}
+
+void KActionSelector::setButtonIcon( const QString &icon, MoveButton button )
+{
+ switch ( button )
+ {
+ case ButtonAdd:
+ d->addIcon = icon;
+ d->btnAdd->setIconSet( SmallIconSet( icon, d->iconSize ) );
+ break;
+ case ButtonRemove:
+ d->removeIcon = icon;
+ d->btnRemove->setIconSet( SmallIconSet( icon, d->iconSize ) );
+ break;
+ case ButtonUp:
+ d->upIcon = icon;
+ d->btnUp->setIconSet( SmallIconSet( icon, d->iconSize ) );
+ break;
+ case ButtonDown:
+ d->downIcon = icon;
+ d->btnDown->setIconSet( SmallIconSet( icon, d->iconSize ) );
+ break;
+ default:
+ kdDebug()<<"KActionSelector::setButtonIcon: DAINBREAD!"<<endl;
+ }
+}
+
+void KActionSelector::setButtonIconSet( const QIconSet &iconset, MoveButton button )
+{
+ switch ( button )
+ {
+ case ButtonAdd:
+ d->btnAdd->setIconSet( iconset );
+ break;
+ case ButtonRemove:
+ d->btnRemove->setIconSet( iconset );
+ break;
+ case ButtonUp:
+ d->btnUp->setIconSet( iconset );
+ break;
+ case ButtonDown:
+ d->btnDown->setIconSet( iconset );
+ break;
+ default:
+ kdDebug()<<"KActionSelector::setButtonIconSet: DAINBREAD!"<<endl;
+ }
+}
+
+void KActionSelector::setButtonTooltip( const QString &tip, MoveButton button )
+{
+ switch ( button )
+ {
+ case ButtonAdd:
+ d->btnAdd->setTextLabel( tip );
+ break;
+ case ButtonRemove:
+ d->btnRemove->setTextLabel( tip );
+ break;
+ case ButtonUp:
+ d->btnUp->setTextLabel( tip );
+ break;
+ case ButtonDown:
+ d->btnDown->setTextLabel( tip );
+ break;
+ default:
+ kdDebug()<<"KActionSelector::setButtonToolTip: DAINBREAD!"<<endl;
+ }
+}
+
+void KActionSelector::setButtonWhatsThis( const QString &text, MoveButton button )
+{
+ switch ( button )
+ {
+ case ButtonAdd:
+ QWhatsThis::add( d->btnAdd, text );
+ break;
+ case ButtonRemove:
+ QWhatsThis::add( d->btnRemove, text );
+ break;
+ case ButtonUp:
+ QWhatsThis::add( d->btnUp, text );
+ break;
+ case ButtonDown:
+ QWhatsThis::add( d->btnDown, text );
+ break;
+ default:
+ kdDebug()<<"KActionSelector::setButtonWhatsThis: DAINBREAD!"<<endl;
+ }
+}
+
+void KActionSelector::setButtonsEnabled()
+{
+ d->btnAdd->setEnabled( d->availableListBox->currentItem() > -1 );
+ d->btnRemove->setEnabled( d->selectedListBox->currentItem() > -1 );
+ d->btnUp->setEnabled( d->selectedListBox->currentItem() > 0 );
+ d->btnDown->setEnabled( d->selectedListBox->currentItem() > -1 &&
+ d->selectedListBox->currentItem() < (int)d->selectedListBox->count() - 1 );
+}
+
+//END Public Methods
+
+//BEGIN Properties
+
+bool KActionSelector::moveOnDoubleClick() const
+{
+ return d->moveOnDoubleClick;
+}
+
+void KActionSelector::setMoveOnDoubleClick( bool b )
+{
+ d->moveOnDoubleClick = b;
+}
+
+bool KActionSelector::keyboardEnabled() const
+{
+ return d->keyboardEnabled;
+}
+
+void KActionSelector::setKeyboardEnabled( bool b )
+{
+ d->keyboardEnabled = b;
+}
+
+QString KActionSelector::availableLabel() const
+{
+ return d->lAvailable->text();
+}
+
+void KActionSelector::setAvailableLabel( const QString &text )
+{
+ d->lAvailable->setText( text );
+}
+
+QString KActionSelector::selectedLabel() const
+{
+ return d->lSelected->text();
+}
+
+void KActionSelector::setSelectedLabel( const QString &text )
+{
+ d->lSelected->setText( text );
+}
+
+KActionSelector::ButtonIconSize KActionSelector::buttonIconSize() const
+{
+ return d->iconSize;
+}
+
+void KActionSelector::setButtonIconSize( ButtonIconSize size )
+{
+ d->iconSize = size;
+ // reload icons
+ loadIcons();
+}
+
+KActionSelector::InsertionPolicy KActionSelector::availableInsertionPolicy() const
+{
+ return d->availableInsertionPolicy;
+}
+
+void KActionSelector::setAvailableInsertionPolicy( InsertionPolicy p )
+{
+ d->availableInsertionPolicy = p;
+}
+
+KActionSelector::InsertionPolicy KActionSelector::selectedInsertionPolicy() const
+{
+ return d->selectedInsertionPolicy;
+}
+
+void KActionSelector::setSelectedInsertionPolicy( InsertionPolicy p )
+{
+ d->selectedInsertionPolicy = p;
+}
+
+bool KActionSelector::showUpDownButtons() const
+{
+ return d->showUpDownButtons;
+}
+
+void KActionSelector::setShowUpDownButtons( bool show )
+{
+ d->showUpDownButtons = show;
+ if ( show )
+ {
+ d->btnUp->show();
+ d->btnDown->show();
+ }
+ else
+ {
+ d->btnUp->hide();
+ d->btnDown->hide();
+ }
+}
+
+//END Properties
+
+//BEGIN Public Slots
+
+void KActionSelector::polish()
+{
+ setButtonsEnabled();
+}
+
+//END Public Slots
+
+//BEGIN Protected
+void KActionSelector::keyPressEvent( QKeyEvent *e )
+{
+ if ( ! d->keyboardEnabled ) return;
+ if ( (e->state() & Qt::ControlButton) )
+ {
+ switch ( e->key() )
+ {
+ case Key_Right:
+ buttonAddClicked();
+ break;
+ case Key_Left:
+ buttonRemoveClicked();
+ break;
+ case Key_Up:
+ buttonUpClicked();
+ break;
+ case Key_Down:
+ buttonDownClicked();
+ break;
+ default:
+ e->ignore();
+ return;
+ }
+ }
+}
+
+bool KActionSelector::eventFilter( QObject *o, QEvent *e )
+{
+ if ( d->keyboardEnabled && e->type() == QEvent::KeyPress )
+ {
+ if ( (((QKeyEvent*)e)->state() & Qt::ControlButton) )
+ {
+ switch ( ((QKeyEvent*)e)->key() )
+ {
+ case Key_Right:
+ buttonAddClicked();
+ break;
+ case Key_Left:
+ buttonRemoveClicked();
+ break;
+ case Key_Up:
+ buttonUpClicked();
+ break;
+ case Key_Down:
+ buttonDownClicked();
+ break;
+ default:
+ return QWidget::eventFilter( o, e );
+ break;
+ }
+ return true;
+ }
+ else if ( o->inherits( "QListBox" ) )
+ {
+ switch ( ((QKeyEvent*)e)->key() )
+ {
+ case Key_Return:
+ case Key_Enter:
+ QListBox *lb = (QListBox*)o;
+ int index = lb->currentItem();
+ if ( index < 0 ) break;
+ moveItem( lb->item( index ) );
+ return true;
+ }
+ }
+ }
+ return QWidget::eventFilter( o, e );
+}
+
+//END Protected
+
+//BEGIN Private Slots
+
+void KActionSelector::buttonAddClicked()
+{
+ // move all selected items from available to selected listbox
+ QListBoxItem *item = d->availableListBox->firstItem();
+ while ( item ) {
+ if ( item->isSelected() ) {
+ d->availableListBox->takeItem( item );
+ d->selectedListBox->insertItem( item, insertionIndex( d->selectedListBox, d->selectedInsertionPolicy ) );
+ d->selectedListBox->setCurrentItem( item );
+ emit added( item );
+ }
+ item = item->next();
+ }
+ if ( d->selectedInsertionPolicy == Sorted )
+ d->selectedListBox->sort();
+ d->selectedListBox->setFocus();
+}
+
+void KActionSelector::buttonRemoveClicked()
+{
+ // move all selected items from selected to available listbox
+ QListBoxItem *item = d->selectedListBox->firstItem();
+ while ( item ) {
+ if ( item->isSelected() ) {
+ d->selectedListBox->takeItem( item );
+ d->availableListBox->insertItem( item, insertionIndex( d->availableListBox, d->availableInsertionPolicy ) );
+ d->availableListBox->setCurrentItem( item );
+ emit removed( item );
+ }
+ item = item->next();
+ }
+ if ( d->availableInsertionPolicy == Sorted )
+ d->availableListBox->sort();
+ d->availableListBox->setFocus();
+}
+
+void KActionSelector::buttonUpClicked()
+{
+ int c = d->selectedListBox->currentItem();
+ if ( c < 0 ) return;
+ QListBoxItem *item = d->selectedListBox->item( c );
+ d->selectedListBox->takeItem( item );
+ d->selectedListBox->insertItem( item, c-1 );
+ d->selectedListBox->setCurrentItem( item );
+ emit movedUp( item );
+}
+
+void KActionSelector::buttonDownClicked()
+{
+ int c = d->selectedListBox->currentItem();
+ if ( c < 0 ) return;
+ QListBoxItem *item = d->selectedListBox->item( c );
+ d->selectedListBox->takeItem( item );
+ d->selectedListBox->insertItem( item, c+1 );
+ d->selectedListBox->setCurrentItem( item );
+ emit movedDown( item );
+}
+
+void KActionSelector::itemDoubleClicked( QListBoxItem *item )
+{
+ if ( d->moveOnDoubleClick )
+ moveItem( item );
+}
+
+//END Private Slots
+
+//BEGIN Private Methods
+
+void KActionSelector::loadIcons()
+{
+ d->btnAdd->setIconSet( SmallIconSet( d->addIcon, d->iconSize ) );
+ d->btnRemove->setIconSet( SmallIconSet( d->removeIcon, d->iconSize ) );
+ d->btnUp->setIconSet( SmallIconSet( d->upIcon, d->iconSize ) );
+ d->btnDown->setIconSet( SmallIconSet( d->downIcon, d->iconSize ) );
+}
+
+void KActionSelector::moveItem( QListBoxItem *item )
+{
+ QListBox *lbFrom = item->listBox();
+ QListBox *lbTo;
+ if ( lbFrom == d->availableListBox )
+ lbTo = d->selectedListBox;
+ else if ( lbFrom == d->selectedListBox )
+ lbTo = d->availableListBox;
+ else //?! somewhat unlikely...
+ return;
+
+ InsertionPolicy p = ( lbTo == d->availableListBox ) ?
+ d->availableInsertionPolicy : d->selectedInsertionPolicy;
+
+ lbFrom->takeItem( item );
+ lbTo->insertItem( item, insertionIndex( lbTo, p ) );
+ lbTo->setFocus();
+ lbTo->setCurrentItem( item );
+
+ if ( p == Sorted )
+ lbTo->sort();
+ if ( lbTo == d->selectedListBox )
+ emit added( item );
+ else
+ emit removed( item );
+}
+
+int KActionSelector::insertionIndex( QListBox *lb, InsertionPolicy policy )
+{
+ int index;
+ switch ( policy )
+ {
+ case BelowCurrent:
+ index = lb->currentItem();
+ if ( index > -1 ) index += 1;
+ break;
+ case AtTop:
+ index = 0;
+ break;
+ default:
+ index = -1;
+ }
+ return index;
+}
+
+//END Private Methods
+#include "kactionselector.moc"
diff --git a/parts/fileselector/kactionselector.h b/parts/fileselector/kactionselector.h
new file mode 100644
index 00000000..bc82e21b
--- /dev/null
+++ b/parts/fileselector/kactionselector.h
@@ -0,0 +1,399 @@
+/* This file is part of the KDE project
+ Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef _KACTION_SELECTOR_H_
+#define _KACTION_SELECTOR_H_
+
+#include <qwidget.h>
+
+class QListBox;
+class QListBoxItem;
+class QKeyEvent;
+class QEvent;
+class QIconSet;
+
+class KActionSelectorPrivate;
+
+/**
+ @short A widget for selecting and arranging actions/objects
+ This widget allows the user to select from a set of objects and arrange
+ the order of the selected ones using two list boxes labeled "Available"
+ and "Used" with horizontal arrows in between to move selected objects between
+ the two, and vertical arrows on the right to arrange the order of the selected
+ objects.
+
+ The widget moves objects to the other listbox when doubleclicked if
+ the property moveOnDoubleClick is set to true (default). See moveOnDoubleClick()
+ and setMoveOnDoubleClick().
+
+ The user control the widget using the keyboard if enabled (default),
+ see keyboardEnabled.
+
+ Note that this may conflist with keyboard selection in the selected list box,
+ if you set that to anything else than QListBox::Single (which is the default).
+
+ To use it, simply construct an instance and then add items to the two listboxes,
+ available through lbAvailable() and lbSelected(). Whenever you want, you can retrieve
+ the selected options using QListBox methods on lbSelected().
+
+ This way, you can use your own QListBoxItem class, allowing you to easily
+ store object data in those.
+
+ When an item is moved to a listbox, it is placed below the current item
+ of that listbox.
+
+ Standard arrow icons are used, but you can use icons of your own choice if desired,
+ see setButtonIcon(). It is also possible to set tooltips and whatsthis help
+ for the buttons. See setButtonTooltip() and setButtonWhatsThis().
+
+ To set whatsthis or tooltips for the listboxes, access them through
+ availableListbox() and selectedListBox().
+
+ All the moving buttons are automatically set enabled as expected.
+
+ Signals are sent each time an item is moved, allowing you to follow the
+ users actions if you need to. See addedToSelection(), removedFromSelection(),
+ movedUp() and movedDown()
+
+ @author Anders Lund <anders@alweb.dk>
+*/
+
+class KActionSelector : public QWidget {
+ Q_OBJECT
+ Q_ENUMS( ButtonIconSize InsertionPolicy )
+ Q_PROPERTY( bool moveOnDoubleClick READ moveOnDoubleClick WRITE setMoveOnDoubleClick )
+ Q_PROPERTY( bool keyboardEnabled READ keyboardEnabled WRITE setKeyboardEnabled )
+ Q_PROPERTY( QString availableLabel READ availableLabel WRITE setAvailableLabel )
+ Q_PROPERTY( QString selectedLabel READ selectedLabel WRITE setSelectedLabel )
+ Q_PROPERTY( ButtonIconSize buttonIconSize READ buttonIconSize WRITE setButtonIconSize )
+ Q_PROPERTY( InsertionPolicy availableInsertionPolicy READ availableInsertionPolicy WRITE setAvailableInsertionPolicy )
+ Q_PROPERTY( InsertionPolicy selectedInsertionPolicy READ selectedInsertionPolicy WRITE setSelectedInsertionPolicy )
+ Q_PROPERTY( bool showUpDownButtons READ showUpDownButtons WRITE setShowUpDownButtons )
+
+public:
+ KActionSelector( QWidget *parent=0, const char *name=0 );
+ ~KActionSelector();
+
+ /**
+ @return The QListBox holding the available actions
+ */
+ QListBox *availableListBox();
+
+ /**
+ @return The QListBox holding the selected actions
+ */
+ QListBox *selectedListBox();
+
+ /**
+ This enum indentifies the moving buttons
+ */
+ enum MoveButton {
+ ButtonAdd,
+ ButtonRemove,
+ ButtonUp,
+ ButtonDown
+ };
+
+ /**
+ This enum identifies the icon sizes, used for the move buttons.
+ The values correspond to the following pixel sizes:
+ @li SmallIcon - the return value of IconSize( KIcon::Small ), the user defined size
+ of a small icon in KDE. This is the default setting.
+ @li Small - 16px
+ @li Medium - 22px
+ @li Large - 32px
+ @li XLarge - 48px
+ */
+ enum ButtonIconSize {
+ SmallIcon,
+ Small,
+ Medium,
+ Large,
+ XLarge
+ };
+
+ /**
+ This enum defines policies for where to insert moved items in a listbox.
+ The following policies are currently defined:
+ @li BelowCurrent - The item is inserted below the listbox'
+ currentItem() or at the end if there is no curent item.
+ @li Sorted - The listbox is sort()ed after one or more items are inserted.
+ @li AtTop - The item is inserted at index 0 in the listbox.
+ @li AtBottom - The item is inserted at the end of the listbox.
+
+ @sa availableInsertionPolicy(), setAvailableInsertionPolicy(),
+ selectedInsertionPolicy(), setSelectedInsertionPolicy().
+ */
+ enum InsertionPolicy {
+ BelowCurrent,
+ Sorted,
+ AtTop,
+ AtBottom
+ };
+
+ /**
+ @return Wheather moveOnDoubleClcik is enabled.
+
+ If enabled, an item in any listbox will be moved to the other one whenever
+ doubleclicked.
+ @sa setMoveOnDoubleClick()
+ */
+ bool moveOnDoubleClick() const;
+
+ /**
+ Sets moveOnDoubleClick to @p enable
+ @sa moveOnDoubleClick()
+ */
+ void setMoveOnDoubleClick( bool enable );
+
+ /**
+ @return Weather keyboard control is enabled.
+
+ When Keyboard control is enabled, the widget will react to
+ the following keyboard actions:
+ @li CTRL + Right - simulate clicking the add button
+ @li CTRL + Left - simulate clicking the remove button
+ @li CTRL + Up - simulate clicking the up button
+ @li CTRL + Down - simulate clicking the down button
+
+ Additionally, pressing RETURN or ENTER on one of the list boxes
+ will cause the current item of that listbox to be moved to the other
+ listbox.
+
+ The keyboard actions are enabled by default.
+
+ @sa setKeyboardEnabled()
+ */
+ bool keyboardEnabled() const;
+
+ /**
+ Sets the keyboard enabled depending on @p enable.
+ @sa keyboardEnabled()
+ */
+ void setKeyboardEnabled( bool enable );
+
+ /**
+ @return The text of the label for the available items listbox.
+ */
+ QString availableLabel() const;
+
+ /**
+ Sets the label for the available items listbox to @p text.
+ Note that this label has the listbox as its @e buddy, so that
+ if you have a single ampersand in the text, the following character
+ will become the accellerator to focus te listbox.
+ */
+ void setAvailableLabel( const QString & text );
+
+ /**
+ @return the label of the selected items listbox.
+ */
+ QString selectedLabel() const;
+
+ /**
+ Sets the label for the selected items listbox to @p text.
+ Note that this label has the listbox as its @e buddy, so that
+ if you have a single ampersand in the text, the following character
+ will become the accellerator to focus te listbox.
+ */
+ void setSelectedLabel( const QString & text );
+
+ /**
+ @return the current ButtonIconSize.
+ */
+ ButtonIconSize buttonIconSize() const;
+
+ /**
+ Sets the button icon size.
+ See ButtonIconSize for the possible values and their pixel meaning.
+ */
+ void setButtonIconSize( ButtonIconSize size );
+
+ /**
+ @return The current insertion policy for the available listbox.
+ The default policy for the available listbox is Sorted.
+ See also InsertionPolicy, setAvailableInsertionPolicy().
+ */
+ InsertionPolicy availableInsertionPolicy() const;
+
+ /**
+ Sets the insertion policy for the available listbox.
+ See also InsertionPolicy, availableInsertionPolicy().
+ */
+ void setAvailableInsertionPolicy( InsertionPolicy policy );
+
+ /**
+ @return The current insertion policy for the selected listbox.
+ The default policy for the selected listbox is BelowCurrent.
+ See also InsertionPolicy, setSelectedInsertionPolicy().
+ */
+ InsertionPolicy selectedInsertionPolicy() const;
+
+ /**
+ Sets the insertion policy for the selected listbox.
+ See also InsertionPolicy, selectedInsertionPolicy().
+ */
+ void setSelectedInsertionPolicy( InsertionPolicy policy );
+
+ /**
+ @return wheather the Up and Down buttons should be displayed.
+ */
+ bool showUpDownButtons() const;
+
+ /**
+ Sets wheather the Up and Down buttons should be displayed
+ according to @p show
+ */
+ void setShowUpDownButtons( bool show );
+
+ /**
+ Sets the pixmap of the button @p button to @p icon.
+ It calls SmallIconSet(pm) to generate the icon set.
+ */
+ void setButtonIcon( const QString &icon, MoveButton button );
+
+ /**
+ Sets the iconset for button @p button to @p iconset.
+ You can use this method to et a costum icon set. Either
+ created by @ref QIconSet, or use the application instance of
+ @ref KIconLoader (recommended).
+ */
+ void setButtonIconSet( const QIconSet &iconset, MoveButton button );
+
+ /**
+ Sets the tooltip for the button @p button to @p tip.
+ */
+ void setButtonTooltip( const QString &tip, MoveButton button );
+
+ /**
+ Sets the whatsthis help for button @p button to @p text.
+ */
+ void setButtonWhatsThis( const QString &text, MoveButton button );
+
+ /**
+ Sets the enabled state of all moving buttons to reflect the current
+ options.
+
+ Be sure to call this if you add or removes items to either listbox after the
+ widget is show()n
+ */
+ void setButtonsEnabled();
+
+signals:
+ /**
+ Emitted when an item is moved to the "selected" listbox.
+ */
+ void added( QListBoxItem *item );
+
+ /**
+ Emitted when an item is moved out of the "selected" listbox.
+ */
+ void removed( QListBoxItem *item );
+
+ /**
+ Emitted when an item is moved upwards in the "selected" listbox.
+ */
+ void movedUp( QListBoxItem *item );
+
+ /**
+ Emitted when an item is moved downwards in the "selected" listbox.
+ */
+ void movedDown( QListBoxItem *item );
+
+ /**
+ Emitted when an item is moved to the "selected" listbox.
+ */
+// void addedToSelection( QListBoxItem *item );
+
+public slots:
+ /**
+ Reimplemented for internal reasons.
+ (calls setButtonsEnabled())
+ */
+ void polish();
+
+protected:
+ /**
+ Reimplamented for internal reasons.
+ */
+ void keyPressEvent( QKeyEvent * );
+
+ /**
+ Reimplemented for internal reasons.
+ */
+ bool eventFilter( QObject *, QEvent * );
+
+private slots:
+ /**
+ Move selected item from available box to the selected box
+ */
+ void buttonAddClicked();
+
+ /**
+ Move selected item from selected box to available box
+ */
+ void buttonRemoveClicked();
+
+ /**
+ Move selected item in selected box upwards
+ */
+ void buttonUpClicked();
+
+ /**
+ Move seleted item in selected box downwards
+ */
+ void buttonDownClicked();
+
+ /**
+ Moves the item @p item to the other listbox if moveOnDoubleClick is enabled.
+ */
+ void itemDoubleClicked( QListBoxItem *item );
+
+ /**
+ connected to both list boxes to set the buttons enabled
+ */
+ void slotCurrentChanged( QListBoxItem * ) { setButtonsEnabled(); };
+
+private:
+
+ /**
+ Move item @p item to the other listbox
+ */
+ void moveItem( QListBoxItem *item );
+
+ /**
+ loads the icons for the move buttons.
+ */
+ void loadIcons();
+
+ /**
+ @return the index to insert an item into listbox @p lb,
+ given InsertionPolicy @p policy.
+
+ Note that if policy is Sorted, this will return -1.
+ Sort the listbox after inserting the item in that case.
+ */
+ int insertionIndex( QListBox *lb, InsertionPolicy policy );
+
+ /**
+ Private data storage
+ */
+ KActionSelectorPrivate *d;
+};
+
+#endif // _KACTION_SELECTOR_H_
diff --git a/parts/fileselector/kbookmarkhandler.cpp b/parts/fileselector/kbookmarkhandler.cpp
new file mode 100644
index 00000000..b1854f1a
--- /dev/null
+++ b/parts/fileselector/kbookmarkhandler.cpp
@@ -0,0 +1,99 @@
+/* This file is part of the KDE project
+ Copyright (C) xxxx KFile Authors
+ Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <qtextstream.h>
+
+#include <kxmlguiclient.h>
+#include <kbookmarkimporter.h>
+#include <kpopupmenu.h>
+#include <ksavefile.h>
+#include <kstandarddirs.h>
+#include <kdiroperator.h>
+#include <kaction.h>
+
+#include "kbookmarkhandler.h"
+#include "kbookmarkhandler.moc"
+
+
+KBookmarkHandler::KBookmarkHandler( KDevFileSelector *parent, KPopupMenu* kpopupmenu )
+ : QObject( parent, "KBookmarkHandler" ),
+ KBookmarkOwner(),
+ mParent( parent ),
+ m_menu( kpopupmenu ),
+ m_importStream( 0L )
+{
+ if (!m_menu)
+ m_menu = new KPopupMenu( parent, "bookmark menu" );
+
+ QString file = locate( "data", "kdevfileselector/fsbookmarks.xml" );
+ if ( file.isEmpty() )
+ file = locateLocal( "data", "kdevfileselector/fsbookmarks.xml" );
+
+ KBookmarkManager *manager = KBookmarkManager::managerForFile( file, false);
+ manager->setUpdate( true );
+ manager->setShowNSBookmarks( false );
+
+ m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu, 0, true );
+}
+
+KBookmarkHandler::~KBookmarkHandler()
+{
+ // delete m_bookmarkMenu; ###
+}
+
+QString KBookmarkHandler::currentURL() const
+{
+ return mParent->dirOperator()->url().url();
+}
+
+
+void KBookmarkHandler::slotNewBookmark( const QString& text,
+ const QCString& url,
+ const QString& additionalInfo )
+{
+ Q_UNUSED( text );
+ *m_importStream << "<bookmark icon=\"" << KMimeType::iconForURL( KURL( url ) );
+ *m_importStream << "\" href=\"" << QString::fromUtf8(url) << "\">\n";
+ *m_importStream << "<title>" << (additionalInfo.isEmpty() ? QString::fromUtf8(url) : additionalInfo) << "</title>\n</bookmark>\n";
+}
+
+void KBookmarkHandler::slotNewFolder( const QString& text, bool /*open*/,
+ const QString& /*additionalInfo*/ )
+{
+ *m_importStream << "<folder icon=\"bookmark_folder\">\n<title=\"";
+ *m_importStream << text << "\">\n";
+}
+
+void KBookmarkHandler::newSeparator()
+{
+ *m_importStream << "<separator/>\n";
+}
+
+void KBookmarkHandler::endFolder()
+{
+ *m_importStream << "</folder>\n";
+}
+
+void KBookmarkHandler::virtual_hook( int id, void* data )
+{ KBookmarkOwner::virtual_hook( id, data ); }
+
diff --git a/parts/fileselector/kbookmarkhandler.h b/parts/fileselector/kbookmarkhandler.h
new file mode 100644
index 00000000..9849443d
--- /dev/null
+++ b/parts/fileselector/kbookmarkhandler.h
@@ -0,0 +1,70 @@
+/* This file is part of the KDE project
+ Copyright (C) xxxx KFile Authors
+ Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef _KBOOKMARKHANDLER_H_
+#define _KBOOKMARKHANDLER_H_
+
+#include <kbookmarkmanager.h>
+#include <kbookmarkmenu.h>
+#include "fileselector_widget.h"
+
+class QTextStream;
+class KPopupMenu;
+class KActionMenu;
+
+class KBookmarkHandler : public QObject, public KBookmarkOwner
+{
+ Q_OBJECT
+
+public:
+ KBookmarkHandler( KDevFileSelector *parent, KPopupMenu *kpopupmenu=0 );
+ ~KBookmarkHandler();
+
+ // KBookmarkOwner interface:
+ virtual void openBookmarkURL( const QString& url ) { emit openURL( url ); }
+ virtual QString currentURL() const;
+
+ KPopupMenu *menu() const { return m_menu; }
+
+signals:
+ void openURL( const QString& url );
+
+private slots:
+ void slotNewBookmark( const QString& text, const QCString& url,
+ const QString& additionalInfo );
+ void slotNewFolder( const QString& text, bool open,
+ const QString& additionalInfo );
+ void newSeparator();
+ void endFolder();
+
+protected:
+ virtual void virtual_hook( int id, void* data );
+
+private:
+ KDevFileSelector *mParent;
+ KPopupMenu *m_menu;
+ KBookmarkMenu *m_bookmarkMenu;
+
+ QTextStream *m_importStream;
+
+ //class KBookmarkHandlerPrivate *d;
+};
+
+
+#endif // _KBOOKMARKHANDLER_H_
diff --git a/parts/fileselector/kdevfileselector.desktop b/parts/fileselector/kdevfileselector.desktop
new file mode 100644
index 00000000..611da8d0
--- /dev/null
+++ b/parts/fileselector/kdevfileselector.desktop
@@ -0,0 +1,89 @@
+[Desktop Entry]
+Type=Service
+Exec=blubb
+Comment=Powerful network transparent file browser utility.
+Comment[ca]=Potent utilitat per a la navegació entre fitxers, transparent a la xarxa.
+Comment[da]=Stærkt netværkstransparent filsøgerredskab.
+Comment[de]=Ein mächtiges, netzwerktransparentes Dateiverwaltungswerkzeug.
+Comment[el]=Ισχυρό εργαλείο περιηγητή αρχείων με δικτυακή υποστήριξη.
+Comment[es]=Potente utilidad de navegación de archivos transparente a la red.
+Comment[et]=Võimas failide lehitsemise rakendus.
+Comment[eu]=Fitxategiak arakatzeko sare gardeneko tresna ahaltsua.
+Comment[fa]=برنامۀ سودمند مرورگر پروندۀ شفاف شبکۀ قوی
+Comment[fr]=Puissant utilitaire de navigateur de fichiers transparent vis-à-vis du réseau.
+Comment[gl]=Potente utilidade de navegación de ficheiros con soporte para navegación da rede de forma transparente.
+Comment[hi]=शक्तिशाली नेटवर्क ट्रांसपेरेन्ट फ़ाइल ब्राउज़र यूटिलिटी
+Comment[hu]=Fájlböngésző program (hálózatkezeléssel)
+Comment[it]=Utilità per la navigazione trasparente dei file in rete.
+Comment[ja]=強力なネットワーク透過ファイルブラウザユーティリティ
+Comment[ms]=Utiliti pelayar fail telus rangkaian yang berkuasa
+Comment[nds]=En mächtig, nettwarktransparent Dateigrieper.
+Comment[ne]=शक्तिशाली सञ्जाल पारदर्शी फाइल ब्राउजर युटिलिटी
+Comment[nl]=Krachtige, netwerktransparante bestandsbrowser.
+Comment[pl]=Potężne narzędzie do przeglądania plików z obsługą sieci.
+Comment[pt]=Utilitário de navegação de ficheiros poderoso.
+Comment[pt_BR]=Poderoso utilitário de navegação de arquivos transparente à rede.
+Comment[ru]=Средство просмотра списка файлов с поддержкой работы по сети.
+Comment[sk]=Výkonný sieťovo-transparentný nástroj na prezeranie súborov.
+Comment[sr]=Моћан програмчић за претраживање фајлова који је независтан од мреже.
+Comment[sr@Latn]=Moćan programčić za pretraživanje fajlova koji je nezavistan od mreže.
+Comment[sv]=Kraftfullt nätverkstransparent filbläddringsverktyg
+Comment[ta]=வலிமையுள்ள வலை பின்னல் ஊடக கோப்பினை தேடும் வசதி.
+Comment[tg]=Воситаи намоиши файлҳо бо тарафдории корҳо бо шабака.
+Comment[tr]=Güçlü, ağdan saydam, dosya gözatma yardımcı programı
+Comment[zh_CN]=强有力的网络文件浏览工具。
+Comment[zh_TW]=強大的網路檔案瀏覽工具。
+Name=KDevFileSelector
+Name[da]=KDevelop filvælger
+Name[de]=Datei-Selektor (KDevelop)
+Name[hi]=के-डेव-फ़ाइल-चयनक
+Name[nds]=KDevelop-Dateigrieper
+Name[pl]=KDevWybórPliku
+Name[sk]=KDev voľba súboru
+Name[sv]=KDevelop filväljare
+Name[ta]=KDev கோப்பு தேர்வாளன்
+Name[tg]=Ҷудосози файли KDev
+Name[zh_TW]=KDevelop 檔案選擇器
+GenericName=File Selector
+GenericName[br]=Dibaber ar restr
+GenericName[ca]=Selector de fitxers
+GenericName[cy]=Dewisydd Ffeiliau
+GenericName[da]=Filvælger
+GenericName[de]=Datei-Selektor
+GenericName[el]=Επιλογέας αρχείων
+GenericName[es]=Selector de archivos
+GenericName[et]=Failide valija
+GenericName[eu]=Fitxategi hautatzailea
+GenericName[fa]=گزینندۀ پرونده
+GenericName[fr]=Sélecteur de fichiers
+GenericName[ga]=Roghnóir na gComhad
+GenericName[gl]=Selector de ficheiros
+GenericName[hi]=फ़ाइल चयनक
+GenericName[hu]=Fájlválasztó
+GenericName[it]=Selettore file
+GenericName[ja]=ファイル選択
+GenericName[ms]=Pemilih Fail
+GenericName[nds]=Dateigrieper
+GenericName[ne]=फाइल चयनकर्ता
+GenericName[nl]=Bestandsselector
+GenericName[pl]=Wybór plików
+GenericName[pt]=Selector de Ficheiros
+GenericName[pt_BR]=Seletor de Arquivo
+GenericName[ru]=Выбор файлов
+GenericName[sk]=Voľba súboru
+GenericName[sl]=Izbirnik datotek
+GenericName[sr]=Бирач фајлова
+GenericName[sr@Latn]=Birač fajlova
+GenericName[sv]=Filväljare
+GenericName[ta]=கோப்பு தேர்வாளர்
+GenericName[tg]=Селектори файлҳо
+GenericName[tr]=Dosya Seçici
+GenericName[zh_CN]=文件选择器
+GenericName[zh_TW]=檔案選擇器
+Icon=fileopen
+ServiceTypes=KDevelop/Plugin
+X-KDE-Library=libkdevfileselector
+X-KDevelop-Version=5
+X-KDevelop-Scope=Global
+X-KDevelop-Mode=AssistantMode
+X-KDevelop-Properties=GlobalFileManagement
diff --git a/parts/fileselector/kdevpart_fileselector.rc b/parts/fileselector/kdevpart_fileselector.rc
new file mode 100644
index 00000000..940e2ab2
--- /dev/null
+++ b/parts/fileselector/kdevpart_fileselector.rc
@@ -0,0 +1,8 @@
+<!DOCTYPE kpartgui>
+<kpartplugin name="fileselector" library="libfileselectorplugin" version="1">
+<MenuBar>
+ <Menu name="help"><Text>&amp;Help</Text>
+ <Action name="help_fileselector"/>
+ </Menu>
+</MenuBar>
+</kpartplugin>