• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

kateglobal.cpp

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

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal