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

List:       kwrite-devel
Subject:    A tree view plugin for Kate
From:       Batiste <batiste () dosimple ! ch>
Date:       2007-11-26 10:50:34
Message-ID: 200711261149.21351.batiste () dosimple ! ch
[Download RAW message or body]

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


["kate_treeview_plugin.diff" (text/x-diff)]

Index: kate/plugins/treeview/Messages.sh
===================================================================
--- kate/plugins/treeview/Messages.sh	(révision 0)
+++ kate/plugins/treeview/Messages.sh	(révision 0)
@@ -0,0 +1,2 @@
+#! /bin/sh
+$XGETTEXT *.cpp -o $podir/katetreeviewplugin.pot
Index: kate/plugins/treeview/katefileselector.cpp
===================================================================
--- kate/plugins/treeview/katefileselector.cpp	(révision 0)
+++ kate/plugins/treeview/katefileselector.cpp	(révision 0)
@@ -0,0 +1,178 @@
+/* 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;
+  tree = 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(fileSelected(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 = \
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);
+  }
+  else
+    current_index = QModelIndex(index);
+}
+
+// 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 && current_index.isValid())
+  {
+    root_is_set = 1;
+    set_root->setText(i18n("Unset work dir"));
+    tree->setRootIndex(model->index(model->filePath(current_index)));
+  }
+  else
+  {
+    root_is_set = 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
===================================================================
--- kate/plugins/treeview/katetreeviewplugin.desktop	(révision 0)
+++ kate/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: kate/plugins/treeview/katefileselector.h
===================================================================
--- kate/plugins/treeview/katefileselector.h	(révision 0)
+++ kate/plugins/treeview/katefileselector.h	(révision 0)
@@ -0,0 +1,122 @@
+/* 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 <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;
+    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
===================================================================
Impossible d'afficher : fichier considéré comme binaire.
svn:mime-type = application/octet-stream

Modification de propriétés sur \
kate/plugins/treeview/icons/ox16-action-curfiledir.png \
___________________________________________________________________ Nom : \
svn:mime-type  + application/octet-stream

Index: kate/plugins/treeview/CMakeLists.txt
===================================================================
--- kate/plugins/treeview/CMakeLists.txt	(révision 0)
+++ kate/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: kate/plugins/CMakeLists.txt
===================================================================
--- kate/plugins/CMakeLists.txt	(révision 735968)
+++ kate/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