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