TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

katefactory.cpp 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License version 2 as published by the Free Software Foundation.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public License
  11. along with this library; see the file COPYING.LIB. If not, write to
  12. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  13. Boston, MA 02110-1301, USA.
  14. */
  15. #include "config.h"
  16. #include "katefactory.h"
  17. #include "katedocument.h"
  18. #include "kateview.h"
  19. #include "katerenderer.h"
  20. #include "katecmds.h"
  21. #include "katefiletype.h"
  22. #include "kateschema.h"
  23. #include "katesearch.h"
  24. #include "kateconfig.h"
  25. #ifndef Q_WS_WIN //todo
  26. #include "katejscript.h"
  27. #endif
  28. #include "kateluaindentscript.h"
  29. #include "../interfaces/katecmd.h"
  30. #include <kvmallocator.h>
  31. #include <tdelocale.h>
  32. #include <kdirwatch.h>
  33. #include <kstaticdeleter.h>
  34. #include <tqapplication.h>
  35. /**
  36. * dummy wrapper factory to be sure nobody external deletes our katefactory
  37. */
  38. class KateFactoryPublic : public KParts::Factory
  39. {
  40. public:
  41. /**
  42. * reimplemented create object method
  43. * @param parentWidget parent widget
  44. * @param widgetName widget name
  45. * @param parent TQObject parent
  46. * @param name object name
  47. * @param classname class name
  48. * @param args additional arguments
  49. * @return constructed part object
  50. */
  51. KParts::Part *createPartObject ( TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const char *classname, const TQStringList &args )
  52. {
  53. return KateFactory::self()->createPartObject (parentWidget, widgetName, parent, name, classname, args);
  54. }
  55. };
  56. K_EXPORT_COMPONENT_FACTORY( libkatepart, KateFactoryPublic )
  57. KateFactory *KateFactory::s_self = 0;
  58. KateFactory::KateFactory ()
  59. : m_aboutData ("katepart", I18N_NOOP("Kate Part"), KATEPART_VERSION,
  60. I18N_NOOP( "Embeddable editor component" ), TDEAboutData::License_LGPL_V2,
  61. I18N_NOOP( "(c) 2000-2004 The Kate Authors" ), 0, "http://kate.kde.org")
  62. , m_instance (&m_aboutData)
  63. , m_plugins (TDETrader::self()->query("KTextEditor/Plugin"))
  64. , m_jscript (0)
  65. {
  66. // set s_self
  67. s_self = this;
  68. //
  69. // fill about data
  70. //
  71. m_aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
  72. m_aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
  73. m_aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
  74. m_aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org");
  75. m_aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" );
  76. m_aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org");
  77. m_aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com");
  78. m_aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at");
  79. m_aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz");
  80. m_aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
  81. m_aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org");
  82. m_aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" );
  83. m_aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" );
  84. m_aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
  85. m_aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
  86. m_aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org");
  87. m_aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "dhdev@gmx.de");
  88. m_aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
  89. m_aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu");
  90. m_aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),"");
  91. m_aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),"");
  92. m_aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),"");
  93. m_aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),"");
  94. m_aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),"");
  95. m_aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),"");
  96. m_aboutData.addCredit ("Daniel Naber","","");
  97. m_aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),"");
  98. m_aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),"");
  99. m_aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), "");
  100. m_aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"","");
  101. m_aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails"));
  102. //
  103. // dir watch
  104. //
  105. m_dirWatch = new KDirWatch ();
  106. //
  107. // filetype man
  108. //
  109. m_fileTypeManager = new KateFileTypeManager ();
  110. //
  111. // schema man
  112. //
  113. m_schemaManager = new KateSchemaManager ();
  114. // config objects
  115. m_documentConfig = new KateDocumentConfig ();
  116. m_viewConfig = new KateViewConfig ();
  117. m_rendererConfig = new KateRendererConfig ();
  118. // vm allocator
  119. m_vm = new KVMAllocator ();
  120. #ifndef Q_WS_WIN //todo
  121. // create script man (search scripts) + register commands
  122. m_jscriptManager = new KateJScriptManager ();
  123. KateCmd::self()->registerCommand (m_jscriptManager);
  124. m_indentScriptManagers.append(new KateIndentJScriptManager());
  125. #else
  126. m_jscriptManager = 0;
  127. #endif
  128. #ifdef HAVE_LUA
  129. m_indentScriptManagers.append(new KateLUAIndentScriptManager());
  130. #endif
  131. //
  132. // init the cmds
  133. //
  134. m_cmds.push_back (new KateCommands::CoreCommands());
  135. m_cmds.push_back (new KateCommands::SedReplace ());
  136. m_cmds.push_back (new KateCommands::Character ());
  137. m_cmds.push_back (new KateCommands::Date ());
  138. m_cmds.push_back (new SearchCommand());
  139. for ( TQValueList<Kate::Command *>::iterator it = m_cmds.begin(); it != m_cmds.end(); ++it )
  140. KateCmd::self()->registerCommand (*it);
  141. }
  142. KateFactory::~KateFactory()
  143. {
  144. /* ?hack? If MainApplication-Interface::quit is called by dcop the factory gets destroyed before all documents are destroyed eg in kwrite.
  145. 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
  146. KStaticDeleter which causes a crash. That's why I ensure here that all documents are destroyed before the factory goes down (JOWENN)*/
  147. while (KateDocument *doc=m_documents.first()) {
  148. s_self=this; /* this is needed because the KStaticDeleter sets the global reference to 0, before it deletes the object it handles.
  149. To prevent a crash again restore the factory pointer temporarily. (jowenn)*/
  150. delete doc;
  151. s_self=0;
  152. }
  153. /*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
  154. if all created objects are deleted before their factory. If somebody sees a problem, let me know*/
  155. delete m_documentConfig;
  156. delete m_viewConfig;
  157. delete m_rendererConfig;
  158. delete m_fileTypeManager;
  159. delete m_schemaManager;
  160. delete m_dirWatch;
  161. delete m_vm;
  162. for ( TQValueList<Kate::Command *>::iterator it = m_cmds.begin(); it != m_cmds.end(); ++it )
  163. delete *it;
  164. // cu manager
  165. delete m_jscriptManager;
  166. m_indentScriptManagers.setAutoDelete(true);
  167. // cu jscript
  168. delete m_jscript;
  169. }
  170. static KStaticDeleter<KateFactory> sdFactory;
  171. KateFactory *KateFactory::self ()
  172. {
  173. if (!s_self) {
  174. sdFactory.setObject(s_self, new KateFactory ());
  175. }
  176. return s_self;
  177. }
  178. KParts::Part *KateFactory::createPartObject ( TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const char *_classname, const TQStringList & )
  179. {
  180. TQCString classname( _classname );
  181. bool bWantSingleView = ( classname != "KTextEditor::Document" && classname != "Kate::Document" );
  182. bool bWantBrowserView = ( classname == "Browser/View" );
  183. bool bWantReadOnly = (bWantBrowserView || ( classname == "KParts::ReadOnlyPart" ));
  184. KParts::ReadWritePart *part = new KateDocument (bWantSingleView, bWantBrowserView, bWantReadOnly, parentWidget, widgetName, parent, name);
  185. part->setReadWrite( !bWantReadOnly );
  186. return part;
  187. }
  188. void KateFactory::registerDocument ( KateDocument *doc )
  189. {
  190. m_documents.append( doc );
  191. }
  192. void KateFactory::deregisterDocument ( KateDocument *doc )
  193. {
  194. m_documents.removeRef( doc );
  195. }
  196. void KateFactory::registerView ( KateView *view )
  197. {
  198. m_views.append( view );
  199. }
  200. void KateFactory::deregisterView ( KateView *view )
  201. {
  202. m_views.removeRef( view );
  203. }
  204. void KateFactory::registerRenderer ( KateRenderer *renderer )
  205. {
  206. m_renderers.append( renderer );
  207. }
  208. void KateFactory::deregisterRenderer ( KateRenderer *renderer )
  209. {
  210. m_renderers.removeRef( renderer );
  211. }
  212. KateJScript *KateFactory::jscript ()
  213. {
  214. #ifndef Q_WS_WIN //todo
  215. if (m_jscript)
  216. return m_jscript;
  217. return m_jscript = new KateJScript ();
  218. #else
  219. return 0;
  220. #endif
  221. }
  222. KateIndentScript KateFactory::indentScript (const TQString &scriptname)
  223. {
  224. KateIndentScript result;
  225. for(uint i=0;i<m_indentScriptManagers.count();i++)
  226. {
  227. result=m_indentScriptManagers.at(i)->script(scriptname);
  228. if (!result.isNull()) return result;
  229. }
  230. return result;
  231. }
  232. // kate: space-indent on; indent-width 2; replace-tabs on;