kateconfig.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003 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 "kateconfig.h"
00020 
00021 #include "katefactory.h"
00022 #include "katerenderer.h"
00023 #include "kateview.h"
00024 #include "katedocument.h"
00025 #include "katefont.h"
00026 #include "kateschema.h"
00027 
00028 #include <math.h>
00029 
00030 #include <kapplication.h>
00031 #include <kconfig.h>
00032 #include <kglobalsettings.h>
00033 #include <kcharsets.h>
00034 #include <klocale.h>
00035 #include <kfinddialog.h>
00036 #include <kreplacedialog.h>
00037 #include <kinstance.h>
00038 #include <kstaticdeleter.h>
00039 
00040 #include <qpopupmenu.h>
00041 #include <qtextcodec.h>
00042 
00043 #include <kdebug.h>
00044 
00045 //BEGIN KateConfig
00046 KateConfig::KateConfig ()
00047  : configSessionNumber (0), configIsRunning (false)
00048 {
00049 }
00050 
00051 KateConfig::~KateConfig ()
00052 {
00053 }
00054 
00055 void KateConfig::configStart ()
00056 {
00057   configSessionNumber++;
00058 
00059   if (configSessionNumber > 1)
00060     return;
00061 
00062   configIsRunning = true;
00063 }
00064 
00065 void KateConfig::configEnd ()
00066 {
00067   if (configSessionNumber == 0)
00068     return;
00069 
00070   configSessionNumber--;
00071 
00072   if (configSessionNumber > 0)
00073     return;
00074 
00075   configIsRunning = false;
00076 
00077   updateConfig ();
00078 }
00079 //END
00080 
00081 //BEGIN KateDocumentConfig
00082 KateDocumentConfig *KateDocumentConfig::s_global = 0;
00083 KateViewConfig *KateViewConfig::s_global = 0;
00084 KateRendererConfig *KateRendererConfig::s_global = 0;
00085 
00086 KateDocumentConfig::KateDocumentConfig ()
00087  : m_tabWidth (8),
00088    m_indentationWidth (2),
00089    m_wordWrapAt (80),
00090    m_configFlags (0),
00091    m_plugins (KateFactory::self()->plugins().count()),
00092    m_tabWidthSet (true),
00093    m_indentationWidthSet (true),
00094    m_indentationModeSet (true),
00095    m_wordWrapSet (true),
00096    m_wordWrapAtSet (true),
00097    m_pageUpDownMovesCursorSet (true),
00098    m_undoStepsSet (true),
00099    m_configFlagsSet (0xFFFF),
00100    m_encodingSet (true),
00101    m_eolSet (true),
00102    m_allowEolDetectionSet (true),
00103    m_backupFlagsSet (true),
00104    m_searchDirConfigDepthSet (true),
00105    m_backupPrefixSet (true),
00106    m_backupSuffixSet (true),
00107    m_pluginsSet (m_plugins.size()),
00108    m_doc (0)
00109 {
00110   s_global = this;
00111 
00112   // init plugin array
00113   m_plugins.fill (false);
00114   m_pluginsSet.fill (true);
00115 
00116   // init with defaults from config or really hardcoded ones
00117   KConfig *config = kapp->config();
00118   config->setGroup("Kate Document Defaults");
00119   readConfig (config);
00120 }
00121 
00122 KateDocumentConfig::KateDocumentConfig (KateDocument *doc)
00123  : m_configFlags (0),
00124    m_plugins (KateFactory::self()->plugins().count()),
00125    m_tabWidthSet (false),
00126    m_indentationWidthSet (false),
00127    m_indentationModeSet (false),
00128    m_wordWrapSet (false),
00129    m_wordWrapAtSet (false),
00130    m_pageUpDownMovesCursorSet (false),
00131    m_undoStepsSet (false),
00132    m_configFlagsSet (0),
00133    m_encodingSet (false),
00134    m_eolSet (false),
00135    m_allowEolDetectionSet (false),
00136    m_backupFlagsSet (false),
00137    m_searchDirConfigDepthSet (false),
00138    m_backupPrefixSet (false),
00139    m_backupSuffixSet (false),
00140    m_pluginsSet (m_plugins.size()),
00141    m_doc (doc)
00142 {
00143   // init plugin array
00144   m_plugins.fill (false);
00145   m_pluginsSet.fill (false);
00146 }
00147 
00148 KateDocumentConfig::~KateDocumentConfig ()
00149 {
00150 }
00151 
00152 void KateDocumentConfig::readConfig (KConfig *config)
00153 {
00154   configStart ();
00155 
00156   setTabWidth (config->readNumEntry("Tab Width", 8));
00157 
00158   setIndentationWidth (config->readNumEntry("Indentation Width", 2));
00159 
00160   setIndentationMode (config->readNumEntry("Indentation Mode", KateDocumentConfig::imNone));
00161 
00162   setWordWrap (config->readBoolEntry("Word Wrap", false));
00163   setWordWrapAt (config->readNumEntry("Word Wrap Column", 80));
00164   setPageUpDownMovesCursor (config->readBoolEntry("PageUp/PageDown Moves Cursor", false));
00165   setUndoSteps(config->readNumEntry("Undo Steps", 0));
00166 
00167   setConfigFlags (config->readNumEntry("Basic Config Flags", KateDocumentConfig::cfTabIndents
00168     | KateDocumentConfig::cfKeepIndentProfile
00169     | KateDocumentConfig::cfWrapCursor
00170     | KateDocumentConfig::cfShowTabs
00171     | KateDocumentConfig::cfSmartHome));
00172 
00173   setEncoding (config->readEntry("Encoding", ""));
00174 
00175   setEol (config->readNumEntry("End of Line", 0));
00176   setAllowEolDetection (config->readBoolEntry("Allow End of Line Detection", true));
00177 
00178   setBackupFlags (config->readNumEntry("Backup Config Flags", 1));
00179 
00180   setSearchDirConfigDepth (config->readNumEntry("Search Dir Config Depth", 3));
00181 
00182   setBackupPrefix (config->readEntry("Backup Prefix", QString ("")));
00183 
00184   setBackupSuffix (config->readEntry("Backup Suffix", QString ("~")));
00185 
00186   // plugins
00187   for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
00188     setPlugin (i, config->readBoolEntry("KTextEditor Plugin " + (KateFactory::self()->plugins())[i]->library(), false));
00189 
00190   configEnd ();
00191 }
00192 
00193 void KateDocumentConfig::writeConfig (KConfig *config)
00194 {
00195   config->writeEntry("Tab Width", tabWidth());
00196 
00197   config->writeEntry("Indentation Width", indentationWidth());
00198   config->writeEntry("Indentation Mode", indentationMode());
00199 
00200   config->writeEntry("Word Wrap", wordWrap());
00201   config->writeEntry("Word Wrap Column", wordWrapAt());
00202 
00203   config->writeEntry("PageUp/PageDown Moves Cursor", pageUpDownMovesCursor());
00204 
00205   config->writeEntry("Undo Steps", undoSteps());
00206 
00207   config->writeEntry("Basic Config Flags", configFlags());
00208 
00209   config->writeEntry("Encoding", encoding());
00210 
00211   config->writeEntry("End of Line", eol());
00212   config->writeEntry("Allow End of Line Detection", allowEolDetection());
00213 
00214   config->writeEntry("Backup Config Flags", backupFlags());
00215 
00216   config->writeEntry("Search Dir Config Depth", searchDirConfigDepth());
00217 
00218   config->writeEntry("Backup Prefix", backupPrefix());
00219 
00220   config->writeEntry("Backup Suffix", backupSuffix());
00221 
00222   // plugins
00223   for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
00224     config->writeEntry("KTextEditor Plugin " + (KateFactory::self()->plugins())[i]->library(), plugin(i));
00225 }
00226 
00227 void KateDocumentConfig::updateConfig ()
00228 {
00229   if (m_doc)
00230   {
00231     m_doc->updateConfig ();
00232     return;
00233   }
00234 
00235   if (isGlobal())
00236   {
00237     for (uint z=0; z < KateFactory::self()->documents()->count(); z++)
00238     {
00239       KateFactory::self()->documents()->at(z)->updateConfig ();
00240     }
00241   }
00242 }
00243 
00244 int KateDocumentConfig::tabWidth () const
00245 {
00246   if (m_tabWidthSet || isGlobal())
00247     return m_tabWidth;
00248 
00249   return s_global->tabWidth();
00250 }
00251 
00252 void KateDocumentConfig::setTabWidth (int tabWidth)
00253 {
00254   if (tabWidth < 1)
00255     return;
00256 
00257   configStart ();
00258 
00259   m_tabWidthSet = true;
00260   m_tabWidth = tabWidth;
00261 
00262   configEnd ();
00263 }
00264 
00265 int KateDocumentConfig::indentationWidth () const
00266 {
00267   if (m_indentationWidthSet || isGlobal())
00268     return m_indentationWidth;
00269 
00270   return s_global->indentationWidth();
00271 }
00272 
00273 void KateDocumentConfig::setIndentationWidth (int indentationWidth)
00274 {
00275   if (indentationWidth < 1)
00276     return;
00277 
00278   configStart ();
00279 
00280   m_indentationWidthSet = true;
00281   m_indentationWidth = indentationWidth;
00282 
00283   configEnd ();
00284 }
00285 
00286 uint KateDocumentConfig::indentationMode () const
00287 {
00288   if (m_indentationModeSet || isGlobal())
00289     return m_indentationMode;
00290 
00291   return s_global->indentationMode();
00292 }
00293 
00294 void KateDocumentConfig::setIndentationMode (uint indentationMode)
00295 {
00296   configStart ();
00297 
00298   m_indentationModeSet = true;
00299   m_indentationMode = indentationMode;
00300 
00301   configEnd ();
00302 }
00303 
00304 bool KateDocumentConfig::wordWrap () const
00305 {
00306   if (m_wordWrapSet || isGlobal())
00307     return m_wordWrap;
00308 
00309   return s_global->wordWrap();
00310 }
00311 
00312 void KateDocumentConfig::setWordWrap (bool on)
00313 {
00314   configStart ();
00315 
00316   m_wordWrapSet = true;
00317   m_wordWrap = on;
00318 
00319   configEnd ();
00320 }
00321 
00322 unsigned int KateDocumentConfig::wordWrapAt () const
00323 {
00324   if (m_wordWrapAtSet || isGlobal())
00325     return m_wordWrapAt;
00326 
00327   return s_global->wordWrapAt();
00328 }
00329 
00330 void KateDocumentConfig::setWordWrapAt (unsigned int col)
00331 {
00332   if (col < 1)
00333     return;
00334 
00335   configStart ();
00336 
00337   m_wordWrapAtSet = true;
00338   m_wordWrapAt = col;
00339 
00340   configEnd ();
00341 }
00342 
00343 uint KateDocumentConfig::undoSteps () const
00344 {
00345   if (m_undoStepsSet || isGlobal())
00346     return m_undoSteps;
00347 
00348   return s_global->undoSteps();
00349 }
00350 
00351 void KateDocumentConfig::setUndoSteps (uint undoSteps)
00352 {
00353   configStart ();
00354 
00355   m_undoStepsSet = true;
00356   m_undoSteps = undoSteps;
00357 
00358   configEnd ();
00359 }
00360 
00361 bool KateDocumentConfig::pageUpDownMovesCursor () const
00362 {
00363   if (m_pageUpDownMovesCursorSet || isGlobal())
00364     return m_pageUpDownMovesCursor;
00365 
00366   return s_global->pageUpDownMovesCursor();
00367 }
00368 
00369 void KateDocumentConfig::setPageUpDownMovesCursor (bool on)
00370 {
00371   configStart ();
00372 
00373   m_pageUpDownMovesCursorSet = true;
00374   m_pageUpDownMovesCursor = on;
00375 
00376   configEnd ();
00377 }
00378 
00379 uint KateDocumentConfig::configFlags () const
00380 {
00381   if (isGlobal())
00382     return m_configFlags;
00383 
00384   return ((s_global->configFlags() & ~ m_configFlagsSet) | m_configFlags);
00385 }
00386 
00387 void KateDocumentConfig::setConfigFlags (KateDocumentConfig::ConfigFlags flag, bool enable)
00388 {
00389   configStart ();
00390 
00391   m_configFlagsSet |= flag;
00392 
00393   if (enable)
00394     m_configFlags = m_configFlags | flag;
00395   else
00396     m_configFlags = m_configFlags & ~ flag;
00397 
00398   configEnd ();
00399 }
00400 
00401 void KateDocumentConfig::setConfigFlags (uint fullFlags)
00402 {
00403   configStart ();
00404 
00405   m_configFlagsSet = 0xFFFF;
00406   m_configFlags = fullFlags;
00407 
00408   configEnd ();
00409 }
00410 
00411 const QString &KateDocumentConfig::encoding () const
00412 {
00413   if (m_encodingSet || isGlobal())
00414     return m_encoding;
00415 
00416   return s_global->encoding();
00417 }
00418 
00419 QTextCodec *KateDocumentConfig::codec ()
00420 {
00421   if (m_encodingSet || isGlobal())
00422   {
00423     if (m_encoding.isEmpty() && isGlobal())
00424       return KGlobal::charsets()->codecForName (QString::fromLatin1(KGlobal::locale()->encoding()));
00425     else if (m_encoding.isEmpty())
00426       return s_global->codec ();
00427     else
00428       return KGlobal::charsets()->codecForName (m_encoding);
00429   }
00430 
00431   return s_global->codec ();
00432 }
00433 
00434 void KateDocumentConfig::setEncoding (const QString &encoding)
00435 {
00436   QString enc = encoding;
00437 
00438   if (!enc.isEmpty())
00439   {
00440     bool found = false;
00441     QTextCodec *codec = KGlobal::charsets()->codecForName (encoding, found);
00442 
00443     if (!found || !codec)
00444       return;
00445 
00446     enc = codec->name();
00447   }
00448 
00449   configStart ();
00450 
00451   if (isGlobal())
00452     KateDocument::setDefaultEncoding (enc);
00453 
00454   m_encodingSet = true;
00455   m_encoding = enc;
00456 
00457   configEnd ();
00458 }
00459 
00460 bool KateDocumentConfig::isSetEncoding () const
00461 {
00462   return m_encodingSet;
00463 }
00464 
00465 int KateDocumentConfig::eol () const
00466 {
00467   if (m_eolSet || isGlobal())
00468     return m_eol;
00469 
00470   return s_global->eol();
00471 }
00472 
00473 QString KateDocumentConfig::eolString ()
00474 {
00475   if (eol() == KateDocumentConfig::eolUnix)
00476     return QString ("\n");
00477   else if (eol() == KateDocumentConfig::eolDos)
00478     return QString ("\r\n");
00479   else if (eol() == KateDocumentConfig::eolMac)
00480     return QString ("\r");
00481 
00482   return QString ("\n");
00483 }
00484 
00485 void KateDocumentConfig::setEol (int mode)
00486 {
00487   configStart ();
00488 
00489   m_eolSet = true;
00490   m_eol = mode;
00491 
00492   configEnd ();
00493 }
00494 
00495 bool KateDocumentConfig::allowEolDetection () const
00496 {
00497   if (m_allowEolDetectionSet || isGlobal())
00498     return m_allowEolDetection;
00499 
00500   return s_global->allowEolDetection();
00501 }
00502 
00503 void KateDocumentConfig::setAllowEolDetection (bool on)
00504 {
00505   configStart ();
00506 
00507   m_allowEolDetectionSet = true;
00508   m_allowEolDetection = on;
00509 
00510   configEnd ();
00511 }
00512 
00513 uint KateDocumentConfig::backupFlags () const
00514 {
00515   if (m_backupFlagsSet || isGlobal())
00516     return m_backupFlags;
00517 
00518   return s_global->backupFlags();
00519 }
00520 
00521 void KateDocumentConfig::setBackupFlags (uint flags)
00522  {
00523   configStart ();
00524 
00525   m_backupFlagsSet = true;
00526   m_backupFlags = flags;
00527 
00528   configEnd ();
00529 }
00530 
00531 const QString &KateDocumentConfig::backupPrefix () const
00532 {
00533   if (m_backupPrefixSet || isGlobal())
00534     return m_backupPrefix;
00535 
00536   return s_global->backupPrefix();
00537 }
00538 
00539 const QString &KateDocumentConfig::backupSuffix () const
00540 {
00541   if (m_backupSuffixSet || isGlobal())
00542     return m_backupSuffix;
00543 
00544   return s_global->backupSuffix();
00545 }
00546 
00547 void KateDocumentConfig::setBackupPrefix (const QString &prefix)
00548 {
00549   configStart ();
00550 
00551   m_backupPrefixSet = true;
00552   m_backupPrefix = prefix;
00553 
00554   configEnd ();
00555 }
00556 
00557 void KateDocumentConfig::setBackupSuffix (const QString &suffix)
00558 {
00559   configStart ();
00560 
00561   m_backupSuffixSet = true;
00562   m_backupSuffix = suffix;
00563 
00564   configEnd ();
00565 }
00566 
00567 bool KateDocumentConfig::plugin (uint index) const
00568 {
00569   if (index >= m_plugins.size())
00570     return false;
00571 
00572   if (m_pluginsSet.at(index) || isGlobal())
00573     return m_plugins.at(index);
00574 
00575   return s_global->plugin (index);
00576 }
00577 
00578 void KateDocumentConfig::setPlugin (uint index, bool load)
00579 {
00580   if (index >= m_plugins.size())
00581     return;
00582 
00583   configStart ();
00584 
00585   m_pluginsSet.setBit(index);
00586   m_plugins.setBit(index, load);
00587 
00588   configEnd ();
00589 }
00590 
00591 int KateDocumentConfig::searchDirConfigDepth () const
00592 {
00593   if (m_searchDirConfigDepthSet || isGlobal())
00594     return m_searchDirConfigDepth;
00595 
00596   return s_global->searchDirConfigDepth ();
00597 }
00598 
00599 void KateDocumentConfig::setSearchDirConfigDepth (int depth)
00600 {
00601   configStart ();
00602 
00603   m_searchDirConfigDepthSet = true;
00604   m_searchDirConfigDepth = depth;
00605 
00606   configEnd ();
00607 }
00608 
00609 //END
00610 
00611 //BEGIN KateViewConfig
00612 KateViewConfig::KateViewConfig ()
00613  :
00614    m_dynWordWrapSet (true),
00615    m_dynWordWrapIndicatorsSet (true),
00616    m_dynWordWrapAlignIndentSet (true),
00617    m_lineNumbersSet (true),
00618    m_scrollBarMarksSet (true),
00619    m_iconBarSet (true),
00620    m_foldingBarSet (true),
00621    m_bookmarkSortSet (true),
00622    m_autoCenterLinesSet (true),
00623    m_searchFlagsSet (true),
00624    m_cmdLineSet (true),
00625    m_defaultMarkTypeSet (true),
00626    m_persistentSelectionSet (true),
00627    m_textToSearchModeSet (true),
00628    m_view (0)
00629 {
00630   s_global = this;
00631 
00632   // init with defaults from config or really hardcoded ones
00633   KConfig *config = kapp->config();
00634   config->setGroup("Kate View Defaults");
00635   readConfig (config);
00636 }
00637 
00638 KateViewConfig::KateViewConfig (KateView *view)
00639  :
00640    m_dynWordWrapSet (false),
00641    m_dynWordWrapIndicatorsSet (false),
00642    m_dynWordWrapAlignIndentSet (false),
00643    m_lineNumbersSet (false),
00644    m_scrollBarMarksSet (false),
00645    m_iconBarSet (false),
00646    m_foldingBarSet (false),
00647    m_bookmarkSortSet (false),
00648    m_autoCenterLinesSet (false),
00649    m_searchFlagsSet (false),
00650    m_cmdLineSet (false),
00651    m_defaultMarkTypeSet (false),
00652    m_persistentSelectionSet (false),
00653    m_textToSearchModeSet (false),
00654    m_view (view)
00655 {
00656 }
00657 
00658 KateViewConfig::~KateViewConfig ()
00659 {
00660 }
00661 
00662 void KateViewConfig::readConfig (KConfig *config)
00663 {
00664   configStart ();
00665 
00666   setDynWordWrap (config->readBoolEntry( "Dynamic Word Wrap", true ));
00667   setDynWordWrapIndicators (config->readNumEntry( "Dynamic Word Wrap Indicators", 1 ));
00668   setDynWordWrapAlignIndent (config->readNumEntry( "Dynamic Word Wrap Align Indent", 80 ));
00669 
00670   setLineNumbers (config->readBoolEntry( "Line Numbers",  false));
00671 
00672   setScrollBarMarks (config->readBoolEntry( "Scroll Bar Marks",  false));
00673 
00674   setIconBar (config->readBoolEntry( "Icon Bar", false ));
00675 
00676   setFoldingBar (config->readBoolEntry( "Folding Bar", true));
00677 
00678   setBookmarkSort (config->readNumEntry( "Bookmark Menu Sorting", 0 ));
00679 
00680   setAutoCenterLines (config->readNumEntry( "Auto Center Lines", 0 ));
00681 
00682   setSearchFlags (config->readNumEntry("Search Config Flags", KFindDialog::FromCursor | KFindDialog::CaseSensitive | KReplaceDialog::PromptOnReplace));
00683 
00684   setCmdLine (config->readBoolEntry( "Command Line", false));
00685 
00686   setDefaultMarkType (config->readNumEntry( "Default Mark Type", KTextEditor::MarkInterface::markType01 ));
00687 
00688   setPersistentSelection (config->readNumEntry( "Persistent Selection", false ));
00689 
00690   setTextToSearchMode (config->readNumEntry( "Text To Search Mode", KateViewConfig::SelectionWord));
00691 
00692   configEnd ();
00693 }
00694 
00695 void KateViewConfig::writeConfig (KConfig *config)
00696 {
00697   config->writeEntry( "Dynamic Word Wrap", dynWordWrap() );
00698   config->writeEntry( "Dynamic Word Wrap Indicators", dynWordWrapIndicators() );
00699   config->writeEntry( "Dynamic Word Wrap Align Indent", dynWordWrapAlignIndent() );
00700 
00701   config->writeEntry( "Line Numbers", lineNumbers() );
00702 
00703   config->writeEntry( "Scroll Bar Marks", scrollBarMarks() );
00704 
00705   config->writeEntry( "Icon Bar", iconBar() );
00706 
00707   config->writeEntry( "Folding Bar", foldingBar() );
00708 
00709   config->writeEntry( "Bookmark Menu Sorting", bookmarkSort() );
00710 
00711   config->writeEntry( "Auto Center Lines", autoCenterLines() );
00712 
00713   config->writeEntry("Search Config Flags", searchFlags());
00714 
00715   config->writeEntry("Command Line", cmdLine());
00716 
00717   config->writeEntry("Default Mark Type", defaultMarkType());
00718 
00719   config->writeEntry("Persistent Selection", persistentSelection());
00720 
00721   config->writeEntry("Text To Search Mode", textToSearchMode());
00722 }
00723 
00724 void KateViewConfig::updateConfig ()
00725 {
00726   if (m_view)
00727   {
00728     m_view->updateConfig ();
00729     return;
00730   }
00731 
00732   if (isGlobal())
00733   {
00734     for (uint z=0; z < KateFactory::self()->views()->count(); z++)
00735     {
00736       KateFactory::self()->views()->at(z)->updateConfig ();
00737     }
00738   }
00739 }
00740 
00741 bool KateViewConfig::dynWordWrap () const
00742 {
00743   if (m_dynWordWrapSet || isGlobal())
00744     return m_dynWordWrap;
00745 
00746   return s_global->dynWordWrap();
00747 }
00748 
00749 void KateViewConfig::setDynWordWrap (bool wrap)
00750 {
00751   configStart ();
00752 
00753   m_dynWordWrapSet = true;
00754   m_dynWordWrap = wrap;
00755 
00756   configEnd ();
00757 }
00758 
00759 int KateViewConfig::dynWordWrapIndicators () const
00760 {
00761   if (m_dynWordWrapIndicatorsSet || isGlobal())
00762     return m_dynWordWrapIndicators;
00763 
00764   return s_global->dynWordWrapIndicators();
00765 }
00766 
00767 void KateViewConfig::setDynWordWrapIndicators (int mode)
00768 {
00769   configStart ();
00770 
00771   m_dynWordWrapIndicatorsSet = true;
00772   m_dynWordWrapIndicators = kMin(80, kMax(0, mode));
00773 
00774   configEnd ();
00775 }
00776 
00777 int KateViewConfig::dynWordWrapAlignIndent () const
00778 {
00779   if (m_dynWordWrapAlignIndentSet || isGlobal())
00780     return m_dynWordWrapAlignIndent;
00781 
00782   return s_global->dynWordWrapAlignIndent();
00783 }
00784 
00785 void KateViewConfig::setDynWordWrapAlignIndent (int indent)
00786 {
00787   configStart ();
00788 
00789   m_dynWordWrapAlignIndentSet = true;
00790   m_dynWordWrapAlignIndent = indent;
00791 
00792   configEnd ();
00793 }
00794 
00795 bool KateViewConfig::lineNumbers () const
00796 {
00797   if (m_lineNumbersSet || isGlobal())
00798     return m_lineNumbers;
00799 
00800   return s_global->lineNumbers();
00801 }
00802 
00803 void KateViewConfig::setLineNumbers (bool on)
00804 {
00805   configStart ();
00806 
00807   m_lineNumbersSet = true;
00808   m_lineNumbers = on;
00809 
00810   configEnd ();
00811 }
00812 
00813 bool KateViewConfig::scrollBarMarks () const
00814 {
00815   if (m_scrollBarMarksSet || isGlobal())
00816     return m_scrollBarMarks;
00817 
00818   return s_global->scrollBarMarks();
00819 }
00820 
00821 void KateViewConfig::setScrollBarMarks (bool on)
00822 {
00823   configStart ();
00824 
00825   m_scrollBarMarksSet = true;
00826   m_scrollBarMarks = on;
00827 
00828   configEnd ();
00829 }
00830 
00831 bool KateViewConfig::iconBar () const
00832 {
00833   if (m_iconBarSet || isGlobal())
00834     return m_iconBar;
00835 
00836   return s_global->iconBar();
00837 }
00838 
00839 void KateViewConfig::setIconBar (bool on)
00840 {
00841   configStart ();
00842 
00843   m_iconBarSet = true;
00844   m_iconBar = on;
00845 
00846   configEnd ();
00847 }
00848 
00849 bool KateViewConfig::foldingBar () const
00850 {
00851   if (m_foldingBarSet || isGlobal())
00852     return m_foldingBar;
00853 
00854   return s_global->foldingBar();
00855 }
00856 
00857 void KateViewConfig::setFoldingBar (bool on)
00858 {
00859   configStart ();
00860 
00861   m_foldingBarSet = true;
00862   m_foldingBar = on;
00863 
00864   configEnd ();
00865 }
00866 
00867 int KateViewConfig::bookmarkSort () const
00868 {
00869   if (m_bookmarkSortSet || isGlobal())
00870     return m_bookmarkSort;
00871 
00872   return s_global->bookmarkSort();
00873 }
00874 
00875 void KateViewConfig::setBookmarkSort (int mode)
00876 {
00877   configStart ();
00878 
00879   m_bookmarkSortSet = true;
00880   m_bookmarkSort = mode;
00881 
00882   configEnd ();
00883 }
00884 
00885 int KateViewConfig::autoCenterLines () const
00886 {
00887   if (m_autoCenterLinesSet || isGlobal())
00888     return m_autoCenterLines;
00889 
00890   return s_global->autoCenterLines();
00891 }
00892 
00893 void KateViewConfig::setAutoCenterLines (int lines)
00894 {
00895   if (lines < 0)
00896     return;
00897 
00898   configStart ();
00899 
00900   m_autoCenterLinesSet = true;
00901   m_autoCenterLines = lines;
00902 
00903   configEnd ();
00904 }
00905 
00906 long KateViewConfig::searchFlags () const
00907 {
00908   if (m_searchFlagsSet || isGlobal())
00909     return m_searchFlags;
00910 
00911   return s_global->searchFlags();
00912 }
00913 
00914 void KateViewConfig::setSearchFlags (long flags)
00915  {
00916   configStart ();
00917 
00918   m_searchFlagsSet = true;
00919   m_searchFlags = flags;
00920 
00921   configEnd ();
00922 }
00923 
00924 bool KateViewConfig::cmdLine () const
00925 {
00926   if (m_cmdLineSet || isGlobal())
00927     return m_cmdLine;
00928 
00929   return s_global->cmdLine();
00930 }
00931 
00932 void KateViewConfig::setCmdLine (bool on)
00933 {
00934   configStart ();
00935 
00936   m_cmdLineSet = true;
00937   m_cmdLine = on;
00938 
00939   configEnd ();
00940 }
00941 
00942 uint KateViewConfig::defaultMarkType () const
00943 {
00944   if (m_defaultMarkTypeSet || isGlobal())
00945     return m_defaultMarkType;
00946 
00947   return s_global->defaultMarkType();
00948 }
00949 
00950 void KateViewConfig::setDefaultMarkType (uint type)
00951 {
00952   configStart ();
00953 
00954   m_defaultMarkTypeSet = true;
00955   m_defaultMarkType = type;
00956 
00957   configEnd ();
00958 }
00959 
00960 bool KateViewConfig::persistentSelection () const
00961 {
00962   if (m_persistentSelectionSet || isGlobal())
00963     return m_persistentSelection;
00964 
00965   return s_global->persistentSelection();
00966 }
00967 
00968 void KateViewConfig::setPersistentSelection (bool on)
00969 {
00970   configStart ();
00971 
00972   m_persistentSelectionSet = true;
00973   m_persistentSelection = on;
00974 
00975   configEnd ();
00976 }
00977 
00978 int KateViewConfig::textToSearchMode () const
00979 {
00980   if (m_textToSearchModeSet || isGlobal())
00981     return m_textToSearchMode;
00982 
00983   return s_global->textToSearchMode();
00984 }
00985 
00986 void KateViewConfig::setTextToSearchMode (int mode)
00987 {
00988   configStart ();
00989 
00990   m_textToSearchModeSet = true;
00991   m_textToSearchMode = mode;
00992 
00993   configEnd ();
00994 }
00995 
00996 //END
00997 
00998 //BEGIN KateRendererConfig
00999 KateRendererConfig::KateRendererConfig ()
01000  :
01001    m_font (new KateFontStruct ()),
01002    m_lineMarkerColor (KTextEditor::MarkInterface::reservedMarkersCount()),
01003    m_schemaSet (true),
01004    m_fontSet (true),
01005    m_wordWrapMarkerSet (true),
01006    m_showIndentationLinesSet (true),
01007    m_backgroundColorSet (true),
01008    m_selectionColorSet (true),
01009    m_highlightedLineColorSet (true),
01010    m_highlightedBracketColorSet (true),
01011    m_wordWrapMarkerColorSet (true),
01012    m_tabMarkerColorSet(true),
01013    m_iconBarColorSet (true),
01014    m_lineNumberColorSet (true),
01015    m_lineMarkerColorSet (m_lineMarkerColor.size()),
01016    m_renderer (0)
01017 {
01018   // init bitarray
01019   m_lineMarkerColorSet.fill (true);
01020 
01021   s_global = this;
01022 
01023   // init with defaults from config or really hardcoded ones
01024   KConfig *config = kapp->config();
01025   config->setGroup("Kate Renderer Defaults");
01026   readConfig (config);
01027 }
01028 
01029 KateRendererConfig::KateRendererConfig (KateRenderer *renderer)
01030  : m_font (0),
01031    m_lineMarkerColor (KTextEditor::MarkInterface::reservedMarkersCount()),
01032    m_schemaSet (false),
01033    m_fontSet (false),
01034    m_wordWrapMarkerSet (false),
01035    m_showIndentationLinesSet (false),
01036    m_backgroundColorSet (false),
01037    m_selectionColorSet (false),
01038    m_highlightedLineColorSet (false),
01039    m_highlightedBracketColorSet (false),
01040    m_wordWrapMarkerColorSet (false),
01041    m_tabMarkerColorSet(false),
01042    m_iconBarColorSet (false),
01043    m_lineNumberColorSet (false),
01044    m_lineMarkerColorSet (m_lineMarkerColor.size()),
01045    m_renderer (renderer)
01046 {
01047   // init bitarray
01048   m_lineMarkerColorSet.fill (false);
01049 }
01050 
01051 KateRendererConfig::~KateRendererConfig ()
01052 {
01053   delete m_font;
01054 }
01055 
01056 void KateRendererConfig::readConfig (KConfig *config)
01057 {
01058   configStart ();
01059 
01060   setSchema (KateFactory::self()->schemaManager()->number (config->readEntry("Schema", KateSchemaManager::normalSchema())));
01061 
01062   setWordWrapMarker (config->readBoolEntry("Word Wrap Marker", false ));
01063 
01064   setShowIndentationLines (config->readBoolEntry( "Show Indentation Lines", false));
01065 
01066   configEnd ();
01067 }
01068 
01069 void KateRendererConfig::writeConfig (KConfig *config)
01070 {
01071   config->writeEntry ("Schema", KateFactory::self()->schemaManager()->name(schema()));
01072 
01073   config->writeEntry("Word Wrap Marker", wordWrapMarker() );
01074 
01075   config->writeEntry("Show Indentation Lines", showIndentationLines());
01076 }
01077 
01078 void KateRendererConfig::updateConfig ()
01079 {
01080   if (m_renderer)
01081   {
01082     m_renderer->updateConfig ();
01083     return;
01084   }
01085 
01086   if (isGlobal())
01087   {
01088     for (uint z=0; z < KateFactory::self()->renderers()->count(); z++)
01089     {
01090       KateFactory::self()->renderers()->at(z)->updateConfig ();
01091     }
01092   }
01093 }
01094 
01095 uint KateRendererConfig::schema () const
01096 {
01097   if (m_schemaSet || isGlobal())
01098     return m_schema;
01099 
01100   return s_global->schema();
01101 }
01102 
01103 void KateRendererConfig::setSchema (uint schema)
01104 {
01105   configStart ();
01106   m_schemaSet = true;
01107   m_schema = schema;
01108   setSchemaInternal( schema );
01109   configEnd ();
01110 }
01111 
01112 void KateRendererConfig::reloadSchema()
01113 {
01114   if ( isGlobal() )
01115     for ( uint z=0; z < KateFactory::self()->renderers()->count(); z++ )
01116       KateFactory::self()->renderers()->at(z)->config()->reloadSchema();
01117 
01118   else if ( m_renderer && m_schemaSet )
01119     setSchemaInternal( m_schema );
01120 }
01121 
01122 void KateRendererConfig::setSchemaInternal( int schema )
01123 {
01124   m_schemaSet = true;
01125   m_schema = schema;
01126 
01127   KConfig *config (KateFactory::self()->schemaManager()->schema(schema));
01128 
01129   QColor tmp0 (KGlobalSettings::baseColor());
01130   QColor tmp1 (KGlobalSettings::highlightColor());
01131   QColor tmp2 (KGlobalSettings::alternateBackgroundColor());
01132   QColor tmp3 ( "#FFFF99" );
01133   QColor tmp4 (tmp2.dark());
01134   QColor tmp5 ( KGlobalSettings::textColor() );
01135   QColor tmp6 ( "#EAE9E8" );
01136   QColor tmp7 ( "#000000" );
01137 
01138   m_backgroundColor = config->readColorEntry("Color Background", &tmp0);
01139   m_backgroundColorSet = true;
01140   m_selectionColor = config->readColorEntry("Color Selection", &tmp1);
01141   m_selectionColorSet = true;
01142   m_highlightedLineColor  = config->readColorEntry("Color Highlighted Line", &tmp2);
01143   m_highlightedLineColorSet = true;
01144   m_highlightedBracketColor = config->readColorEntry("Color Highlighted Bracket", &tmp3);
01145   m_highlightedBracketColorSet = true;
01146   m_wordWrapMarkerColor = config->readColorEntry("Color Word Wrap Marker", &tmp4);
01147   m_wordWrapMarkerColorSet = true;
01148   m_tabMarkerColor = config->readColorEntry("Color Tab Marker", &tmp5);
01149   m_tabMarkerColorSet = true;
01150   m_iconBarColor  = config->readColorEntry("Color Icon Bar", &tmp6);
01151   m_iconBarColorSet = true;
01152   m_lineNumberColor = config->readColorEntry("Color Line Number", &tmp7);
01153   m_lineNumberColorSet = true;
01154 
01155     // same std colors like in KateDocument::markColor
01156   QColor mark[7];
01157   mark[0] = Qt::blue;
01158   mark[1] = Qt::red;
01159   mark[2] = Qt::yellow;
01160   mark[3] = Qt::magenta;
01161   mark[4] = Qt::gray;
01162   mark[5] = Qt::green;
01163   mark[6] = Qt::red;
01164 
01165   for (int i = 1; i <= KTextEditor::MarkInterface::reservedMarkersCount(); i++) {
01166     QColor col = config->readColorEntry(QString("Color MarkType%1").arg(i), &mark[i - 1]);
01167     int index = i-1;
01168     m_lineMarkerColorSet[index] = true;
01169     m_lineMarkerColor[index] = col;
01170   }
01171 
01172   QFont f (KGlobalSettings::fixedFont());
01173 
01174   if (!m_fontSet)
01175   {
01176     m_fontSet = true;
01177     m_font = new KateFontStruct ();
01178   }
01179 
01180   m_font->setFont(config->readFontEntry("Font", &f));
01181 }
01182 
01183 KateFontStruct *KateRendererConfig::fontStruct ()
01184 {
01185   if (m_fontSet || isGlobal())
01186     return m_font;
01187 
01188   return s_global->fontStruct ();
01189 }
01190 
01191 QFont *KateRendererConfig::font()
01192 {
01193   return &(fontStruct ()->myFont);
01194 }
01195 
01196 KateFontMetrics *KateRendererConfig::fontMetrics()
01197 {
01198   return &(fontStruct ()->myFontMetrics);
01199 }
01200 
01201 void KateRendererConfig::setFont(const QFont &font)
01202 {
01203   configStart ();
01204 
01205   if (!m_fontSet)
01206   {
01207     m_fontSet = true;
01208     m_font = new KateFontStruct ();
01209   }
01210 
01211   m_font->setFont(font);
01212 
01213   configEnd ();
01214 }
01215 
01216 bool KateRendererConfig::wordWrapMarker () const
01217 {
01218   if (m_wordWrapMarkerSet || isGlobal())
01219     return m_wordWrapMarker;
01220 
01221   return s_global->wordWrapMarker();
01222 }
01223 
01224 void KateRendererConfig::setWordWrapMarker (bool on)
01225 {
01226   configStart ();
01227 
01228   m_wordWrapMarkerSet = true;
01229   m_wordWrapMarker = on;
01230 
01231   configEnd ();
01232 }
01233 
01234 const QColor& KateRendererConfig::backgroundColor() const
01235 {
01236   if (m_backgroundColorSet || isGlobal())
01237     return m_backgroundColor;
01238 
01239   return s_global->backgroundColor();
01240 }
01241 
01242 void KateRendererConfig::setBackgroundColor (const QColor &col)
01243 {
01244   configStart ();
01245 
01246   m_backgroundColorSet = true;
01247   m_backgroundColor = col;
01248 
01249   configEnd ();
01250 }
01251 
01252 const QColor& KateRendererConfig::selectionColor() const
01253 {
01254   if (m_selectionColorSet || isGlobal())
01255     return m_selectionColor;
01256 
01257   return s_global->selectionColor();
01258 }
01259 
01260 void KateRendererConfig::setSelectionColor (const QColor &col)
01261 {
01262   configStart ();
01263 
01264   m_selectionColorSet = true;
01265   m_selectionColor = col;
01266 
01267   configEnd ();
01268 }
01269 
01270 const QColor& KateRendererConfig::highlightedLineColor() const
01271 {
01272   if (m_highlightedLineColorSet || isGlobal())
01273     return m_highlightedLineColor;
01274 
01275   return s_global->highlightedLineColor();
01276 }
01277 
01278 void KateRendererConfig::setHighlightedLineColor (const QColor &col)
01279 {
01280   configStart ();
01281 
01282   m_highlightedLineColorSet = true;
01283   m_highlightedLineColor = col;
01284 
01285   configEnd ();
01286 }
01287 
01288 const QColor& KateRendererConfig::lineMarkerColor(KTextEditor::MarkInterface::MarkTypes type) const
01289 {
01290   int index = 0;
01291   if (type > 0) { while((type >> index++) ^ 1) {} }
01292   index -= 1;
01293 
01294   if ( index < 0 || index >= KTextEditor::MarkInterface::reservedMarkersCount() )
01295   {
01296     static QColor dummy;
01297     return dummy;
01298   }
01299 
01300   if (m_lineMarkerColorSet[index] || isGlobal())
01301     return m_lineMarkerColor[index];
01302 
01303   return s_global->lineMarkerColor( type );
01304 }
01305 
01306 void KateRendererConfig::setLineMarkerColor (const QColor &col, KTextEditor::MarkInterface::MarkTypes type)
01307 {
01308   int index = static_cast<int>( log(static_cast<double>(type)) / log(2.0) );
01309   Q_ASSERT( index >= 0 && index < KTextEditor::MarkInterface::reservedMarkersCount() );
01310   configStart ();
01311 
01312   m_lineMarkerColorSet[index] = true;
01313   m_lineMarkerColor[index] = col;
01314 
01315   configEnd ();
01316 }
01317 
01318 const QColor& KateRendererConfig::highlightedBracketColor() const
01319 {
01320   if (m_highlightedBracketColorSet || isGlobal())
01321     return m_highlightedBracketColor;
01322 
01323   return s_global->highlightedBracketColor();
01324 }
01325 
01326 void KateRendererConfig::setHighlightedBracketColor (const QColor &col)
01327 {
01328   configStart ();
01329 
01330   m_highlightedBracketColorSet = true;
01331   m_highlightedBracketColor = col;
01332 
01333   configEnd ();
01334 }
01335 
01336 const QColor& KateRendererConfig::wordWrapMarkerColor() const
01337 {
01338   if (m_wordWrapMarkerColorSet || isGlobal())
01339     return m_wordWrapMarkerColor;
01340 
01341   return s_global->wordWrapMarkerColor();
01342 }
01343 
01344 void KateRendererConfig::setWordWrapMarkerColor (const QColor &col)
01345 {
01346   configStart ();
01347 
01348   m_wordWrapMarkerColorSet = true;
01349   m_wordWrapMarkerColor = col;
01350 
01351   configEnd ();
01352 }
01353 
01354 const QColor& KateRendererConfig::tabMarkerColor() const
01355 {
01356   if (m_tabMarkerColorSet || isGlobal())
01357     return m_tabMarkerColor;
01358 
01359   return s_global->tabMarkerColor();
01360 }
01361 
01362 void KateRendererConfig::setTabMarkerColor (const QColor &col)
01363 {
01364   configStart ();
01365 
01366   m_tabMarkerColorSet = true;
01367   m_tabMarkerColor = col;
01368 
01369   configEnd ();
01370 }
01371 
01372 const QColor& KateRendererConfig::iconBarColor() const
01373 {
01374   if (m_iconBarColorSet || isGlobal())
01375     return m_iconBarColor;
01376 
01377   return s_global->iconBarColor();
01378 }
01379 
01380 void KateRendererConfig::setIconBarColor (const QColor &col)
01381 {
01382   configStart ();
01383 
01384   m_iconBarColorSet = true;
01385   m_iconBarColor = col;
01386 
01387   configEnd ();
01388 }
01389 
01390 const QColor& KateRendererConfig::lineNumberColor() const
01391 {
01392   if (m_lineNumberColorSet || isGlobal())
01393     return m_lineNumberColor;
01394 
01395   return s_global->lineNumberColor();
01396 }
01397 
01398 void KateRendererConfig::setLineNumberColor (const QColor &col)
01399 {
01400   configStart ();
01401 
01402   m_lineNumberColorSet = true;
01403   m_lineNumberColor = col;
01404 
01405   configEnd ();
01406 }
01407 
01408 bool KateRendererConfig::showIndentationLines () const
01409 {
01410   if (m_showIndentationLinesSet || isGlobal())
01411     return m_showIndentationLines;
01412 
01413   return s_global->showIndentationLines();
01414 }
01415 
01416 void KateRendererConfig::setShowIndentationLines (bool on)
01417 {
01418   configStart ();
01419 
01420   m_showIndentationLinesSet = true;
01421   m_showIndentationLines = on;
01422 
01423   configEnd ();
01424 }
01425 
01426 //END
01427 
01428 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Home | KDE Accessibility Home | Description of Access Keys