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