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

kate

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

kate

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

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kate by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |