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

List:       kwrite-devel
Subject:    Patch for moving LoadSaveFilterCheck in KTextEditor
From:       Cyrille Berger <cberger () cberger ! net>
Date:       2008-03-26 14:10:51
Message-ID: 200803261510.51799.cberger () cberger ! net
[Download RAW message or body]

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/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/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;
-



_______________________________________________
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