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

List:       ktexteditor-devel
Subject:    Re: Patch for moving LoadSaveFilterCheck in KTextEditor
From:       Cyrille Berger <cberger () cberger ! net>
Date:       2008-03-26 20:44:52
Message-ID: 200803262144.52255.cberger () cberger ! net
[Download RAW message or body]

Hi,

And actually the full patch, with the added interface. And cc to 
ktexteditor-devel@kde.org and jowenn following Dominik Haumann's suggestion.

On Wednesday 26 March 2008, you wrote:
> Hi,
>
> Please put me in CC in your answer, since I am not subscribed to the list.
>
> I didn't receive any input on my previous mail on the subject, so I decided
> to try to provide a patch, the way I would do it, and ask for your opinion
> about it.
>
> So here is a first try for having LoadSaveFilterCheck available to plugins.
>
> So basically you have to write an implementation of LoadSaveFilterCheck.
> And then you add it to the LoadSaveFilterCheckRegistry using a a
> KTextEditor::Plugin.
>
> It obviously lack of documentation, and I have disabled
> the "KatePythonEncodingCheck", but once I have received the agreement that
> I am on the good track (or the bad track but that I have made the
> correction) I will fix those issues.
>
> So what do you think ?



-- 
Cyrille Berger

["texteditor-loadsavefiltercheck.diff" (text/x-diff)]

Index: interfaces/ktexteditor/loadsavefiltercheckregistry.h
===================================================================
--- interfaces/ktexteditor/loadsavefiltercheckregistry.h	(revision 0)
+++ interfaces/ktexteditor/loadsavefiltercheckregistry.h	(revision 0)
@@ -0,0 +1,50 @@
+/* This file is part of the KDE libraries
+   Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
+   Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
+   Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
+   Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
+   Copyright (C) 2007 Mirko Stocker <me@misto.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 02111-13020, USA.
+*/
+
+#ifndef _LOADSAVEFILTERCHECKREGISTRY_H_
+#define _LOADSAVEFILTERCHECKREGISTRY_H_
+
+#include <ktexteditor/ktexteditor_export.h>
+
+namespace KTextEditor
+{
+  class Document;
+  class LoadSaveFilterCheck;
+  class KTEXTEDITOR_EXPORT LoadSaveFilterCheckRegistry
+  {
+    public:
+      LoadSaveFilterCheckRegistry();
+      ~LoadSaveFilterCheckRegistry();
+      bool preSavePostDialogFilterCheck(const QString& \
pluginName,KTextEditor::Document *document); +      void postLoadFilter(const \
QString& pluginName,KTextEditor::Document *document); +      void addFilter(const \
QString& pluginName, LoadSaveFilterCheck* plugin); +    private:
+      struct Private;
+      Private* const d;
+  };
+
+
+}
+
+#endif
+
+// kate: space-indent on; indent-width 2; replace-tabs on;
Index: interfaces/ktexteditor/ktexteditor.cpp
===================================================================
--- interfaces/ktexteditor/ktexteditor.cpp	(revision 790219)
+++ interfaces/ktexteditor/ktexteditor.cpp	(working copy)
@@ -52,6 +52,7 @@
 #include "documentadaptor_p.h"
 #include "documentadaptor_p.moc"
 
+#include "loadsavefiltercheckregistry.h"
 
 //#include <kaction.h>
 #include <kparts/factory.h>
@@ -225,6 +226,14 @@
   return documentEnd() == Cursor::start();
 }
 
+LoadSaveFilterCheckRegistry* Document::loadSaveFilterCheckRegistry()
+{
+  K_GLOBAL_STATIC(LoadSaveFilterCheckRegistry, s_loadSaveFilterCheckRegistry)
+  return s_loadSaveFilterCheckRegistry;
+}
+
+
+
 ConfigPage::ConfigPage ( QWidget *parent )
   : QWidget (parent)
   , d(0)
@@ -398,4 +407,3 @@
 }
 
 // kate: space-indent on; indent-width 2; replace-tabs on;
-
Index: interfaces/ktexteditor/loadsavefiltercheck.h
===================================================================
--- interfaces/ktexteditor/loadsavefiltercheck.h	(revision 0)
+++ interfaces/ktexteditor/loadsavefiltercheck.h	(revision 0)
@@ -0,0 +1,47 @@
+/* This file is part of the KDE libraries
+   Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
+   Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
+   Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
+   Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
+   Copyright (C) 2007 Mirko Stocker <me@misto.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 02111-13020, USA.
+*/
+
+#ifndef _LOADSAVEFILTERCHECKPLUGIN_H_
+#define _LOADSAVEFILTERCHECKPLUGIN_H_
+
+namespace KTextEditor {
+  class Document;
+  class KTEXTEDITOR_EXPORT LoadSaveFilterCheck {
+    public:
+      LoadSaveFilterCheck() {}
+      virtual ~LoadSaveFilterCheck(){}
+      /**
+      * This one should be called once everything is set up for
+      * saving (especially the encoding has been determind
+      * (example: used for checking python source encoding headers))
+      */
+      virtual bool preSavePostDialogFilterCheck(KTextEditor::Document *document) =0;
+      /**
+      * this one should be called once the document has been completely
+      * loaded and configured (encoding,highlighting, ...))
+      */
+      virtual void postLoadFilter(KTextEditor::Document *document) =0;
+  };
+
+}
+
+#endif
Index: interfaces/ktexteditor/loadsavefiltercheckregistry.cpp
===================================================================
--- interfaces/ktexteditor/loadsavefiltercheckregistry.cpp	(revision 0)
+++ interfaces/ktexteditor/loadsavefiltercheckregistry.cpp	(revision 0)
@@ -0,0 +1,63 @@
+/* This file is part of the KDE libraries
+   Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
+   Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
+   Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
+   Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
+   Copyright (C) 2007 Mirko Stocker <me@misto.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 02111-13020, USA.
+*/
+
+#include "loadsavefiltercheckregistry.h"
+
+#include <QHash>
+
+#include "loadsavefiltercheck.h"
+
+using namespace KTextEditor;
+
+struct LoadSaveFilterCheckRegistry::Private {
+  QHash <QString,LoadSaveFilterCheck*> plugins;
+};
+
+LoadSaveFilterCheckRegistry::LoadSaveFilterCheckRegistry() : d(new Private)
+{
+}
+
+LoadSaveFilterCheckRegistry::~LoadSaveFilterCheckRegistry()
+{
+  QHashIterator<QString,LoadSaveFilterCheck*> i(d->plugins);
+  while (i.hasNext())
+    i.next();
+  delete i.value();
+  d->plugins.clear();
+}
+bool LoadSaveFilterCheckRegistry::preSavePostDialogFilterCheck(const QString& \
pluginName,KTextEditor::Document *document) { +  LoadSaveFilterCheck *plug = \
d->plugins.value(pluginName); +  if (!plug) return false;
+  return plug->preSavePostDialogFilterCheck(document);
+}
+void LoadSaveFilterCheckRegistry::postLoadFilter(const QString& \
pluginName,KTextEditor::Document *document) { +  LoadSaveFilterCheck *plug = \
d->plugins.value(pluginName); +  if (!plug) return;
+  plug->postLoadFilter(document);
+}
+
+void LoadSaveFilterCheckRegistry::addFilter(const QString& pluginName, \
LoadSaveFilterCheck* plugin) +{
+  d->plugins[ pluginName ] = plugin;
+}
+
+// kate: space-indent on; indent-width 2; replace-tabs on;
Index: interfaces/ktexteditor/CMakeLists.txt
===================================================================
--- interfaces/ktexteditor/CMakeLists.txt	(revision 790219)
+++ interfaces/ktexteditor/CMakeLists.txt	(working copy)
@@ -17,6 +17,7 @@
    codecompletionmodel.cpp
    configinterface.cpp
    smartinterface.cpp
+   loadsavefiltercheckregistry.cpp
    )
 
 
@@ -59,6 +60,8 @@
     codecompletionmodel.h
     configinterface.h
     containerinterface.h
+    loadsavefiltercheck.h
+    loadsavefiltercheckregistry.h
     DESTINATION  ${INCLUDE_INSTALL_DIR}/ktexteditor COMPONENT Devel)
 
 install( FILES ktexteditor.desktop ktexteditorplugin.desktop  DESTINATION  \
                ${SERVICETYPES_INSTALL_DIR} )
Index: interfaces/ktexteditor/document.h
===================================================================
--- interfaces/ktexteditor/document.h	(revision 790219)
+++ interfaces/ktexteditor/document.h	(working copy)
@@ -37,6 +37,7 @@
 
 class Editor;
 class View;
+class LoadSaveFilterCheckRegistry;
 
 /**
  * \brief A KParts derived class representing a text document.
@@ -692,6 +693,8 @@
   protected:
     void setOpeningError(bool errors);
     void setOpeningErrorMessage(const QString& message);
+  public:
+    static LoadSaveFilterCheckRegistry* loadSaveFilterCheckRegistry();
 };
 
 }
Index: kate/document/katedocument.cpp
===================================================================
--- kate/document/katedocument.cpp	(revision 790219)
+++ kate/document/katedocument.cpp	(working copy)
@@ -21,6 +21,7 @@
 */
 
 //BEGIN includes
+#include <ktexteditor/loadsavefiltercheckregistry.h>
 #include "katedocument.h"
 #include "katedocument.moc"
 #include "katekeyinterceptorfunctor.h"
@@ -105,19 +106,7 @@
 
 static int dummy = 0;
 
-#ifdef __GNUC__
-#warning consider moving this to KTextEditor
-#endif
-class LoadSaveFilterCheckPlugin {
-  public:
-    LoadSaveFilterCheckPlugin() {}
-    virtual ~LoadSaveFilterCheckPlugin(){}
-    /*this one should be called once everything is set up for saving (especially the \
encoding has been determind (example: used for checking python source encoding \
                headers))*/
-    virtual bool preSavePostDialogFilterCheck(KTextEditor::Document *document) =0;
-    /*this one should be called once the document has been completely loaded and \
                configured (encoding,highlighting, ...))*/
-    virtual void postLoadFilter(KTextEditor::Document *document) =0;
-};
-
+#if 0
 class KatePythonEncodingCheck: public LoadSaveFilterCheckPlugin {
   public:
     KatePythonEncodingCheck():LoadSaveFilterCheckPlugin(){interpreterLine=QRegExp(QString("#!.*$"));}
 @@ -176,42 +165,8 @@
       QRegExp interpreterLine;
 };
 
-class KateDocument::LoadSaveFilterCheckPlugins
-{
-  public:
-    LoadSaveFilterCheckPlugins() { m_plugins["python-encoding"]=new \
                KatePythonEncodingCheck();}
-    ~LoadSaveFilterCheckPlugins() {
-      QHashIterator<QString,LoadSaveFilterCheckPlugin*>i(m_plugins);
-        while (i.hasNext())
-          i.next();
-          delete i.value();
-      m_plugins.clear();
-    }
-    bool preSavePostDialogFilterCheck(const QString& pluginName,KateDocument \
                *document) {
-      LoadSaveFilterCheckPlugin *plug=getPlugin(pluginName);
-      if (!plug) return false;
-      return plug->preSavePostDialogFilterCheck(document);
-    }
-    void postLoadFilter(const QString& pluginName,KateDocument *document) {
-      LoadSaveFilterCheckPlugin *plug=getPlugin(pluginName);
-      if (!plug) return;
-      plug->postLoadFilter(document);
-    }
-  private:
-    LoadSaveFilterCheckPlugin *getPlugin(const QString & pluginName)
-    {
-      if (!m_plugins.contains(pluginName))
-      {
-#ifdef __GNUC__
-#warning implement dynamic loading here
 #endif
-      }
-      if (!m_plugins.contains(pluginName)) return 0;
-      return m_plugins[pluginName];
-    }
-    QHash <QString,LoadSaveFilterCheckPlugin*> m_plugins;
-};
-
+                                                                                
 //BEGIN d'tor, c'tor
 //
 // KateDocument Constructor
@@ -3416,7 +3371,7 @@
 
     if (!m_postLoadFilterChecks.isEmpty())
     {
-      LoadSaveFilterCheckPlugins *lscps=loadSaveFilterCheckPlugins();
+      KTextEditor::LoadSaveFilterCheckRegistry *lscps=loadSaveFilterCheckRegistry();
       foreach(const QString& checkplugin, m_postLoadFilterChecks)
       {
          lscps->postLoadFilter(checkplugin,this);
@@ -3629,7 +3584,7 @@
 
   if (!m_preSavePostDialogFilterChecks.isEmpty())
   {
-    LoadSaveFilterCheckPlugins *lscps=loadSaveFilterCheckPlugins();
+    KTextEditor::LoadSaveFilterCheckRegistry *lscps=loadSaveFilterCheckRegistry();
     foreach(const QString& checkplugin, m_preSavePostDialogFilterChecks)
     {
        if (lscps->preSavePostDialogFilterCheck(checkplugin,this)==false)
@@ -6285,18 +6240,10 @@
   return smartLocked;
 }
 
-
-KateDocument::LoadSaveFilterCheckPlugins* KateDocument::loadSaveFilterCheckPlugins()
-{
-  K_GLOBAL_STATIC(KateDocument::LoadSaveFilterCheckPlugins, \
                s_loadSaveFilterCheckPlugins)
-  return s_loadSaveFilterCheckPlugins;
-}
-
-
-
 // Kill our helpers again
 #ifdef FAST_DEBUG_ENABLE
 # undef FAST_DEBUG_ENABLE
 #endif
 #undef FAST_DEBUG
 
+// kate: space-indent on; indent-width 2; replace-tabs on;
Index: kate/document/katedocument.h
===================================================================
--- kate/document/katedocument.h	(revision 790219)
+++ kate/document/katedocument.h	(working copy)
@@ -46,7 +46,7 @@
 #include "kateautoindent.h"
 #include "katenamespace.h"
 
-namespace KTextEditor { class Plugin; class Attribute; }
+namespace KTextEditor { class Plugin; class Attribute; class \
LoadSaveFilterCheckRegistry; }  
 namespace KIO { class TransferJob; }
 
@@ -1126,17 +1126,13 @@
   protected Q_SLOTS:
       void testTemplateCode();
       void dumpRegionTree();
-  public:
-      class LoadSaveFilterCheckPlugins;
   private:
       void setPreSavePostDialogFilterChecks(QStringList plugins) \
{m_preSavePostDialogFilterChecks=plugins;}  QStringList \
                m_preSavePostDialogFilterChecks;
       void setPostLoadFilterChecks(QStringList plugins) \
{m_postLoadFilterChecks=plugins;}  QStringList m_postLoadFilterChecks;
-      static LoadSaveFilterCheckPlugins* loadSaveFilterCheckPlugins();
 };
 
 #endif
 
 // kate: space-indent on; indent-width 2; replace-tabs on;
-



_______________________________________________
KTextEditor-Devel mailing list
KTextEditor-Devel@kde.org
https://mail.kde.org/mailman/listinfo/ktexteditor-devel


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

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