TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kateconfig.cpp 31KB

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