Kate
kateconfig.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2007, 2008 Matthew Woehlke <mw_triad@users.sourceforge.net> 00003 Copyright (C) 2003 Christoph Cullmann <cullmann@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "kateconfig.h" 00021 00022 #include "kateglobal.h" 00023 #include "katerenderer.h" 00024 #include "kateview.h" 00025 #include "katedocument.h" 00026 #include "kateschema.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 <kcomponentdata.h> 00037 #include <kdebug.h> 00038 00039 #include <QtCore/QTextCodec> 00040 #include <QStringListModel> 00041 00042 //BEGIN KateConfig 00043 KateConfig::KateConfig () 00044 : configSessionNumber (0), configIsRunning (false) 00045 { 00046 } 00047 00048 KateConfig::~KateConfig () 00049 { 00050 } 00051 00052 void KateConfig::configStart () 00053 { 00054 configSessionNumber++; 00055 00056 if (configSessionNumber > 1) 00057 return; 00058 00059 configIsRunning = true; 00060 } 00061 00062 void KateConfig::configEnd () 00063 { 00064 if (configSessionNumber == 0) 00065 return; 00066 00067 configSessionNumber--; 00068 00069 if (configSessionNumber > 0) 00070 return; 00071 00072 configIsRunning = false; 00073 00074 updateConfig (); 00075 } 00076 //END 00077 00078 //BEGIN KateDocumentConfig 00079 KateGlobalConfig *KateGlobalConfig::s_global = 0; 00080 KateDocumentConfig *KateDocumentConfig::s_global = 0; 00081 KateViewConfig *KateViewConfig::s_global = 0; 00082 KateRendererConfig *KateRendererConfig::s_global = 0; 00083 00084 KateGlobalConfig::KateGlobalConfig () 00085 { 00086 s_global = this; 00087 00088 // init with defaults from config or really hardcoded ones 00089 KConfigGroup cg( KGlobal::config(), "Kate Part Defaults"); 00090 readConfig (cg); 00091 } 00092 00093 KateGlobalConfig::~KateGlobalConfig () 00094 { 00095 } 00096 00097 void KateGlobalConfig::readConfig (const KConfigGroup &config) 00098 { 00099 configStart (); 00100 00101 setProberType ((KEncodingProber::ProberType)config.readEntry("Encoding Prober Type", (int)KEncodingProber::Universal)); 00102 setFallbackEncoding (config.readEntry("Fallback Encoding", "")); 00103 00104 configEnd (); 00105 } 00106 00107 void KateGlobalConfig::writeConfig (KConfigGroup &config) 00108 { 00109 config.writeEntry("Encoding Prober Type", (int)proberType()); 00110 config.writeEntry("Fallback Encoding", fallbackEncoding()); 00111 } 00112 00113 void KateGlobalConfig::updateConfig () 00114 { 00115 } 00116 00117 void KateGlobalConfig::setProberType (KEncodingProber::ProberType proberType) 00118 { 00119 configStart (); 00120 m_proberType = proberType; 00121 configEnd (); 00122 } 00123 00124 const QString &KateGlobalConfig::fallbackEncoding () const 00125 { 00126 return m_fallbackEncoding; 00127 } 00128 00129 QTextCodec *KateGlobalConfig::fallbackCodec () const 00130 { 00131 if (m_fallbackEncoding.isEmpty()) 00132 return QTextCodec::codecForName("ISO 8859-15"); 00133 00134 return KGlobal::charsets()->codecForName (m_fallbackEncoding); 00135 } 00136 00137 bool KateGlobalConfig::setFallbackEncoding (const QString &encoding) 00138 { 00139 QTextCodec *codec; 00140 bool found = false; 00141 if (encoding.isEmpty()) 00142 { 00143 codec = s_global->fallbackCodec(); 00144 found = true; 00145 } 00146 else 00147 codec = KGlobal::charsets()->codecForName (encoding, found); 00148 00149 if (!found || !codec) 00150 return false; 00151 00152 configStart (); 00153 m_fallbackEncoding = codec->name(); 00154 configEnd (); 00155 return true; 00156 } 00157 00158 KateDocumentConfig::KateDocumentConfig () 00159 : m_indentationWidth (2), 00160 m_tabWidth (8), 00161 m_tabHandling (tabSmart), 00162 m_configFlags (0), 00163 m_wordWrapAt (80), 00164 m_tabWidthSet (true), 00165 m_indentationWidthSet (true), 00166 m_indentationModeSet (true), 00167 m_wordWrapSet (true), 00168 m_wordWrapAtSet (true), 00169 m_pageUpDownMovesCursorSet (true), 00170 m_keepExtraSpacesSet (false), 00171 m_indentPastedTextSet (false), 00172 m_backspaceIndentsSet (false), 00173 m_smartHomeSet (false), 00174 m_wrapCursorSet (false), 00175 m_autoBracketsSet (false), 00176 m_showTabsSet (false), 00177 m_showSpacesSet (false), 00178 m_replaceTabsDynSet (false), 00179 m_removeTrailingDynSet (false), 00180 m_removeSpacesSet (false), 00181 m_overwiteModeSet (false), 00182 m_tabIndentsSet (false), 00183 m_encodingSet (true), 00184 m_eolSet (true), 00185 m_bomSet (true), 00186 m_allowEolDetectionSet (false), 00187 m_allowSimpleModeSet (false), 00188 m_backupFlagsSet (true), 00189 m_searchDirConfigDepthSet (true), 00190 m_backupPrefixSet (true), 00191 m_backupSuffixSet (true), 00192 m_swapFileNoSyncSet (true), 00193 m_onTheFlySpellCheckSet (true), 00194 m_doc (0) 00195 { 00196 s_global = this; 00197 00198 // init with defaults from config or really hardcoded ones 00199 KConfigGroup cg( KGlobal::config(), "Kate Document Defaults"); 00200 readConfig (cg); 00201 } 00202 00203 KateDocumentConfig::KateDocumentConfig (const KConfigGroup &cg) 00204 : m_indentationWidth (2), 00205 m_tabWidth (8), 00206 m_tabHandling (tabSmart), 00207 m_configFlags (0), 00208 m_wordWrapAt (80), 00209 m_tabWidthSet (true), 00210 m_indentationWidthSet (true), 00211 m_indentationModeSet (true), 00212 m_wordWrapSet (true), 00213 m_wordWrapAtSet (true), 00214 m_pageUpDownMovesCursorSet (true), 00215 m_keepExtraSpacesSet (false), 00216 m_indentPastedTextSet (false), 00217 m_backspaceIndentsSet (false), 00218 m_smartHomeSet (false), 00219 m_wrapCursorSet (false), 00220 m_autoBracketsSet (false), 00221 m_showTabsSet (false), 00222 m_showSpacesSet (false), 00223 m_replaceTabsDynSet (false), 00224 m_removeTrailingDynSet (false), 00225 m_removeSpacesSet (false), 00226 m_overwiteModeSet (false), 00227 m_tabIndentsSet (false), 00228 m_encodingSet (true), 00229 m_eolSet (true), 00230 m_bomSet (true), 00231 m_allowEolDetectionSet (false), 00232 m_allowSimpleModeSet (false), 00233 m_backupFlagsSet (true), 00234 m_searchDirConfigDepthSet (true), 00235 m_backupPrefixSet (true), 00236 m_backupSuffixSet (true), 00237 m_swapFileNoSyncSet (true), 00238 m_onTheFlySpellCheckSet (true), 00239 m_doc (0) 00240 { 00241 // init with defaults from config or really hardcoded ones 00242 readConfig (cg); 00243 } 00244 00245 KateDocumentConfig::KateDocumentConfig (KateDocument *doc) 00246 : m_tabHandling (tabSmart), 00247 m_configFlags (0), 00248 m_tabWidthSet (false), 00249 m_indentationWidthSet (false), 00250 m_indentationModeSet (false), 00251 m_wordWrapSet (false), 00252 m_wordWrapAtSet (false), 00253 m_pageUpDownMovesCursorSet (false), 00254 m_keepExtraSpacesSet (false), 00255 m_indentPastedTextSet (false), 00256 m_backspaceIndentsSet (false), 00257 m_smartHomeSet (false), 00258 m_wrapCursorSet (false), 00259 m_autoBracketsSet (false), 00260 m_showTabsSet (false), 00261 m_showSpacesSet (false), 00262 m_replaceTabsDynSet (false), 00263 m_removeTrailingDynSet (false), 00264 m_removeSpacesSet (false), 00265 m_overwiteModeSet (false), 00266 m_tabIndentsSet (false), 00267 m_encodingSet (false), 00268 m_eolSet (false), 00269 m_bomSet (false), 00270 m_allowEolDetectionSet (false), 00271 m_allowSimpleModeSet (false), 00272 m_backupFlagsSet (false), 00273 m_searchDirConfigDepthSet (false), 00274 m_backupPrefixSet (false), 00275 m_backupSuffixSet (false), 00276 m_swapFileNoSyncSet (false), 00277 m_onTheFlySpellCheckSet (false), 00278 m_doc (doc) 00279 { 00280 } 00281 00282 KateDocumentConfig::~KateDocumentConfig () 00283 { 00284 } 00285 00286 void KateDocumentConfig::readConfig (const KConfigGroup &config) 00287 { 00288 configStart (); 00289 00290 setTabWidth (config.readEntry("Tab Width", 8)); 00291 00292 setIndentationWidth (config.readEntry("Indentation Width", 2)); 00293 00294 setIndentationMode (config.readEntry("Indentation Mode", "")); 00295 00296 setTabHandling (config.readEntry("Tab Handling", int(KateDocumentConfig::tabSmart))); 00297 00298 setWordWrap (config.readEntry("Word Wrap", false)); 00299 setWordWrapAt (config.readEntry("Word Wrap Column", 80)); 00300 setPageUpDownMovesCursor (config.readEntry("PageUp/PageDown Moves Cursor", false)); 00301 00302 setSmartHome (config.readEntry("Smart Home", true)); 00303 setWrapCursor (config.readEntry("Wrap Cursor", true)); 00304 setShowTabs (config.readEntry("Show Tabs", true)); 00305 setTabIndents (config.readEntry("Indent On Tab", true)); 00306 setKeepExtraSpaces (config.readEntry("Keep Extra Spaces", false)); 00307 setIndentPastedText (config.readEntry("Indent On Text Paste", false)); 00308 setBackspaceIndents (config.readEntry("Indent On Backspace", false)); 00309 setAutoBrackets (config.readEntry("Automatically Insert Closing Brackets", false)); 00310 setShowSpaces (config.readEntry("Show Spaces", false)); 00311 setReplaceTabsDyn (config.readEntry("ReplaceTabsDyn", false)); 00312 setRemoveTrailingDyn (config.readEntry("RemoveTrailingDyn", false)); 00313 setRemoveSpaces (config.readEntry("Remove Spaces", false)); 00314 setOvr (config.readEntry("Overwrite Mode", false)); 00315 00316 setEncoding (config.readEntry("Encoding", "")); 00317 00318 setEol (config.readEntry("End of Line", 0)); 00319 setAllowEolDetection (config.readEntry("Allow End of Line Detection", true)); 00320 00321 setBom (config.readEntry("BOM",false)); 00322 00323 setAllowSimpleMode (config.readEntry("Allow Simple Mode", true)); 00324 00325 setBackupFlags (config.readEntry("Backup Config Flags", 1)); 00326 00327 setSearchDirConfigDepth (config.readEntry("Search Dir Config Depth", 3)); 00328 00329 setBackupPrefix (config.readEntry("Backup Prefix", QString (""))); 00330 00331 setBackupSuffix (config.readEntry("Backup Suffix", QString ("~"))); 00332 00333 setSwapFileNoSync (config.readEntry("No sync", false)); 00334 00335 setOnTheFlySpellCheck(config.readEntry("On-The-Fly Spellcheck", false)); 00336 00337 configEnd (); 00338 } 00339 00340 void KateDocumentConfig::writeConfig (KConfigGroup &config) 00341 { 00342 config.writeEntry("Tab Width", tabWidth()); 00343 00344 config.writeEntry("Indentation Width", indentationWidth()); 00345 config.writeEntry("Indentation Mode", indentationMode()); 00346 00347 config.writeEntry("Tab Handling", tabHandling()); 00348 00349 config.writeEntry("Word Wrap", wordWrap()); 00350 config.writeEntry("Word Wrap Column", wordWrapAt()); 00351 00352 config.writeEntry("PageUp/PageDown Moves Cursor", pageUpDownMovesCursor()); 00353 00354 config.writeEntry("Smart Home", smartHome()); 00355 config.writeEntry("Wrap Cursor", wrapCursor()); 00356 config.writeEntry("Show Tabs", showTabs()); 00357 config.writeEntry("Indent On Tab", tabIndentsEnabled()); 00358 config.writeEntry("Keep Extra Spaces", keepExtraSpaces()); 00359 config.writeEntry("Indent On Text Paste", indentPastedText()); 00360 config.writeEntry("Indent On Backspace", backspaceIndents()); 00361 config.writeEntry("Automatically Insert Closing Brackets", autoBrackets()); 00362 config.writeEntry("Show Spaces", showSpaces()); 00363 config.writeEntry("ReplaceTabsDyn", replaceTabsDyn()); 00364 config.writeEntry("RemoveTrailingDyn", removeTrailingDyn()); 00365 config.writeEntry("Remove Spaces", removeSpaces()); 00366 config.writeEntry("Overwrite Mode", ovr()); 00367 00368 config.writeEntry("Encoding", encoding()); 00369 00370 config.writeEntry("End of Line", eol()); 00371 config.writeEntry("Allow End of Line Detection", allowEolDetection()); 00372 00373 config.writeEntry("BOM",bom()); 00374 00375 config.writeEntry("Allow Simple Mode", allowSimpleMode()); 00376 00377 config.writeEntry("Backup Config Flags", backupFlags()); 00378 00379 config.writeEntry("Search Dir Config Depth", searchDirConfigDepth()); 00380 00381 config.writeEntry("Backup Prefix", backupPrefix()); 00382 00383 config.writeEntry("Backup Suffix", backupSuffix()); 00384 00385 config.writeEntry("No sync", swapFileNoSync()); 00386 00387 config.writeEntry("On-The-Fly Spellcheck", onTheFlySpellCheck()); 00388 } 00389 00390 void KateDocumentConfig::updateConfig () 00391 { 00392 if (m_doc) 00393 { 00394 m_doc->updateConfig (); 00395 return; 00396 } 00397 00398 if (isGlobal()) 00399 { 00400 for (int z=0; z < KateGlobal::self()->kateDocuments().size(); ++z) 00401 (KateGlobal::self()->kateDocuments())[z]->updateConfig (); 00402 } 00403 } 00404 00405 int KateDocumentConfig::tabWidth () const 00406 { 00407 if (m_tabWidthSet || isGlobal()) 00408 return m_tabWidth; 00409 00410 return s_global->tabWidth(); 00411 } 00412 00413 void KateDocumentConfig::setTabWidth (int tabWidth) 00414 { 00415 if (tabWidth < 1) 00416 return; 00417 00418 configStart (); 00419 00420 m_tabWidthSet = true; 00421 m_tabWidth = tabWidth; 00422 00423 configEnd (); 00424 } 00425 00426 int KateDocumentConfig::indentationWidth () const 00427 { 00428 if (m_indentationWidthSet || isGlobal()) 00429 return m_indentationWidth; 00430 00431 return s_global->indentationWidth(); 00432 } 00433 00434 void KateDocumentConfig::setIndentationWidth (int indentationWidth) 00435 { 00436 if (indentationWidth < 1) 00437 return; 00438 00439 configStart (); 00440 00441 m_indentationWidthSet = true; 00442 m_indentationWidth = indentationWidth; 00443 00444 configEnd (); 00445 } 00446 00447 const QString &KateDocumentConfig::indentationMode () const 00448 { 00449 if (m_indentationModeSet || isGlobal()) 00450 return m_indentationMode; 00451 00452 return s_global->indentationMode(); 00453 } 00454 00455 void KateDocumentConfig::setIndentationMode (const QString &indentationMode) 00456 { 00457 configStart (); 00458 00459 m_indentationModeSet = true; 00460 m_indentationMode = indentationMode; 00461 00462 configEnd (); 00463 } 00464 00465 uint KateDocumentConfig::tabHandling () const 00466 { 00467 // This setting is purly a user preference, 00468 // hence, there exists only the global setting. 00469 if (isGlobal()) 00470 return m_tabHandling; 00471 00472 return s_global->tabHandling(); 00473 } 00474 00475 void KateDocumentConfig::setTabHandling (uint tabHandling) 00476 { 00477 configStart (); 00478 00479 m_tabHandling = tabHandling; 00480 00481 configEnd (); 00482 } 00483 00484 bool KateDocumentConfig::wordWrap () const 00485 { 00486 if (m_wordWrapSet || isGlobal()) 00487 return m_wordWrap; 00488 00489 return s_global->wordWrap(); 00490 } 00491 00492 void KateDocumentConfig::setWordWrap (bool on) 00493 { 00494 configStart (); 00495 00496 m_wordWrapSet = true; 00497 m_wordWrap = on; 00498 00499 configEnd (); 00500 } 00501 00502 unsigned int KateDocumentConfig::wordWrapAt () const 00503 { 00504 if (m_wordWrapAtSet || isGlobal()) 00505 return m_wordWrapAt; 00506 00507 return s_global->wordWrapAt(); 00508 } 00509 00510 void KateDocumentConfig::setWordWrapAt (unsigned int col) 00511 { 00512 if (col < 1) 00513 return; 00514 00515 configStart (); 00516 00517 m_wordWrapAtSet = true; 00518 m_wordWrapAt = col; 00519 00520 configEnd (); 00521 } 00522 00523 bool KateDocumentConfig::pageUpDownMovesCursor () const 00524 { 00525 if (m_pageUpDownMovesCursorSet || isGlobal()) 00526 return m_pageUpDownMovesCursor; 00527 00528 return s_global->pageUpDownMovesCursor(); 00529 } 00530 00531 void KateDocumentConfig::setPageUpDownMovesCursor (bool on) 00532 { 00533 configStart (); 00534 00535 m_pageUpDownMovesCursorSet = true; 00536 m_pageUpDownMovesCursor = on; 00537 00538 configEnd (); 00539 } 00540 00541 void KateDocumentConfig::setKeepExtraSpaces(bool on) 00542 { 00543 configStart (); 00544 00545 m_keepExtraSpacesSet = true; 00546 m_keepExtraSpaces = on; 00547 00548 configEnd (); 00549 } 00550 00551 bool KateDocumentConfig::keepExtraSpaces() const 00552 { 00553 if (m_keepExtraSpacesSet || isGlobal()) 00554 return m_keepExtraSpaces; 00555 00556 return s_global->keepExtraSpaces(); 00557 } 00558 00559 void KateDocumentConfig::setIndentPastedText(bool on) 00560 { 00561 configStart (); 00562 00563 m_indentPastedTextSet = true; 00564 m_indentPastedText = on; 00565 00566 configEnd (); 00567 } 00568 00569 bool KateDocumentConfig::indentPastedText() const 00570 { 00571 if (m_indentPastedTextSet || isGlobal()) 00572 return m_indentPastedText; 00573 00574 return s_global->indentPastedText(); 00575 } 00576 00577 void KateDocumentConfig::setBackspaceIndents(bool on) 00578 { 00579 configStart (); 00580 00581 m_backspaceIndentsSet = true; 00582 m_backspaceIndents = on; 00583 00584 configEnd (); 00585 } 00586 00587 bool KateDocumentConfig::backspaceIndents() const 00588 { 00589 if (m_backspaceIndentsSet || isGlobal()) 00590 return m_backspaceIndents; 00591 00592 return s_global->backspaceIndents(); 00593 } 00594 00595 void KateDocumentConfig::setSmartHome(bool on) 00596 { 00597 configStart (); 00598 00599 m_smartHomeSet = true; 00600 m_smartHome = on; 00601 00602 configEnd (); 00603 } 00604 00605 bool KateDocumentConfig::smartHome() const 00606 { 00607 if (m_smartHomeSet || isGlobal()) 00608 return m_smartHome; 00609 00610 return s_global->smartHome(); 00611 } 00612 00613 void KateDocumentConfig::setWrapCursor(bool on) 00614 { 00615 configStart (); 00616 00617 m_wrapCursorSet = true; 00618 m_wrapCursor = on; 00619 00620 configEnd (); 00621 } 00622 00623 bool KateDocumentConfig::wrapCursor() const 00624 { 00625 if (m_wrapCursorSet || isGlobal()) 00626 return m_wrapCursor; 00627 00628 return s_global->wrapCursor(); 00629 } 00630 00631 void KateDocumentConfig::setAutoBrackets(bool on) 00632 { 00633 configStart (); 00634 00635 m_autoBracketsSet = true; 00636 m_autoBrackets = on; 00637 00638 configEnd (); 00639 } 00640 00641 bool KateDocumentConfig::autoBrackets() const 00642 { 00643 if (m_autoBracketsSet || isGlobal()) 00644 return m_autoBrackets; 00645 00646 return s_global->autoBrackets(); 00647 } 00648 00649 void KateDocumentConfig::setShowTabs(bool on) 00650 { 00651 configStart (); 00652 00653 m_showTabsSet = true; 00654 m_showTabs = on; 00655 00656 configEnd (); 00657 } 00658 00659 bool KateDocumentConfig::showTabs() const 00660 { 00661 if (m_showTabsSet || isGlobal()) 00662 return m_showTabs; 00663 00664 return s_global->showTabs(); 00665 } 00666 00667 void KateDocumentConfig::setShowSpaces(bool on) 00668 { 00669 configStart (); 00670 00671 m_showSpacesSet = true; 00672 m_showSpaces = on; 00673 00674 configEnd (); 00675 } 00676 00677 bool KateDocumentConfig::showSpaces() const 00678 { 00679 if (m_showSpacesSet || isGlobal()) 00680 return m_showSpaces; 00681 00682 return s_global->showSpaces(); 00683 } 00684 00685 void KateDocumentConfig::setReplaceTabsDyn(bool on) 00686 { 00687 configStart (); 00688 00689 m_replaceTabsDynSet = true; 00690 m_replaceTabsDyn = on; 00691 00692 configEnd (); 00693 } 00694 00695 bool KateDocumentConfig::replaceTabsDyn() const 00696 { 00697 if (m_replaceTabsDynSet || isGlobal()) 00698 return m_replaceTabsDyn; 00699 00700 return s_global->replaceTabsDyn(); 00701 } 00702 00703 void KateDocumentConfig::setRemoveTrailingDyn(bool on) 00704 { 00705 configStart (); 00706 00707 m_removeTrailingDynSet = true; 00708 m_removeTrailingDyn = on; 00709 00710 configEnd (); 00711 } 00712 00713 bool KateDocumentConfig::removeTrailingDyn() const 00714 { 00715 if (m_removeTrailingDynSet || isGlobal()) 00716 return m_removeTrailingDyn; 00717 00718 return s_global->removeTrailingDyn(); 00719 } 00720 00721 void KateDocumentConfig::setRemoveSpaces(bool on) 00722 { 00723 configStart (); 00724 00725 m_removeSpacesSet = true; 00726 m_removeSpaces = on; 00727 00728 configEnd (); 00729 } 00730 00731 bool KateDocumentConfig::removeSpaces() const 00732 { 00733 if (m_removeSpacesSet || isGlobal()) 00734 return m_removeSpaces; 00735 00736 return s_global->removeSpaces(); 00737 } 00738 00739 void KateDocumentConfig::setOvr(bool on) 00740 { 00741 configStart (); 00742 00743 m_overwiteModeSet = true; 00744 m_overwiteMode = on; 00745 00746 configEnd (); 00747 } 00748 00749 bool KateDocumentConfig::ovr() const 00750 { 00751 if (m_overwiteModeSet || isGlobal()) 00752 return m_overwiteMode; 00753 00754 return s_global->ovr(); 00755 } 00756 00757 void KateDocumentConfig::setTabIndents(bool on) 00758 { 00759 configStart (); 00760 00761 m_tabIndentsSet = true; 00762 m_tabIndents = on; 00763 00764 configEnd (); 00765 } 00766 00767 bool KateDocumentConfig::tabIndentsEnabled() const 00768 { 00769 if (m_tabIndentsSet || isGlobal()) 00770 return m_tabIndents; 00771 00772 return s_global->tabIndentsEnabled(); 00773 } 00774 00775 const QString &KateDocumentConfig::encoding () const 00776 { 00777 if (m_encodingSet || isGlobal()) 00778 return m_encoding; 00779 00780 return s_global->encoding(); 00781 } 00782 00783 QTextCodec *KateDocumentConfig::codec () const 00784 { 00785 if (m_encodingSet || isGlobal()) 00786 { 00787 if (m_encoding.isEmpty() && isGlobal()) 00788 return KGlobal::locale()->codecForEncoding(); 00789 else if (m_encoding.isEmpty()) 00790 return s_global->codec (); 00791 else 00792 return KGlobal::charsets()->codecForName (m_encoding); 00793 } 00794 00795 return s_global->codec (); 00796 } 00797 00798 bool KateDocumentConfig::setEncoding (const QString &encoding) 00799 { 00800 QTextCodec *codec; 00801 bool found = false; 00802 if (encoding.isEmpty()) 00803 { 00804 codec = s_global->codec(); 00805 found=true; 00806 } 00807 else 00808 codec = KGlobal::charsets()->codecForName (encoding, found); 00809 00810 if (!found || !codec) 00811 return false; 00812 00813 configStart (); 00814 m_encodingSet = true; 00815 m_encoding = codec->name(); 00816 00817 if (isGlobal()) 00818 KateGlobal::self()->setDefaultEncoding (m_encoding); 00819 00820 configEnd (); 00821 return true; 00822 } 00823 00824 bool KateDocumentConfig::isSetEncoding () const 00825 { 00826 return m_encodingSet; 00827 } 00828 00829 int KateDocumentConfig::eol () const 00830 { 00831 if (m_eolSet || isGlobal()) 00832 return m_eol; 00833 00834 return s_global->eol(); 00835 } 00836 00837 QString KateDocumentConfig::eolString () 00838 { 00839 if (eol() == KateDocumentConfig::eolUnix) 00840 return QString ("\n"); 00841 else if (eol() == KateDocumentConfig::eolDos) 00842 return QString ("\r\n"); 00843 else if (eol() == KateDocumentConfig::eolMac) 00844 return QString ("\r"); 00845 00846 return QString ("\n"); 00847 } 00848 00849 void KateDocumentConfig::setEol (int mode) 00850 { 00851 configStart (); 00852 00853 m_eolSet = true; 00854 m_eol = mode; 00855 00856 configEnd (); 00857 } 00858 00859 void KateDocumentConfig::setBom (bool bom) 00860 { 00861 configStart (); 00862 00863 m_bomSet = true; 00864 m_bom = bom; 00865 00866 configEnd (); 00867 } 00868 00869 bool KateDocumentConfig::bom() const 00870 { 00871 if (m_bomSet || isGlobal()) 00872 return m_bom; 00873 return s_global->bom(); 00874 } 00875 00876 00877 bool KateDocumentConfig::allowEolDetection () const 00878 { 00879 if (m_allowEolDetectionSet || isGlobal()) 00880 return m_allowEolDetection; 00881 00882 return s_global->allowEolDetection(); 00883 } 00884 00885 void KateDocumentConfig::setAllowEolDetection (bool on) 00886 { 00887 configStart (); 00888 00889 m_allowEolDetectionSet = true; 00890 m_allowEolDetection = on; 00891 00892 configEnd (); 00893 } 00894 00895 00896 bool KateDocumentConfig::allowSimpleMode () const 00897 { 00898 if (m_allowSimpleModeSet || isGlobal()) 00899 return m_allowSimpleMode; 00900 00901 return s_global->allowSimpleMode(); 00902 } 00903 00904 void KateDocumentConfig::setAllowSimpleMode (bool on) 00905 { 00906 configStart (); 00907 00908 m_allowSimpleModeSet = true; 00909 m_allowSimpleMode = on; 00910 00911 configEnd (); 00912 } 00913 00914 uint KateDocumentConfig::backupFlags () const 00915 { 00916 if (m_backupFlagsSet || isGlobal()) 00917 return m_backupFlags; 00918 00919 return s_global->backupFlags(); 00920 } 00921 00922 void KateDocumentConfig::setBackupFlags (uint flags) 00923 { 00924 configStart (); 00925 00926 m_backupFlagsSet = true; 00927 m_backupFlags = flags; 00928 00929 configEnd (); 00930 } 00931 00932 const QString &KateDocumentConfig::backupPrefix () const 00933 { 00934 if (m_backupPrefixSet || isGlobal()) 00935 return m_backupPrefix; 00936 00937 return s_global->backupPrefix(); 00938 } 00939 00940 const QString &KateDocumentConfig::backupSuffix () const 00941 { 00942 if (m_backupSuffixSet || isGlobal()) 00943 return m_backupSuffix; 00944 00945 return s_global->backupSuffix(); 00946 } 00947 00948 void KateDocumentConfig::setBackupPrefix (const QString &prefix) 00949 { 00950 configStart (); 00951 00952 m_backupPrefixSet = true; 00953 m_backupPrefix = prefix; 00954 00955 configEnd (); 00956 } 00957 00958 void KateDocumentConfig::setBackupSuffix (const QString &suffix) 00959 { 00960 configStart (); 00961 00962 m_backupSuffixSet = true; 00963 m_backupSuffix = suffix; 00964 00965 configEnd (); 00966 } 00967 00968 bool KateDocumentConfig::swapFileNoSync() const 00969 { 00970 if (m_swapFileNoSyncSet || isGlobal()) 00971 return m_swapFileNoSync; 00972 00973 return s_global->swapFileNoSync(); 00974 } 00975 00976 void KateDocumentConfig::setSwapFileNoSync(bool on) 00977 { 00978 configStart(); 00979 00980 m_swapFileNoSyncSet = true; 00981 m_swapFileNoSync = on; 00982 00983 configEnd(); 00984 } 00985 00986 int KateDocumentConfig::searchDirConfigDepth () const 00987 { 00988 if (m_searchDirConfigDepthSet || isGlobal()) 00989 return m_searchDirConfigDepth; 00990 00991 return s_global->searchDirConfigDepth (); 00992 } 00993 00994 void KateDocumentConfig::setSearchDirConfigDepth (int depth) 00995 { 00996 configStart (); 00997 00998 m_searchDirConfigDepthSet = true; 00999 m_searchDirConfigDepth = depth; 01000 01001 configEnd (); 01002 } 01003 01004 bool KateDocumentConfig::onTheFlySpellCheck() const 01005 { 01006 if(isGlobal()) { 01007 // WARNING: this is slightly hackish, but it's currently the only way to 01008 // do it, see also the KTextEdit class 01009 KConfigGroup configGroup(KGlobal::config(), "Spelling"); 01010 return configGroup.readEntry("checkerEnabledByDefault", false); 01011 } 01012 if (m_onTheFlySpellCheckSet) { 01013 return m_onTheFlySpellCheck; 01014 } 01015 01016 return s_global->onTheFlySpellCheck(); 01017 } 01018 01019 void KateDocumentConfig::setOnTheFlySpellCheck(bool on) 01020 { 01021 configStart (); 01022 01023 m_onTheFlySpellCheckSet = true; 01024 m_onTheFlySpellCheck = on; 01025 01026 configEnd (); 01027 } 01028 01029 01030 01031 01032 //END 01033 01034 //BEGIN KateViewConfig 01035 KateViewConfig::KateViewConfig () 01036 : 01037 m_dynWordWrapSet (true), 01038 m_dynWordWrapIndicatorsSet (true), 01039 m_dynWordWrapAlignIndentSet (true), 01040 m_lineNumbersSet (true), 01041 m_scrollBarMarksSet (true), 01042 m_iconBarSet (true), 01043 m_foldingBarSet (true), 01044 m_bookmarkSortSet (true), 01045 m_autoCenterLinesSet (true), 01046 m_searchFlagsSet (true), 01047 m_defaultMarkTypeSet (true), 01048 m_persistentSelectionSet (true), 01049 m_viInputModeSet (true), 01050 m_viInputModeStealKeysSet (true), 01051 m_automaticCompletionInvocationSet (true), 01052 m_wordCompletionSet (true), 01053 m_wordCompletionMinimalWordLengthSet (true), 01054 m_smartCopyCutSet (true), 01055 m_scrollPastEndSet (true), 01056 m_allowMarkMenu (true), 01057 m_view (0) 01058 { 01059 s_global = this; 01060 01061 // init with defaults from config or really hardcoded ones 01062 KConfigGroup config( KGlobal::config(), "Kate View Defaults"); 01063 readConfig (config); 01064 } 01065 01066 KateViewConfig::KateViewConfig (KateView *view) 01067 : 01068 m_searchFlags (PowerModePlainText), 01069 m_maxHistorySize (100), 01070 m_dynWordWrapSet (false), 01071 m_dynWordWrapIndicatorsSet (false), 01072 m_dynWordWrapAlignIndentSet (false), 01073 m_lineNumbersSet (false), 01074 m_scrollBarMarksSet (false), 01075 m_iconBarSet (false), 01076 m_foldingBarSet (false), 01077 m_bookmarkSortSet (false), 01078 m_autoCenterLinesSet (false), 01079 m_searchFlagsSet (false), 01080 m_defaultMarkTypeSet (false), 01081 m_persistentSelectionSet (false), 01082 m_viInputModeSet (false), 01083 m_viInputModeStealKeysSet (false), 01084 m_automaticCompletionInvocationSet (false), 01085 m_wordCompletionSet (false), 01086 m_wordCompletionMinimalWordLengthSet (false), 01087 m_smartCopyCutSet (false), 01088 m_scrollPastEndSet (false), 01089 m_allowMarkMenu (true), 01090 m_view (view) 01091 { 01092 } 01093 01094 KateViewConfig::~KateViewConfig () 01095 { 01096 } 01097 01098 01099 // TODO Extract more keys to constants for maintainability 01100 static const char * const KEY_SEARCH_REPLACE_FLAGS = "Search/Replace Flags"; 01101 static const char * const KEY_PATTERN_HISTORY = "Search Pattern History"; 01102 static const char * const KEY_REPLACEMENT_HISTORY = "Replacement Text History"; 01103 01104 01105 void KateViewConfig::readConfig ( const KConfigGroup &config) 01106 { 01107 configStart (); 01108 01109 // default off again, until this is usable for large size documents 01110 setDynWordWrap (config.readEntry( "Dynamic Word Wrap", false )); 01111 setDynWordWrapIndicators (config.readEntry( "Dynamic Word Wrap Indicators", 1 )); 01112 setDynWordWrapAlignIndent (config.readEntry( "Dynamic Word Wrap Align Indent", 80 )); 01113 01114 setLineNumbers (config.readEntry( "Line Numbers", false)); 01115 01116 setScrollBarMarks (config.readEntry( "Scroll Bar Marks", false)); 01117 01118 setIconBar (config.readEntry( "Icon Bar", false )); 01119 01120 setFoldingBar (config.readEntry( "Folding Bar", true)); 01121 01122 setBookmarkSort (config.readEntry( "Bookmark Menu Sorting", 0 )); 01123 01124 setAutoCenterLines (config.readEntry( "Auto Center Lines", 0 )); 01125 01126 setSearchFlags(config.readEntry(KEY_SEARCH_REPLACE_FLAGS, 01127 IncFromCursor|PowerMatchCase|PowerModePlainText)); 01128 01129 m_maxHistorySize = config.readEntry("Maximum Search History Size", 100); 01130 01131 setDefaultMarkType (config.readEntry( "Default Mark Type", int(KTextEditor::MarkInterface::markType01) )); 01132 setAllowMarkMenu (config.readEntry( "Allow Mark Menu", true )); 01133 01134 setPersistentSelection (config.readEntry( "Persistent Selection", false )); 01135 01136 setViInputMode (config.readEntry( "Vi Input Mode", false)); 01137 setViInputModeStealKeys (config.readEntry( "Vi Input Mode Steal Keys", false)); 01138 setViInputModeHideStatusBar (config.readEntry( "Vi Input Mode Hide Status Bar", false)); 01139 01140 setAutomaticCompletionInvocation (config.readEntry( "Auto Completion", true )); 01141 setWordCompletion (config.readEntry( "Word Completion", true )); 01142 setWordCompletionMinimalWordLength (config.readEntry( "Word Completion Minimal Word Length", 3 )); 01143 setSmartCopyCut (config.readEntry( "Smart Copy Cut", false )); 01144 setScrollPastEnd (config.readEntry( "Scroll Past End", false )); 01145 01146 if (isGlobal()) { 01147 // Read search pattern history 01148 QStringList patternHistory = config.readEntry(KEY_PATTERN_HISTORY, QStringList()); 01149 m_patternHistoryModel.setStringList(patternHistory); 01150 01151 // Read replacement text history 01152 QStringList replacementHistory = config.readEntry(KEY_REPLACEMENT_HISTORY, QStringList()); 01153 m_replacementHistoryModel.setStringList(replacementHistory); 01154 } 01155 01156 configEnd (); 01157 } 01158 01159 void KateViewConfig::writeConfig (KConfigGroup &config) 01160 { 01161 config.writeEntry( "Dynamic Word Wrap", dynWordWrap() ); 01162 config.writeEntry( "Dynamic Word Wrap Indicators", dynWordWrapIndicators() ); 01163 config.writeEntry( "Dynamic Word Wrap Align Indent", dynWordWrapAlignIndent() ); 01164 01165 config.writeEntry( "Line Numbers", lineNumbers() ); 01166 01167 config.writeEntry( "Scroll Bar Marks", scrollBarMarks() ); 01168 01169 config.writeEntry( "Icon Bar", iconBar() ); 01170 01171 config.writeEntry( "Folding Bar", foldingBar() ); 01172 01173 config.writeEntry( "Bookmark Menu Sorting", bookmarkSort() ); 01174 01175 config.writeEntry( "Auto Center Lines", autoCenterLines() ); 01176 01177 config.writeEntry(KEY_SEARCH_REPLACE_FLAGS, int(searchFlags())); 01178 01179 config.writeEntry("Maximum Search History Size", m_maxHistorySize); 01180 01181 config.writeEntry("Default Mark Type", defaultMarkType()); 01182 01183 config.writeEntry("Allow Mark Menu", allowMarkMenu()); 01184 01185 config.writeEntry("Persistent Selection", persistentSelection()); 01186 01187 config.writeEntry( "Auto Completion", automaticCompletionInvocation()); 01188 config.writeEntry( "Word Completion", wordCompletion()); 01189 config.writeEntry( "Word Completion Minimal Word Length", wordCompletionMinimalWordLength()); 01190 01191 config.writeEntry( "Smart Copy Cut", smartCopyCut() ); 01192 config.writeEntry( "Scroll Past End" , scrollPastEnd() ); 01193 01194 config.writeEntry( "Vi Input Mode", viInputMode()); 01195 01196 config.writeEntry( "Vi Input Mode Steal Keys", viInputModeStealKeys()); 01197 01198 config.writeEntry( "Vi Input Mode Hide Status Bar", viInputModeHideStatusBar()); 01199 01200 01201 if (isGlobal()) { 01202 // Write search pattern history 01203 config.writeEntry(KEY_PATTERN_HISTORY, m_patternHistoryModel.stringList()); 01204 01205 // Write replacement text history 01206 config.writeEntry(KEY_REPLACEMENT_HISTORY, m_replacementHistoryModel.stringList()); 01207 } 01208 } 01209 01210 void KateViewConfig::updateConfig () 01211 { 01212 if (m_view) 01213 { 01214 m_view->updateConfig (); 01215 return; 01216 } 01217 01218 if (isGlobal()) 01219 { 01220 for (int z=0; z < KateGlobal::self()->views().size(); ++z) 01221 (KateGlobal::self()->views())[z]->updateConfig (); 01222 } 01223 } 01224 01225 bool KateViewConfig::dynWordWrap () const 01226 { 01227 if (m_dynWordWrapSet || isGlobal()) 01228 return m_dynWordWrap; 01229 01230 return s_global->dynWordWrap(); 01231 } 01232 01233 void KateViewConfig::setDynWordWrap (bool wrap) 01234 { 01235 configStart (); 01236 01237 m_dynWordWrapSet = true; 01238 m_dynWordWrap = wrap; 01239 01240 configEnd (); 01241 } 01242 01243 int KateViewConfig::dynWordWrapIndicators () const 01244 { 01245 if (m_dynWordWrapIndicatorsSet || isGlobal()) 01246 return m_dynWordWrapIndicators; 01247 01248 return s_global->dynWordWrapIndicators(); 01249 } 01250 01251 void KateViewConfig::setDynWordWrapIndicators (int mode) 01252 { 01253 configStart (); 01254 01255 m_dynWordWrapIndicatorsSet = true; 01256 m_dynWordWrapIndicators = qBound(0, mode, 80); 01257 01258 configEnd (); 01259 } 01260 01261 int KateViewConfig::dynWordWrapAlignIndent () const 01262 { 01263 if (m_dynWordWrapAlignIndentSet || isGlobal()) 01264 return m_dynWordWrapAlignIndent; 01265 01266 return s_global->dynWordWrapAlignIndent(); 01267 } 01268 01269 void KateViewConfig::setDynWordWrapAlignIndent (int indent) 01270 { 01271 configStart (); 01272 01273 m_dynWordWrapAlignIndentSet = true; 01274 m_dynWordWrapAlignIndent = indent; 01275 01276 configEnd (); 01277 } 01278 01279 bool KateViewConfig::lineNumbers () const 01280 { 01281 if (m_lineNumbersSet || isGlobal()) 01282 return m_lineNumbers; 01283 01284 return s_global->lineNumbers(); 01285 } 01286 01287 void KateViewConfig::setLineNumbers (bool on) 01288 { 01289 configStart (); 01290 01291 m_lineNumbersSet = true; 01292 m_lineNumbers = on; 01293 01294 configEnd (); 01295 } 01296 01297 bool KateViewConfig::scrollBarMarks () const 01298 { 01299 if (m_scrollBarMarksSet || isGlobal()) 01300 return m_scrollBarMarks; 01301 01302 return s_global->scrollBarMarks(); 01303 } 01304 01305 void KateViewConfig::setScrollBarMarks (bool on) 01306 { 01307 configStart (); 01308 01309 m_scrollBarMarksSet = true; 01310 m_scrollBarMarks = on; 01311 01312 configEnd (); 01313 } 01314 01315 bool KateViewConfig::iconBar () const 01316 { 01317 if (m_iconBarSet || isGlobal()) 01318 return m_iconBar; 01319 01320 return s_global->iconBar(); 01321 } 01322 01323 void KateViewConfig::setIconBar (bool on) 01324 { 01325 configStart (); 01326 01327 m_iconBarSet = true; 01328 m_iconBar = on; 01329 01330 configEnd (); 01331 } 01332 01333 bool KateViewConfig::foldingBar () const 01334 { 01335 if (m_foldingBarSet || isGlobal()) 01336 return m_foldingBar; 01337 01338 return s_global->foldingBar(); 01339 } 01340 01341 void KateViewConfig::setFoldingBar (bool on) 01342 { 01343 configStart (); 01344 01345 m_foldingBarSet = true; 01346 m_foldingBar = on; 01347 01348 configEnd (); 01349 } 01350 01351 int KateViewConfig::bookmarkSort () const 01352 { 01353 if (m_bookmarkSortSet || isGlobal()) 01354 return m_bookmarkSort; 01355 01356 return s_global->bookmarkSort(); 01357 } 01358 01359 void KateViewConfig::setBookmarkSort (int mode) 01360 { 01361 configStart (); 01362 01363 m_bookmarkSortSet = true; 01364 m_bookmarkSort = mode; 01365 01366 configEnd (); 01367 } 01368 01369 int KateViewConfig::autoCenterLines () const 01370 { 01371 if (m_autoCenterLinesSet || isGlobal()) 01372 return m_autoCenterLines; 01373 01374 return s_global->autoCenterLines(); 01375 } 01376 01377 void KateViewConfig::setAutoCenterLines (int lines) 01378 { 01379 if (lines < 0) 01380 return; 01381 01382 configStart (); 01383 01384 m_autoCenterLinesSet = true; 01385 m_autoCenterLines = lines; 01386 01387 configEnd (); 01388 } 01389 01390 long KateViewConfig::searchFlags () const 01391 { 01392 if (m_searchFlagsSet || isGlobal()) 01393 return m_searchFlags; 01394 01395 return s_global->searchFlags(); 01396 } 01397 01398 void KateViewConfig::setSearchFlags (long flags) 01399 { 01400 configStart (); 01401 01402 m_searchFlagsSet = true; 01403 m_searchFlags = flags; 01404 01405 configEnd (); 01406 } 01407 01408 QStringListModel *KateViewConfig::patternHistoryModel() 01409 { 01410 // always return global history 01411 if (isGlobal()) 01412 return &m_patternHistoryModel; 01413 01414 return s_global->patternHistoryModel(); 01415 } 01416 01417 int KateViewConfig::maxHistorySize() const 01418 { 01419 return m_maxHistorySize; 01420 } 01421 01422 QStringListModel *KateViewConfig::replacementHistoryModel() 01423 { 01424 // always return global history 01425 if (isGlobal()) 01426 return &m_replacementHistoryModel; 01427 01428 return s_global->replacementHistoryModel(); 01429 } 01430 01431 uint KateViewConfig::defaultMarkType () const 01432 { 01433 if (m_defaultMarkTypeSet || isGlobal()) 01434 return m_defaultMarkType; 01435 01436 return s_global->defaultMarkType(); 01437 } 01438 01439 void KateViewConfig::setDefaultMarkType (uint type) 01440 { 01441 configStart (); 01442 01443 m_defaultMarkTypeSet = true; 01444 m_defaultMarkType = type; 01445 01446 configEnd (); 01447 } 01448 01449 bool KateViewConfig::allowMarkMenu() const 01450 { 01451 return m_allowMarkMenu; 01452 } 01453 01454 void KateViewConfig::setAllowMarkMenu (bool allow) 01455 { 01456 m_allowMarkMenu = allow; 01457 } 01458 01459 bool KateViewConfig::persistentSelection () const 01460 { 01461 if (m_persistentSelectionSet || isGlobal()) 01462 return m_persistentSelection; 01463 01464 return s_global->persistentSelection(); 01465 } 01466 01467 void KateViewConfig::setPersistentSelection (bool on) 01468 { 01469 configStart (); 01470 01471 m_persistentSelectionSet = true; 01472 m_persistentSelection = on; 01473 01474 configEnd (); 01475 } 01476 01477 bool KateViewConfig::viInputMode () const 01478 { 01479 if (m_viInputModeSet || isGlobal()) 01480 return m_viInputMode; 01481 01482 return s_global->viInputMode(); 01483 } 01484 01485 void KateViewConfig::setViInputMode (bool on) 01486 { 01487 configStart (); 01488 01489 m_viInputModeSet = true; 01490 m_viInputMode = on; 01491 01492 // update all views and show/hide the status bar 01493 foreach (KateView* view, KateGlobal::self()->views() ) { 01494 if (on && !m_viInputModeHideStatusBar) { 01495 view->showViModeBar(); 01496 } else { 01497 view->hideViModeBar(); 01498 } 01499 } 01500 01501 // make sure to turn off edits mergin when leaving vi input mode 01502 if (!on && m_view) { 01503 m_view->doc()->setUndoMergeAllEdits(false); 01504 } 01505 01506 configEnd (); 01507 } 01508 01509 bool KateViewConfig::viInputModeStealKeys () const 01510 { 01511 if (m_viInputModeStealKeysSet || isGlobal()) 01512 return m_viInputModeStealKeys; 01513 01514 return s_global->viInputModeStealKeys(); 01515 } 01516 01517 void KateViewConfig::setViInputModeStealKeys (bool on) 01518 { 01519 configStart (); 01520 01521 m_viInputModeStealKeysSet = true; 01522 m_viInputModeStealKeys = on; 01523 01524 configEnd (); 01525 } 01526 01527 bool KateViewConfig::viInputModeHideStatusBar () const 01528 { 01529 if (m_viInputModeHideStatusBarSet || isGlobal()) 01530 return m_viInputModeHideStatusBar; 01531 01532 return s_global->viInputModeHideStatusBar(); 01533 } 01534 01535 void KateViewConfig::setViInputModeHideStatusBar (bool on) 01536 { 01537 configStart (); 01538 01539 m_viInputModeHideStatusBarSet = true; 01540 m_viInputModeHideStatusBar = on; 01541 01542 // update all views and show/hide the status bar 01543 foreach (KateView* view, KateGlobal::self()->views() ) { 01544 if (on && m_viInputMode) { 01545 view->hideViModeBar(); 01546 } else if (viInputMode()) { 01547 view->showViModeBar(); 01548 } 01549 } 01550 01551 configEnd (); 01552 } 01553 01554 01555 bool KateViewConfig::automaticCompletionInvocation () const 01556 { 01557 if (m_automaticCompletionInvocationSet || isGlobal()) 01558 return m_automaticCompletionInvocation; 01559 01560 return s_global->automaticCompletionInvocation(); 01561 } 01562 01563 void KateViewConfig::setAutomaticCompletionInvocation (bool on) 01564 { 01565 configStart (); 01566 01567 m_automaticCompletionInvocationSet = true; 01568 m_automaticCompletionInvocation = on; 01569 01570 configEnd (); 01571 } 01572 01573 bool KateViewConfig::wordCompletion () const 01574 { 01575 if (m_wordCompletionSet || isGlobal()) 01576 return m_wordCompletion; 01577 01578 return s_global->wordCompletion(); 01579 } 01580 01581 void KateViewConfig::setWordCompletion (bool on) 01582 { 01583 configStart (); 01584 01585 m_wordCompletionSet = true; 01586 m_wordCompletion = on; 01587 01588 configEnd (); 01589 } 01590 01591 int KateViewConfig::wordCompletionMinimalWordLength () const 01592 { 01593 if (m_wordCompletionMinimalWordLengthSet || isGlobal()) 01594 return m_wordCompletionMinimalWordLength; 01595 01596 return s_global->wordCompletionMinimalWordLength(); 01597 } 01598 01599 void KateViewConfig::setWordCompletionMinimalWordLength (int length) 01600 { 01601 configStart (); 01602 01603 m_wordCompletionMinimalWordLengthSet = true; 01604 m_wordCompletionMinimalWordLength = length; 01605 01606 configEnd (); 01607 } 01608 01609 bool KateViewConfig::smartCopyCut () const 01610 { 01611 if (m_smartCopyCutSet || isGlobal()) 01612 return m_smartCopyCut; 01613 01614 return s_global->smartCopyCut(); 01615 } 01616 01617 void KateViewConfig::setSmartCopyCut (bool on) 01618 { 01619 configStart (); 01620 01621 m_smartCopyCutSet = true; 01622 m_smartCopyCut = on; 01623 01624 configEnd (); 01625 } 01626 01627 bool KateViewConfig::scrollPastEnd () const 01628 { 01629 if (m_scrollPastEndSet || isGlobal()) 01630 return m_scrollPastEnd; 01631 01632 return s_global->scrollPastEnd(); 01633 } 01634 01635 void KateViewConfig::setScrollPastEnd (bool on) 01636 { 01637 configStart (); 01638 01639 m_scrollPastEndSet = true; 01640 m_scrollPastEnd = on; 01641 01642 configEnd (); 01643 } 01644 01645 //END 01646 01647 //BEGIN KateRendererConfig 01648 KateRendererConfig::KateRendererConfig () 01649 : m_fontMetrics(QFont()), 01650 m_lineMarkerColor (KTextEditor::MarkInterface::reservedMarkersCount()), 01651 m_schemaSet (true), 01652 m_fontSet (true), 01653 m_wordWrapMarkerSet (true), 01654 m_showIndentationLinesSet (true), 01655 m_showWholeBracketExpressionSet (true), 01656 m_backgroundColorSet (true), 01657 m_selectionColorSet (true), 01658 m_highlightedLineColorSet (true), 01659 m_highlightedBracketColorSet (true), 01660 m_wordWrapMarkerColorSet (true), 01661 m_tabMarkerColorSet(true), 01662 m_iconBarColorSet (true), 01663 m_lineNumberColorSet (true), 01664 m_spellingMistakeLineColorSet (true), 01665 m_templateColorsSet(true), 01666 m_lineMarkerColorSet (m_lineMarkerColor.size()), 01667 m_renderer (0) 01668 { 01669 // init bitarray 01670 m_lineMarkerColorSet.fill (true); 01671 01672 s_global = this; 01673 01674 // init with defaults from config or really hardcoded ones 01675 KConfigGroup config(KGlobal::config(), "Kate Renderer Defaults"); 01676 readConfig (config); 01677 } 01678 01679 KateRendererConfig::KateRendererConfig (KateRenderer *renderer) 01680 : m_fontMetrics(QFont()), 01681 m_lineMarkerColor (KTextEditor::MarkInterface::reservedMarkersCount()), 01682 m_schemaSet (false), 01683 m_fontSet (false), 01684 m_wordWrapMarkerSet (false), 01685 m_showIndentationLinesSet (false), 01686 m_showWholeBracketExpressionSet (false), 01687 m_backgroundColorSet (false), 01688 m_selectionColorSet (false), 01689 m_highlightedLineColorSet (false), 01690 m_highlightedBracketColorSet (false), 01691 m_wordWrapMarkerColorSet (false), 01692 m_tabMarkerColorSet(false), 01693 m_iconBarColorSet (false), 01694 m_lineNumberColorSet (false), 01695 m_spellingMistakeLineColorSet (false), 01696 m_templateColorsSet(false), 01697 m_lineMarkerColorSet (m_lineMarkerColor.size()), 01698 m_renderer (renderer) 01699 { 01700 // init bitarray 01701 m_lineMarkerColorSet.fill (false); 01702 } 01703 01704 KateRendererConfig::~KateRendererConfig () 01705 { 01706 } 01707 01708 void KateRendererConfig::readConfig (const KConfigGroup &config) 01709 { 01710 configStart (); 01711 01712 setSchema (config.readEntry("Schema", KateSchemaManager::normalSchema())); 01713 01714 setWordWrapMarker (config.readEntry("Word Wrap Marker", false )); 01715 01716 setShowIndentationLines (config.readEntry( "Show Indentation Lines", false)); 01717 01718 setShowWholeBracketExpression (config.readEntry( "Show Whole Bracket Expression", false)); 01719 01720 configEnd (); 01721 } 01722 01723 void KateRendererConfig::writeConfig (KConfigGroup& config) 01724 { 01725 config.writeEntry ("Schema", schema()); 01726 01727 config.writeEntry("Word Wrap Marker", wordWrapMarker() ); 01728 01729 config.writeEntry("Show Indentation Lines", showIndentationLines()); 01730 01731 config.writeEntry("Show Whole Bracket Expression", showWholeBracketExpression()); 01732 } 01733 01734 void KateRendererConfig::updateConfig () 01735 { 01736 if (m_renderer) 01737 { 01738 m_renderer->updateConfig (); 01739 return; 01740 } 01741 01742 if (isGlobal()) 01743 { 01744 for (int z=0; z < KateGlobal::self()->views().size(); ++z) 01745 (KateGlobal::self()->views())[z]->renderer()->updateConfig (); 01746 } 01747 } 01748 01749 const QString &KateRendererConfig::schema () const 01750 { 01751 if (m_schemaSet || isGlobal()) 01752 return m_schema; 01753 01754 return s_global->schema(); 01755 } 01756 01757 void KateRendererConfig::setSchema (const QString &schema) 01758 { 01759 configStart (); 01760 m_schemaSet = true; 01761 m_schema = schema; 01762 setSchemaInternal( schema ); 01763 configEnd (); 01764 } 01765 01766 void KateRendererConfig::reloadSchema() 01767 { 01768 if ( isGlobal() ) 01769 foreach (KateView* view, KateGlobal::self()->views() ) 01770 view->renderer()->config()->reloadSchema(); 01771 01772 else if ( m_renderer && m_schemaSet ) 01773 setSchemaInternal( m_schema ); 01774 } 01775 01776 void KateRendererConfig::setSchemaInternal( const QString &schema ) 01777 { 01778 m_schemaSet = true; 01779 m_schema = schema; 01780 01781 KConfigGroup config = KateGlobal::self()->schemaManager()->schema(KateGlobal::self()->schemaManager()->number(schema)); 01782 01783 // NOTE keep in sync with KateSchemaConfigColorTab::schemaChanged 01784 KColorScheme schemeView(QPalette::Active, KColorScheme::View); 01785 KColorScheme schemeWindow(QPalette::Active, KColorScheme::Window); 01786 KColorScheme schemeSelection(QPalette::Active, KColorScheme::Selection); 01787 KColorScheme schemeTooltip(QPalette::Active, KColorScheme::Tooltip); 01788 QColor tmp0( schemeView.background().color() ); 01789 QColor tmp1( schemeSelection.background().color() ); 01790 QColor tmp2( schemeView.background(KColorScheme::AlternateBackground).color() ); 01791 // using KColorUtils::shade wasn't working really well 01792 qreal bgLuma = KColorUtils::luma( tmp0 ); 01793 QColor tmp3( KColorUtils::tint(tmp0, schemeView.decoration(KColorScheme::HoverColor).color()) ); 01794 QColor tmp4( KColorUtils::shade( tmp0, bgLuma > 0.3 ? -0.15 : 0.03 ) ); 01795 QColor tmp5( KColorUtils::shade( tmp0, bgLuma > 0.7 ? -0.35 : 0.3 ) ); 01796 QColor tmp6( schemeWindow.background().color() ); 01797 QColor tmp7( schemeWindow.foreground().color() ); 01798 QColor tmp8( schemeView.foreground(KColorScheme::NegativeText).color() ); 01799 01800 m_backgroundColor = config.readEntry("Color Background", tmp0); 01801 m_backgroundColorSet = true; 01802 m_selectionColor = config.readEntry("Color Selection", tmp1); 01803 m_selectionColorSet = true; 01804 m_highlightedLineColor = config.readEntry("Color Highlighted Line", tmp2); 01805 m_highlightedLineColorSet = true; 01806 m_highlightedBracketColor = config.readEntry("Color Highlighted Bracket", tmp3); 01807 m_highlightedBracketColorSet = true; 01808 m_wordWrapMarkerColor = config.readEntry("Color Word Wrap Marker", tmp4); 01809 m_wordWrapMarkerColorSet = true; 01810 m_tabMarkerColor = config.readEntry("Color Tab Marker", tmp5); 01811 m_tabMarkerColorSet = true; 01812 m_iconBarColor = config.readEntry("Color Icon Bar", tmp6); 01813 m_iconBarColorSet = true; 01814 m_lineNumberColor = config.readEntry("Color Line Number", tmp7); 01815 m_lineNumberColorSet = true; 01816 m_spellingMistakeLineColor = config.readEntry("Color Spelling Mistake Line", tmp8); 01817 m_spellingMistakeLineColorSet = true; 01818 01819 // same std colors like in KateDocument::markColor 01820 QColor mark[7]; 01821 mark[0] = Qt::blue; 01822 mark[1] = Qt::red; 01823 mark[2] = Qt::yellow; 01824 mark[3] = Qt::magenta; 01825 mark[4] = Qt::gray; 01826 mark[5] = Qt::green; 01827 mark[6] = Qt::red; 01828 01829 for (int i = 1; i <= KTextEditor::MarkInterface::reservedMarkersCount(); i++) { 01830 QColor col = config.readEntry(QString("Color MarkType%1").arg(i), mark[i - 1]); 01831 int index = i-1; 01832 m_lineMarkerColorSet[index] = true; 01833 m_lineMarkerColor[index] = col; 01834 } 01835 01836 QFont f (KGlobalSettings::fixedFont()); 01837 01838 m_font = config.readEntry("Font", f); 01839 m_fontMetrics = QFontMetrics(m_font); 01840 m_fontSet = true; 01841 01842 m_templateBackgroundColor=config.readEntry(QString("Color Template Background"), 01843 schemeTooltip.background(KColorScheme::NormalBackground).color()); 01844 01845 m_templateEditablePlaceholderColor = config.readEntry(QString("Color Template Editable Placeholder"), 01846 schemeTooltip.background(KColorScheme::NeutralBackground).color()); 01847 01848 m_templateFocusedEditablePlaceholderColor=config.readEntry(QString("Color Template Focused Editable Placeholder"), 01849 schemeTooltip.background(KColorScheme::PositiveBackground).color()); 01850 01851 m_templateNotEditablePlaceholderColor=config.readEntry(QString("Color Template Not Editable Placeholder"), 01852 schemeTooltip.background(KColorScheme::NegativeBackground).color()); 01853 01854 m_templateColorsSet=true; 01855 } 01856 01857 const QFont& KateRendererConfig::font() const 01858 { 01859 if (m_fontSet || isGlobal()) 01860 return m_font; 01861 01862 return s_global->font(); 01863 } 01864 01865 const QFontMetrics& KateRendererConfig::fontMetrics() const 01866 { 01867 if (m_fontSet || isGlobal()) 01868 return m_fontMetrics; 01869 01870 return s_global->fontMetrics(); 01871 } 01872 01873 void KateRendererConfig::setFont(const QFont &font) 01874 { 01875 configStart (); 01876 01877 m_fontSet = true; 01878 m_font = font; 01879 m_fontMetrics = QFontMetrics(m_font); 01880 01881 configEnd (); 01882 } 01883 01884 bool KateRendererConfig::wordWrapMarker () const 01885 { 01886 if (m_wordWrapMarkerSet || isGlobal()) 01887 return m_wordWrapMarker; 01888 01889 return s_global->wordWrapMarker(); 01890 } 01891 01892 void KateRendererConfig::setWordWrapMarker (bool on) 01893 { 01894 configStart (); 01895 01896 m_wordWrapMarkerSet = true; 01897 m_wordWrapMarker = on; 01898 01899 configEnd (); 01900 } 01901 01902 const QColor& KateRendererConfig::backgroundColor() const 01903 { 01904 if (m_backgroundColorSet || isGlobal()) 01905 return m_backgroundColor; 01906 01907 return s_global->backgroundColor(); 01908 } 01909 01910 void KateRendererConfig::setBackgroundColor (const QColor &col) 01911 { 01912 configStart (); 01913 01914 m_backgroundColorSet = true; 01915 m_backgroundColor = col; 01916 01917 configEnd (); 01918 } 01919 01920 const QColor& KateRendererConfig::selectionColor() const 01921 { 01922 if (m_selectionColorSet || isGlobal()) 01923 return m_selectionColor; 01924 01925 return s_global->selectionColor(); 01926 } 01927 01928 void KateRendererConfig::setSelectionColor (const QColor &col) 01929 { 01930 configStart (); 01931 01932 m_selectionColorSet = true; 01933 m_selectionColor = col; 01934 01935 configEnd (); 01936 } 01937 01938 const QColor& KateRendererConfig::highlightedLineColor() const 01939 { 01940 if (m_highlightedLineColorSet || isGlobal()) 01941 return m_highlightedLineColor; 01942 01943 return s_global->highlightedLineColor(); 01944 } 01945 01946 void KateRendererConfig::setHighlightedLineColor (const QColor &col) 01947 { 01948 configStart (); 01949 01950 m_highlightedLineColorSet = true; 01951 m_highlightedLineColor = col; 01952 01953 configEnd (); 01954 } 01955 01956 const QColor& KateRendererConfig::lineMarkerColor(KTextEditor::MarkInterface::MarkTypes type) const 01957 { 01958 int index = 0; 01959 if (type > 0) { while((type >> index++) ^ 1) {} } 01960 index -= 1; 01961 01962 if ( index < 0 || index >= KTextEditor::MarkInterface::reservedMarkersCount() ) 01963 { 01964 static QColor dummy; 01965 return dummy; 01966 } 01967 01968 if (m_lineMarkerColorSet[index] || isGlobal()) 01969 return m_lineMarkerColor[index]; 01970 01971 return s_global->lineMarkerColor( type ); 01972 } 01973 01974 void KateRendererConfig::setLineMarkerColor (const QColor &col, KTextEditor::MarkInterface::MarkTypes type) 01975 { 01976 int index = static_cast<int>( log(static_cast<double>(type)) / log(2.0) ); 01977 Q_ASSERT( index >= 0 && index < KTextEditor::MarkInterface::reservedMarkersCount() ); 01978 configStart (); 01979 01980 m_lineMarkerColorSet[index] = true; 01981 m_lineMarkerColor[index] = col; 01982 01983 configEnd (); 01984 } 01985 01986 const QColor& KateRendererConfig::highlightedBracketColor() const 01987 { 01988 if (m_highlightedBracketColorSet || isGlobal()) 01989 return m_highlightedBracketColor; 01990 01991 return s_global->highlightedBracketColor(); 01992 } 01993 01994 void KateRendererConfig::setHighlightedBracketColor (const QColor &col) 01995 { 01996 configStart (); 01997 01998 m_highlightedBracketColorSet = true; 01999 m_highlightedBracketColor = col; 02000 02001 configEnd (); 02002 } 02003 02004 const QColor& KateRendererConfig::wordWrapMarkerColor() const 02005 { 02006 if (m_wordWrapMarkerColorSet || isGlobal()) 02007 return m_wordWrapMarkerColor; 02008 02009 return s_global->wordWrapMarkerColor(); 02010 } 02011 02012 void KateRendererConfig::setWordWrapMarkerColor (const QColor &col) 02013 { 02014 configStart (); 02015 02016 m_wordWrapMarkerColorSet = true; 02017 m_wordWrapMarkerColor = col; 02018 02019 configEnd (); 02020 } 02021 02022 const QColor& KateRendererConfig::tabMarkerColor() const 02023 { 02024 if (m_tabMarkerColorSet || isGlobal()) 02025 return m_tabMarkerColor; 02026 02027 return s_global->tabMarkerColor(); 02028 } 02029 02030 void KateRendererConfig::setTabMarkerColor (const QColor &col) 02031 { 02032 configStart (); 02033 02034 m_tabMarkerColorSet = true; 02035 m_tabMarkerColor = col; 02036 02037 configEnd (); 02038 } 02039 02040 const QColor& KateRendererConfig::iconBarColor() const 02041 { 02042 if (m_iconBarColorSet || isGlobal()) 02043 return m_iconBarColor; 02044 02045 return s_global->iconBarColor(); 02046 } 02047 02048 void KateRendererConfig::setIconBarColor (const QColor &col) 02049 { 02050 configStart (); 02051 02052 m_iconBarColorSet = true; 02053 m_iconBarColor = col; 02054 02055 configEnd (); 02056 } 02057 02058 02059 const QColor &KateRendererConfig::templateBackgroundColor() const { 02060 if (m_templateColorsSet || isGlobal()) 02061 return m_templateBackgroundColor; 02062 02063 return s_global->templateBackgroundColor(); 02064 } 02065 const QColor &KateRendererConfig::templateEditablePlaceholderColor() const { 02066 if (m_templateColorsSet || isGlobal()) 02067 return m_templateEditablePlaceholderColor; 02068 02069 return s_global->templateEditablePlaceholderColor(); 02070 } 02071 const QColor &KateRendererConfig::templateFocusedEditablePlaceholderColor() const { 02072 if (m_templateColorsSet || isGlobal()) 02073 return m_templateFocusedEditablePlaceholderColor; 02074 02075 return s_global->templateFocusedEditablePlaceholderColor(); 02076 } 02077 const QColor &KateRendererConfig::templateNotEditablePlaceholderColor() const { 02078 if (m_templateColorsSet || isGlobal()) 02079 return m_templateNotEditablePlaceholderColor; 02080 02081 return s_global->templateNotEditablePlaceholderColor(); 02082 } 02083 02084 02085 const QColor& KateRendererConfig::lineNumberColor() const 02086 { 02087 if (m_lineNumberColorSet || isGlobal()) 02088 return m_lineNumberColor; 02089 02090 return s_global->lineNumberColor(); 02091 } 02092 02093 void KateRendererConfig::setLineNumberColor (const QColor &col) 02094 { 02095 configStart (); 02096 02097 m_lineNumberColorSet = true; 02098 m_lineNumberColor = col; 02099 02100 configEnd (); 02101 } 02102 02103 const QColor& KateRendererConfig::spellingMistakeLineColor() const 02104 { 02105 if (m_spellingMistakeLineColorSet || isGlobal()) 02106 return m_spellingMistakeLineColor; 02107 02108 return s_global->spellingMistakeLineColor(); 02109 } 02110 02111 void KateRendererConfig::setSpellingMistakeKineColor (const QColor &col) 02112 { 02113 configStart (); 02114 02115 m_spellingMistakeLineColorSet = true; 02116 m_spellingMistakeLineColor = col; 02117 02118 configEnd (); 02119 } 02120 02121 bool KateRendererConfig::showIndentationLines () const 02122 { 02123 if (m_showIndentationLinesSet || isGlobal()) 02124 return m_showIndentationLines; 02125 02126 return s_global->showIndentationLines(); 02127 } 02128 02129 void KateRendererConfig::setShowIndentationLines (bool on) 02130 { 02131 configStart (); 02132 02133 m_showIndentationLinesSet = true; 02134 m_showIndentationLines = on; 02135 02136 configEnd (); 02137 } 02138 02139 bool KateRendererConfig::showWholeBracketExpression () const 02140 { 02141 if (m_showWholeBracketExpressionSet || isGlobal()) 02142 return m_showWholeBracketExpression; 02143 02144 return s_global->showWholeBracketExpression(); 02145 } 02146 02147 void KateRendererConfig::setShowWholeBracketExpression (bool on) 02148 { 02149 configStart (); 02150 02151 m_showWholeBracketExpressionSet = true; 02152 m_showWholeBracketExpression = on; 02153 02154 configEnd (); 02155 } 02156 02157 //END 02158 02159 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference