From kwrite-devel Mon Nov 26 10:50:34 2007 From: Batiste Date: Mon, 26 Nov 2007 10:50:34 +0000 To: kwrite-devel Subject: A tree view plugin for Kate Message-Id: <200711261149.21351.batiste () dosimple ! ch> X-MARC-Message: https://marc.info/?l=kwrite-devel&m=119607423430213 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_BNySHr+RN5GQZ8v" --Boundary-00=_BNySHr+RN5GQZ8v Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, I use Kate for my programing tasks. I am missing a tree view a lot because on our projects a lot of files have the same name (Django programming with python) and kate default document view does not provide a way to easly differencitate them. A tree, being visualy hierachical, solve this this problem. So I tried to make a very basic plugin using the QTreeView object and I was happy to see that it was not as difficult as I tought. I have used the revision 735968 from the KDE trunk. I know that this plugin is very rough, so I will be happy if you can take a look a it and comment for improvments. My goal is to reach the quality required to integrate the Kde repository. Attached: the patch for kdesdk Keep the amazing work, Batiste Bieler --Boundary-00=_BNySHr+RN5GQZ8v Content-Type: text/x-diff; charset="iso-8859-1"; name="kate_treeview_plugin.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="kate_treeview_plugin.diff" Index: kate/plugins/treeview/Messages.sh =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kate/plugins/treeview/Messages.sh (r=C3=A9vision 0) +++ kate/plugins/treeview/Messages.sh (r=C3=A9vision 0) @@ -0,0 +1,2 @@ +#! /bin/sh +$XGETTEXT *.cpp -o $podir/katetreeviewplugin.pot Index: kate/plugins/treeview/katefileselector.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kate/plugins/treeview/katefileselector.cpp (r=C3=A9vision 0) +++ kate/plugins/treeview/katefileselector.cpp (r=C3=A9vision 0) @@ -0,0 +1,178 @@ +/* This file is part of the KDE project + Copyright (C) 2007 Batiste Bieler + + 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 Licen= se + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +//BEGIN Includes +#include "katefileselector.h" +#include "katefileselector.moc" + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +//END Includes + +K_EXPORT_COMPONENT_FACTORY( katetreeviewplugin, KGenericFactory( "katetreeviewplugin" ) ) + +KateFileSelectorPlugin::KateFileSelectorPlugin( QObject* parent, const QSt= ringList&): + Kate::Plugin ( (Kate::Application*)parent ) +{ +} + +Kate::PluginView *KateFileSelectorPlugin::createView (Kate::MainWindow *ma= inWindow) +{ + Kate::DocumentManager * documentManager =3D application()->documentManag= er(); + KateFileSelectorPluginView* kateFileSelectorPluginView =3D new KateFileS= electorPluginView(mainWindow, documentManager); + m_fileSelector =3D kateFileSelectorPluginView->kateFileSelector(); + return kateFileSelectorPluginView; +} + +KateFileSelectorPluginView::KateFileSelectorPluginView (Kate::MainWindow *= mainWindow, Kate::DocumentManager * documentManager) + : Kate::PluginView (mainWindow) +{ + // init console + QWidget *toolview =3D mainWindow->createToolView ("kate_private_plugin_k= atetreeviewplugin", Kate::MainWindow::Left, SmallIcon("document-open"), i18= n("Treeview Browser")); + m_fileSelector =3D new KateFileSelector(mainWindow, toolview, documentMa= nager); +} + + +KateFileSelectorPluginView::~KateFileSelectorPluginView () +{ + // cleanup, kill toolview + console + delete m_fileSelector->parentWidget(); +} + +uint KateFileSelectorPlugin::configPages() const +{ + return 0; +} + +Kate::PluginConfigPage *KateFileSelectorPlugin::configPage (uint number, Q= Widget *parent, const char *name) +{ =20 + return 0; +} + +QString KateFileSelectorPlugin::configPageName (uint number) const +{ + if (number !=3D 0) return QString(); + kDebug() << "Returning a config page name"; + return i18n("File Selector"); +} + +QString KateFileSelectorPlugin::configPageFullName (uint number) const +{ + if (number !=3D 0) return QString(); + return i18n("File Selector Settings"); +} + +KIcon KateFileSelectorPlugin::configPageIcon (uint number) const +{ + if (number !=3D 0) return KIcon(); + return KIcon("document-open"); +} + +//BEGIN Constructor/destructor +KateFileSelector::KateFileSelector( Kate::MainWindow *mainWindow, QWidget = * parent,=20 + Kate::DocumentManager * documentM, con= st char * name ) + : KVBox (parent), + mainwin(mainWindow) +{ + setObjectName(name); + //mActionCollection =3D new KActionCollection( this ); + =20 + set_root =3D new QPushButton(i18n("Set root dir"), this); + documentManager =3D documentM; + + root_is_set =3D 0; + model =3D new QDirModel; + tree =3D new QTreeView(this); + tree->setModel(model); + tree->setSelectionMode(QAbstractItemView::MultiSelection); + tree->setColumnHidden(1, true); + tree->setColumnHidden(2, true); + tree->setColumnHidden(3, true); + tree->setAlternatingRowColors(true); + connect(tree, SIGNAL(clicked(const QModelIndex&)), this, SLOT(fileSelect= ed(const QModelIndex&))); + connect(set_root, SIGNAL(clicked()), this, SLOT(setRoot())); + connect(documentManager, SIGNAL(documentDeleted (KTextEditor::Document *= )), this, SLOT(clearSelection(KTextEditor::Document *))); +} + +KateFileSelector::~KateFileSelector() +{} +//END Constructor/Destructor + +//BEGIN Public Slots +void ::KateFileSelector::fileSelected(const QModelIndex & index) +{ + if(!model->isDir(index)) + { + // open the document and give focus to it + mainwin->openUrl(model->filePath(index)); + // the tree display in not very good when the focus is lost + KTextEditor::Document * document =3D documentManager->findUrl(model->f= ilePath(index)); + // force selection display if the case the user click two times on=20 + // the same item + QItemSelectionModel * selectionModel =3D tree->selectionModel(); + selectionModel->select(index, QItemSelectionModel::Select); + } + else + current_index =3D QModelIndex(index); +} + +// deselect all items that are not in the document manager +void ::KateFileSelector::clearSelection(KTextEditor::Document * doc) +{ + QList documents =3D documentManager->documents(); + QItemSelectionModel * selectionModel =3D tree->selectionModel(); + QModelIndexList indexList =3D selectionModel->selectedIndexes(); + for(int i=3D0; i < indexList.size(); i++) + { + QModelIndex index =3D indexList.at(i); + if(!documentManager->findUrl(model->filePath(index))) + { + selectionModel->select(index, QItemSelectionModel::Deselect); + } + } +} + +void ::KateFileSelector::setRoot() +{ + if(root_is_set=3D=3D0 && current_index.isValid()) + { + root_is_set =3D 1; + set_root->setText(i18n("Unset work dir")); + tree->setRootIndex(model->index(model->filePath(current_index))); + } + else + { + root_is_set =3D 0; + set_root->setText(i18n("Set work dir")); + tree->setRootIndex(model->index(QDir::rootPath())); + } +} +//END Public Slots + +// kate: space-indent on; indent-width 2; replace-tabs on; Index: kate/plugins/treeview/katetreeviewplugin.desktop =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kate/plugins/treeview/katetreeviewplugin.desktop (r=C3=A9vision 0) +++ kate/plugins/treeview/katetreeviewplugin.desktop (r=C3=A9vision 0) @@ -0,0 +1,12 @@ +[Desktop Entry] +Encoding=3DUTF-8 +Type=3DService +ServiceTypes=3DKate/Plugin +X-KDE-Library=3Dkatetreeviewplugin +X-Kate-Version=3D2.8 +Name=3DTreeview file browser +Name[fr]=3DNavigateur par vue arborescente +Comment=3DTreeview file browser +Comment[fr]=3DNavigateur par vue arborescente +X-Kate-MajorProfiles=3DKate +X-Kate-MinorProfiles=3D* Index: kate/plugins/treeview/katefileselector.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kate/plugins/treeview/katefileselector.h (r=C3=A9vision 0) +++ kate/plugins/treeview/katefileselector.h (r=C3=A9vision 0) @@ -0,0 +1,122 @@ +/* This file is part of the KDE project + Copyright (C) 2007 Batiste Bieler + + 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 Licen= se + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_FILESELECTOR_H__ +#define __KATE_FILESELECTOR_H__ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +//#include + +class KateFileSelector; + +class KateFileSelectorPlugin: public Kate::Plugin, public Kate::PluginConf= igPageInterface +{ + Q_OBJECT + Q_INTERFACES(Kate::PluginConfigPageInterface) + public: + explicit KateFileSelectorPlugin( QObject* parent =3D 0, const QStringL= ist& =3D QStringList() ); + virtual ~KateFileSelectorPlugin() + {} + + Kate::PluginView *createView (Kate::MainWindow *mainWindow); + + uint configPages() const; + Kate::PluginConfigPage *configPage (uint number =3D 0, QWidget *parent= =3D 0, const char *name =3D 0); + QString configPageName (uint number =3D 0) const; + QString configPageFullName (uint number =3D 0) const; + KIcon configPageIcon (uint number =3D 0) const; + KateFileSelector *m_fileSelector; +}; + +class KateFileSelectorPluginView : public Kate::PluginView +{ + Q_OBJECT + + public: + /** + * Constructor. + */ + KateFileSelectorPluginView (Kate::MainWindow *mainWindow, Kate::Docume= ntManager * documentManager); + + /** + * Virtual destructor. + */ + ~KateFileSelectorPluginView (); + KateFileSelector * kateFileSelector() const { return m_fileSelector; } + =20 + private: + KateFileSelector * m_fileSelector; +}; + +class KateFileSelector : public KVBox +{ + Q_OBJECT + + public: + + explicit KateFileSelector( Kate::MainWindow *mainWindow =3D 0, QWidget= * parent =3D 0,=20 + Kate::DocumentManager * documentM =3D 0,con= st char * name =3D 0 ); + ~KateFileSelector(); =20 + KActionCollection *actionCollection() + { + return mActionCollection; + } + + Kate::DocumentManager * documentManager; + QDirModel * model; + QTreeView * tree; + QPushButton * set_root; + int root_is_set; + QModelIndex current_index; + + public Q_SLOTS: + void fileSelected(const QModelIndex &); + void setRoot(); + void clearSelection(KTextEditor::Document *); + + private Q_SLOTS: + + protected: + + public: + Kate::MainWindow* mainWindow() + { + return mainwin; + } + private: + KActionCollection *mActionCollection; + Kate::MainWindow *mainwin; +}; + +#endif //__KATE_FILESELECTOR_H__ + +// kate: space-indent on; indent-width 2; replace-tabs on; Index: kate/plugins/treeview/icons/ox16-action-curfiledir.png =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Impossible d'afficher : fichier consid=C3=A9r=C3=A9 comme binaire. svn:mime-type =3D application/octet-stream Modification de propri=C3=A9t=C3=A9s sur kate/plugins/treeview/icons/ox16-a= ction-curfiledir.png ___________________________________________________________________ Nom : svn:mime-type + application/octet-stream Index: kate/plugins/treeview/CMakeLists.txt =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kate/plugins/treeview/CMakeLists.txt (r=C3=A9vision 0) +++ kate/plugins/treeview/CMakeLists.txt (r=C3=A9vision 0) @@ -0,0 +1,21 @@ + +add_subdirectory( icons ) + + +########### next target ############### + +set(katetreeviewplugin_PART_SRCS katefileselector.cpp) #kbookmarkhandler.c= pp ) + + +kde4_add_plugin(katetreeviewplugin ${katetreeviewplugin_PART_SRCS}) + + +target_link_libraries(katetreeviewplugin ${KDE4_KFILE_LIBS} kateinterfaces= ) + +install(TARGETS katetreeviewplugin DESTINATION ${PLUGIN_INSTALL_DIR} ) + + +########### install files ############### + +install( FILES katetreeviewplugin.desktop DESTINATION ${SERVICES_INSTALL= _DIR} ) + Index: kate/plugins/CMakeLists.txt =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kate/plugins/CMakeLists.txt (r=C3=A9vision 735968) +++ kate/plugins/CMakeLists.txt (copie de travail) @@ -16,6 +16,7 @@ add_subdirectory( quickdocumentswitcher ) =20 add_subdirectory( filetemplates ) +add_subdirectory( treeview ) =20 =20 #add_subdirectory( htmltools ) --Boundary-00=_BNySHr+RN5GQZ8v Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ KWrite-Devel mailing list KWrite-Devel@kde.org https://mail.kde.org/mailman/listinfo/kwrite-devel --Boundary-00=_BNySHr+RN5GQZ8v--