• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • part
kateconfig.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2003 Christoph Cullmann <cullmann@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "kateconfig.h"
20 
21 #include "katefactory.h"
22 #include "katerenderer.h"
23 #include "kateview.h"
24 #include "katedocument.h"
25 #include "katefont.h"
26 #include "kateschema.h"
27 
28 #include <math.h>
29 
30 #include <tdeapplication.h>
31 #include <tdeconfig.h>
32 #include <tdeglobalsettings.h>
33 #include <kcharsets.h>
34 #include <tdelocale.h>
35 #include <kfinddialog.h>
36 #include <kreplacedialog.h>
37 #include <kinstance.h>
38 #include <kstaticdeleter.h>
39 
40 #include <tqpopupmenu.h>
41 #include <tqtextcodec.h>
42 
43 #include <kdebug.h>
44 
45 //BEGIN KateConfig
46 KateConfig::KateConfig ()
47  : configSessionNumber (0), configIsRunning (false)
48 {
49 }
50 
51 KateConfig::~KateConfig ()
52 {
53 }
54 
55 void KateConfig::configStart ()
56 {
57  configSessionNumber++;
58 
59  if (configSessionNumber > 1)
60  return;
61 
62  configIsRunning = true;
63 }
64 
65 void KateConfig::configEnd ()
66 {
67  if (configSessionNumber == 0)
68  return;
69 
70  configSessionNumber--;
71 
72  if (configSessionNumber > 0)
73  return;
74 
75  configIsRunning = false;
76 
77  updateConfig ();
78 }
79 //END
80 
81 //BEGIN KateDocumentConfig
82 KateDocumentConfig *KateDocumentConfig::s_global = 0;
83 KateViewConfig *KateViewConfig::s_global = 0;
84 KateRendererConfig *KateRendererConfig::s_global = 0;
85 
86 KateDocumentConfig::KateDocumentConfig ()
87  : m_tabWidth (8),
88  m_indentationWidth (2),
89  m_wordWrapAt (80),
90  m_configFlags (0),
91  m_plugins (KateFactory::self()->plugins().count()),
92  m_tabWidthSet (true),
93  m_indentationWidthSet (true),
94  m_indentationModeSet (true),
95  m_wordWrapSet (true),
96  m_wordWrapAtSet (true),
97  m_pageUpDownMovesCursorSet (true),
98  m_undoStepsSet (true),
99  m_configFlagsSet (0xFFFF),
100  m_encodingSet (true),
101  m_eolSet (true),
102  m_allowEolDetectionSet (true),
103  m_backupFlagsSet (true),
104  m_searchDirConfigDepthSet (true),
105  m_backupPrefixSet (true),
106  m_backupSuffixSet (true),
107  m_pluginsSet (m_plugins.size()),
108  m_doc (0)
109 {
110  s_global = this;
111 
112  // init plugin array
113  m_plugins.fill (false);
114  m_pluginsSet.fill (true);
115 
116  // init with defaults from config or really hardcoded ones
117  TDEConfig *config = kapp->config();
118  config->setGroup("Kate Document Defaults");
119  readConfig (config);
120 }
121 
122 KateDocumentConfig::KateDocumentConfig (KateDocument *doc)
123  : m_configFlags (0),
124  m_plugins (KateFactory::self()->plugins().count()),
125  m_tabWidthSet (false),
126  m_indentationWidthSet (false),
127  m_indentationModeSet (false),
128  m_wordWrapSet (false),
129  m_wordWrapAtSet (false),
130  m_pageUpDownMovesCursorSet (false),
131  m_undoStepsSet (false),
132  m_configFlagsSet (0),
133  m_encodingSet (false),
134  m_eolSet (false),
135  m_allowEolDetectionSet (false),
136  m_backupFlagsSet (false),
137  m_searchDirConfigDepthSet (false),
138  m_backupPrefixSet (false),
139  m_backupSuffixSet (false),
140  m_pluginsSet (m_plugins.size()),
141  m_doc (doc)
142 {
143  // init plugin array
144  m_plugins.fill (false);
145  m_pluginsSet.fill (false);
146 }
147 
148 KateDocumentConfig::~KateDocumentConfig ()
149 {
150 }
151 
152 void KateDocumentConfig::readConfig (TDEConfig *config)
153 {
154  configStart ();
155 
156  setTabWidth (config->readNumEntry("Tab Width", 8));
157 
158  setIndentationWidth (config->readNumEntry("Indentation Width", 2));
159 
160  setIndentationMode (config->readNumEntry("Indentation Mode", KateDocumentConfig::imNone));
161 
162  setWordWrap (config->readBoolEntry("Word Wrap", false));
163  setWordWrapAt (config->readNumEntry("Word Wrap Column", 80));
164  setPageUpDownMovesCursor (config->readBoolEntry("PageUp/PageDown Moves Cursor", false));
165  setUndoSteps(config->readNumEntry("Undo Steps", 0));
166 
167  setConfigFlags (config->readNumEntry("Basic Config Flags", KateDocumentConfig::cfTabIndents
168  | KateDocumentConfig::cfKeepIndentProfile
169  | KateDocumentConfig::cfWrapCursor
170  | KateDocumentConfig::cfShowTabs
171  | KateDocumentConfig::cfSmartHome
172  | KateDocumentConfig::cfIndentPastedText));
173 
174  setEncoding (config->readEntry("Encoding", ""));
175 
176  setEol (config->readNumEntry("End of Line", 0));
177  setAllowEolDetection (config->readBoolEntry("Allow End of Line Detection", true));
178 
179  setBackupFlags (config->readNumEntry("Backup Config Flags", 1));
180 
181  setSearchDirConfigDepth (config->readNumEntry("Search Dir Config Depth", 3));
182 
183  setBackupPrefix (config->readEntry("Backup Prefix", TQString ("")));
184 
185  setBackupSuffix (config->readEntry("Backup Suffix", TQString ("~")));
186 
187  // plugins
188  for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
189  setPlugin (i, config->readBoolEntry("KTextEditor Plugin " + (KateFactory::self()->plugins())[i]->library(), false));
190 
191  configEnd ();
192 }
193 
194 void KateDocumentConfig::writeConfig (TDEConfig *config)
195 {
196  config->writeEntry("Tab Width", tabWidth());
197 
198  config->writeEntry("Indentation Width", indentationWidth());
199  config->writeEntry("Indentation Mode", indentationMode());
200 
201  config->writeEntry("Word Wrap", wordWrap());
202  config->writeEntry("Word Wrap Column", wordWrapAt());
203 
204  config->writeEntry("PageUp/PageDown Moves Cursor", pageUpDownMovesCursor());
205 
206  config->writeEntry("Undo Steps", undoSteps());
207 
208  config->writeEntry("Basic Config Flags", configFlags());
209 
210  config->writeEntry("Encoding", encoding());
211 
212  config->writeEntry("End of Line", eol());
213  config->writeEntry("Allow End of Line Detection", allowEolDetection());
214 
215  config->writeEntry("Backup Config Flags", backupFlags());
216 
217  config->writeEntry("Search Dir Config Depth", searchDirConfigDepth());
218 
219  config->writeEntry("Backup Prefix", backupPrefix());
220 
221  config->writeEntry("Backup Suffix", backupSuffix());
222 
223  // plugins
224  for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
225  config->writeEntry("KTextEditor Plugin " + (KateFactory::self()->plugins())[i]->library(), plugin(i));
226 }
227 
228 void KateDocumentConfig::updateConfig ()
229 {
230  if (m_doc)
231  {
232  m_doc->updateConfig ();
233  return;
234  }
235 
236  if (isGlobal())
237  {
238  for (uint z=0; z < KateFactory::self()->documents()->count(); z++)
239  {
240  KateFactory::self()->documents()->at(z)->updateConfig ();
241  }
242  }
243 }
244 
245 int KateDocumentConfig::tabWidth () const
246 {
247  if (m_tabWidthSet || isGlobal())
248  return m_tabWidth;
249 
250  return s_global->tabWidth();
251 }
252 
253 void KateDocumentConfig::setTabWidth (int tabWidth)
254 {
255  if (tabWidth < 1)
256  return;
257 
258  configStart ();
259 
260  m_tabWidthSet = true;
261  m_tabWidth = tabWidth;
262 
263  configEnd ();
264 }
265 
266 int KateDocumentConfig::indentationWidth () const
267 {
268  if (m_indentationWidthSet || isGlobal())
269  return m_indentationWidth;
270 
271  return s_global->indentationWidth();
272 }
273 
274 void KateDocumentConfig::setIndentationWidth (int indentationWidth)
275 {
276  if (indentationWidth < 1)
277  return;
278 
279  configStart ();
280 
281  m_indentationWidthSet = true;
282  m_indentationWidth = indentationWidth;
283 
284  configEnd ();
285 }
286 
287 uint KateDocumentConfig::indentationMode () const
288 {
289  if (m_indentationModeSet || isGlobal())
290  return m_indentationMode;
291 
292  return s_global->indentationMode();
293 }
294 
295 void KateDocumentConfig::setIndentationMode (uint indentationMode)
296 {
297  configStart ();
298 
299  m_indentationModeSet = true;
300  m_indentationMode = indentationMode;
301 
302  configEnd ();
303 }
304 
305 bool KateDocumentConfig::wordWrap () const
306 {
307  if (m_wordWrapSet || isGlobal())
308  return m_wordWrap;
309 
310  return s_global->wordWrap();
311 }
312 
313 void KateDocumentConfig::setWordWrap (bool on)
314 {
315  configStart ();
316 
317  m_wordWrapSet = true;
318  m_wordWrap = on;
319 
320  configEnd ();
321 }
322 
323 unsigned int KateDocumentConfig::wordWrapAt () const
324 {
325  if (m_wordWrapAtSet || isGlobal())
326  return m_wordWrapAt;
327 
328  return s_global->wordWrapAt();
329 }
330 
331 void KateDocumentConfig::setWordWrapAt (unsigned int col)
332 {
333  if (col < 1)
334  return;
335 
336  configStart ();
337 
338  m_wordWrapAtSet = true;
339  m_wordWrapAt = col;
340 
341  configEnd ();
342 }
343 
344 uint KateDocumentConfig::undoSteps () const
345 {
346  if (m_undoStepsSet || isGlobal())
347  return m_undoSteps;
348 
349  return s_global->undoSteps();
350 }
351 
352 void KateDocumentConfig::setUndoSteps (uint undoSteps)
353 {
354  configStart ();
355 
356  m_undoStepsSet = true;
357  m_undoSteps = undoSteps;
358 
359  configEnd ();
360 }
361 
362 bool KateDocumentConfig::pageUpDownMovesCursor () const
363 {
364  if (m_pageUpDownMovesCursorSet || isGlobal())
365  return m_pageUpDownMovesCursor;
366 
367  return s_global->pageUpDownMovesCursor();
368 }
369 
370 void KateDocumentConfig::setPageUpDownMovesCursor (bool on)
371 {
372  configStart ();
373 
374  m_pageUpDownMovesCursorSet = true;
375  m_pageUpDownMovesCursor = on;
376 
377  configEnd ();
378 }
379 
380 uint KateDocumentConfig::configFlags () const
381 {
382  if (isGlobal())
383  return m_configFlags;
384 
385  return ((s_global->configFlags() & ~ m_configFlagsSet) | m_configFlags);
386 }
387 
388 void KateDocumentConfig::setConfigFlags (KateDocumentConfig::ConfigFlags flag, bool enable)
389 {
390  configStart ();
391 
392  m_configFlagsSet |= flag;
393 
394  if (enable)
395  m_configFlags = m_configFlags | flag;
396  else
397  m_configFlags = m_configFlags & ~ flag;
398 
399  configEnd ();
400 }
401 
402 void KateDocumentConfig::setConfigFlags (uint fullFlags)
403 {
404  configStart ();
405 
406  m_configFlagsSet = 0xFFFF;
407  m_configFlags = fullFlags;
408 
409  configEnd ();
410 }
411 
412 const TQString &KateDocumentConfig::encoding () const
413 {
414  if (m_encodingSet || isGlobal())
415  return m_encoding;
416 
417  return s_global->encoding();
418 }
419 
420 TQTextCodec *KateDocumentConfig::codec ()
421 {
422  if (m_encodingSet || isGlobal())
423  {
424  if (m_encoding.isEmpty() && isGlobal())
425  return TDEGlobal::charsets()->codecForName (TQString::fromLatin1(TDEGlobal::locale()->encoding()));
426  else if (m_encoding.isEmpty())
427  return s_global->codec ();
428  else
429  return TDEGlobal::charsets()->codecForName (m_encoding);
430  }
431 
432  return s_global->codec ();
433 }
434 
435 void KateDocumentConfig::setEncoding (const TQString &encoding)
436 {
437  TQString enc = encoding;
438 
439  if (!enc.isEmpty())
440  {
441  bool found = false;
442  TQTextCodec *codec = TDEGlobal::charsets()->codecForName (encoding, found);
443 
444  if (!found || !codec)
445  return;
446 
447  enc = codec->name();
448  }
449 
450  configStart ();
451 
452  if (isGlobal())
453  KateDocument::setDefaultEncoding (enc);
454 
455  m_encodingSet = true;
456  m_encoding = enc;
457 
458  configEnd ();
459 }
460 
461 bool KateDocumentConfig::isSetEncoding () const
462 {
463  return m_encodingSet;
464 }
465 
466 int KateDocumentConfig::eol () const
467 {
468  if (m_eolSet || isGlobal())
469  return m_eol;
470 
471  return s_global->eol();
472 }
473 
474 TQString KateDocumentConfig::eolString ()
475 {
476  if (eol() == KateDocumentConfig::eolUnix)
477  return TQString ("\n");
478  else if (eol() == KateDocumentConfig::eolDos)
479  return TQString ("\r\n");
480  else if (eol() == KateDocumentConfig::eolMac)
481  return TQString ("\r");
482 
483  return TQString ("\n");
484 }
485 
486 void KateDocumentConfig::setEol (int mode)
487 {
488  configStart ();
489 
490  m_eolSet = true;
491  m_eol = mode;
492 
493  configEnd ();
494 }
495 
496 bool KateDocumentConfig::allowEolDetection () const
497 {
498  if (m_allowEolDetectionSet || isGlobal())
499  return m_allowEolDetection;
500 
501  return s_global->allowEolDetection();
502 }
503 
504 void KateDocumentConfig::setAllowEolDetection (bool on)
505 {
506  configStart ();
507 
508  m_allowEolDetectionSet = true;
509  m_allowEolDetection = on;
510 
511  configEnd ();
512 }
513 
514 uint KateDocumentConfig::backupFlags () const
515 {
516  if (m_backupFlagsSet || isGlobal())
517  return m_backupFlags;
518 
519  return s_global->backupFlags();
520 }
521 
522 void KateDocumentConfig::setBackupFlags (uint flags)
523  {
524  configStart ();
525 
526  m_backupFlagsSet = true;
527  m_backupFlags = flags;
528 
529  configEnd ();
530 }
531 
532 const TQString &KateDocumentConfig::backupPrefix () const
533 {
534  if (m_backupPrefixSet || isGlobal())
535  return m_backupPrefix;
536 
537  return s_global->backupPrefix();
538 }
539 
540 const TQString &KateDocumentConfig::backupSuffix () const
541 {
542  if (m_backupSuffixSet || isGlobal())
543  return m_backupSuffix;
544 
545  return s_global->backupSuffix();
546 }
547 
548 void KateDocumentConfig::setBackupPrefix (const TQString &prefix)
549 {
550  configStart ();
551 
552  m_backupPrefixSet = true;
553  m_backupPrefix = prefix;
554 
555  configEnd ();
556 }
557 
558 void KateDocumentConfig::setBackupSuffix (const TQString &suffix)
559 {
560  configStart ();
561 
562  m_backupSuffixSet = true;
563  m_backupSuffix = suffix;
564 
565  configEnd ();
566 }
567 
568 bool KateDocumentConfig::plugin (uint index) const
569 {
570  if (index >= m_plugins.size())
571  return false;
572 
573  if (m_pluginsSet.at(index) || isGlobal())
574  return m_plugins.at(index);
575 
576  return s_global->plugin (index);
577 }
578 
579 void KateDocumentConfig::setPlugin (uint index, bool load)
580 {
581  if (index >= m_plugins.size())
582  return;
583 
584  configStart ();
585 
586  m_pluginsSet.setBit(index);
587  m_plugins.setBit(index, load);
588 
589  configEnd ();
590 }
591 
592 int KateDocumentConfig::searchDirConfigDepth () const
593 {
594  if (m_searchDirConfigDepthSet || isGlobal())
595  return m_searchDirConfigDepth;
596 
597  return s_global->searchDirConfigDepth ();
598 }
599 
600 void KateDocumentConfig::setSearchDirConfigDepth (int depth)
601 {
602  configStart ();
603 
604  m_searchDirConfigDepthSet = true;
605  m_searchDirConfigDepth = depth;
606 
607  configEnd ();
608 }
609 
610 //END
611 
612 //BEGIN KateViewConfig
613 KateViewConfig::KateViewConfig ()
614  :
615  m_dynWordWrapSet (true),
616  m_dynWordWrapIndicatorsSet (true),
617  m_dynWordWrapAlignIndentSet (true),
618  m_lineNumbersSet (true),
619  m_scrollBarMarksSet (true),
620  m_iconBarSet (true),
621  m_foldingBarSet (true),
622  m_bookmarkSortSet (true),
623  m_autoCenterLinesSet (true),
624  m_searchFlagsSet (true),
625  m_cmdLineSet (true),
626  m_defaultMarkTypeSet (true),
627  m_persistentSelectionSet (true),
628  m_textToSearchModeSet (true),
629  m_view (0)
630 {
631  s_global = this;
632 
633  // init with defaults from config or really hardcoded ones
634  TDEConfig *config = kapp->config();
635  config->setGroup("Kate View Defaults");
636  readConfig (config);
637 }
638 
639 KateViewConfig::KateViewConfig (KateView *view)
640  :
641  m_dynWordWrapSet (false),
642  m_dynWordWrapIndicatorsSet (false),
643  m_dynWordWrapAlignIndentSet (false),
644  m_lineNumbersSet (false),
645  m_scrollBarMarksSet (false),
646  m_iconBarSet (false),
647  m_foldingBarSet (false),
648  m_bookmarkSortSet (false),
649  m_autoCenterLinesSet (false),
650  m_searchFlagsSet (false),
651  m_cmdLineSet (false),
652  m_defaultMarkTypeSet (false),
653  m_persistentSelectionSet (false),
654  m_textToSearchModeSet (false),
655  m_view (view)
656 {
657 }
658 
659 KateViewConfig::~KateViewConfig ()
660 {
661 }
662 
663 void KateViewConfig::readConfig (TDEConfig *config)
664 {
665  configStart ();
666 
667  setDynWordWrap (config->readBoolEntry( "Dynamic Word Wrap", true ));
668  setDynWordWrapIndicators (config->readNumEntry( "Dynamic Word Wrap Indicators", 1 ));
669  setDynWordWrapAlignIndent (config->readNumEntry( "Dynamic Word Wrap Align Indent", 80 ));
670 
671  setLineNumbers (config->readBoolEntry( "Line Numbers", false));
672 
673  setScrollBarMarks (config->readBoolEntry( "Scroll Bar Marks", false));
674 
675  setIconBar (config->readBoolEntry( "Icon Bar", false ));
676 
677  setFoldingBar (config->readBoolEntry( "Folding Bar", true));
678 
679  setBookmarkSort (config->readNumEntry( "Bookmark Menu Sorting", 0 ));
680 
681  setAutoCenterLines (config->readNumEntry( "Auto Center Lines", 0 ));
682 
683  setSearchFlags (config->readNumEntry("Search Config Flags", KFindDialog::FromCursor | KFindDialog::CaseSensitive | KReplaceDialog::PromptOnReplace));
684 
685  setCmdLine (config->readBoolEntry( "Command Line", false));
686 
687  setDefaultMarkType (config->readNumEntry( "Default Mark Type", KTextEditor::MarkInterface::markType01 ));
688 
689  setPersistentSelection (config->readNumEntry( "Persistent Selection", false ));
690 
691  setTextToSearchMode (config->readNumEntry( "Text To Search Mode", KateViewConfig::SelectionWord));
692 
693  configEnd ();
694 }
695 
696 void KateViewConfig::writeConfig (TDEConfig *config)
697 {
698  config->writeEntry( "Dynamic Word Wrap", dynWordWrap() );
699  config->writeEntry( "Dynamic Word Wrap Indicators", dynWordWrapIndicators() );
700  config->writeEntry( "Dynamic Word Wrap Align Indent", dynWordWrapAlignIndent() );
701 
702  config->writeEntry( "Line Numbers", lineNumbers() );
703 
704  config->writeEntry( "Scroll Bar Marks", scrollBarMarks() );
705 
706  config->writeEntry( "Icon Bar", iconBar() );
707 
708  config->writeEntry( "Folding Bar", foldingBar() );
709 
710  config->writeEntry( "Bookmark Menu Sorting", bookmarkSort() );
711 
712  config->writeEntry( "Auto Center Lines", autoCenterLines() );
713 
714  config->writeEntry("Search Config Flags", searchFlags());
715 
716  config->writeEntry("Command Line", cmdLine());
717 
718  config->writeEntry("Default Mark Type", defaultMarkType());
719 
720  config->writeEntry("Persistent Selection", persistentSelection());
721 
722  config->writeEntry("Text To Search Mode", textToSearchMode());
723 }
724 
725 void KateViewConfig::updateConfig ()
726 {
727  if (m_view)
728  {
729  m_view->updateConfig ();
730  return;
731  }
732 
733  if (isGlobal())
734  {
735  for (uint z=0; z < KateFactory::self()->views()->count(); z++)
736  {
737  KateFactory::self()->views()->at(z)->updateConfig ();
738  }
739  }
740 }
741 
742 bool KateViewConfig::dynWordWrap () const
743 {
744  if (m_dynWordWrapSet || isGlobal())
745  return m_dynWordWrap;
746 
747  return s_global->dynWordWrap();
748 }
749 
750 void KateViewConfig::setDynWordWrap (bool wrap)
751 {
752  configStart ();
753 
754  m_dynWordWrapSet = true;
755  m_dynWordWrap = wrap;
756 
757  configEnd ();
758 }
759 
760 int KateViewConfig::dynWordWrapIndicators () const
761 {
762  if (m_dynWordWrapIndicatorsSet || isGlobal())
763  return m_dynWordWrapIndicators;
764 
765  return s_global->dynWordWrapIndicators();
766 }
767 
768 void KateViewConfig::setDynWordWrapIndicators (int mode)
769 {
770  configStart ();
771 
772  m_dynWordWrapIndicatorsSet = true;
773  m_dynWordWrapIndicators = kMin(80, kMax(0, mode));
774 
775  configEnd ();
776 }
777 
778 int KateViewConfig::dynWordWrapAlignIndent () const
779 {
780  if (m_dynWordWrapAlignIndentSet || isGlobal())
781  return m_dynWordWrapAlignIndent;
782 
783  return s_global->dynWordWrapAlignIndent();
784 }
785 
786 void KateViewConfig::setDynWordWrapAlignIndent (int indent)
787 {
788  configStart ();
789 
790  m_dynWordWrapAlignIndentSet = true;
791  m_dynWordWrapAlignIndent = indent;
792 
793  configEnd ();
794 }
795 
796 bool KateViewConfig::lineNumbers () const
797 {
798  if (m_lineNumbersSet || isGlobal())
799  return m_lineNumbers;
800 
801  return s_global->lineNumbers();
802 }
803 
804 void KateViewConfig::setLineNumbers (bool on)
805 {
806  configStart ();
807 
808  m_lineNumbersSet = true;
809  m_lineNumbers = on;
810 
811  configEnd ();
812 }
813 
814 bool KateViewConfig::scrollBarMarks () const
815 {
816  if (m_scrollBarMarksSet || isGlobal())
817  return m_scrollBarMarks;
818 
819  return s_global->scrollBarMarks();
820 }
821 
822 void KateViewConfig::setScrollBarMarks (bool on)
823 {
824  configStart ();
825 
826  m_scrollBarMarksSet = true;
827  m_scrollBarMarks = on;
828 
829  configEnd ();
830 }
831 
832 bool KateViewConfig::iconBar () const
833 {
834  if (m_iconBarSet || isGlobal())
835  return m_iconBar;
836 
837  return s_global->iconBar();
838 }
839 
840 void KateViewConfig::setIconBar (bool on)
841 {
842  configStart ();
843 
844  m_iconBarSet = true;
845  m_iconBar = on;
846 
847  configEnd ();
848 }
849 
850 bool KateViewConfig::foldingBar () const
851 {
852  if (m_foldingBarSet || isGlobal())
853  return m_foldingBar;
854 
855  return s_global->foldingBar();
856 }
857 
858 void KateViewConfig::setFoldingBar (bool on)
859 {
860  configStart ();
861 
862  m_foldingBarSet = true;
863  m_foldingBar = on;
864 
865  configEnd ();
866 }
867 
868 int KateViewConfig::bookmarkSort () const
869 {
870  if (m_bookmarkSortSet || isGlobal())
871  return m_bookmarkSort;
872 
873  return s_global->bookmarkSort();
874 }
875 
876 void KateViewConfig::setBookmarkSort (int mode)
877 {
878  configStart ();
879 
880  m_bookmarkSortSet = true;
881  m_bookmarkSort = mode;
882 
883  configEnd ();
884 }
885 
886 int KateViewConfig::autoCenterLines () const
887 {
888  if (m_autoCenterLinesSet || isGlobal())
889  return m_autoCenterLines;
890 
891  return s_global->autoCenterLines();
892 }
893 
894 void KateViewConfig::setAutoCenterLines (int lines)
895 {
896  if (lines < 0)
897  return;
898 
899  configStart ();
900 
901  m_autoCenterLinesSet = true;
902  m_autoCenterLines = lines;
903 
904  configEnd ();
905 }
906 
907 long KateViewConfig::searchFlags () const
908 {
909  if (m_searchFlagsSet || isGlobal())
910  return m_searchFlags;
911 
912  return s_global->searchFlags();
913 }
914 
915 void KateViewConfig::setSearchFlags (long flags)
916  {
917  configStart ();
918 
919  m_searchFlagsSet = true;
920  m_searchFlags = flags;
921 
922  configEnd ();
923 }
924 
925 bool KateViewConfig::cmdLine () const
926 {
927  if (m_cmdLineSet || isGlobal())
928  return m_cmdLine;
929 
930  return s_global->cmdLine();
931 }
932 
933 void KateViewConfig::setCmdLine (bool on)
934 {
935  configStart ();
936 
937  m_cmdLineSet = true;
938  m_cmdLine = on;
939 
940  configEnd ();
941 }
942 
943 uint KateViewConfig::defaultMarkType () const
944 {
945  if (m_defaultMarkTypeSet || isGlobal())
946  return m_defaultMarkType;
947 
948  return s_global->defaultMarkType();
949 }
950 
951 void KateViewConfig::setDefaultMarkType (uint type)
952 {
953  configStart ();
954 
955  m_defaultMarkTypeSet = true;
956  m_defaultMarkType = type;
957 
958  configEnd ();
959 }
960 
961 bool KateViewConfig::persistentSelection () const
962 {
963  if (m_persistentSelectionSet || isGlobal())
964  return m_persistentSelection;
965 
966  return s_global->persistentSelection();
967 }
968 
969 void KateViewConfig::setPersistentSelection (bool on)
970 {
971  configStart ();
972 
973  m_persistentSelectionSet = true;
974  m_persistentSelection = on;
975 
976  configEnd ();
977 }
978 
979 int KateViewConfig::textToSearchMode () const
980 {
981  if (m_textToSearchModeSet || isGlobal())
982  return m_textToSearchMode;
983 
984  return s_global->textToSearchMode();
985 }
986 
987 void KateViewConfig::setTextToSearchMode (int mode)
988 {
989  configStart ();
990 
991  m_textToSearchModeSet = true;
992  m_textToSearchMode = mode;
993 
994  configEnd ();
995 }
996 
997 //END
998 
999 //BEGIN KateRendererConfig
1000 KateRendererConfig::KateRendererConfig ()
1001  :
1002  m_font (new KateFontStruct ()),
1003  m_lineMarkerColor (KTextEditor::MarkInterface::reservedMarkersCount()),
1004  m_schemaSet (true),
1005  m_fontSet (true),
1006  m_wordWrapMarkerSet (true),
1007  m_showIndentationLinesSet (true),
1008  m_backgroundColorSet (true),
1009  m_selectionColorSet (true),
1010  m_highlightedLineColorSet (true),
1011  m_highlightedBracketColorSet (true),
1012  m_wordWrapMarkerColorSet (true),
1013  m_tabMarkerColorSet(true),
1014  m_iconBarColorSet (true),
1015  m_lineNumberColorSet (true),
1016  m_lineMarkerColorSet (m_lineMarkerColor.size()),
1017  m_renderer (0)
1018 {
1019  // init bitarray
1020  m_lineMarkerColorSet.fill (true);
1021 
1022  s_global = this;
1023 
1024  // init with defaults from config or really hardcoded ones
1025  TDEConfig *config = kapp->config();
1026  config->setGroup("Kate Renderer Defaults");
1027  readConfig (config);
1028 }
1029 
1030 KateRendererConfig::KateRendererConfig (KateRenderer *renderer)
1031  : m_font (0),
1032  m_lineMarkerColor (KTextEditor::MarkInterface::reservedMarkersCount()),
1033  m_schemaSet (false),
1034  m_fontSet (false),
1035  m_wordWrapMarkerSet (false),
1036  m_showIndentationLinesSet (false),
1037  m_backgroundColorSet (false),
1038  m_selectionColorSet (false),
1039  m_highlightedLineColorSet (false),
1040  m_highlightedBracketColorSet (false),
1041  m_wordWrapMarkerColorSet (false),
1042  m_tabMarkerColorSet(false),
1043  m_iconBarColorSet (false),
1044  m_lineNumberColorSet (false),
1045  m_lineMarkerColorSet (m_lineMarkerColor.size()),
1046  m_renderer (renderer)
1047 {
1048  // init bitarray
1049  m_lineMarkerColorSet.fill (false);
1050 }
1051 
1052 KateRendererConfig::~KateRendererConfig ()
1053 {
1054  delete m_font;
1055 }
1056 
1057 void KateRendererConfig::readConfig (TDEConfig *config)
1058 {
1059  configStart ();
1060 
1061  setSchema (KateFactory::self()->schemaManager()->number (config->readEntry("Schema", KateSchemaManager::normalSchema())));
1062 
1063  setWordWrapMarker (config->readBoolEntry("Word Wrap Marker", false ));
1064 
1065  setShowIndentationLines (config->readBoolEntry( "Show Indentation Lines", false));
1066 
1067  configEnd ();
1068 }
1069 
1070 void KateRendererConfig::writeConfig (TDEConfig *config)
1071 {
1072  config->writeEntry ("Schema", KateFactory::self()->schemaManager()->name(schema()));
1073 
1074  config->writeEntry("Word Wrap Marker", wordWrapMarker() );
1075 
1076  config->writeEntry("Show Indentation Lines", showIndentationLines());
1077 }
1078 
1079 void KateRendererConfig::updateConfig ()
1080 {
1081  if (m_renderer)
1082  {
1083  m_renderer->updateConfig ();
1084  return;
1085  }
1086 
1087  if (isGlobal())
1088  {
1089  for (uint z=0; z < KateFactory::self()->renderers()->count(); z++)
1090  {
1091  KateFactory::self()->renderers()->at(z)->updateConfig ();
1092  }
1093  }
1094 }
1095 
1096 uint KateRendererConfig::schema () const
1097 {
1098  if (m_schemaSet || isGlobal())
1099  return m_schema;
1100 
1101  return s_global->schema();
1102 }
1103 
1104 void KateRendererConfig::setSchema (uint schema)
1105 {
1106  configStart ();
1107  m_schemaSet = true;
1108  m_schema = schema;
1109  setSchemaInternal( schema );
1110  configEnd ();
1111 }
1112 
1113 void KateRendererConfig::reloadSchema()
1114 {
1115  if ( isGlobal() )
1116  for ( uint z=0; z < KateFactory::self()->renderers()->count(); z++ )
1117  KateFactory::self()->renderers()->at(z)->config()->reloadSchema();
1118 
1119  else if ( m_renderer && m_schemaSet )
1120  setSchemaInternal( m_schema );
1121 }
1122 
1123 void KateRendererConfig::setSchemaInternal( int schema )
1124 {
1125  m_schemaSet = true;
1126  m_schema = schema;
1127 
1128  TDEConfig *config (KateFactory::self()->schemaManager()->schema(schema));
1129 
1130  TQColor tmp0 (TDEGlobalSettings::baseColor());
1131  TQColor tmp1 (TDEGlobalSettings::highlightColor());
1132  TQColor tmp2 (TDEGlobalSettings::alternateBackgroundColor());
1133  TQColor tmp3 ( "#FFFF99" );
1134  TQColor tmp4 (tmp2.dark());
1135  TQColor tmp5 ( TDEGlobalSettings::textColor() );
1136  TQColor tmp6 ( "#EAE9E8" );
1137  TQColor tmp7 ( "#000000" );
1138 
1139  m_backgroundColor = config->readColorEntry("Color Background", &tmp0);
1140  m_backgroundColorSet = true;
1141  m_selectionColor = config->readColorEntry("Color Selection", &tmp1);
1142  m_selectionColorSet = true;
1143  m_highlightedLineColor = config->readColorEntry("Color Highlighted Line", &tmp2);
1144  m_highlightedLineColorSet = true;
1145  m_highlightedBracketColor = config->readColorEntry("Color Highlighted Bracket", &tmp3);
1146  m_highlightedBracketColorSet = true;
1147  m_wordWrapMarkerColor = config->readColorEntry("Color Word Wrap Marker", &tmp4);
1148  m_wordWrapMarkerColorSet = true;
1149  m_tabMarkerColor = config->readColorEntry("Color Tab Marker", &tmp5);
1150  m_tabMarkerColorSet = true;
1151  m_iconBarColor = config->readColorEntry("Color Icon Bar", &tmp6);
1152  m_iconBarColorSet = true;
1153  m_lineNumberColor = config->readColorEntry("Color Line Number", &tmp7);
1154  m_lineNumberColorSet = true;
1155 
1156  // same std colors like in KateDocument::markColor
1157  TQColor mark[7];
1158  mark[0] = Qt::blue;
1159  mark[1] = Qt::red;
1160  mark[2] = Qt::yellow;
1161  mark[3] = Qt::magenta;
1162  mark[4] = Qt::gray;
1163  mark[5] = Qt::green;
1164  mark[6] = Qt::red;
1165 
1166  for (int i = 1; i <= KTextEditor::MarkInterface::reservedMarkersCount(); i++) {
1167  TQColor col = config->readColorEntry(TQString("Color MarkType%1").arg(i), &mark[i - 1]);
1168  int index = i-1;
1169  m_lineMarkerColorSet[index] = true;
1170  m_lineMarkerColor[index] = col;
1171  }
1172 
1173  TQFont f (TDEGlobalSettings::fixedFont());
1174 
1175  if (!m_fontSet)
1176  {
1177  m_fontSet = true;
1178  m_font = new KateFontStruct ();
1179  }
1180 
1181  m_font->setFont(config->readFontEntry("Font", &f));
1182 }
1183 
1184 KateFontStruct *KateRendererConfig::fontStruct ()
1185 {
1186  if (m_fontSet || isGlobal())
1187  return m_font;
1188 
1189  return s_global->fontStruct ();
1190 }
1191 
1192 TQFont *KateRendererConfig::font()
1193 {
1194  return &(fontStruct ()->myFont);
1195 }
1196 
1197 KateFontMetrics *KateRendererConfig::fontMetrics()
1198 {
1199  return &(fontStruct ()->myFontMetrics);
1200 }
1201 
1202 void KateRendererConfig::setFont(const TQFont &font)
1203 {
1204  configStart ();
1205 
1206  if (!m_fontSet)
1207  {
1208  m_fontSet = true;
1209  m_font = new KateFontStruct ();
1210  }
1211 
1212  m_font->setFont(font);
1213 
1214  configEnd ();
1215 }
1216 
1217 bool KateRendererConfig::wordWrapMarker () const
1218 {
1219  if (m_wordWrapMarkerSet || isGlobal())
1220  return m_wordWrapMarker;
1221 
1222  return s_global->wordWrapMarker();
1223 }
1224 
1225 void KateRendererConfig::setWordWrapMarker (bool on)
1226 {
1227  configStart ();
1228 
1229  m_wordWrapMarkerSet = true;
1230  m_wordWrapMarker = on;
1231 
1232  configEnd ();
1233 }
1234 
1235 const TQColor& KateRendererConfig::backgroundColor() const
1236 {
1237  if (m_backgroundColorSet || isGlobal())
1238  return m_backgroundColor;
1239 
1240  return s_global->backgroundColor();
1241 }
1242 
1243 void KateRendererConfig::setBackgroundColor (const TQColor &col)
1244 {
1245  configStart ();
1246 
1247  m_backgroundColorSet = true;
1248  m_backgroundColor = col;
1249 
1250  configEnd ();
1251 }
1252 
1253 const TQColor& KateRendererConfig::selectionColor() const
1254 {
1255  if (m_selectionColorSet || isGlobal())
1256  return m_selectionColor;
1257 
1258  return s_global->selectionColor();
1259 }
1260 
1261 void KateRendererConfig::setSelectionColor (const TQColor &col)
1262 {
1263  configStart ();
1264 
1265  m_selectionColorSet = true;
1266  m_selectionColor = col;
1267 
1268  configEnd ();
1269 }
1270 
1271 const TQColor& KateRendererConfig::highlightedLineColor() const
1272 {
1273  if (m_highlightedLineColorSet || isGlobal())
1274  return m_highlightedLineColor;
1275 
1276  return s_global->highlightedLineColor();
1277 }
1278 
1279 void KateRendererConfig::setHighlightedLineColor (const TQColor &col)
1280 {
1281  configStart ();
1282 
1283  m_highlightedLineColorSet = true;
1284  m_highlightedLineColor = col;
1285 
1286  configEnd ();
1287 }
1288 
1289 const TQColor& KateRendererConfig::lineMarkerColor(KTextEditor::MarkInterface::MarkTypes type) const
1290 {
1291  int index = 0;
1292  if (type > 0) { while((type >> index++) ^ 1) {} }
1293  index -= 1;
1294 
1295  if ( index < 0 || index >= KTextEditor::MarkInterface::reservedMarkersCount() )
1296  {
1297  static TQColor dummy;
1298  return dummy;
1299  }
1300 
1301  if (m_lineMarkerColorSet[index] || isGlobal())
1302  return m_lineMarkerColor[index];
1303 
1304  return s_global->lineMarkerColor( type );
1305 }
1306 
1307 void KateRendererConfig::setLineMarkerColor (const TQColor &col, KTextEditor::MarkInterface::MarkTypes type)
1308 {
1309  int index = static_cast<int>( log(static_cast<double>(type)) / log(2.0) );
1310  Q_ASSERT( index >= 0 && index < KTextEditor::MarkInterface::reservedMarkersCount() );
1311  configStart ();
1312 
1313  m_lineMarkerColorSet[index] = true;
1314  m_lineMarkerColor[index] = col;
1315 
1316  configEnd ();
1317 }
1318 
1319 const TQColor& KateRendererConfig::highlightedBracketColor() const
1320 {
1321  if (m_highlightedBracketColorSet || isGlobal())
1322  return m_highlightedBracketColor;
1323 
1324  return s_global->highlightedBracketColor();
1325 }
1326 
1327 void KateRendererConfig::setHighlightedBracketColor (const TQColor &col)
1328 {
1329  configStart ();
1330 
1331  m_highlightedBracketColorSet = true;
1332  m_highlightedBracketColor = col;
1333 
1334  configEnd ();
1335 }
1336 
1337 const TQColor& KateRendererConfig::wordWrapMarkerColor() const
1338 {
1339  if (m_wordWrapMarkerColorSet || isGlobal())
1340  return m_wordWrapMarkerColor;
1341 
1342  return s_global->wordWrapMarkerColor();
1343 }
1344 
1345 void KateRendererConfig::setWordWrapMarkerColor (const TQColor &col)
1346 {
1347  configStart ();
1348 
1349  m_wordWrapMarkerColorSet = true;
1350  m_wordWrapMarkerColor = col;
1351 
1352  configEnd ();
1353 }
1354 
1355 const TQColor& KateRendererConfig::tabMarkerColor() const
1356 {
1357  if (m_tabMarkerColorSet || isGlobal())
1358  return m_tabMarkerColor;
1359 
1360  return s_global->tabMarkerColor();
1361 }
1362 
1363 void KateRendererConfig::setTabMarkerColor (const TQColor &col)
1364 {
1365  configStart ();
1366 
1367  m_tabMarkerColorSet = true;
1368  m_tabMarkerColor = col;
1369 
1370  configEnd ();
1371 }
1372 
1373 const TQColor& KateRendererConfig::iconBarColor() const
1374 {
1375  if (m_iconBarColorSet || isGlobal())
1376  return m_iconBarColor;
1377 
1378  return s_global->iconBarColor();
1379 }
1380 
1381 void KateRendererConfig::setIconBarColor (const TQColor &col)
1382 {
1383  configStart ();
1384 
1385  m_iconBarColorSet = true;
1386  m_iconBarColor = col;
1387 
1388  configEnd ();
1389 }
1390 
1391 const TQColor& KateRendererConfig::lineNumberColor() const
1392 {
1393  if (m_lineNumberColorSet || isGlobal())
1394  return m_lineNumberColor;
1395 
1396  return s_global->lineNumberColor();
1397 }
1398 
1399 void KateRendererConfig::setLineNumberColor (const TQColor &col)
1400 {
1401  configStart ();
1402 
1403  m_lineNumberColorSet = true;
1404  m_lineNumberColor = col;
1405 
1406  configEnd ();
1407 }
1408 
1409 bool KateRendererConfig::showIndentationLines () const
1410 {
1411  if (m_showIndentationLinesSet || isGlobal())
1412  return m_showIndentationLines;
1413 
1414  return s_global->showIndentationLines();
1415 }
1416 
1417 void KateRendererConfig::setShowIndentationLines (bool on)
1418 {
1419  configStart ();
1420 
1421  m_showIndentationLinesSet = true;
1422  m_showIndentationLines = on;
1423 
1424  configEnd ();
1425 }
1426 
1427 //END
TDEConfig
KateConfig::updateConfig
virtual void updateConfig()=0
do the real update
TDEGlobalSettings::baseColor
static TQColor baseColor()
KateConfig::configEnd
void configEnd()
end a config change transaction, update the concerned documents/views/renderers
Definition: kateconfig.cpp:65
TDEGlobalSettings::highlightColor
static TQColor highlightColor()
KateConfig::configStart
void configStart()
start some config changes this method is needed to init some kind of transaction for config changes...
Definition: kateconfig.cpp:55
KateRenderer
Handles all of the work of rendering the text (used for the views and printing)
Definition: katerenderer.h:42
tdelocale.h
KateConfig::KateConfig
KateConfig()
Default Constructor.
Definition: kateconfig.cpp:46
TDEGlobal::charsets
static KCharsets * charsets()
TDEGlobalSettings::textColor
static TQColor textColor()
KTextEditor
Definition: katebookmarks.h:28
TDEGlobal::locale
static TDELocale * locale()
KCharsets::codecForName
TQTextCodec * codecForName(const TQString &name) const
TDEGlobalSettings::fixedFont
static TQFont fixedFont()
KateConfig::~KateConfig
virtual ~KateConfig()
Virtual Destructor.
Definition: kateconfig.cpp:51
TDEStdAccel::name
TQString name(StdAccel id)
TDEGlobalSettings::alternateBackgroundColor
static TQColor alternateBackgroundColor()

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.8.8
This website is maintained by Timothy Pearson.