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.

katedialogs.cpp 61KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
  3. Copyright (C) 2003 Christoph Cullmann <cullmann@kde.org>
  4. Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
  5. Based on work of:
  6. Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public
  9. License version 2 as published by the Free Software Foundation.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public License
  15. along with this library; see the file COPYING.LIB. If not, write to
  16. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. Boston, MA 02110-1301, USA.
  18. */
  19. //BEGIN Includes
  20. #include "katedialogs.h"
  21. #include "katedialogs.moc"
  22. #include "kateautoindent.h"
  23. #include "katebuffer.h"
  24. #include "kateconfig.h"
  25. #include "katedocument.h"
  26. #include "katefactory.h"
  27. #include "kateschema.h"
  28. #include "katesyntaxdocument.h"
  29. #include "kateview.h"
  30. #include <tdetexteditor/configinterfaceextension.h>
  31. #include <tdetexteditor/plugin.h>
  32. #include <tdeio/job.h>
  33. #include <tdeio/jobclasses.h>
  34. #include <tdeio/netaccess.h>
  35. #include <tdeaccel.h>
  36. #include <tdeapplication.h>
  37. #include <kbuttonbox.h>
  38. #include <kcharsets.h>
  39. #include <kcolorbutton.h>
  40. #include <kcolorcombo.h>
  41. #include <kcolordialog.h>
  42. #include <kcombobox.h>
  43. #include <tdeconfig.h>
  44. #include <kdebug.h>
  45. #include <tdefontdialog.h>
  46. #include <tdeglobal.h>
  47. #include <tdeglobalsettings.h>
  48. #include <kiconloader.h>
  49. #include <kkeybutton.h>
  50. #include <kkeydialog.h>
  51. #include <klineedit.h>
  52. #include <tdelistview.h>
  53. #include <tdelocale.h>
  54. #include <tdemessagebox.h>
  55. #include <kmimetypechooser.h>
  56. #include <knuminput.h>
  57. #include <tdeparts/componentfactory.h>
  58. #include <tdepopupmenu.h>
  59. #include <kprocess.h>
  60. #include <kprocio.h>
  61. #include <kregexpeditorinterface.h>
  62. #include <krun.h>
  63. #include <kseparator.h>
  64. #include <kstandarddirs.h>
  65. #include <tdetempfile.h>
  66. #include <tqbuttongroup.h>
  67. #include <tqcheckbox.h>
  68. #include <tqcombobox.h>
  69. #include <tqdialog.h>
  70. #include <tqdom.h>
  71. #include <tqfile.h>
  72. #include <tqgrid.h>
  73. #include <tqgroupbox.h>
  74. #include <tqhbox.h>
  75. #include <tqheader.h>
  76. #include <tqhgroupbox.h>
  77. #include <tqlabel.h>
  78. #include <tqlayout.h>
  79. #include <tqlineedit.h>
  80. #include <tqlistbox.h>
  81. #include <tqlistview.h>
  82. #include <tqmap.h>
  83. #include <tqobjectlist.h>
  84. #include <tqpainter.h>
  85. #include <tqpointarray.h>
  86. #include <tqptrcollection.h>
  87. #include <tqpushbutton.h>
  88. #include <tqradiobutton.h>
  89. #include <tqslider.h>
  90. #include <tqspinbox.h>
  91. #include <tqstringlist.h>
  92. #include <tqtabwidget.h>
  93. #include <tqtextcodec.h>
  94. #include <tqtoolbutton.h>
  95. #include <tqvbox.h>
  96. #include <tqvgroupbox.h>
  97. #include <tqwhatsthis.h>
  98. #include <tqwidgetstack.h>
  99. // trailing slash is important
  100. #define HLDOWNLOADPATH "http://kate.kde.org/syntax/"
  101. //END
  102. //BEGIN KateConfigPage
  103. KateConfigPage::KateConfigPage ( TQWidget *parent, const char *name )
  104. : Kate::ConfigPage (parent, name)
  105. , m_changed (false)
  106. {
  107. connect (this, TQT_SIGNAL(changed()), this, TQT_SLOT(somethingHasChanged ()));
  108. }
  109. KateConfigPage::~KateConfigPage ()
  110. {
  111. }
  112. void KateConfigPage::somethingHasChanged ()
  113. {
  114. m_changed = true;
  115. kdDebug (13000) << "TEST: something changed on the config page: " << this << endl;
  116. }
  117. //END KateConfigPage
  118. //BEGIN KateIndentConfigTab
  119. const int KateIndentConfigTab::flags[] = {
  120. KateDocument::cfSpaceIndent,
  121. KateDocument::cfKeepIndentProfile,
  122. KateDocument::cfKeepExtraSpaces,
  123. KateDocument::cfTabIndents,
  124. KateDocument::cfBackspaceIndents,
  125. KateDocumentConfig::cfDoxygenAutoTyping,
  126. KateDocumentConfig::cfMixedIndent,
  127. KateDocumentConfig::cfIndentPastedText
  128. };
  129. KateIndentConfigTab::KateIndentConfigTab(TQWidget *parent)
  130. : KateConfigPage(parent)
  131. {
  132. TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
  133. int configFlags = KateDocumentConfig::global()->configFlags();
  134. TQVGroupBox *gbAuto = new TQVGroupBox(i18n("Automatic Indentation"), this);
  135. TQHBox *indentLayout = new TQHBox(gbAuto);
  136. indentLayout->setSpacing(KDialog::spacingHint());
  137. TQLabel *indentLabel = new TQLabel(i18n("&Indentation mode:"), indentLayout);
  138. m_indentMode = new KComboBox (indentLayout);
  139. m_indentMode->insertStringList (KateAutoIndent::listModes());
  140. indentLabel->setBuddy(m_indentMode);
  141. m_configPage = new TQPushButton(SmallIconSet("configure"), i18n("Configure..."), indentLayout);
  142. opt[5] = new TQCheckBox(i18n("Insert leading Doxygen \"*\" when typing"), gbAuto);
  143. opt[7] = new TQCheckBox(i18n("Adjust indentation of code pasted from the clipboard"), gbAuto);
  144. TQVGroupBox *gbSpaces = new TQVGroupBox(i18n("Indentation with Spaces"), this);
  145. TQVBox *spaceLayout = new TQVBox(gbSpaces);
  146. opt[0] = new TQCheckBox(i18n("Use &spaces instead of tabs to indent"), spaceLayout );
  147. opt[6] = new TQCheckBox(i18n("Emacs style mixed mode"), spaceLayout);
  148. indentationWidth = new KIntNumInput(KateDocumentConfig::global()->indentationWidth(), spaceLayout);
  149. indentationWidth->setRange(1, 16, 1, false);
  150. indentationWidth->setLabel(i18n("Number of spaces:"), AlignVCenter);
  151. opt[1] = new TQCheckBox(i18n("Keep indent &profile"), this);
  152. opt[2] = new TQCheckBox(i18n("&Keep extra spaces"), this);
  153. TQVGroupBox *keys = new TQVGroupBox(i18n("Keys to Use"), this);
  154. opt[3] = new TQCheckBox(i18n("&Tab key indents"), keys);
  155. opt[4] = new TQCheckBox(i18n("&Backspace key indents"), keys);
  156. TQRadioButton *rb1, *rb2, *rb3;
  157. m_tabs = new TQButtonGroup( 1, Qt::Horizontal, i18n("Tab Key Mode if Nothing Selected"), this );
  158. m_tabs->setRadioButtonExclusive( true );
  159. m_tabs->insert( rb1=new TQRadioButton( i18n("Insert indent &characters"), m_tabs ), 0 );
  160. m_tabs->insert( rb2=new TQRadioButton( i18n("I&nsert tab character"), m_tabs ), 1 );
  161. m_tabs->insert( rb3=new TQRadioButton( i18n("Indent current &line"), m_tabs ), 2 );
  162. opt[0]->setChecked(configFlags & flags[0]);
  163. opt[1]->setChecked(configFlags & flags[1]);
  164. opt[2]->setChecked(configFlags & flags[2]);
  165. opt[3]->setChecked(configFlags & flags[3]);
  166. opt[4]->setChecked(configFlags & flags[4]);
  167. opt[5]->setChecked(configFlags & flags[5]);
  168. opt[6]->setChecked(configFlags & flags[6]);
  169. opt[7]->setChecked(configFlags & flags[7]);
  170. layout->addWidget(gbAuto);
  171. layout->addWidget(gbSpaces);
  172. layout->addWidget(opt[1]);
  173. layout->addWidget(opt[2]);
  174. layout->addWidget(keys);
  175. layout->addWidget(m_tabs, 0);
  176. layout->addStretch();
  177. // What is this? help
  178. TQWhatsThis::add(opt[0], i18n(
  179. "Check this if you want to indent with spaces rather than tabs."));
  180. TQWhatsThis::add(opt[2], i18n(
  181. "Indentations of more than the selected number of spaces will not be "
  182. "shortened."));
  183. TQWhatsThis::add(opt[3], i18n(
  184. "This allows the <b>Tab</b> key to be used to increase the indentation "
  185. "level."));
  186. TQWhatsThis::add(opt[4], i18n(
  187. "This allows the <b>Backspace</b> key to be used to decrease the "
  188. "indentation level."));
  189. TQWhatsThis::add(opt[5], i18n(
  190. "Automatically inserts a leading \"*\" while typing within a Doxygen "
  191. "style comment."));
  192. TQWhatsThis::add( opt[6], i18n(
  193. "Use a mix of tab and space characters for indentation.") );
  194. TQWhatsThis::add( opt[7], i18n(
  195. "If this option is selected, pasted code from the clipboard is indented. "
  196. "Triggering the <b>undo</b>-action removes the indentation.") );
  197. TQWhatsThis::add(indentationWidth, i18n("The number of spaces to indent with."));
  198. TQWhatsThis::add(m_configPage, i18n(
  199. "If this button is enabled, additional indenter specific options are "
  200. "available and can be configured in an extra dialog.") );
  201. reload ();
  202. //
  203. // after initial reload, connect the stuff for the changed () signal
  204. //
  205. connect(m_indentMode, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotChanged()));
  206. connect(m_indentMode, TQT_SIGNAL(activated(int)), this, TQT_SLOT(indenterSelected(int)));
  207. connect( opt[0], TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(somethingToggled()));
  208. connect( opt[0], TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  209. connect( opt[1], TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  210. connect( opt[2], TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  211. connect( opt[3], TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  212. connect( opt[4], TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  213. connect( opt[5], TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  214. connect( opt[6], TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  215. connect( opt[7], TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  216. connect(indentationWidth, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged()));
  217. connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  218. connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  219. connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  220. connect(m_configPage, TQT_SIGNAL(clicked()), this, TQT_SLOT(configPage()));
  221. }
  222. void KateIndentConfigTab::somethingToggled() {
  223. indentationWidth->setEnabled(opt[0]->isChecked());
  224. opt[6]->setEnabled(opt[0]->isChecked());
  225. }
  226. void KateIndentConfigTab::indenterSelected (int index)
  227. {
  228. if (index == KateDocumentConfig::imCStyle || index == KateDocumentConfig::imCSAndS)
  229. opt[5]->setEnabled(true);
  230. else
  231. opt[5]->setEnabled(false);
  232. m_configPage->setEnabled( KateAutoIndent::hasConfigPage(index) );
  233. }
  234. void KateIndentConfigTab::configPage()
  235. {
  236. uint index = m_indentMode->currentItem();
  237. if ( KateAutoIndent::hasConfigPage(index) )
  238. {
  239. KDialogBase dlg(this, "indenter_config_dialog", true, i18n("Configure Indenter"),
  240. KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Cancel, true);
  241. TQVBox *box = new TQVBox(&dlg);
  242. box->setSpacing( KDialog::spacingHint() );
  243. dlg.setMainWidget(box);
  244. new TQLabel("<qt><b>" + KateAutoIndent::modeDescription(index) + "</b></qt>", box);
  245. new KSeparator(KSeparator::HLine, box);
  246. IndenterConfigPage* page = KateAutoIndent::configPage(box, index);
  247. if (!page) return;
  248. box->setStretchFactor(page, 1);
  249. connect( &dlg, TQT_SIGNAL(okClicked()), page, TQT_SLOT(apply()) );
  250. dlg.resize(400, 300);
  251. dlg.exec();
  252. }
  253. }
  254. void KateIndentConfigTab::apply ()
  255. {
  256. // nothing changed, no need to apply stuff
  257. if (!changed())
  258. return;
  259. m_changed = false;
  260. KateDocumentConfig::global()->configStart ();
  261. int configFlags, z;
  262. configFlags = KateDocumentConfig::global()->configFlags();
  263. for (z = 0; z < numFlags; z++) {
  264. configFlags &= ~flags[z];
  265. if (opt[z]->isChecked()) configFlags |= flags[z];
  266. }
  267. KateDocumentConfig::global()->setConfigFlags(configFlags);
  268. KateDocumentConfig::global()->setIndentationWidth(indentationWidth->value());
  269. KateDocumentConfig::global()->setIndentationMode(m_indentMode->currentItem());
  270. KateDocumentConfig::global()->setConfigFlags (KateDocumentConfig::cfTabIndentsMode, 2 == m_tabs->id (m_tabs->selected()));
  271. KateDocumentConfig::global()->setConfigFlags (KateDocumentConfig::cfTabInsertsTab, 1 == m_tabs->id (m_tabs->selected()));
  272. KateDocumentConfig::global()->configEnd ();
  273. }
  274. void KateIndentConfigTab::reload ()
  275. {
  276. if (KateDocumentConfig::global()->configFlags() & KateDocumentConfig::cfTabIndentsMode)
  277. m_tabs->setButton (2);
  278. else if (KateDocumentConfig::global()->configFlags() & KateDocumentConfig::cfTabInsertsTab)
  279. m_tabs->setButton (1);
  280. else
  281. m_tabs->setButton (0);
  282. m_indentMode->setCurrentItem (KateDocumentConfig::global()->indentationMode());
  283. somethingToggled ();
  284. indenterSelected (m_indentMode->currentItem());
  285. }
  286. //END KateIndentConfigTab
  287. //BEGIN KateSelectConfigTab
  288. const int KateSelectConfigTab::flags[] = {};
  289. KateSelectConfigTab::KateSelectConfigTab(TQWidget *parent)
  290. : KateConfigPage(parent)
  291. {
  292. int configFlags = KateDocumentConfig::global()->configFlags();
  293. TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
  294. TQVGroupBox *gbCursor = new TQVGroupBox(i18n("Text Cursor Movement"), this);
  295. opt[0] = new TQCheckBox(i18n("Smart ho&me and smart end"), gbCursor);
  296. opt[0]->setChecked(configFlags & KateDocumentConfig::cfSmartHome);
  297. connect(opt[0], TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  298. opt[1] = new TQCheckBox(i18n("Wrap c&ursor"), gbCursor);
  299. opt[1]->setChecked(configFlags & KateDocumentConfig::cfWrapCursor);
  300. connect(opt[1], TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  301. e6 = new TQCheckBox(i18n("&PageUp/PageDown moves cursor"), gbCursor);
  302. e6->setChecked(KateDocumentConfig::global()->pageUpDownMovesCursor());
  303. connect(e6, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  304. e4 = new KIntNumInput(KateViewConfig::global()->autoCenterLines(), gbCursor);
  305. e4->setRange(0, 1000000, 1, false);
  306. e4->setLabel(i18n("Autocenter cursor (lines):"), AlignVCenter);
  307. connect(e4, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged()));
  308. layout->addWidget(gbCursor);
  309. TQRadioButton *rb1, *rb2;
  310. m_tabs = new TQButtonGroup( 1, Qt::Horizontal, i18n("Selection Mode"), this );
  311. layout->add (m_tabs);
  312. m_tabs->setRadioButtonExclusive( true );
  313. m_tabs->insert( rb1=new TQRadioButton( i18n("&Normal"), m_tabs ), 0 );
  314. m_tabs->insert( rb2=new TQRadioButton( i18n("&Persistent"), m_tabs ), 1 );
  315. layout->addStretch();
  316. TQWhatsThis::add(rb1, i18n(
  317. "Selections will be overwritten by typed text and will be lost on "
  318. "cursor movement."));
  319. TQWhatsThis::add(rb2, i18n(
  320. "Selections will stay even after cursor movement and typing."));
  321. TQWhatsThis::add(e4, i18n(
  322. "Sets the number of lines to maintain visible above and below the "
  323. "cursor when possible."));
  324. TQWhatsThis::add(opt[0], i18n(
  325. "When selected, pressing the home key will cause the cursor to skip "
  326. "whitespace and go to the start of a line's text. "
  327. "The same applies for the end key."));
  328. TQWhatsThis::add(opt[1], i18n(
  329. "When on, moving the insertion cursor using the <b>Left</b> and "
  330. "<b>Right</b> keys will go on to previous/next line at beginning/end of "
  331. "the line, similar to most editors.<p>When off, the insertion cursor "
  332. "cannot be moved left of the line start, but it can be moved off the "
  333. "line end, which can be very handy for programmers."));
  334. TQWhatsThis::add(e6, i18n("Selects whether the PageUp and PageDown keys should alter the vertical position of the cursor relative to the top of the view."));
  335. reload ();
  336. //
  337. // after initial reload, connect the stuff for the changed () signal
  338. //
  339. connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  340. connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  341. }
  342. void KateSelectConfigTab::apply ()
  343. {
  344. // nothing changed, no need to apply stuff
  345. if (!changed())
  346. return;
  347. m_changed = false;
  348. KateViewConfig::global()->configStart ();
  349. KateDocumentConfig::global()->configStart ();
  350. int configFlags = KateDocumentConfig::global()->configFlags();
  351. configFlags &= ~KateDocumentConfig::cfSmartHome;
  352. configFlags &= ~KateDocumentConfig::cfWrapCursor;
  353. if (opt[0]->isChecked()) configFlags |= KateDocumentConfig::cfSmartHome;
  354. if (opt[1]->isChecked()) configFlags |= KateDocumentConfig::cfWrapCursor;
  355. KateDocumentConfig::global()->setConfigFlags(configFlags);
  356. KateViewConfig::global()->setAutoCenterLines(kMax(0, e4->value()));
  357. KateDocumentConfig::global()->setPageUpDownMovesCursor(e6->isChecked());
  358. KateViewConfig::global()->setPersistentSelection (m_tabs->id (m_tabs->selected()) == 1);
  359. KateDocumentConfig::global()->configEnd ();
  360. KateViewConfig::global()->configEnd ();
  361. }
  362. void KateSelectConfigTab::reload ()
  363. {
  364. if (KateViewConfig::global()->persistentSelection())
  365. m_tabs->setButton (1);
  366. else
  367. m_tabs->setButton (0);
  368. }
  369. //END KateSelectConfigTab
  370. //BEGIN KateEditConfigTab
  371. const int KateEditConfigTab::flags[] = {KateDocument::cfWordWrap,
  372. KateDocument::cfAutoBrackets, KateDocument::cfShowTabs,
  373. KateDocumentConfig::cfReplaceTabsDyn, KateDocumentConfig::cfRemoveTrailingDyn};
  374. KateEditConfigTab::KateEditConfigTab(TQWidget *parent)
  375. : KateConfigPage(parent)
  376. {
  377. TQVBoxLayout *mainLayout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
  378. int configFlags = KateDocumentConfig::global()->configFlags();
  379. TQVGroupBox *gbWhiteSpace = new TQVGroupBox(i18n("Tabulators"), this);
  380. opt[3] = new TQCheckBox( i18n("&Insert spaces instead of tabulators"), gbWhiteSpace );
  381. opt[3]->setChecked( configFlags & KateDocumentConfig::cfReplaceTabsDyn );
  382. connect( opt[3], TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()) );
  383. opt[2] = new TQCheckBox(i18n("&Show tabulators"), gbWhiteSpace);
  384. opt[2]->setChecked(configFlags & flags[2]);
  385. connect(opt[2], TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  386. e2 = new KIntNumInput(KateDocumentConfig::global()->tabWidth(), gbWhiteSpace);
  387. e2->setRange(1, 16, 1, false);
  388. e2->setLabel(i18n("Tab width:"), AlignVCenter);
  389. connect(e2, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged()));
  390. mainLayout->addWidget(gbWhiteSpace);
  391. TQVGroupBox *gbWordWrap = new TQVGroupBox(i18n("Static Word Wrap"), this);
  392. opt[0] = new TQCheckBox(i18n("Enable static &word wrap"), gbWordWrap);
  393. opt[0]->setChecked(KateDocumentConfig::global()->wordWrap());
  394. connect(opt[0], TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  395. m_wwmarker = new TQCheckBox( i18n("&Show static word wrap marker (if applicable)"), gbWordWrap );
  396. m_wwmarker->setChecked( KateRendererConfig::global()->wordWrapMarker() );
  397. connect(m_wwmarker, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  398. e1 = new KIntNumInput(KateDocumentConfig::global()->wordWrapAt(), gbWordWrap);
  399. e1->setRange(20, 200, 1, false);
  400. e1->setLabel(i18n("Wrap words at:"), AlignVCenter);
  401. connect(e1, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged()));
  402. mainLayout->addWidget(gbWordWrap);
  403. opt[4] = new TQCheckBox( i18n("Remove &trailing spaces"), this );
  404. mainLayout->addWidget( opt[4] );
  405. opt[4]->setChecked( configFlags & KateDocumentConfig::cfRemoveTrailingDyn );
  406. connect( opt[4], TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()) );
  407. opt[1] = new TQCheckBox(i18n("Auto &brackets"), this);
  408. mainLayout->addWidget(opt[1]);
  409. opt[1]->setChecked(configFlags & flags[1]);
  410. connect(opt[1], TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  411. e3 = new KIntNumInput(e2, KateDocumentConfig::global()->undoSteps(), this);
  412. e3->setRange(0, 1000000, 1, false);
  413. e3->setSpecialValueText( i18n("Unlimited") );
  414. e3->setLabel(i18n("Maximum undo steps:"), AlignVCenter);
  415. mainLayout->addWidget(e3);
  416. connect(e3, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged()));
  417. TQHBoxLayout *e5Layout = new TQHBoxLayout(mainLayout);
  418. TQLabel *e5Label = new TQLabel(i18n("Smart search t&ext from:"), this);
  419. e5Layout->addWidget(e5Label);
  420. e5 = new KComboBox (this);
  421. e5->insertItem( i18n("Nowhere") );
  422. e5->insertItem( i18n("Selection Only") );
  423. e5->insertItem( i18n("Selection, then Current Word") );
  424. e5->insertItem( i18n("Current Word Only") );
  425. e5->insertItem( i18n("Current Word, then Selection") );
  426. e5->setCurrentItem(KateViewConfig::global()->textToSearchMode());
  427. e5Layout->addWidget(e5);
  428. e5Label->setBuddy(e5);
  429. connect(e5, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotChanged()));
  430. mainLayout->addStretch();
  431. // What is this? help
  432. TQWhatsThis::add(opt[0], i18n(
  433. "Automatically start a new line of text when the current line exceeds "
  434. "the length specified by the <b>Wrap words at:</b> option."
  435. "<p>This option does not wrap existing lines of text - use the <b>Apply "
  436. "Static Word Wrap</b> option in the <b>Tools</b> menu for that purpose."
  437. "<p>If you want lines to be <i>visually wrapped</i> instead, according "
  438. "to the width of the view, enable <b>Dynamic Word Wrap</b> in the "
  439. "<b>View Defaults</b> config page."));
  440. TQWhatsThis::add(e1, i18n(
  441. "If the Word Wrap option is selected this entry determines the length "
  442. "(in characters) at which the editor will automatically start a new line."));
  443. TQWhatsThis::add(opt[1], i18n(
  444. "When the user types a left bracket ([,(, or {) KateView automatically "
  445. "enters the right bracket (}, ), or ]) to the right of the cursor."));
  446. TQWhatsThis::add(opt[2], i18n(
  447. "The editor will display a symbol to indicate the presence of a tab in "
  448. "the text."));
  449. TQWhatsThis::add(e3, i18n(
  450. "Sets the number of undo/redo steps to record. More steps uses more memory."));
  451. TQString gstfwt = i18n(
  452. "This determines where KateView will get the search text from "
  453. "(this will be automatically entered into the Find Text dialog): "
  454. "<br>"
  455. "<ul>"
  456. "<li><b>Nowhere:</b> Don't guess the search text."
  457. "</li>"
  458. "<li><b>Selection Only:</b> Use the current text selection, "
  459. "if available."
  460. "</li>"
  461. "<li><b>Selection, then Current Word:</b> Use the current "
  462. "selection if available, otherwise use the current word."
  463. "</li>"
  464. "<li><b>Current Word Only:</b> Use the word that the cursor "
  465. "is currently resting on, if available."
  466. "</li>"
  467. "<li><b>Current Word, then Selection:</b> Use the current "
  468. "word if available, otherwise use the current selection."
  469. "</li>"
  470. "</ul>"
  471. "Note that, in all the above modes, if a search string has "
  472. "not been or cannot be determined, then the Find Text Dialog "
  473. "will fall back to the last search text.");
  474. TQWhatsThis::add(e5Label, gstfwt);
  475. TQWhatsThis::add(e5, gstfwt);
  476. TQWhatsThis::add( opt[3], i18n(
  477. "If this is enabled, the editor will calculate the number of spaces up to "
  478. "the next tab position as defined by the tab width, and insert that number "
  479. "of spaces instead of a TAB character." ) );
  480. TQWhatsThis::add( opt[4], i18n(
  481. "If this is enabled, the editor will remove any trailing whitespace on "
  482. "lines when they are left by the insertion cursor.") );
  483. TQWhatsThis::add( m_wwmarker, i18n(
  484. "<p>If this option is checked, a vertical line will be drawn at the word "
  485. "wrap column as defined in the <strong>Editing</strong> properties."
  486. "<p>Note that the word wrap marker is only drawn if you use a fixed "
  487. "pitch font." ));
  488. }
  489. void KateEditConfigTab::apply ()
  490. {
  491. // nothing changed, no need to apply stuff
  492. if (!changed())
  493. return;
  494. m_changed = false;
  495. KateViewConfig::global()->configStart ();
  496. KateDocumentConfig::global()->configStart ();
  497. int configFlags, z;
  498. configFlags = KateDocumentConfig::global()->configFlags();
  499. for (z = 1; z < numFlags; z++) {
  500. configFlags &= ~flags[z];
  501. if (opt[z]->isChecked()) configFlags |= flags[z];
  502. }
  503. KateDocumentConfig::global()->setConfigFlags(configFlags);
  504. KateDocumentConfig::global()->setWordWrapAt(e1->value());
  505. KateDocumentConfig::global()->setWordWrap (opt[0]->isChecked());
  506. KateDocumentConfig::global()->setTabWidth(e2->value());
  507. if (e3->value() <= 0)
  508. KateDocumentConfig::global()->setUndoSteps(0);
  509. else
  510. KateDocumentConfig::global()->setUndoSteps(e3->value());
  511. KateViewConfig::global()->setTextToSearchMode(e5->currentItem());
  512. KateRendererConfig::global()->setWordWrapMarker (m_wwmarker->isChecked());
  513. KateDocumentConfig::global()->configEnd ();
  514. KateViewConfig::global()->configEnd ();
  515. }
  516. void KateEditConfigTab::reload ()
  517. {
  518. }
  519. //END KateEditConfigTab
  520. //BEGIN KateViewDefaultsConfig
  521. KateViewDefaultsConfig::KateViewDefaultsConfig(TQWidget *parent)
  522. :KateConfigPage(parent)
  523. {
  524. TQRadioButton *rb1;
  525. TQRadioButton *rb2;
  526. TQVBoxLayout *blay=new TQVBoxLayout(this,0,KDialog::spacingHint());
  527. TQVGroupBox *gbWordWrap = new TQVGroupBox(i18n("Word Wrap"), this);
  528. m_dynwrap=new TQCheckBox(i18n("&Dynamic word wrap"),gbWordWrap);
  529. TQHBox *m_dynwrapIndicatorsLay = new TQHBox (gbWordWrap);
  530. m_dynwrapIndicatorsLabel = new TQLabel( i18n("Dynamic word wrap indicators (if applicable):"), m_dynwrapIndicatorsLay );
  531. m_dynwrapIndicatorsCombo = new KComboBox( m_dynwrapIndicatorsLay );
  532. m_dynwrapIndicatorsCombo->insertItem( i18n("Off") );
  533. m_dynwrapIndicatorsCombo->insertItem( i18n("Follow Line Numbers") );
  534. m_dynwrapIndicatorsCombo->insertItem( i18n("Always On") );
  535. m_dynwrapIndicatorsLabel->setBuddy(m_dynwrapIndicatorsCombo);
  536. m_dynwrapAlignLevel = new KIntNumInput(gbWordWrap);
  537. m_dynwrapAlignLevel->setLabel(i18n("Vertically align dynamically wrapped lines to indentation depth:"));
  538. m_dynwrapAlignLevel->setRange(0, 80, 10);
  539. // xgettext:no-c-format
  540. m_dynwrapAlignLevel->setSuffix(i18n("% of View Width"));
  541. m_dynwrapAlignLevel->setSpecialValueText(i18n("Disabled"));
  542. blay->addWidget(gbWordWrap);
  543. TQVGroupBox *gbFold = new TQVGroupBox(i18n("Code Folding"), this);
  544. m_folding=new TQCheckBox(i18n("Show &folding markers (if available)"), gbFold );
  545. m_collapseTopLevel = new TQCheckBox( i18n("Collapse toplevel folding nodes"), gbFold );
  546. m_collapseTopLevel->hide ();
  547. blay->addWidget(gbFold);
  548. TQVGroupBox *gbBar = new TQVGroupBox(i18n("Borders"), this);
  549. m_icons=new TQCheckBox(i18n("Show &icon border"),gbBar);
  550. m_line=new TQCheckBox(i18n("Show &line numbers"),gbBar);
  551. m_scrollBarMarks=new TQCheckBox(i18n("Show &scrollbar marks"),gbBar);
  552. blay->addWidget(gbBar);
  553. m_bmSort = new TQButtonGroup( 1, Qt::Horizontal, i18n("Sort Bookmarks Menu"), this );
  554. m_bmSort->setRadioButtonExclusive( true );
  555. m_bmSort->insert( rb1=new TQRadioButton( i18n("By &position"), m_bmSort ), 0 );
  556. m_bmSort->insert( rb2=new TQRadioButton( i18n("By c&reation"), m_bmSort ), 1 );
  557. blay->addWidget(m_bmSort, 0 );
  558. m_showIndentLines = new TQCheckBox(i18n("Show indentation lines"), this);
  559. m_showIndentLines->setChecked(KateRendererConfig::global()->showIndentationLines());
  560. blay->addWidget(m_showIndentLines);
  561. blay->addStretch(1000);
  562. TQWhatsThis::add(m_dynwrap,i18n(
  563. "If this option is checked, the text lines will be wrapped at the view "
  564. "border on the screen."));
  565. TQString wtstr = i18n("Choose when the Dynamic Word Wrap Indicators should be displayed");
  566. TQWhatsThis::add(m_dynwrapIndicatorsLabel, wtstr);
  567. TQWhatsThis::add(m_dynwrapIndicatorsCombo, wtstr);
  568. // xgettext:no-c-format
  569. TQWhatsThis::add(m_dynwrapAlignLevel, i18n(
  570. "<p>Enables the start of dynamically wrapped lines to be aligned "
  571. "vertically to the indentation level of the first line. This can help "
  572. "to make code and markup more readable.</p><p>Additionally, this allows "
  573. "you to set a maximum width of the screen, as a percentage, after which "
  574. "dynamically wrapped lines will no longer be vertically aligned. For "
  575. "example, at 50%, lines whose indentation levels are deeper than 50% of "
  576. "the width of the screen will not have vertical alignment applied to "
  577. "subsequent wrapped lines.</p>"));
  578. TQWhatsThis::add(m_line,i18n(
  579. "If this option is checked, every new view will display line numbers "
  580. "on the left hand side."));
  581. TQWhatsThis::add(m_icons,i18n(
  582. "If this option is checked, every new view will display an icon border "
  583. "on the left hand side.<br><br>The icon border shows bookmark signs, "
  584. "for instance."));
  585. TQWhatsThis::add(m_scrollBarMarks,i18n(
  586. "If this option is checked, every new view will show marks on the "
  587. "vertical scrollbar.<br><br>These marks will, for instance, show "
  588. "bookmarks."));
  589. TQWhatsThis::add(m_folding,i18n(
  590. "If this option is checked, every new view will display marks for code "
  591. "folding, if code folding is available."));
  592. TQWhatsThis::add(m_bmSort,i18n(
  593. "Choose how the bookmarks should be ordered in the <b>Bookmarks</b> menu."));
  594. TQWhatsThis::add(rb1,i18n(
  595. "The bookmarks will be ordered by the line numbers they are placed at."));
  596. TQWhatsThis::add(rb2,i18n(
  597. "Each new bookmark will be added to the bottom, independently from "
  598. "where it is placed in the document."));
  599. TQWhatsThis::add(m_showIndentLines, i18n(
  600. "If this is enabled, the editor will display vertical lines to help "
  601. "identify indent lines.") );
  602. reload();
  603. //
  604. // after initial reload, connect the stuff for the changed () signal
  605. //
  606. connect(m_dynwrap, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  607. connect(m_dynwrapIndicatorsCombo, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotChanged()));
  608. connect(m_dynwrapAlignLevel, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged()));
  609. connect(m_icons, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  610. connect(m_scrollBarMarks, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  611. connect(m_line, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  612. connect(m_folding, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  613. connect(m_collapseTopLevel, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()) );
  614. connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  615. connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  616. connect(m_showIndentLines, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  617. }
  618. KateViewDefaultsConfig::~KateViewDefaultsConfig()
  619. {
  620. }
  621. void KateViewDefaultsConfig::apply ()
  622. {
  623. // nothing changed, no need to apply stuff
  624. if (!changed())
  625. return;
  626. m_changed = false;
  627. KateViewConfig::global()->configStart ();
  628. KateRendererConfig::global()->configStart ();
  629. KateViewConfig::global()->setDynWordWrap (m_dynwrap->isChecked());
  630. KateViewConfig::global()->setDynWordWrapIndicators (m_dynwrapIndicatorsCombo->currentItem ());
  631. KateViewConfig::global()->setDynWordWrapAlignIndent(m_dynwrapAlignLevel->value());
  632. KateViewConfig::global()->setLineNumbers (m_line->isChecked());
  633. KateViewConfig::global()->setIconBar (m_icons->isChecked());
  634. KateViewConfig::global()->setScrollBarMarks (m_scrollBarMarks->isChecked());
  635. KateViewConfig::global()->setFoldingBar (m_folding->isChecked());
  636. KateViewConfig::global()->setBookmarkSort (m_bmSort->id (m_bmSort->selected()));
  637. KateRendererConfig::global()->setShowIndentationLines(m_showIndentLines->isChecked());
  638. KateRendererConfig::global()->configEnd ();
  639. KateViewConfig::global()->configEnd ();
  640. }
  641. void KateViewDefaultsConfig::reload ()
  642. {
  643. m_dynwrap->setChecked(KateViewConfig::global()->dynWordWrap());
  644. m_dynwrapIndicatorsCombo->setCurrentItem( KateViewConfig::global()->dynWordWrapIndicators() );
  645. m_dynwrapAlignLevel->setValue(KateViewConfig::global()->dynWordWrapAlignIndent());
  646. m_line->setChecked(KateViewConfig::global()->lineNumbers());
  647. m_icons->setChecked(KateViewConfig::global()->iconBar());
  648. m_scrollBarMarks->setChecked(KateViewConfig::global()->scrollBarMarks());
  649. m_folding->setChecked(KateViewConfig::global()->foldingBar());
  650. m_bmSort->setButton( KateViewConfig::global()->bookmarkSort() );
  651. m_showIndentLines->setChecked(KateRendererConfig::global()->showIndentationLines());
  652. }
  653. void KateViewDefaultsConfig::reset () {;}
  654. void KateViewDefaultsConfig::defaults (){;}
  655. //END KateViewDefaultsConfig
  656. //BEGIN KateEditKeyConfiguration
  657. KateEditKeyConfiguration::KateEditKeyConfiguration( TQWidget* parent, KateDocument* doc )
  658. : KateConfigPage( parent )
  659. {
  660. m_doc = doc;
  661. m_ready = false;
  662. }
  663. void KateEditKeyConfiguration::showEvent ( TQShowEvent * )
  664. {
  665. if (!m_ready)
  666. {
  667. (new TQVBoxLayout(this))->setAutoAdd(true);
  668. KateView* view = (KateView*)m_doc->views().at(0);
  669. m_ac = view->editActionCollection();
  670. m_keyChooser = new KKeyChooser( m_ac, this, false );
  671. connect( m_keyChooser, TQT_SIGNAL( keyChange() ), this, TQT_SLOT( slotChanged() ) );
  672. m_keyChooser->show ();
  673. m_ready = true;
  674. }
  675. TQWidget::show ();
  676. }
  677. void KateEditKeyConfiguration::apply()
  678. {
  679. if ( ! changed() )
  680. return;
  681. m_changed = false;
  682. if (m_ready)
  683. {
  684. m_keyChooser->commitChanges();
  685. m_ac->writeShortcutSettings( "Katepart Shortcuts" );
  686. }
  687. }
  688. //END KateEditKeyConfiguration
  689. //BEGIN KateSaveConfigTab
  690. KateSaveConfigTab::KateSaveConfigTab( TQWidget *parent )
  691. : KateConfigPage( parent )
  692. {
  693. int configFlags = KateDocumentConfig::global()->configFlags();
  694. TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
  695. TQVGroupBox *gbEnc = new TQVGroupBox(i18n("File Format"), this);
  696. layout->addWidget( gbEnc );
  697. TQHBox *e5Layout = new TQHBox(gbEnc);
  698. TQLabel *e5Label = new TQLabel(i18n("&Encoding:"), e5Layout);
  699. m_encoding = new KComboBox (e5Layout);
  700. e5Label->setBuddy(m_encoding);
  701. e5Layout = new TQHBox(gbEnc);
  702. e5Label = new TQLabel(i18n("End &of line:"), e5Layout);
  703. m_eol = new KComboBox (e5Layout);
  704. e5Label->setBuddy(m_eol);
  705. allowEolDetection = new TQCheckBox(i18n("&Automatic end of line detection"), gbEnc);
  706. m_eol->insertItem (i18n("UNIX"));
  707. m_eol->insertItem (i18n("DOS/Windows"));
  708. m_eol->insertItem (i18n("Macintosh"));
  709. TQVGroupBox *gbMem = new TQVGroupBox(i18n("Memory Usage"), this);
  710. layout->addWidget( gbMem );
  711. e5Layout = new TQHBox(gbMem);
  712. e5Layout->setSpacing (32);
  713. blockCountLabel = new TQLabel(i18n("Maximum loaded &blocks per file:"), e5Layout);
  714. blockCount = new TQSpinBox (4, 512, 4, e5Layout);
  715. blockCount->setValue (KateBuffer::maxLoadedBlocks());
  716. blockCountLabel->setBuddy(blockCount);
  717. TQVGroupBox *gbWhiteSpace = new TQVGroupBox(i18n("Automatic Cleanups on Load/Save"), this);
  718. layout->addWidget( gbWhiteSpace );
  719. removeSpaces = new TQCheckBox(i18n("Re&move trailing spaces"), gbWhiteSpace);
  720. removeSpaces->setChecked(configFlags & KateDocument::cfRemoveSpaces);
  721. TQVGroupBox *dirConfigBox = new TQVGroupBox(i18n("Folder Config File"), this);
  722. layout->addWidget( dirConfigBox );
  723. dirSearchDepth = new KIntNumInput(KateDocumentConfig::global()->searchDirConfigDepth(), dirConfigBox);
  724. dirSearchDepth->setRange(-1, 64, 1, false);
  725. dirSearchDepth->setSpecialValueText( i18n("Do not use config file") );
  726. dirSearchDepth->setLabel(i18n("Se&arch depth for config file:"), AlignVCenter);
  727. TQGroupBox *gb = new TQGroupBox( 1, Qt::Horizontal, i18n("Backup on Save"), this );
  728. layout->addWidget( gb );
  729. cbLocalFiles = new TQCheckBox( i18n("&Local files"), gb );
  730. cbRemoteFiles = new TQCheckBox( i18n("&Remote files"), gb );
  731. TQHBox *hbBuPrefix = new TQHBox( gb );
  732. TQLabel *lBuPrefix = new TQLabel( i18n("&Prefix:"), hbBuPrefix );
  733. leBuPrefix = new TQLineEdit( hbBuPrefix );
  734. lBuPrefix->setBuddy( leBuPrefix );
  735. TQHBox *hbBuSuffix = new TQHBox( gb );
  736. TQLabel *lBuSuffix = new TQLabel( i18n("&Suffix:"), hbBuSuffix );
  737. leBuSuffix = new TQLineEdit( hbBuSuffix );
  738. lBuSuffix->setBuddy( leBuSuffix );
  739. layout->addStretch();
  740. TQWhatsThis::add(removeSpaces, i18n(
  741. "The editor will automatically eliminate extra spaces at the ends of "
  742. "lines of text while loading/saving the file."));
  743. TQWhatsThis::add( gb, i18n(
  744. "<p>Backing up on save will cause Kate to copy the disk file to "
  745. "'&lt;prefix&gt;&lt;filename&gt;&lt;suffix&gt;' before saving changes."
  746. "<p>The suffix defaults to <strong>~</strong> and prefix is empty by default" ) );
  747. TQWhatsThis::add( allowEolDetection, i18n(
  748. "Check this if you want the editor to autodetect the end of line type."
  749. "The first found end of line type will be used for the whole file.") );
  750. TQWhatsThis::add( cbLocalFiles, i18n(
  751. "Check this if you want backups of local files when saving") );
  752. TQWhatsThis::add( cbRemoteFiles, i18n(
  753. "Check this if you want backups of remote files when saving") );
  754. TQWhatsThis::add( leBuPrefix, i18n(
  755. "Enter the prefix to prepend to the backup file names" ) );
  756. TQWhatsThis::add( leBuSuffix, i18n(
  757. "Enter the suffix to add to the backup file names" ) );
  758. TQWhatsThis::add(dirSearchDepth, i18n(
  759. "The editor will search the given number of folder levels upwards for .kateconfig file"
  760. " and load the settings line from it." ));
  761. TQWhatsThis::add(blockCount, i18n(
  762. "The editor will load given number of blocks (of around 2048 lines) of text into memory;"
  763. " if the filesize is bigger than this the other blocks are swapped "
  764. " to disk and loaded transparently as-needed.<br>"
  765. " This can cause little delays while navigating in the document; a larger block count"
  766. " increases the editing speed at the cost of memory. <br>For normal usage, just choose the highest possible"
  767. " block count: limit it only if you have problems with the memory usage."));
  768. reload();
  769. //
  770. // after initial reload, connect the stuff for the changed () signal
  771. //
  772. connect(m_encoding, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotChanged()));
  773. connect(m_eol, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotChanged()));
  774. connect( allowEolDetection, TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  775. connect(blockCount, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged()));
  776. connect(removeSpaces, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
  777. connect( cbLocalFiles, TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  778. connect( cbRemoteFiles, TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slotChanged() ) );
  779. connect(dirSearchDepth, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged()));
  780. connect( leBuPrefix, TQT_SIGNAL( textChanged ( const TQString & ) ), this, TQT_SLOT( slotChanged() ) );
  781. connect( leBuSuffix, TQT_SIGNAL( textChanged ( const TQString & ) ), this, TQT_SLOT( slotChanged() ) );
  782. }
  783. void KateSaveConfigTab::apply()
  784. {
  785. // nothing changed, no need to apply stuff
  786. if (!changed())
  787. return;
  788. m_changed = false;
  789. KateBuffer::setMaxLoadedBlocks (blockCount->value());
  790. KateDocumentConfig::global()->configStart ();
  791. if ( leBuSuffix->text().isEmpty() && leBuPrefix->text().isEmpty() ) {
  792. KMessageBox::information(
  793. this,
  794. i18n("You did not provide a backup suffix or prefix. Using default suffix: '~'"),
  795. i18n("No Backup Suffix or Prefix")
  796. );
  797. leBuSuffix->setText( "~" );
  798. }
  799. uint f( 0 );
  800. if ( cbLocalFiles->isChecked() )
  801. f |= KateDocumentConfig::LocalFiles;
  802. if ( cbRemoteFiles->isChecked() )
  803. f |= KateDocumentConfig::RemoteFiles;
  804. KateDocumentConfig::global()->setBackupFlags(f);
  805. KateDocumentConfig::global()->setBackupPrefix(leBuPrefix->text());
  806. KateDocumentConfig::global()->setBackupSuffix(leBuSuffix->text());
  807. KateDocumentConfig::global()->setSearchDirConfigDepth(dirSearchDepth->value());
  808. int configFlags = KateDocumentConfig::global()->configFlags();
  809. configFlags &= ~KateDocument::cfRemoveSpaces; // clear flag
  810. if (removeSpaces->isChecked()) configFlags |= KateDocument::cfRemoveSpaces; // set flag if checked
  811. KateDocumentConfig::global()->setConfigFlags(configFlags);
  812. KateDocumentConfig::global()->setEncoding((m_encoding->currentItem() == 0) ? "" : TDEGlobal::charsets()->encodingForName(m_encoding->currentText()));
  813. KateDocumentConfig::global()->setEol(m_eol->currentItem());
  814. KateDocumentConfig::global()->setAllowEolDetection(allowEolDetection->isChecked());
  815. KateDocumentConfig::global()->configEnd ();
  816. }
  817. void KateSaveConfigTab::reload()
  818. {
  819. // encoding
  820. m_encoding->clear ();
  821. m_encoding->insertItem (i18n("TDE Default"));
  822. m_encoding->setCurrentItem(0);
  823. TQStringList encodings (TDEGlobal::charsets()->descriptiveEncodingNames());
  824. int insert = 1;
  825. for (uint i=0; i < encodings.count(); i++)
  826. {
  827. bool found = false;
  828. TQTextCodec *codecForEnc = TDEGlobal::charsets()->codecForName(TDEGlobal::charsets()->encodingForName(encodings[i]), found);
  829. if (found)
  830. {
  831. m_encoding->insertItem (encodings[i]);
  832. if ( codecForEnc->name() == KateDocumentConfig::global()->encoding() )
  833. {
  834. m_encoding->setCurrentItem(insert);
  835. }
  836. insert++;
  837. }
  838. }
  839. // eol
  840. m_eol->setCurrentItem(KateDocumentConfig::global()->eol());
  841. allowEolDetection->setChecked(KateDocumentConfig::global()->allowEolDetection());
  842. dirSearchDepth->setValue(KateDocumentConfig::global()->searchDirConfigDepth());
  843. // other stuff
  844. uint f ( KateDocumentConfig::global()->backupFlags() );
  845. cbLocalFiles->setChecked( f & KateDocumentConfig::LocalFiles );
  846. cbRemoteFiles->setChecked( f & KateDocumentConfig::RemoteFiles );
  847. leBuPrefix->setText( KateDocumentConfig::global()->backupPrefix() );
  848. leBuSuffix->setText( KateDocumentConfig::global()->backupSuffix() );
  849. }
  850. void KateSaveConfigTab::reset()
  851. {
  852. }
  853. void KateSaveConfigTab::defaults()
  854. {
  855. cbLocalFiles->setChecked( true );
  856. cbRemoteFiles->setChecked( false );
  857. leBuPrefix->setText( "" );
  858. leBuSuffix->setText( "~" );
  859. }
  860. //END KateSaveConfigTab
  861. //BEGIN PluginListItem
  862. class KatePartPluginListItem : public TQCheckListItem
  863. {
  864. public:
  865. KatePartPluginListItem(bool checked, uint i, const TQString &name, TQListView *parent);
  866. uint pluginIndex () const { return index; }
  867. protected:
  868. void stateChange(bool);
  869. private:
  870. uint index;
  871. bool silentStateChange;
  872. };
  873. KatePartPluginListItem::KatePartPluginListItem(bool checked, uint i, const TQString &name, TQListView *parent)
  874. : TQCheckListItem(parent, name, CheckBox)
  875. , index(i)
  876. , silentStateChange(false)
  877. {
  878. silentStateChange = true;
  879. setOn(checked);
  880. silentStateChange = false;
  881. }
  882. void KatePartPluginListItem::stateChange(bool b)
  883. {
  884. if(!silentStateChange)
  885. static_cast<KatePartPluginListView *>(listView())->stateChanged(this, b);
  886. }
  887. //END
  888. //BEGIN PluginListView
  889. KatePartPluginListView::KatePartPluginListView(TQWidget *parent, const char *name)
  890. : TDEListView(parent, name)
  891. {
  892. }
  893. void KatePartPluginListView::stateChanged(KatePartPluginListItem *item, bool b)
  894. {
  895. emit stateChange(item, b);
  896. }
  897. //END
  898. //BEGIN KatePartPluginConfigPage
  899. KatePartPluginConfigPage::KatePartPluginConfigPage (TQWidget *parent) : KateConfigPage (parent, "")
  900. {
  901. // sizemanagment
  902. TQGridLayout *grid = new TQGridLayout( this, 1, 1 );
  903. grid->setSpacing( KDialogBase::spacingHint() );
  904. listView = new KatePartPluginListView(this);
  905. listView->addColumn(i18n("Name"));
  906. listView->addColumn(i18n("Comment"));
  907. grid->addWidget( listView, 0, 0);
  908. for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
  909. {
  910. KatePartPluginListItem *item = new KatePartPluginListItem(KateDocumentConfig::global()->plugin(i), i, (KateFactory::self()->plugins())[i]->name(), listView);
  911. item->setText(0, (KateFactory::self()->plugins())[i]->name());
  912. item->setText(1, (KateFactory::self()->plugins())[i]->comment());
  913. m_items.append (item);
  914. }
  915. // configure button
  916. btnConfigure = new TQPushButton( i18n("Configure..."), this );
  917. btnConfigure->setEnabled( false );
  918. grid->addWidget( btnConfigure, 1, 0, Qt::AlignRight );
  919. connect( btnConfigure, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotConfigure()) );
  920. connect( listView, TQT_SIGNAL(selectionChanged(TQListViewItem*)), this, TQT_SLOT(slotCurrentChanged(TQListViewItem*)) );
  921. connect( listView, TQT_SIGNAL(stateChange(KatePartPluginListItem *, bool)),
  922. this, TQT_SLOT(slotStateChanged(KatePartPluginListItem *, bool)));
  923. connect(listView, TQT_SIGNAL(stateChange(KatePartPluginListItem *, bool)), this, TQT_SLOT(slotChanged()));
  924. }
  925. KatePartPluginConfigPage::~KatePartPluginConfigPage ()
  926. {
  927. }
  928. void KatePartPluginConfigPage::apply ()
  929. {
  930. // nothing changed, no need to apply stuff
  931. if (!changed())
  932. return;
  933. m_changed = false;
  934. KateDocumentConfig::global()->configStart ();
  935. for (uint i=0; i < m_items.count(); i++)
  936. KateDocumentConfig::global()->setPlugin (m_items.at(i)->pluginIndex(), m_items.at(i)->isOn());
  937. KateDocumentConfig::global()->configEnd ();
  938. }
  939. void KatePartPluginConfigPage::slotStateChanged( KatePartPluginListItem *item, bool b )
  940. {
  941. if ( b )
  942. slotCurrentChanged( (TQListViewItem*)item );
  943. }
  944. void KatePartPluginConfigPage::slotCurrentChanged( TQListViewItem* i )
  945. {
  946. KatePartPluginListItem *item = static_cast<KatePartPluginListItem *>(i);
  947. if ( ! item ) return;
  948. bool b = false;
  949. if ( item->isOn() )
  950. {
  951. // load this plugin, and see if it has config pages
  952. KTextEditor::Plugin *plugin = KTextEditor::createPlugin(TQFile::encodeName((KateFactory::self()->plugins())[item->pluginIndex()]->library()));
  953. if ( plugin ) {
  954. KTextEditor::ConfigInterfaceExtension *cie = KTextEditor::configInterfaceExtension( plugin );
  955. b = ( cie && cie->configPages() );
  956. }
  957. }
  958. btnConfigure->setEnabled( b );
  959. }
  960. void KatePartPluginConfigPage::slotConfigure()
  961. {
  962. KatePartPluginListItem *item = static_cast<KatePartPluginListItem*>(listView->currentItem());
  963. KTextEditor::Plugin *plugin =
  964. KTextEditor::createPlugin(TQFile::encodeName((KateFactory::self()->plugins())[item->pluginIndex()]->library()));
  965. if ( ! plugin ) return;
  966. KTextEditor::ConfigInterfaceExtension *cife =
  967. KTextEditor::configInterfaceExtension( plugin );
  968. if ( ! cife )
  969. return;
  970. if ( ! cife->configPages() )
  971. return;
  972. // If we have only one page, we use a simple dialog, else an icon list type
  973. KDialogBase::DialogType dt =
  974. cife->configPages() > 1 ?
  975. KDialogBase::IconList : // still untested
  976. KDialogBase::Plain;
  977. TQString name = (KateFactory::self()->plugins())[item->pluginIndex()]->name();
  978. KDialogBase *kd = new KDialogBase ( dt,
  979. i18n("Configure %1").arg( name ),
  980. KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Help,
  981. KDialogBase::Ok,
  982. this );
  983. TQPtrList<KTextEditor::ConfigPage> editorPages;
  984. for (uint i = 0; i < cife->configPages (); i++)
  985. {
  986. TQWidget *page;
  987. if ( dt == KDialogBase::IconList )
  988. {
  989. TQStringList path;
  990. path.clear();
  991. path << cife->configPageName( i );
  992. page = kd->addVBoxPage( path, cife->configPageFullName (i),
  993. cife->configPagePixmap(i, TDEIcon::SizeMedium) );
  994. }
  995. else
  996. {
  997. page = kd->plainPage();
  998. TQVBoxLayout *_l = new TQVBoxLayout( page );
  999. _l->setAutoAdd( true );
  1000. }
  1001. editorPages.append( cife->configPage( i, page ) );
  1002. }
  1003. if (kd->exec())
  1004. {
  1005. for( uint i=0; i<editorPages.count(); i++ )
  1006. {
  1007. editorPages.at( i )->apply();
  1008. }
  1009. }
  1010. delete kd;
  1011. }
  1012. //END KatePartPluginConfigPage
  1013. //BEGIN KateHlConfigPage
  1014. KateHlConfigPage::KateHlConfigPage (TQWidget *parent, KateDocument *doc)
  1015. : KateConfigPage (parent, "")
  1016. , hlData (0)
  1017. , m_doc (doc)
  1018. {
  1019. TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
  1020. // hl chooser
  1021. TQHBox *hbHl = new TQHBox( this );
  1022. layout->add (hbHl);
  1023. hbHl->setSpacing( KDialog::spacingHint() );
  1024. TQLabel *lHl = new TQLabel( i18n("H&ighlight:"), hbHl );
  1025. hlCombo = new TQComboBox( false, hbHl );
  1026. lHl->setBuddy( hlCombo );
  1027. connect( hlCombo, TQT_SIGNAL(activated(int)),
  1028. this, TQT_SLOT(hlChanged(int)) );
  1029. for( int i = 0; i < KateHlManager::self()->highlights(); i++) {
  1030. if (KateHlManager::self()->hlSection(i).length() > 0)
  1031. hlCombo->insertItem(KateHlManager::self()->hlSection(i) + TQString ("/") + KateHlManager::self()->hlNameTranslated(i));
  1032. else
  1033. hlCombo->insertItem(KateHlManager::self()->hlNameTranslated(i));
  1034. }
  1035. TQGroupBox *gbInfo = new TQGroupBox( 1, Qt::Horizontal, i18n("Information"), this );
  1036. layout->add (gbInfo);
  1037. // author
  1038. TQHBox *hb1 = new TQHBox( gbInfo);
  1039. new TQLabel( i18n("Author:"), hb1 );
  1040. author = new TQLabel (hb1);
  1041. author->setTextFormat (TQt::RichText);
  1042. // license
  1043. TQHBox *hb2 = new TQHBox( gbInfo);
  1044. new TQLabel( i18n("License:"), hb2 );
  1045. license = new TQLabel (hb2);
  1046. TQGroupBox *gbProps = new TQGroupBox( 1, Qt::Horizontal, i18n("Properties"), this );
  1047. layout->add (gbProps);
  1048. // file & mime types
  1049. TQHBox *hbFE = new TQHBox( gbProps);
  1050. TQLabel *lFileExts = new TQLabel( i18n("File e&xtensions:"), hbFE );
  1051. wildcards = new TQLineEdit( hbFE );
  1052. lFileExts->setBuddy( wildcards );
  1053. TQHBox *hbMT = new TQHBox( gbProps );
  1054. TQLabel *lMimeTypes = new TQLabel( i18n("MIME &types:"), hbMT);
  1055. mimetypes = new TQLineEdit( hbMT );
  1056. lMimeTypes->setBuddy( mimetypes );
  1057. TQHBox *hbMT2 = new TQHBox( gbProps );
  1058. TQLabel *lprio = new TQLabel( i18n("Prio&rity:"), hbMT2);
  1059. priority = new KIntNumInput( hbMT2 );
  1060. lprio->setBuddy( priority );
  1061. TQToolButton *btnMTW = new TQToolButton(hbMT);
  1062. btnMTW->setIconSet(TQIconSet(SmallIcon("wizard")));
  1063. connect(btnMTW, TQT_SIGNAL(clicked()), this, TQT_SLOT(showMTDlg()));
  1064. // download/new buttons
  1065. TQHBox *hbBtns = new TQHBox( this );
  1066. layout->add (hbBtns);
  1067. ((TQBoxLayout*)hbBtns->layout())->addStretch(1); // hmm.
  1068. hbBtns->setSpacing( KDialog::spacingHint() );
  1069. TQPushButton *btnDl = new TQPushButton(i18n("Do&wnload..."), hbBtns);
  1070. connect( btnDl, TQT_SIGNAL(clicked()), this, TQT_SLOT(hlDownload()) );
  1071. int currentHl = m_doc ? m_doc->hlMode() : 0;
  1072. hlCombo->setCurrentItem( currentHl );
  1073. hlChanged( currentHl );
  1074. TQWhatsThis::add( hlCombo, i18n(
  1075. "Choose a <em>Syntax Highlight mode</em> from this list to view its "
  1076. "properties below.") );
  1077. TQWhatsThis::add( wildcards, i18n(
  1078. "The list of file extensions used to determine which files to highlight "
  1079. "using the current syntax highlight mode.") );
  1080. TQWhatsThis::add( mimetypes, i18n(
  1081. "The list of Mime Types used to determine which files to highlight "
  1082. "using the current highlight mode.<p>Click the wizard button on the "
  1083. "left of the entry field to display the MimeType selection dialog.") );
  1084. TQWhatsThis::add( btnMTW, i18n(
  1085. "Display a dialog with a list of all available mime types to choose from."
  1086. "<p>The <strong>File Extensions</strong> entry will automatically be "
  1087. "edited as well.") );
  1088. TQWhatsThis::add( btnDl, i18n(
  1089. "Click this button to download new or updated syntax highlight "
  1090. "descriptions from the Kate website.") );
  1091. layout->addStretch ();
  1092. connect( wildcards, TQT_SIGNAL( textChanged ( const TQString & ) ), this, TQT_SLOT( slotChanged() ) );
  1093. connect( mimetypes, TQT_SIGNAL( textChanged ( const TQString & ) ), this, TQT_SLOT( slotChanged() ) );
  1094. connect( priority, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) );
  1095. }
  1096. KateHlConfigPage::~KateHlConfigPage ()
  1097. {
  1098. }
  1099. void KateHlConfigPage::apply ()
  1100. {
  1101. // nothing changed, no need to apply stuff
  1102. if (!changed())
  1103. return;
  1104. m_changed = false;
  1105. writeback();
  1106. for ( TQIntDictIterator<KateHlData> it( hlDataDict ); it.current(); ++it )
  1107. KateHlManager::self()->getHl( it.currentKey() )->setData( it.current() );
  1108. KateHlManager::self()->getTDEConfig()->sync ();
  1109. }
  1110. void KateHlConfigPage::reload ()
  1111. {
  1112. }
  1113. void KateHlConfigPage::hlChanged(int z)
  1114. {
  1115. writeback();
  1116. KateHighlighting *hl = KateHlManager::self()->getHl( z );
  1117. if (!hl)
  1118. {
  1119. hlData = 0;
  1120. return;
  1121. }
  1122. if ( !hlDataDict.find( z ) )
  1123. hlDataDict.insert( z, hl->getData() );
  1124. hlData = hlDataDict.find( z );
  1125. wildcards->setText(hlData->wildcards);
  1126. mimetypes->setText(hlData->mimetypes);
  1127. priority->setValue(hlData->priority);
  1128. // split author string if needed into multiple lines !
  1129. TQStringList l= TQStringList::split (TQRegExp("[,;]"), hl->author());
  1130. author->setText (l.join ("<br>"));
  1131. license->setText (hl->license());
  1132. }
  1133. void KateHlConfigPage::writeback()
  1134. {
  1135. if (hlData)
  1136. {
  1137. hlData->wildcards = wildcards->text();
  1138. hlData->mimetypes = mimetypes->text();
  1139. hlData->priority = priority->value();
  1140. }
  1141. }
  1142. void KateHlConfigPage::hlDownload()
  1143. {
  1144. KateHlDownloadDialog diag(this,"hlDownload",true);
  1145. diag.exec();
  1146. }
  1147. void KateHlConfigPage::showMTDlg()
  1148. {
  1149. TQString text = i18n("Select the MimeTypes you want highlighted using the '%1' syntax highlight rules.\nPlease note that this will automatically edit the associated file extensions as well.").arg( hlCombo->currentText() );
  1150. TQStringList list = TQStringList::split( TQRegExp("\\s*;\\s*"), mimetypes->text() );
  1151. KMimeTypeChooserDialog d( i18n("Select Mime Types"), text, list, "text", this );
  1152. if ( d.exec() == KDialogBase::Accepted ) {
  1153. // do some checking, warn user if mime types or patterns are removed.
  1154. // if the lists are empty, and the fields not, warn.
  1155. wildcards->setText(d.chooser()->patterns().join(";"));
  1156. mimetypes->setText(d.chooser()->mimeTypes().join(";"));
  1157. }
  1158. }
  1159. //END KateHlConfigPage
  1160. //BEGIN KateHlDownloadDialog
  1161. KateHlDownloadDialog::KateHlDownloadDialog(TQWidget *parent, const char *name, bool modal)
  1162. :KDialogBase(KDialogBase::Swallow, i18n("Highlight Download"), User1|Close, User1, parent, name, modal, true, i18n("&Install"))
  1163. {
  1164. TQVBox* vbox = new TQVBox(this);
  1165. setMainWidget(vbox);
  1166. vbox->setSpacing(spacingHint());
  1167. new TQLabel(i18n("Select the syntax highlighting files you want to update:"), vbox);
  1168. list = new TQListView(vbox);
  1169. list->addColumn("");
  1170. list->addColumn(i18n("Name"));
  1171. list->addColumn(i18n("Installed"));
  1172. list->addColumn(i18n("Latest"));
  1173. list->setSelectionMode(TQListView::Multi);
  1174. list->setAllColumnsShowFocus(true);
  1175. new TQLabel(i18n("<b>Note:</b> New versions are selected automatically."), vbox);
  1176. actionButton (User1)->setIconSet(SmallIconSet("ok"));
  1177. transferJob = TDEIO::get(
  1178. KURL(TQString(HLDOWNLOADPATH)
  1179. + TQString("update-")
  1180. + TQString(KATEPART_VERSION)
  1181. + TQString(".xml")), true, true );
  1182. connect(transferJob, TQT_SIGNAL(data(TDEIO::Job *, const TQByteArray &)),
  1183. this, TQT_SLOT(listDataReceived(TDEIO::Job *, const TQByteArray &)));
  1184. // void data( TDEIO::Job *, const TQByteArray &data);
  1185. resize(450, 400);
  1186. }
  1187. KateHlDownloadDialog::~KateHlDownloadDialog(){}
  1188. void KateHlDownloadDialog::listDataReceived(TDEIO::Job *, const TQByteArray &data)
  1189. {
  1190. if (!transferJob || transferJob->isErrorPage())
  1191. {
  1192. actionButton(User1)->setEnabled(false);
  1193. return;
  1194. }
  1195. listData+=TQString(data);
  1196. kdDebug(13000)<<TQString("CurrentListData: ")<<listData<<endl<<endl;
  1197. kdDebug(13000)<<TQString(TQString("Data length: %1").arg(data.size()))<<endl;
  1198. kdDebug(13000)<<TQString(TQString("listData length: %1").arg(listData.length()))<<endl;
  1199. if (data.size()==0)
  1200. {
  1201. if (listData.length()>0)
  1202. {
  1203. TQString installedVersion;
  1204. KateHlManager *hlm=KateHlManager::self();
  1205. TQDomDocument doc;
  1206. doc.setContent(listData);
  1207. TQDomElement DocElem=doc.documentElement();
  1208. TQDomNode n=DocElem.firstChild();
  1209. KateHighlighting *hl = 0;
  1210. if (n.isNull()) kdDebug(13000)<<"There is no usable childnode"<<endl;
  1211. while (!n.isNull())
  1212. {
  1213. installedVersion=" --";
  1214. TQDomElement e=n.toElement();
  1215. if (!e.isNull())
  1216. kdDebug(13000)<<TQString("NAME: ")<<e.tagName()<<TQString(" - ")<<e.attribute("name")<<endl;
  1217. n=n.nextSibling();
  1218. TQString Name=e.attribute("name");
  1219. for (int i=0;i<hlm->highlights();i++)
  1220. {
  1221. hl=hlm->getHl(i);
  1222. if (hl && hl->name()==Name)
  1223. {
  1224. installedVersion=" "+hl->version();
  1225. break;
  1226. }
  1227. else hl = 0;
  1228. }
  1229. // autoselect entry if new or updated.
  1230. TQListViewItem* entry = new TQListViewItem(
  1231. list, "", e.attribute("name"), installedVersion,
  1232. e.attribute("version"),e.attribute("url"));
  1233. if (!hl || hl->version() < e.attribute("version"))
  1234. {
  1235. entry->setSelected(true);
  1236. entry->setPixmap(0, SmallIcon(("knewstuff")));
  1237. }
  1238. }
  1239. }
  1240. }
  1241. }
  1242. void KateHlDownloadDialog::slotUser1()
  1243. {
  1244. TQString destdir=TDEGlobal::dirs()->saveLocation("data","katepart/syntax/");
  1245. for (TQListViewItem *it=list->firstChild();it;it=it->nextSibling())
  1246. {
  1247. if (list->isSelected(it))
  1248. {
  1249. KURL src(it->text(4));
  1250. TQString filename=src.fileName(false);
  1251. TQString dest = destdir+filename;
  1252. TDEIO::NetAccess::download(src,dest, this);
  1253. }
  1254. }
  1255. // update Config !!
  1256. KateSyntaxDocument doc (true);
  1257. }
  1258. //END KateHlDownloadDialog
  1259. //BEGIN KateGotoLineDialog
  1260. KateGotoLineDialog::KateGotoLineDialog(TQWidget *parent, int line, int max)
  1261. : KDialogBase(parent, 0L, true, i18n("Go to Line"), Ok | Cancel, Ok) {
  1262. TQWidget *page = new TQWidget(this);
  1263. setMainWidget(page);
  1264. TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
  1265. e1 = new KIntNumInput(line, page);
  1266. e1->setRange(1, max);
  1267. e1->setEditFocus(true);
  1268. TQLabel *label = new TQLabel( e1,i18n("&Go to line:"), page );
  1269. topLayout->addWidget(label);
  1270. topLayout->addWidget(e1);
  1271. topLayout->addSpacing(spacingHint()); // A little bit extra space
  1272. topLayout->addStretch(10);
  1273. e1->setFocus();
  1274. }
  1275. int KateGotoLineDialog::getLine() {
  1276. return e1->value();
  1277. }
  1278. //END KateGotoLineDialog
  1279. //BEGIN KateModOnHdPrompt
  1280. KateModOnHdPrompt::KateModOnHdPrompt( KateDocument *doc,
  1281. int modtype,
  1282. const TQString &reason,
  1283. TQWidget *parent )
  1284. : KDialogBase( parent, "", true, "", Ok|Apply|Cancel|User1 ),
  1285. m_doc( doc ),
  1286. m_modtype ( modtype ),
  1287. m_tmpfile( 0 )
  1288. {
  1289. TQString title, btnOK, whatisok;
  1290. if ( modtype == 3 ) // deleted
  1291. {
  1292. title = i18n("File Was Deleted on Disk");
  1293. btnOK = i18n("&Save File As...");
  1294. whatisok = i18n("Lets you select a location and save the file again.");
  1295. } else {
  1296. title = i18n("File Changed on Disk");
  1297. btnOK = i18n("&Reload File");
  1298. whatisok = i18n("Reload the file from disk. If you have unsaved changes, "
  1299. "they will be lost.");
  1300. }
  1301. setButtonText( Ok, btnOK);
  1302. setButtonText( Apply, i18n("&Ignore") );
  1303. setButtonWhatsThis( Ok, whatisok );
  1304. setButtonWhatsThis( Apply, i18n("Ignore the changes. You will not be prompted again.") );
  1305. setButtonWhatsThis( Cancel, i18n("Do nothing. Next time you focus the file, "
  1306. "or try to save it or close it, you will be prompted again.") );
  1307. enableButtonSeparator( true );
  1308. setCaption( title );
  1309. TQFrame *w = makeMainWidget();
  1310. TQVBoxLayout *lo = new TQVBoxLayout( w );
  1311. TQHBoxLayout *lo1 = new TQHBoxLayout( lo );
  1312. TQLabel *icon = new TQLabel( w );
  1313. icon->setPixmap( DesktopIcon("messagebox_warning" ) );
  1314. lo1->addWidget( icon );
  1315. lo1->addWidget( new TQLabel( reason + "\n\n" + i18n("What do you want to do?"), w ) );
  1316. // If the file isn't deleted, present a diff button, and a overwrite action.
  1317. if ( modtype != 3 )
  1318. {
  1319. TQHBoxLayout *lo2 = new TQHBoxLayout( lo );
  1320. TQPushButton *btnDiff = new TQPushButton( i18n("&View Difference"), w );
  1321. lo2->addStretch( 1 );
  1322. lo2->addWidget( btnDiff );
  1323. connect( btnDiff, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotDiff()) );
  1324. TQWhatsThis::add( btnDiff, i18n(
  1325. "Calculates the difference between the editor contents and the disk "
  1326. "file using diff(1) and opens the diff file with the default application "
  1327. "for that.") );
  1328. setButtonText( User1, i18n("Overwrite") );
  1329. setButtonWhatsThis( User1, i18n("Overwrite the disk file with the editor content.") );
  1330. }
  1331. else
  1332. showButton( User1, false );
  1333. }
  1334. KateModOnHdPrompt::~KateModOnHdPrompt()
  1335. {
  1336. }
  1337. void KateModOnHdPrompt::slotDiff()
  1338. {
  1339. // Start a TDEProcess that creates a diff
  1340. KProcIO *p = new KProcIO();
  1341. p->setComm( TDEProcess::All );
  1342. *p << "diff" << "-u" << "-" << m_doc->url().path();
  1343. connect( p, TQT_SIGNAL(processExited(TDEProcess*)), this, TQT_SLOT(slotPDone(TDEProcess*)) );
  1344. connect( p, TQT_SIGNAL(readReady(KProcIO*)), this, TQT_SLOT(slotPRead(KProcIO*)) );
  1345. setCursor( WaitCursor );
  1346. p->start( TDEProcess::NotifyOnExit, true );
  1347. uint lastln = m_doc->numLines();
  1348. for ( uint l = 0; l < lastln; l++ )
  1349. p->writeStdin( m_doc->textLine( l ) );
  1350. p->closeWhenDone();
  1351. }
  1352. void KateModOnHdPrompt::slotPRead( KProcIO *p)
  1353. {
  1354. // create a file for the diff if we haven't one allready
  1355. if ( ! m_tmpfile )
  1356. m_tmpfile = new KTempFile();
  1357. // put all the data we have in it
  1358. TQString stmp;
  1359. bool dataRead = false;
  1360. while ( p->readln( stmp, false ) > -1 )
  1361. {
  1362. *m_tmpfile->textStream() << stmp << endl;
  1363. dataRead = true;
  1364. }
  1365. // dominik: only ackRead(), when we *really* read data, otherwise, this slot
  1366. // is called initity times, which leads to a crash
  1367. if( dataRead )
  1368. p->ackRead();
  1369. }
  1370. void KateModOnHdPrompt::slotPDone( TDEProcess *p )
  1371. {
  1372. setCursor( ArrowCursor );
  1373. if( ! m_tmpfile )
  1374. {
  1375. // dominik: there were only whitespace changes, so that the diff returned by
  1376. // diff(1) has 0 bytes. So slotPRead() is never called, as there is
  1377. // no data, so that m_tmpfile was never created and thus is NULL.
  1378. // NOTE: would be nice, if we could produce a fake-diff, so that kompare
  1379. // tells us "The files are identical". Right now, we get an ugly
  1380. // "Could not parse diff output".
  1381. m_tmpfile = new KTempFile();
  1382. }
  1383. m_tmpfile->close();
  1384. if ( ! p->normalExit() /*|| p->exitStatus()*/ )
  1385. {
  1386. KMessageBox::sorry( this,
  1387. i18n("The diff command failed. Please make sure that "
  1388. "diff(1) is installed and in your PATH."),
  1389. i18n("Error Creating Diff") );
  1390. delete m_tmpfile;
  1391. m_tmpfile = 0;
  1392. return;
  1393. }
  1394. KRun::runURL( m_tmpfile->name(), "text/x-diff", true );
  1395. delete m_tmpfile;
  1396. m_tmpfile = 0;
  1397. }
  1398. void KateModOnHdPrompt::slotApply()
  1399. {
  1400. if ( KMessageBox::warningContinueCancel(
  1401. this,
  1402. i18n("Ignoring means that you will not be warned again (unless "
  1403. "the disk file changes once more): if you save the document, you "
  1404. "will overwrite the file on disk; if you do not save then the disk file "
  1405. "(if present) is what you have."),
  1406. i18n("You Are on Your Own"),
  1407. KStdGuiItem::cont(),
  1408. "kate_ignore_modonhd" ) != KMessageBox::Continue )
  1409. return;
  1410. done(Ignore);
  1411. }
  1412. void KateModOnHdPrompt::slotOk()
  1413. {
  1414. done( m_modtype == 3 ? Save : Reload );
  1415. }
  1416. void KateModOnHdPrompt::slotUser1()
  1417. {
  1418. done( Overwrite );
  1419. }
  1420. //END KateModOnHdPrompt
  1421. // kate: space-indent on; indent-width 2; replace-tabs on;