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