[prev in list] [next in list] [prev in thread] [next in thread]
List: kwrite-devel
Subject: Re: A tree view plugin for Kate
From: Batiste <batiste () dosimple ! ch>
Date: 2007-12-20 14:28:43
Message-ID: 200712201525.59634.batiste () dosimple ! ch
[Download RAW message or body]
Hello,
I tried to get pykde working with my distribution but compilation failed
somewhere. So pate is not for me at the moment. Maybe I will try it with Kde4.
So I have worked on my my treeview plugin by adding a file name filter. It
works but it seems that QDirModel doesn't like the user setNameFilters if the
QTreeView have a root index setted.
If you try this treeview plugin, by setting a root directory and using a
filter (In the QLineEdit) by pressing several times enter key the QTreeView
display is going mad.
I suspect a bug in Qt...
Any idea?
> I have a "Directory Project" plugin that does a tree view of any
> selected directory. It also allows for search-as-you-type for any
> file under the selected directory, like TextMate's Find Files (ctrl-h)
> command. It keeps the tree view (and the search-as-you-type widget)
> synced to the filesystem with KDirWatch... or at least it tries to.
>
> Here's a screenshot if interested:
> http://i14.tinypic.com/6shoj8o.png
>
> It requires Pate to work:
> http://paul.giannaros.org/pate/
>
> If you're having trouble installing Pate in Ubuntu, see this page:
> http://blog.stochasticbytes.com/2007/11/installing-pate-for-kate.html
>
> My plugin is a work in progress, but it works fairly well already. I
> use it everyday at work. Gotta use svn to get/install it:
> svn co http://stochasticbytes.com/svn/directory_project
>
> I going to update how it does the Find Files feature soon.
>
> -- Christopher
>
-------------------------------------------------------
["kate.treeview-plugin.diff" (text/x-diff)]
Index: plugins/treeview/Messages.sh
===================================================================
--- plugins/treeview/Messages.sh (révision 0)
+++ plugins/treeview/Messages.sh (révision 0)
@@ -0,0 +1,2 @@
+#! /bin/sh
+$XGETTEXT *.cpp -o $podir/katetreeviewplugin.pot
Index: plugins/treeview/katefileselector.cpp
===================================================================
--- plugins/treeview/katefileselector.cpp (révision 0)
+++ plugins/treeview/katefileselector.cpp (révision 0)
@@ -0,0 +1,214 @@
+/* This file is part of the KDE project
+ Copyright (C) 2007 Batiste Bieler <batiste@dosimple.ch>
+
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+//BEGIN Includes
+#include "katefileselector.h"
+#include "katefileselector.moc"
+
+#include <khbox.h>
+#include <kvbox.h>
+#include <kstyle.h>
+#include <kurl.h>
+
+#include <QApplication>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kgenericfactory.h>
+#include <kate/mainwindow.h>
+#include <kate/documentmanager.h>
+#include <ktexteditor/view.h>
+//END Includes
+
+K_EXPORT_COMPONENT_FACTORY( katetreeviewplugin, \
KGenericFactory<KateFileSelectorPlugin>( "katetreeviewplugin" ) ) +
+KateFileSelectorPlugin::KateFileSelectorPlugin( QObject* parent, const \
QStringList&): + Kate::Plugin ( (Kate::Application*)parent )
+{
+}
+
+Kate::PluginView *KateFileSelectorPlugin::createView (Kate::MainWindow *mainWindow)
+{
+ Kate::DocumentManager * documentManager = application()->documentManager();
+ KateFileSelectorPluginView* kateFileSelectorPluginView = new \
KateFileSelectorPluginView(mainWindow, documentManager); + m_fileSelector = \
kateFileSelectorPluginView->kateFileSelector(); + return kateFileSelectorPluginView;
+}
+
+KateFileSelectorPluginView::KateFileSelectorPluginView (Kate::MainWindow \
*mainWindow, Kate::DocumentManager * documentManager) + : Kate::PluginView \
(mainWindow) +{
+ // init console
+ QWidget *toolview = mainWindow->createToolView \
("kate_private_plugin_katetreeviewplugin", Kate::MainWindow::Left, \
SmallIcon("document-open"), i18n("Treeview Browser")); + m_fileSelector = new \
KateFileSelector(mainWindow, toolview, documentManager); +}
+
+
+KateFileSelectorPluginView::~KateFileSelectorPluginView ()
+{
+ // cleanup, kill toolview + console
+ delete m_fileSelector->parentWidget();
+}
+
+uint KateFileSelectorPlugin::configPages() const
+{
+ return 0;
+}
+
+Kate::PluginConfigPage *KateFileSelectorPlugin::configPage (uint number, QWidget \
*parent, const char *name) +{
+ return 0;
+}
+
+QString KateFileSelectorPlugin::configPageName (uint number) const
+{
+ if (number != 0) return QString();
+ kDebug() << "Returning a config page name";
+ return i18n("File Selector");
+}
+
+QString KateFileSelectorPlugin::configPageFullName (uint number) const
+{
+ if (number != 0) return QString();
+ return i18n("File Selector Settings");
+}
+
+KIcon KateFileSelectorPlugin::configPageIcon (uint number) const
+{
+ if (number != 0) return KIcon();
+ return KIcon("document-open");
+}
+
+//BEGIN Constructor/destructor
+KateFileSelector::KateFileSelector( Kate::MainWindow *mainWindow, QWidget * parent,
+ Kate::DocumentManager * documentM, const char * \
name ) + : KVBox (parent),
+ mainwin(mainWindow)
+{
+ setObjectName(name);
+ //mActionCollection = new KActionCollection( this );
+
+ set_root = new QPushButton(i18n("Set root dir"), this);
+ documentManager = documentM;
+
+ root_is_set = 0;
+ model = new QDirModel;
+ current_path = QString();
+ tree = new QTreeView(this);
+ model->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
+ 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(fileSelected(const \
QModelIndex&))); + connect(set_root, SIGNAL(clicked()), this, SLOT(setRoot()));
+ connect(documentManager, SIGNAL(documentDeleted (KTextEditor::Document *)), this, \
SLOT(clearSelection(KTextEditor::Document *))); + filter = new QLineEdit(this);
+ //filters = QStringList();
+ connect(filter, SIGNAL(editingFinished()), this, SLOT(setFilter()));
+}
+
+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 = \
documentManager->findUrl(model->filePath(index)); + // force selection display if \
the case the user click two times on + // the same item
+ QItemSelectionModel * selectionModel = tree->selectionModel();
+ selectionModel->select(index, QItemSelectionModel::Select);
+ //connect(document, SIGNAL(textChanged(KTextEditor::Document)), this, \
SLOT(documentChanged(KTextEditor::Document))); + }
+ else if(index.isValid())
+ {
+ current_path = model->filePath(index);
+ }
+}
+
+void ::KateFileSelector::setFilter()
+{
+ if(filter->displayText().trimmed()=="")
+ {
+ QStringList filters;
+ filters << "*";
+ model->setNameFilters(filters);
+ }
+ else
+ {
+ //apparently, filters seems to create bugs with QDirModel
+ model->setNameFilters(filter->displayText().split(' '));
+ }
+}
+
+void ::KateFileSelector::documentChanged(KTextEditor::Document *document)
+{
+ kDebug() << "document changed " << document;
+}
+
+// deselect all items that are not in the document manager
+void ::KateFileSelector::clearSelection(KTextEditor::Document * doc)
+{
+ QList<KTextEditor::Document*> documents = documentManager->documents();
+ QItemSelectionModel * selectionModel = tree->selectionModel();
+ QModelIndexList indexList = selectionModel->selectedIndexes();
+ for(int i=0; i < indexList.size(); i++)
+ {
+ QModelIndex index = indexList.at(i);
+ if(!documentManager->findUrl(model->filePath(index)))
+ {
+ selectionModel->select(index, QItemSelectionModel::Deselect);
+ }
+ }
+}
+
+void ::KateFileSelector::setRoot()
+{
+ if(root_is_set==0)
+ {
+ QModelIndex new_index = model->index(current_path);
+ if(!new_index.isValid())
+ return;
+ root_is_set = 1;
+ set_root->setText(i18n("Unset work dir"));
+ tree->setRootIndex(new_index);
+ }
+ else
+ {
+ root_is_set = 0;
+ filter->setText("");
+ set_root->setText(i18n("Set work dir"));
+ tree->setRootIndex(model->index(QDir::rootPath()));
+ QStringList filters;
+ filters << "*";
+ filter->setText("");
+ model->setNameFilters(filters);
+ }
+}
+//END Public Slots
+
+// kate: space-indent on; indent-width 2; replace-tabs on;
Index: plugins/treeview/katetreeviewplugin.desktop
===================================================================
--- plugins/treeview/katetreeviewplugin.desktop (révision 0)
+++ plugins/treeview/katetreeviewplugin.desktop (révision 0)
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Encoding=UTF-8
+Type=Service
+ServiceTypes=Kate/Plugin
+X-KDE-Library=katetreeviewplugin
+X-Kate-Version=2.8
+Name=Treeview file browser
+Name[fr]=Navigateur par vue arborescente
+Comment=Treeview file browser
+Comment[fr]=Navigateur par vue arborescente
+X-Kate-MajorProfiles=Kate
+X-Kate-MinorProfiles=*
Index: plugins/treeview/katefileselector.h
===================================================================
--- plugins/treeview/katefileselector.h (révision 0)
+++ plugins/treeview/katefileselector.h (révision 0)
@@ -0,0 +1,128 @@
+/* This file is part of the KDE project
+ Copyright (C) 2007 Batiste Bieler <batiste@dosimple.ch>
+
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __KATE_FILESELECTOR_H__
+#define __KATE_FILESELECTOR_H__
+
+#include <kate/application.h>
+#include <kate/documentmanager.h>
+#include <ktexteditor/document.h>
+#include <kate/plugin.h>
+#include <kate/mainwindow.h>
+#include <kate/pluginconfigpageinterface.h>
+#include <kstyle.h>
+
+#include <kvbox.h>
+
+#include <QLayout>
+#include <QPushButton>
+#include <QDirModel>
+#include <QTreeView>
+#include <QAbstractItemView>
+#include <QLineEdit>
+//#include <QHeaderView>
+
+class KateFileSelector;
+
+class KateFileSelectorPlugin: public Kate::Plugin, public \
Kate::PluginConfigPageInterface +{
+ Q_OBJECT
+ Q_INTERFACES(Kate::PluginConfigPageInterface)
+ public:
+ explicit KateFileSelectorPlugin( QObject* parent = 0, const QStringList& = \
QStringList() ); + virtual ~KateFileSelectorPlugin()
+ {}
+
+ Kate::PluginView *createView (Kate::MainWindow *mainWindow);
+
+ uint configPages() const;
+ Kate::PluginConfigPage *configPage (uint number = 0, QWidget *parent = 0, const \
char *name = 0); + QString configPageName (uint number = 0) const;
+ QString configPageFullName (uint number = 0) const;
+ KIcon configPageIcon (uint number = 0) const;
+ KateFileSelector *m_fileSelector;
+};
+
+class KateFileSelectorPluginView : public Kate::PluginView
+{
+ Q_OBJECT
+
+ public:
+ /**
+ * Constructor.
+ */
+ KateFileSelectorPluginView (Kate::MainWindow *mainWindow, Kate::DocumentManager \
* documentManager); +
+ /**
+ * Virtual destructor.
+ */
+ ~KateFileSelectorPluginView ();
+ KateFileSelector * kateFileSelector() const { return m_fileSelector; }
+
+ private:
+ KateFileSelector * m_fileSelector;
+};
+
+class KateFileSelector : public KVBox
+{
+ Q_OBJECT
+
+ public:
+
+ explicit KateFileSelector( Kate::MainWindow *mainWindow = 0, QWidget * parent = \
0, + Kate::DocumentManager * documentM = 0,const char \
* name = 0 ); + ~KateFileSelector();
+ KActionCollection *actionCollection()
+ {
+ return mActionCollection;
+ }
+
+ Kate::DocumentManager * documentManager;
+ QDirModel * model;
+ QTreeView * tree;
+ QLineEdit * filter;
+ //QStringList filters;
+ QPushButton * set_root;
+ int root_is_set;
+ //QModelIndex current_index;
+ QString current_path;
+
+ public Q_SLOTS:
+ void setFilter();
+ void fileSelected(const QModelIndex &);
+ void documentChanged(KTextEditor::Document *document);
+ 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: plugins/treeview/icons/ox16-action-curfiledir.png
===================================================================
Impossible d'afficher : fichier considéré comme binaire.
svn:mime-type = application/octet-stream
Modification de propriétés sur plugins/treeview/icons/ox16-action-curfiledir.png
___________________________________________________________________
Nom : svn:mime-type
+ application/octet-stream
Index: plugins/treeview/CMakeLists.txt
===================================================================
--- plugins/treeview/CMakeLists.txt (révision 0)
+++ plugins/treeview/CMakeLists.txt (révision 0)
@@ -0,0 +1,21 @@
+
+add_subdirectory( icons )
+
+
+########### next target ###############
+
+set(katetreeviewplugin_PART_SRCS katefileselector.cpp) #kbookmarkhandler.cpp )
+
+
+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: plugins/CMakeLists.txt
===================================================================
--- plugins/CMakeLists.txt (révision 750501)
+++ plugins/CMakeLists.txt (copie de travail)
@@ -16,6 +16,7 @@
add_subdirectory( quickdocumentswitcher )
add_subdirectory( filetemplates )
+add_subdirectory( treeview )
#add_subdirectory( htmltools )
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://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