katefactory.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "config.h"
00020 #include "katefactory.h"
00021 
00022 #include "katedocument.h"
00023 #include "kateview.h"
00024 #include "katerenderer.h"
00025 #include "katecmds.h"
00026 #include "katefiletype.h"
00027 #include "kateschema.h"
00028 #include "katesearch.h"
00029 #include "kateconfig.h"
00030 #ifndef Q_WS_WIN //todo
00031 #include "katejscript.h"
00032 #endif
00033 #include "kateluaindentscript.h"
00034 #include "../interfaces/katecmd.h"
00035 
00036 #include <kvmallocator.h>
00037 #include <klocale.h>
00038 #include <kdirwatch.h>
00039 #include <kstaticdeleter.h>
00040 
00041 #include <qapplication.h>
00042 
00046 class KateFactoryPublic : public KParts::Factory
00047 {
00048   public:
00058     KParts::Part *createPartObject ( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *classname, const QStringList &args )
00059     {
00060       return KateFactory::self()->createPartObject (parentWidget, widgetName, parent, name, classname, args);
00061     }
00062 };
00063 
00064 K_EXPORT_COMPONENT_FACTORY( libkatepart, KateFactoryPublic )
00065 
00066 KateFactory *KateFactory::s_self = 0;
00067 
00068 KateFactory::KateFactory ()
00069  : m_aboutData ("katepart", I18N_NOOP("Kate Part"), KATEPART_VERSION,
00070              I18N_NOOP( "Embeddable editor component" ), KAboutData::License_LGPL_V2,
00071              I18N_NOOP( "(c) 2000-2004 The Kate Authors" ), 0, "http://kate.kde.org")
00072  , m_instance (&m_aboutData)
00073  , m_plugins (KTrader::self()->query("KTextEditor/Plugin"))
00074  , m_jscript (0)
00075 {
00076   // set s_self
00077   s_self = this;
00078 
00079   //
00080   // fill about data
00081   //
00082   m_aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
00083   m_aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
00084   m_aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
00085   m_aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org");
00086   m_aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" );
00087   m_aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org");
00088   m_aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com");
00089   m_aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at");
00090   m_aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz");
00091   m_aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
00092   m_aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org");
00093   m_aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" );
00094   m_aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" );
00095   m_aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
00096   m_aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
00097   m_aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org");
00098   m_aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "dhdev@gmx.de");
00099 
00100   m_aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
00101   m_aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu");
00102   m_aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),"");
00103   m_aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),"");
00104   m_aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),"");
00105   m_aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),"");
00106   m_aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),"");
00107   m_aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),"");
00108   m_aboutData.addCredit ("Daniel Naber","","");
00109   m_aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),"");
00110   m_aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),"");
00111   m_aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), "");
00112   m_aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"","");
00113 
00114   m_aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails"));
00115 
00116   //
00117   // dir watch
00118   //
00119   m_dirWatch = new KDirWatch ();
00120 
00121   //
00122   // filetype man
00123   //
00124   m_fileTypeManager = new KateFileTypeManager ();
00125 
00126   //
00127   // schema man
00128   //
00129   m_schemaManager = new KateSchemaManager ();
00130 
00131   // config objects
00132   m_documentConfig = new KateDocumentConfig ();
00133   m_viewConfig = new KateViewConfig ();
00134   m_rendererConfig = new KateRendererConfig ();
00135 
00136   // vm allocator
00137   m_vm = new KVMAllocator ();
00138 
00139 #ifndef Q_WS_WIN //todo
00140   // create script man (search scripts) + register commands
00141   m_jscriptManager = new KateJScriptManager ();
00142   KateCmd::self()->registerCommand (m_jscriptManager);
00143   m_indentScriptManagers.append(new KateIndentJScriptManager());
00144 #else
00145   m_jscriptManager = 0;
00146 #endif
00147 #ifdef HAVE_LUA
00148   m_indentScriptManagers.append(new KateLUAIndentScriptManager());
00149 #endif
00150   //
00151   // init the cmds
00152   //
00153   m_cmds.push_back (new KateCommands::CoreCommands());
00154   m_cmds.push_back (new KateCommands::SedReplace ());
00155   m_cmds.push_back (new KateCommands::Character ());
00156   m_cmds.push_back (new KateCommands::Date ());
00157   m_cmds.push_back (new SearchCommand());
00158 
00159   for ( QValueList<Kate::Command *>::iterator it = m_cmds.begin(); it != m_cmds.end(); ++it )
00160     KateCmd::self()->registerCommand (*it);
00161 }
00162 
00163 KateFactory::~KateFactory()
00164 {
00165   /* ?hack? If  MainApplication-Interface::quit is called by dcop the factory gets destroyed before all documents are destroyed eg in kwrite.
00166   This could happen in other apps too. Since the documents try to unregister a new factory is created (in the ::self call) and registered with a
00167   KStaticDeleter which causes a crash. That's why I ensure here that all documents are destroyed before the factory goes down (JOWENN)*/
00168   while (KateDocument *doc=m_documents.first()) {
00169     s_self=this; /* this is needed because the KStaticDeleter sets the global reference to 0, before it deletes the object it handles.
00170     To prevent a crash again restore the factory pointer temporarily. (jowenn)*/
00171     delete doc;
00172     s_self=0;
00173   }
00174   /*another solution would be to set a flag in the documents, and inhibit calling of the deregistering methods, but I don't see a problem
00175   if all created objects are deleted before their factory. If somebody sees a problem, let me know*/
00176 
00177   delete m_documentConfig;
00178   delete m_viewConfig;
00179   delete m_rendererConfig;
00180 
00181   delete m_fileTypeManager;
00182   delete m_schemaManager;
00183 
00184   delete m_dirWatch;
00185 
00186   delete m_vm;
00187 
00188   for ( QValueList<Kate::Command *>::iterator it = m_cmds.begin(); it != m_cmds.end(); ++it )
00189     delete *it;
00190 
00191   // cu manager
00192   delete m_jscriptManager;
00193   m_indentScriptManagers.setAutoDelete(true);
00194   // cu jscript
00195   delete m_jscript;
00196 }
00197 
00198 static KStaticDeleter<KateFactory> sdFactory;
00199 
00200 KateFactory *KateFactory::self ()
00201 {
00202   if (!s_self) {
00203     sdFactory.setObject(s_self, new KateFactory ());
00204   }
00205   return s_self;
00206 }
00207 
00208 KParts::Part *KateFactory::createPartObject ( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *_classname, const QStringList & )
00209 {
00210   QCString classname( _classname );
00211   bool bWantSingleView = ( classname != "KTextEditor::Document" && classname != "Kate::Document" );
00212   bool bWantBrowserView = ( classname == "Browser/View" );
00213   bool bWantReadOnly = (bWantBrowserView || ( classname == "KParts::ReadOnlyPart" ));
00214 
00215   KParts::ReadWritePart *part = new KateDocument (bWantSingleView, bWantBrowserView, bWantReadOnly, parentWidget, widgetName, parent, name);
00216   part->setReadWrite( !bWantReadOnly );
00217 
00218   return part;
00219 }
00220 
00221 void KateFactory::registerDocument ( KateDocument *doc )
00222 {
00223   m_documents.append( doc );
00224 }
00225 
00226 void KateFactory::deregisterDocument ( KateDocument *doc )
00227 {
00228   m_documents.removeRef( doc );
00229 }
00230 
00231 void KateFactory::registerView ( KateView *view )
00232 {
00233   m_views.append( view );
00234 }
00235 
00236 void KateFactory::deregisterView ( KateView *view )
00237 {
00238   m_views.removeRef( view );
00239 }
00240 
00241 void KateFactory::registerRenderer ( KateRenderer  *renderer )
00242 {
00243   m_renderers.append( renderer );
00244 }
00245 
00246 void KateFactory::deregisterRenderer ( KateRenderer  *renderer )
00247 {
00248   m_renderers.removeRef( renderer );
00249 }
00250 
00251 KateJScript *KateFactory::jscript ()
00252 {
00253 #ifndef Q_WS_WIN //todo
00254   if (m_jscript)
00255     return m_jscript;
00256 
00257   return m_jscript = new KateJScript ();
00258 #else
00259   return 0;
00260 #endif
00261 }
00262 
00263 
00264 KateIndentScript KateFactory::indentScript (const QString &scriptname)
00265 {
00266   KateIndentScript result;
00267   for(uint i=0;i<m_indentScriptManagers.count();i++)
00268   {
00269     result=m_indentScriptManagers.at(i)->script(scriptname);
00270     if (!result.isNull()) return result;
00271   }
00272   return result;
00273 }
00274 
00275 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Home | KDE Accessibility Home | Description of Access Keys