Kate
kateglobal.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries and the Kate part. 00002 * 00003 * Copyright (C) 2001-2010 Christoph Cullmann <cullmann@kde.org> 00004 * Copyright (C) 2009 Erlend Hamberg <ehamberg@gmail.com> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "kateglobal.h" 00023 #include "kateglobal.moc" 00024 00025 #include "katedocument.h" 00026 #include "kateview.h" 00027 #include "katerenderer.h" 00028 #include "katecmds.h" 00029 #include "katemodemanager.h" 00030 #include "kateschema.h" 00031 #include "kateconfig.h" 00032 #include "katescriptmanager.h" 00033 #include "katecmd.h" 00034 #include "katebuffer.h" 00035 #include "katepartpluginmanager.h" 00036 #include "kateviglobal.h" 00037 #include "katewordcompletion.h" 00038 #include "spellcheck/spellcheck.h" 00039 00040 #include <klocale.h> 00041 #include <kservicetypetrader.h> 00042 #include <kdirwatch.h> 00043 #include <kdebug.h> 00044 #include <kdeversion.h> 00045 #include <kpagedialog.h> 00046 #include <kpagewidgetmodel.h> 00047 #include <kiconloader.h> 00048 00049 #include <QtCore/QPointer> 00050 00051 #include <QtGui/QBoxLayout> 00052 00053 KateGlobal *KateGlobal::s_self = 0; 00054 00055 int KateGlobal::s_ref = 0; 00056 00057 QString KateGlobal::katePartVersion() 00058 { 00059 return QString("3.6"); 00060 } 00061 00062 KateGlobal::KateGlobal () 00063 : KTextEditor::Editor (0) 00064 , m_aboutData ("katepart", 0, ki18n("Kate Part"), katePartVersion().toLatin1(), 00065 ki18n( "Embeddable editor component" ), KAboutData::License_LGPL_V2, 00066 ki18n( "(c) 2000-2009 The Kate Authors" ), KLocalizedString(), "http://www.kate-editor.org") 00067 , m_componentData (&m_aboutData) 00068 { 00069 // set s_self 00070 s_self = this; 00071 00072 // load the kate part translation catalog 00073 KGlobal::locale()->insertCatalog("katepart4"); 00074 00075 // 00076 // fill about data 00077 // 00078 m_aboutData.setProgramIconName("preferences-plugin"); 00079 m_aboutData.addAuthor (ki18n("Christoph Cullmann"), ki18n("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de"); 00080 m_aboutData.addAuthor (ki18n("Anders Lund"), ki18n("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk"); 00081 m_aboutData.addAuthor (ki18n("Joseph Wenninger"), ki18n("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371"); 00082 m_aboutData.addAuthor (ki18n("Hamish Rodda"), ki18n("Core Developer"), "rodda@kde.org"); 00083 m_aboutData.addAuthor (ki18n("Dominik Haumann"), ki18n("Core Developer"), "dhaumann@kde.de"); 00084 m_aboutData.addAuthor (ki18n("Erlend Hamberg"), ki18n("Vi Input Mode"), "ehamberg@gmail.com", "http://hamberg.no/erlend"); 00085 m_aboutData.addAuthor (ki18n("Bernhard Beschow"), ki18n("Developer"), "bbeschow@cs.tu-berlin.de", "https://user.cs.tu-berlin.de/~bbeschow"); 00086 m_aboutData.addAuthor (ki18n("Waldo Bastian"), ki18n( "The cool buffersystem" ), "bastian@kde.org" ); 00087 m_aboutData.addAuthor (ki18n("Charles Samuels"), ki18n("The Editing Commands"), "charles@kde.org"); 00088 m_aboutData.addAuthor (ki18n("Matt Newell"), ki18n("Testing, ..."), "newellm@proaxis.com"); 00089 m_aboutData.addAuthor (ki18n("Michael Bartl"), ki18n("Former Core Developer"), "michael.bartl1@chello.at"); 00090 m_aboutData.addAuthor (ki18n("Michael McCallum"), ki18n("Core Developer"), "gholam@xtra.co.nz"); 00091 m_aboutData.addAuthor (ki18n("Jochen Wilhemly"), ki18n( "KWrite Author" ), "digisnap@cs.tu-berlin.de" ); 00092 m_aboutData.addAuthor (ki18n("Michael Koch"), ki18n("KWrite port to KParts"), "koch@kde.org"); 00093 m_aboutData.addAuthor (ki18n("Christian Gebauer"), KLocalizedString(), "gebauer@kde.org" ); 00094 m_aboutData.addAuthor (ki18n("Simon Hausmann"), KLocalizedString(), "hausmann@kde.org" ); 00095 m_aboutData.addAuthor (ki18n("Glen Parker"), ki18n("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com"); 00096 m_aboutData.addAuthor (ki18n("Scott Manson"), ki18n("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net"); 00097 m_aboutData.addAuthor (ki18n("John Firebaugh"), ki18n("Patches and more"), "jfirebaugh@kde.org"); 00098 m_aboutData.addAuthor (ki18n("Andreas Kling"), ki18n("Developer"), "kling@impul.se"); 00099 m_aboutData.addAuthor (ki18n("Mirko Stocker"), ki18n("Various bugfixes"), "me@misto.ch", "http://misto.ch/"); 00100 m_aboutData.addAuthor (ki18n("Matthew Woehlke"), ki18n("Selection, KColorScheme integration"), "mw_triad@users.sourceforge.net"); 00101 m_aboutData.addAuthor (ki18n("Sebastian Pipping"), ki18n("Search bar back- and front-end"), "webmaster@hartwork.org", "http://www.hartwork.org/"); 00102 m_aboutData.addAuthor (ki18n("Michel Ludwig"), ki18n("On-the-fly spell checking"), "michel.ludwig@kdemail.net"); 00103 00104 m_aboutData.addCredit (ki18n("Matteo Merli"), ki18n("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it"); 00105 m_aboutData.addCredit (ki18n("Rocky Scaletta"), ki18n("Highlighting for VHDL"), "rocky@purdue.edu"); 00106 m_aboutData.addCredit (ki18n("Yury Lebedev"), ki18n("Highlighting for SQL"),""); 00107 m_aboutData.addCredit (ki18n("Chris Ross"), ki18n("Highlighting for Ferite"),""); 00108 m_aboutData.addCredit (ki18n("Nick Roux"), ki18n("Highlighting for ILERPG"),""); 00109 m_aboutData.addCredit (ki18n("Carsten Niehaus"), ki18n("Highlighting for LaTeX"),""); 00110 m_aboutData.addCredit (ki18n("Per Wigren"), ki18n("Highlighting for Makefiles, Python"),""); 00111 m_aboutData.addCredit (ki18n("Jan Fritz"), ki18n("Highlighting for Python"),""); 00112 m_aboutData.addCredit (ki18n("Daniel Naber")); 00113 m_aboutData.addCredit (ki18n("Roland Pabel"), ki18n("Highlighting for Scheme"),""); 00114 m_aboutData.addCredit (ki18n("Cristi Dumitrescu"), ki18n("PHP Keyword/Datatype list"),""); 00115 m_aboutData.addCredit (ki18n("Carsten Pfeiffer"), ki18n("Very nice help"), ""); 00116 m_aboutData.addCredit (ki18n("Bruno Massa"), ki18n("Highlighting for Lua"), "brmassa@gmail.com"); 00117 00118 m_aboutData.addCredit (ki18n("All people who have contributed and I have forgotten to mention")); 00119 00120 m_aboutData.setTranslator(ki18nc("NAME OF TRANSLATORS","Your names"), ki18nc("EMAIL OF TRANSLATORS","Your emails")); 00121 00122 // 00123 // dir watch 00124 // 00125 m_dirWatch = new KDirWatch (); 00126 00127 // 00128 // command manager 00129 // 00130 m_cmdManager = new KateCmd (); 00131 00132 // 00133 // hl manager 00134 // 00135 m_hlManager = new KateHlManager (); 00136 00137 // 00138 // mode man 00139 // 00140 m_modeManager = new KateModeManager (); 00141 00142 // 00143 // schema man 00144 // 00145 m_schemaManager = new KateSchemaManager (); 00146 00147 // 00148 // vi input mode global 00149 // 00150 m_viInputModeGlobal = new KateViGlobal (); 00151 00152 // 00153 // spell check manager 00154 // 00155 m_spellCheckManager = new KateSpellCheckManager (); 00156 00157 // config objects 00158 m_globalConfig = new KateGlobalConfig (); 00159 m_documentConfig = new KateDocumentConfig (); 00160 m_viewConfig = new KateViewConfig (); 00161 m_rendererConfig = new KateRendererConfig (); 00162 00163 // create script manager (search scripts) 00164 m_scriptManager = new KateScriptManager (); 00165 00166 // 00167 // plugin manager 00168 // 00169 m_pluginManager = new KatePartPluginManager (); 00170 00171 // 00172 // init the cmds 00173 // 00174 m_cmds.push_back (new KateCommands::CoreCommands()); 00175 m_cmds.push_back (new KateCommands::ViCommands()); 00176 m_cmds.push_back (new KateCommands::AppCommands()); 00177 m_cmds.push_back (new KateCommands::SedReplace ()); 00178 m_cmds.push_back (new KateCommands::Character ()); 00179 m_cmds.push_back (new KateCommands::Date ()); 00180 00181 for ( QList<KTextEditor::Command *>::iterator it = m_cmds.begin(); it != m_cmds.end(); ++it ) 00182 m_cmdManager->registerCommand (*it); 00183 00184 // global word completion model 00185 m_wordCompletionModel = new KateWordCompletionModel (this); 00186 } 00187 00188 KateGlobal::~KateGlobal() 00189 { 00190 delete m_pluginManager; 00191 00192 delete m_globalConfig; 00193 delete m_documentConfig; 00194 delete m_viewConfig; 00195 delete m_rendererConfig; 00196 00197 delete m_modeManager; 00198 delete m_schemaManager; 00199 00200 delete m_dirWatch; 00201 00202 // you too 00203 qDeleteAll (m_cmds); 00204 00205 // cu managers 00206 delete m_scriptManager; 00207 delete m_hlManager; 00208 delete m_cmdManager; 00209 00210 delete m_viInputModeGlobal; 00211 delete m_spellCheckManager; 00212 00213 // cu model 00214 delete m_wordCompletionModel; 00215 00216 s_self = 0; 00217 } 00218 00219 KTextEditor::Document *KateGlobal::createDocument ( QObject *parent ) 00220 { 00221 KateDocument *doc = new KateDocument (false, false, false, 0, parent); 00222 00223 emit documentCreated (this, doc); 00224 00225 return doc; 00226 } 00227 00228 const QList<KTextEditor::Document*> &KateGlobal::documents () 00229 { 00230 return m_docs; 00231 } 00232 00233 //BEGIN KTextEditor::Editor config stuff 00234 void KateGlobal::readConfig(KConfig *config) 00235 { 00236 if( !config ) 00237 config = KGlobal::config().data(); 00238 00239 KateGlobalConfig::global()->readConfig (KConfigGroup(config, "Kate Part Defaults")); 00240 00241 KateDocumentConfig::global()->readConfig (KConfigGroup(config, "Kate Document Defaults")); 00242 00243 KateViewConfig::global()->readConfig (KConfigGroup(config, "Kate View Defaults")); 00244 00245 KateRendererConfig::global()->readConfig (KConfigGroup(config, "Kate Renderer Defaults")); 00246 00247 m_viInputModeGlobal->readConfig( KConfigGroup( config, "Kate Vi Input Mode Settings" ) ); 00248 } 00249 00250 void KateGlobal::writeConfig(KConfig *config) 00251 { 00252 if( !config ) 00253 config = KGlobal::config().data(); 00254 00255 KConfigGroup cgGlobal(config, "Kate Part Defaults"); 00256 KateGlobalConfig::global()->writeConfig (cgGlobal); 00257 00258 KConfigGroup cg(config, "Kate Document Defaults"); 00259 KateDocumentConfig::global()->writeConfig (cg); 00260 00261 KConfigGroup cgDefault(config, "Kate View Defaults"); 00262 KateViewConfig::global()->writeConfig (cgDefault); 00263 00264 KConfigGroup cgRenderer(config, "Kate Renderer Defaults"); 00265 KateRendererConfig::global()->writeConfig (cgRenderer); 00266 00267 KConfigGroup cgViInputMode(config, "Kate Vi Input Mode Settings"); 00268 m_viInputModeGlobal->writeConfig (cgViInputMode); 00269 00270 config->sync(); 00271 } 00272 //END KTextEditor::Editor config stuff 00273 00274 bool KateGlobal::configDialogSupported () const 00275 { 00276 return true; 00277 } 00278 00279 void KateGlobal::configDialog(QWidget *parent) 00280 { 00281 QPointer<KPageDialog> kd = new KPageDialog(parent); 00282 kd->setCaption( i18n("Configure") ); 00283 kd->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Help ); 00284 kd->setFaceType( KPageDialog::List ); 00285 kd->setHelp( QString(), KGlobal::mainComponent().componentName() ); 00286 00287 QList<KTextEditor::ConfigPage*> editorPages; 00288 00289 for (int i = 0; i < configPages (); ++i) 00290 { 00291 const QString name = configPageName (i); 00292 00293 QFrame *page = new QFrame(); 00294 00295 KPageWidgetItem *item = kd->addPage( page, name ); 00296 item->setHeader( configPageFullName (i) ); 00297 item->setIcon( configPageIcon(i) ); 00298 00299 QVBoxLayout *topLayout = new QVBoxLayout( page ); 00300 topLayout->setMargin( 0 ); 00301 00302 KTextEditor::ConfigPage *cp = configPage(i, page); 00303 topLayout->addWidget( cp); 00304 editorPages.append (cp); 00305 } 00306 00307 if (kd->exec() && kd) 00308 { 00309 KateGlobalConfig::global()->configStart (); 00310 KateDocumentConfig::global()->configStart (); 00311 KateViewConfig::global()->configStart (); 00312 KateRendererConfig::global()->configStart (); 00313 00314 for (int i=0; i < editorPages.count(); ++i) 00315 { 00316 editorPages.at(i)->apply(); 00317 } 00318 00319 KateGlobalConfig::global()->configEnd (); 00320 KateDocumentConfig::global()->configEnd (); 00321 KateViewConfig::global()->configEnd (); 00322 KateRendererConfig::global()->configEnd (); 00323 00324 writeConfig (); 00325 } 00326 00327 delete kd; 00328 } 00329 00330 int KateGlobal::configPages () const 00331 { 00332 return 5; 00333 } 00334 00335 KTextEditor::ConfigPage *KateGlobal::configPage (int number, QWidget *parent) 00336 { 00337 switch( number ) 00338 { 00339 case 0: 00340 return new KateViewDefaultsConfig (parent); 00341 00342 case 1: 00343 return new KateSchemaConfigPage (parent); 00344 00345 case 2: 00346 return new KateEditConfigTab (parent); 00347 00348 case 3: 00349 return new KateSaveConfigTab (parent); 00350 00351 case 4: 00352 return new KatePartPluginConfigPage (parent); 00353 00354 default: 00355 return 0; 00356 } 00357 00358 return 0; 00359 } 00360 00361 QString KateGlobal::configPageName (int number) const 00362 { 00363 switch( number ) 00364 { 00365 case 0: 00366 return i18n ("Appearance"); 00367 00368 case 1: 00369 return i18n ("Fonts & Colors"); 00370 00371 case 2: 00372 return i18n ("Editing"); 00373 00374 case 3: 00375 return i18n("Open/Save"); 00376 00377 case 4: 00378 return i18n ("Extensions"); 00379 00380 default: 00381 return QString (""); 00382 } 00383 00384 return QString (""); 00385 } 00386 00387 QString KateGlobal::configPageFullName (int number) const 00388 { 00389 switch( number ) 00390 { 00391 case 0: 00392 return i18n("Appearance"); 00393 00394 case 1: 00395 return i18n ("Font & Color Schemas"); 00396 00397 case 2: 00398 return i18n ("Editing Options"); 00399 00400 case 3: 00401 return i18n("File Opening & Saving"); 00402 00403 case 4: 00404 return i18n ("Extensions Manager"); 00405 00406 default: 00407 return QString (""); 00408 } 00409 00410 return QString (""); 00411 } 00412 00413 KIcon KateGlobal::configPageIcon (int number) const 00414 { 00415 switch( number ) 00416 { 00417 case 0: 00418 return KIcon("preferences-desktop-theme"); 00419 00420 case 1: 00421 return KIcon("preferences-desktop-color"); 00422 00423 case 2: 00424 return KIcon("accessories-text-editor"); 00425 00426 case 3: 00427 return KIcon("document-save"); 00428 00429 case 4: 00430 return KIcon("preferences-plugin"); 00431 00432 default: 00433 return KIcon("document-properties"); 00434 } 00435 00436 return KIcon("document-properties"); 00437 } 00438 00439 KateGlobal *KateGlobal::self () 00440 { 00441 if (!s_self) { 00442 new KateGlobal (); 00443 } 00444 00445 return s_self; 00446 } 00447 00448 void KateGlobal::registerDocument ( KateDocument *doc ) 00449 { 00450 KateGlobal::incRef (); 00451 m_documents.append( doc ); 00452 m_docs.append (doc); 00453 } 00454 00455 void KateGlobal::deregisterDocument ( KateDocument *doc ) 00456 { 00457 m_docs.removeAll (doc); 00458 m_documents.removeAll( doc ); 00459 KateGlobal::decRef (); 00460 } 00461 00462 void KateGlobal::registerView ( KateView *view ) 00463 { 00464 KateGlobal::incRef (); 00465 m_views.append( view ); 00466 } 00467 00468 void KateGlobal::deregisterView ( KateView *view ) 00469 { 00470 m_views.removeAll( view ); 00471 KateGlobal::decRef (); 00472 } 00473 00474 //BEGIN command interface 00475 bool KateGlobal::registerCommand (KTextEditor::Command *cmd) 00476 {return m_cmdManager->registerCommand(cmd);} 00477 00478 bool KateGlobal::unregisterCommand (KTextEditor::Command *cmd) 00479 {return m_cmdManager->unregisterCommand(cmd);} 00480 00481 KTextEditor::Command *KateGlobal::queryCommand (const QString &cmd) const 00482 {return m_cmdManager->queryCommand(cmd);} 00483 00484 QList<KTextEditor::Command*> KateGlobal::commands() const 00485 {return m_cmdManager->commands();} 00486 00487 QStringList KateGlobal::commandList() const 00488 {return m_cmdManager->commandList();} 00489 //END command interface 00490 00491 00492 //BEGIN container interface 00493 QObject * KateGlobal::container() 00494 {return m_container.data();} 00495 00496 void KateGlobal::setContainer( QObject * container ) 00497 {m_container=container;} 00498 //END container interface 00499 00500 00501 00502 KTextEditor::TemplateScript* KateGlobal::registerTemplateScript (QObject* owner, const QString& script) 00503 { 00504 return scriptManager()->registerTemplateScript(owner, script); 00505 } 00506 00507 void KateGlobal::unregisterTemplateScript(KTextEditor::TemplateScript* templateScript) 00508 { 00509 scriptManager()->unregisterTemplateScript(templateScript); 00510 } 00511 00512 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference