--Boundary-00=_+ZO7HIoJQtHV5D4 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, Here is an updated version of the patch after discussing the previous version with Dominik Haumann: now there is a plugin interface : KTextEditor::PluginFilterExtension* , plugins should implement that, then katepart check if the plugin inherits it, and made it available for use in document. -- Cyrille Berger --Boundary-00=_+ZO7HIoJQtHV5D4 Content-Type: text/x-diff; charset="iso-8859-15"; name="texteditor-loadsavefiltercheck.2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="texteditor-loadsavefiltercheck.2.diff" Index: interfaces/ktexteditor/CMakeLists.txt =================================================================== --- interfaces/ktexteditor/CMakeLists.txt (revision 790219) +++ interfaces/ktexteditor/CMakeLists.txt (working copy) @@ -59,6 +59,7 @@ codecompletionmodel.h configinterface.h containerinterface.h + pluginfilterextension.h DESTINATION ${INCLUDE_INSTALL_DIR}/ktexteditor COMPONENT Devel) install( FILES ktexteditor.desktop ktexteditorplugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) Index: interfaces/ktexteditor/pluginfilterextension.h =================================================================== --- interfaces/ktexteditor/pluginfilterextension.h (revision 0) +++ interfaces/ktexteditor/pluginfilterextension.h (revision 0) @@ -0,0 +1,66 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001-2004 Christoph Cullmann + Copyright (C) 2001 Joseph Wenninger + Copyright (C) 1999 Jochen Wilhelmy + Copyright (C) 2006 Hamish Rodda + Copyright (C) 2007 Mirko Stocker + + 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 _PLUGINFILTEREXTENSION_H_ +#define _PLUGINFILTEREXTENSION_H_ + +#include +#include +#include + +namespace KTextEditor { + class Document; + /** + * This plugin allows to filter a file after loading and before saving. + * For instance, this can be used either for applying a transformation + * to a file or either that it validates or to save into a distributed + * version control system. + */ + class KTEXTEDITOR_EXPORT PluginFilterExtension { + public: + PluginFilterExtension() {} + virtual ~PluginFilterExtension(){} + /** + * 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 preSaveFilter(KTextEditor::Document *document) const =0; + /** + * this one should be called once the document has been completely + * loaded and configured (encoding,highlighting, ...)) + */ + virtual void postLoadFilter(KTextEditor::Document *document) const =0; + /** + * @return the list of mime type that are supported by this filter, + * or empty if it apply for all mime types + */ + virtual QList mimeType() const = 0; + /** + * @return a wildcard for files supported by this filter. + */ + virtual QString wildCard() const =0; + }; + +} + +#endif Index: kate/utils/katepartpluginmanager.cpp =================================================================== --- kate/utils/katepartpluginmanager.cpp (revision 790219) +++ kate/utils/katepartpluginmanager.cpp (working copy) @@ -24,6 +24,7 @@ #include "kateglobal.h" +#include #include #include #include @@ -187,6 +188,11 @@ item.plugin = KTextEditor::createPlugin (item.service, this); Q_ASSERT(item.plugin); item.load = (item.plugin != 0); + KTextEditor::PluginFilterExtension* pluginFilterExtension = dynamic_cast(item.plugin); + if( pluginFilterExtension ) + { + m_filtersExtension[ item.saveName() ] = pluginFilterExtension; + } } void KatePartPluginManager::unloadPlugin (KatePartPluginInfo &item) @@ -250,4 +256,9 @@ } } +const KTextEditor::PluginFilterExtension* KatePartPluginManager::filterExtension(const QString& name) +{ + return m_filtersExtension.value( name ); +} + // kate: space-indent on; indent-width 2; replace-tabs on; Index: kate/utils/katepartpluginmanager.h =================================================================== --- kate/utils/katepartpluginmanager.h (revision 790219) +++ kate/utils/katepartpluginmanager.h (working copy) @@ -31,6 +31,7 @@ namespace KTextEditor { class Plugin; + class PluginFilterExtension; class Document; class View; } @@ -78,12 +79,15 @@ { return m_pluginList; } + + const KTextEditor::PluginFilterExtension* filterExtension(const QString& name); private: void setupPluginList (); KConfig *m_config; KatePartPluginList m_pluginList; + QMap m_filtersExtension; }; #endif // KATEPLUGINMANAGER_H Index: kate/document/katedocument.cpp =================================================================== --- kate/document/katedocument.cpp (revision 790219) +++ kate/document/katedocument.cpp (working copy) @@ -21,6 +21,7 @@ */ //BEGIN includes +#include #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() { - QHashIteratori(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 m_plugins; -}; - + //BEGIN d'tor, c'tor // // KateDocument Constructor @@ -3416,10 +3371,13 @@ if (!m_postLoadFilterChecks.isEmpty()) { - LoadSaveFilterCheckPlugins *lscps=loadSaveFilterCheckPlugins(); foreach(const QString& checkplugin, m_postLoadFilterChecks) { - lscps->postLoadFilter(checkplugin,this); + const KTextEditor::PluginFilterExtension* extension = KatePartPluginManager::self()->filterExtension( checkplugin ); + if( extension ) + { + extension->postLoadFilter(this); + } } } } @@ -3629,10 +3587,10 @@ if (!m_preSavePostDialogFilterChecks.isEmpty()) { - LoadSaveFilterCheckPlugins *lscps=loadSaveFilterCheckPlugins(); foreach(const QString& checkplugin, m_preSavePostDialogFilterChecks) { - if (lscps->preSavePostDialogFilterCheck(checkplugin,this)==false) + const KTextEditor::PluginFilterExtension* extension = KatePartPluginManager::self()->filterExtension( checkplugin ); + if (extension && extension->preSaveFilter(this)==false) return false; } } @@ -6285,18 +6243,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) @@ -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; - --Boundary-00=_+ZO7HIoJQtHV5D4 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ KTextEditor-Devel mailing list KTextEditor-Devel@kde.org https://mail.kde.org/mailman/listinfo/ktexteditor-devel --Boundary-00=_+ZO7HIoJQtHV5D4--