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 Copyright (C) 2006 Dominik Haumann <dhdev@gmx.de>
6 Copyright (C) 2007 Mirko Stocker <me@misto.ch>
7 Copyright (C) 2009 Michel Ludwig <michel.ludwig@kdemail.net>
8 Copyright (C) 2009 Erlend Hamberg <ehamberg@gmail.com>
9
10 Based on work of:
11 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
12
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Library General Public
15 License version 2 as published by the Free Software Foundation.
16
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
21
22 You should have received a copy of the GNU Library General Public License
23 along with this library; see the file COPYING.LIB. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 Boston, MA 02110-1301, USA.
26*/
27
28//BEGIN Includes
29#include "katedialogs.h"
30#include "katedialogs.moc"
31
32#include "kateautoindent.h"
33#include "katebuffer.h"
34#include "kateconfig.h"
35#include "katedocument.h"
36#include "kateglobal.h"
37#include "kateviglobal.h"
38#include "katevikeyparser.h"
39#include "kateschema.h"
40#include "katesyntaxdocument.h"
41#include "katemodeconfigpage.h"
42#include "kateview.h"
43#include "katepartpluginmanager.h"
44#include "kpluginselector.h"
45#include "spellcheck/spellcheck.h"
46
47// auto generated ui files
48#include "ui_modonhdwidget.h"
49#include "ui_textareaappearanceconfigwidget.h"
50#include "ui_bordersappearanceconfigwidget.h"
51#include "ui_navigationconfigwidget.h"
52#include "ui_editconfigwidget.h"
53#include "ui_indentationconfigwidget.h"
54#include "ui_completionconfigtab.h"
55#include "ui_opensaveconfigwidget.h"
56#include "ui_opensaveconfigadvwidget.h"
57#include "ui_viinputmodeconfigwidget.h"
58#include "ui_spellcheckconfigwidget.h"
59
60#include <ktexteditor/plugin.h>
61
62#include <kio/job.h>
63#include <kio/jobclasses.h>
64#include <kio/netaccess.h>
65
66#include <kapplication.h>
67#include <kcharsets.h>
68#include <kcolorbutton.h>
69#include <kcolorcombo.h>
70#include <kcolordialog.h>
71#include <kcombobox.h>
72#include <kconfig.h>
73#include <kdebug.h>
74#include <kfontdialog.h>
75#include <kglobal.h>
76#include <kglobalsettings.h>
77#include <kiconloader.h>
78#include <kshortcutsdialog.h>
79#include <klineedit.h>
80#include <klocale.h>
81#include <kmessagebox.h>
82#include <kmimetypechooser.h>
83#include <knuminput.h>
84#include <kmenu.h>
85#include <kprocess.h>
86#include <krun.h>
87#include <kseparator.h>
88#include <kstandarddirs.h>
89#include <ktemporaryfile.h>
90#include <kpushbutton.h>
91#include <kvbox.h>
92#include <kactioncollection.h>
93#include <kplugininfo.h>
94#include <ktabwidget.h>
95
96//#include <knewstuff/knewstuff.h>
97#include <QtGui/QCheckBox>
98#include <QtGui/QComboBox>
99#include <QtGui/QDialog>
100#include <QtCore/QFile>
101#include <QtGui/QGroupBox>
102#include <QtGui/QLabel>
103#include <QtGui/QLayout>
104#include <QtCore/QMap>
105#include <QtCore/QObject>
106#include <QtGui/QPainter>
107#include <QtGui/QRadioButton>
108#include <QtGui/QSlider>
109#include <QtCore/QStringList>
110#include <QtGui/QTabWidget>
111#include <QtCore/QTextCodec>
112#include <QtCore/QTextStream>
113#include <QtGui/QToolButton>
114#include <QtGui/QWhatsThis>
115#include <QtGui/QKeyEvent>
116#include <QtXml/QDomDocument>
117
118// trailing slash is important
119#define HLDOWNLOADPATH "http://kate.kde.org/syntax/"
120
121//END
122
123//BEGIN KateConfigPage
124KateConfigPage::KateConfigPage ( QWidget *parent, const char * )
125 : KTextEditor::ConfigPage (parent)
126 , m_changed (false)
127{
128 connect (this, SIGNAL(changed()), this, SLOT(somethingHasChanged()));
129}
130
131KateConfigPage::~KateConfigPage ()
132{
133}
134
135void KateConfigPage::slotChanged()
136{
137 emit changed();
138}
139
140void KateConfigPage::somethingHasChanged ()
141{
142 m_changed = true;
143 kDebug (13000) << "TEST: something changed on the config page: " << this;
144}
145//END KateConfigPage
146
147//BEGIN KateIndentConfigTab
148KateIndentConfigTab::KateIndentConfigTab(QWidget *parent)
149 : KateConfigPage(parent)
150{
151 // This will let us have more separation between this page and
152 // the KTabWidget edge (ereslibre)
153 QVBoxLayout *layout = new QVBoxLayout;
154 QWidget *newWidget = new QWidget(this);
155
156 ui = new Ui::IndentationConfigWidget();
157 ui->setupUi( newWidget );
158
159 ui->cmbMode->addItems (KateAutoIndent::listModes());
160
161 ui->label->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
162 connect(ui->label, SIGNAL(linkActivated(QString)), this, SLOT(showWhatsThis(QString)));
163
164 // What's This? help can be found in the ui file
165
166 reload ();
167
168 //
169 // after initial reload, connect the stuff for the changed () signal
170 //
171
172 connect(ui->cmbMode, SIGNAL(activated(int)), this, SLOT(slotChanged()));
173 connect(ui->rbIndentWithTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
174 connect(ui->rbIndentWithSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
175 connect(ui->rbIndentMixed, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
176 connect(ui->rbIndentWithTabs, SIGNAL(toggled(bool)), ui->sbIndentWidth, SLOT(setDisabled(bool)));
177
178 connect(ui->chkKeepExtraSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
179 connect(ui->chkIndentPaste, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
180 connect(ui->chkBackspaceUnindents, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
181
182 connect(ui->sbTabWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
183 connect(ui->sbIndentWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
184
185 connect(ui->rbTabAdvances, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
186 connect(ui->rbTabIndents, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
187 connect(ui->rbTabSmart, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
188
189 layout->addWidget(newWidget);
190 setLayout(layout);
191}
192
193KateIndentConfigTab::~KateIndentConfigTab()
194{
195 delete ui;
196}
197
198void KateIndentConfigTab::slotChanged()
199{
200 if (ui->rbIndentWithTabs->isChecked())
201 ui->sbIndentWidth->setValue(ui->sbTabWidth->value());
202
203 KateConfigPage::slotChanged();
204}
205
206void KateIndentConfigTab::showWhatsThis(const QString& text)
207{
208 QWhatsThis::showText(QCursor::pos(), text);
209}
210
211void KateIndentConfigTab::apply ()
212{
213 // nothing changed, no need to apply stuff
214 if (!hasChanged())
215 return;
216 m_changed = false;
217
218 KateDocumentConfig::global()->configStart ();
219
220 KateDocumentConfig::global()->setKeepExtraSpaces(ui->chkKeepExtraSpaces->isChecked());
221 KateDocumentConfig::global()->setBackspaceIndents(ui->chkBackspaceUnindents->isChecked());
222 KateDocumentConfig::global()->setIndentPastedText(ui->chkIndentPaste->isChecked());
223 KateDocumentConfig::global()->setIndentationWidth(ui->sbIndentWidth->value());
224 KateDocumentConfig::global()->setIndentationMode(KateAutoIndent::modeName(ui->cmbMode->currentIndex()));
225 KateDocumentConfig::global()->setTabWidth(ui->sbTabWidth->value());
226 KateDocumentConfig::global()->setReplaceTabsDyn(ui->rbIndentWithSpaces->isChecked());
227
228 if (ui->rbTabAdvances->isChecked())
229 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabInsertsTab );
230 else if (ui->rbTabIndents->isChecked())
231 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabIndents );
232 else
233 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabSmart );
234
235 KateDocumentConfig::global()->configEnd ();
236}
237
238void KateIndentConfigTab::reload ()
239{
240 ui->sbTabWidth->setSuffix(ki18np(" character", " characters"));
241 ui->sbTabWidth->setValue(KateDocumentConfig::global()->tabWidth());
242 ui->sbIndentWidth->setSuffix(ki18np(" character", " characters"));
243 ui->sbIndentWidth->setValue(KateDocumentConfig::global()->indentationWidth());
244 ui->chkKeepExtraSpaces->setChecked(KateDocumentConfig::global()->keepExtraSpaces());
245 ui->chkIndentPaste->setChecked(KateDocumentConfig::global()->indentPastedText());
246 ui->chkBackspaceUnindents->setChecked(KateDocumentConfig::global()->backspaceIndents());
247
248 ui->rbTabAdvances->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabInsertsTab );
249 ui->rbTabIndents->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabIndents );
250 ui->rbTabSmart->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabSmart );
251
252 ui->cmbMode->setCurrentIndex (KateAutoIndent::modeNumber (KateDocumentConfig::global()->indentationMode()));
253
254 if (KateDocumentConfig::global()->replaceTabsDyn())
255 ui->rbIndentWithSpaces->setChecked (true);
256 else
257 {
258 if (KateDocumentConfig::global()->indentationWidth() == KateDocumentConfig::global()->tabWidth())
259 ui->rbIndentWithTabs->setChecked (true);
260 else
261 ui->rbIndentMixed->setChecked (true);
262 }
263
264 ui->sbIndentWidth->setEnabled(!ui->rbIndentWithTabs->isChecked());
265}
266//END KateIndentConfigTab
267
268//BEGIN KateCompletionConfigTab
269KateCompletionConfigTab::KateCompletionConfigTab(QWidget *parent)
270 : KateConfigPage(parent)
271{
272 // This will let us have more separation between this page and
273 // the KTabWidget edge (ereslibre)
274 QVBoxLayout *layout = new QVBoxLayout;
275 QWidget *newWidget = new QWidget(this);
276
277 ui = new Ui::CompletionConfigTab ();
278 ui->setupUi( newWidget );
279
280 // What's This? help can be found in the ui file
281
282 reload ();
283
284 //
285 // after initial reload, connect the stuff for the changed () signal
286 //
287
288 connect(ui->chkAutoCompletionEnabled, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
289 connect(ui->gbWordCompletion, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
290 connect(ui->gbKeywordCompletion, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
291 connect(ui->minimalWordLength, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
292 connect(ui->removeTail, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
293
294 layout->addWidget(newWidget);
295 setLayout(layout);
296}
297
298KateCompletionConfigTab::~KateCompletionConfigTab()
299{
300 delete ui;
301}
302
303void KateCompletionConfigTab::showWhatsThis(const QString& text)
304{
305 QWhatsThis::showText(QCursor::pos(), text);
306}
307
308void KateCompletionConfigTab::apply ()
309{
310 // nothing changed, no need to apply stuff
311 if (!hasChanged())
312 return;
313 m_changed = false;
314
315 KateViewConfig::global()->configStart ();
316 KateViewConfig::global()->setAutomaticCompletionInvocation (ui->chkAutoCompletionEnabled->isChecked());
317 KateViewConfig::global()->setWordCompletion (ui->gbWordCompletion->isChecked());
318 KateViewConfig::global()->setWordCompletionMinimalWordLength (ui->minimalWordLength->value());
319 KateViewConfig::global()->setWordCompletionRemoveTail (ui->removeTail->isChecked());
320 KateViewConfig::global()->setKeywordCompletion (ui->gbKeywordCompletion->isChecked());
321 KateViewConfig::global()->configEnd ();
322}
323
324void KateCompletionConfigTab::reload ()
325{
326 ui->chkAutoCompletionEnabled->setChecked( KateViewConfig::global()->automaticCompletionInvocation () );
327 ui->gbWordCompletion->setChecked( KateViewConfig::global()->wordCompletion () );
328 ui->gbKeywordCompletion->setChecked( KateViewConfig::global()->keywordCompletion () );
329 ui->minimalWordLength->setValue (KateViewConfig::global()->wordCompletionMinimalWordLength ());
330 ui->removeTail->setChecked (KateViewConfig::global()->wordCompletionRemoveTail ());
331}
332//END KateCompletionConfigTab
333
334//BEGIN KateViInputModeConfigTab
335KateViInputModeConfigTab::KateViInputModeConfigTab(QWidget *parent)
336 : KateConfigPage(parent)
337{
338 // This will let us have more separation between this page and
339 // the QTabWidget edge (ereslibre)
340 QVBoxLayout *layout = new QVBoxLayout;
341 QWidget *newWidget = new QWidget(this);
342
343 ui = new Ui::ViInputModeConfigWidget();
344 ui->setupUi(newWidget);
345
346 // Make the header take all the width in equal parts.
347 ui->tblNormalModeMappings->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
348 ui->tblInsertModeMappings->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
349 ui->tblVisualModeMappings->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
350
351 // What's This? help can be found in the ui file
352 reload();
353
354 //
355 // after initial reload, connect the stuff for the changed () signal
356 //
357
358 connect(ui->chkViInputModeDefault, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
359 connect(ui->chkViCommandsOverride, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
360 connect(ui->chkViRelLineNumbers, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
361 connect(ui->tblNormalModeMappings, SIGNAL(cellChanged(int,int)), this, SLOT(slotChanged()));
362 connect(ui->btnAddNewRow, SIGNAL(clicked()), this, SLOT(addMappingRow()));
363 connect(ui->btnAddNewRow, SIGNAL(clicked()), this, SLOT(slotChanged()));
364 connect(ui->btnRemoveSelectedRows, SIGNAL(clicked()), this, SLOT(removeSelectedMappingRows()));
365 connect(ui->btnRemoveSelectedRows, SIGNAL(clicked()), this, SLOT(slotChanged()));
366 connect(ui->btnImportNormal, SIGNAL(clicked()), this, SLOT(importNormalMappingRow()));
367 connect(ui->btnImportNormal, SIGNAL(clicked()), this, SLOT(slotChanged()));
368
369 layout->addWidget(newWidget);
370 setLayout(layout);
371}
372
373KateViInputModeConfigTab::~KateViInputModeConfigTab()
374{
375 delete ui;
376}
377
378void KateViInputModeConfigTab::applyTab(QTableWidget *mappingsTable, KateViGlobal::MappingMode mode)
379{
380 KateGlobal::self()->viInputModeGlobal()->clearMappings(mode);
381
382 for (int i = 0; i < mappingsTable->rowCount(); i++) {
383 QTableWidgetItem *from = mappingsTable->item(i, 0);
384 QTableWidgetItem *to = mappingsTable->item(i, 1);
385 QTableWidgetItem *recursive = mappingsTable->item(i, 2);
386
387 if (from && to && recursive) {
388 const KateViGlobal::MappingRecursion recursion = recursive->checkState() == Qt::Checked ?
389 KateViGlobal::Recursive :
390 KateViGlobal::NonRecursive;
391 KateGlobal::self()->viInputModeGlobal()->addMapping(mode, from->text(), to->text(), recursion);
392 }
393 }
394}
395
396void KateViInputModeConfigTab::reloadTab(QTableWidget *mappingsTable, KateViGlobal::MappingMode mode)
397{
398 QStringList l = KateGlobal::self()->viInputModeGlobal()->getMappings(mode);
399 mappingsTable->setRowCount(l.size());
400
401 int i = 0;
402 foreach (const QString &f, l) {
403 QTableWidgetItem *from = new QTableWidgetItem(KateViKeyParser::self()->decodeKeySequence(f));
404 QString s = KateGlobal::self()->viInputModeGlobal()->getMapping(mode, f);
405 QTableWidgetItem *to = new QTableWidgetItem(KateViKeyParser::self()->decodeKeySequence(s));
406 QTableWidgetItem *recursive = new QTableWidgetItem();
407 recursive->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
408 const bool isRecursive = KateGlobal::self()->viInputModeGlobal()->isMappingRecursive(mode, f);
409 recursive->setCheckState(isRecursive ? Qt::Checked : Qt::Unchecked);
410
411 mappingsTable->setItem(i, 0, from);
412 mappingsTable->setItem(i, 1, to);
413 mappingsTable->setItem(i, 2, recursive);
414
415 i++;
416 }
417}
418
419void KateViInputModeConfigTab::apply()
420{
421 // nothing changed, no need to apply stuff
422 if (!hasChanged()) {
423 return;
424 }
425 m_changed = false;
426
427 KateViewConfig::global()->configStart();
428
429 // General options.
430 KateViewConfig::global()->setViInputMode(ui->chkViInputModeDefault->isChecked());
431 KateViewConfig::global()->setViRelativeLineNumbers(ui->chkViRelLineNumbers->isChecked());
432 KateViewConfig::global()->setViInputModeStealKeys(ui->chkViCommandsOverride->isChecked());
433
434 // Mappings.
435 applyTab(ui->tblNormalModeMappings, KateViGlobal::NormalModeMapping);
436 applyTab(ui->tblInsertModeMappings, KateViGlobal::InsertModeMapping);
437 applyTab(ui->tblVisualModeMappings, KateViGlobal::VisualModeMapping);
438
439 KateViewConfig::global()->configEnd();
440}
441
442void KateViInputModeConfigTab::reload()
443{
444 // General options.
445 ui->chkViInputModeDefault->setChecked(KateViewConfig::global()->viInputMode());
446 ui->chkViRelLineNumbers->setChecked( KateViewConfig::global()->viRelativeLineNumbers());
447 ui->chkViCommandsOverride->setChecked(KateViewConfig::global()->viInputModeStealKeys());
448
449 // Mappings.
450 reloadTab(ui->tblNormalModeMappings, KateViGlobal::NormalModeMapping);
451 reloadTab(ui->tblInsertModeMappings, KateViGlobal::InsertModeMapping);
452 reloadTab(ui->tblVisualModeMappings, KateViGlobal::VisualModeMapping);
453}
454
455void KateViInputModeConfigTab::showWhatsThis(const QString &text)
456{
457 QWhatsThis::showText(QCursor::pos(), text);
458}
459
460void KateViInputModeConfigTab::addMappingRow()
461{
462 // Pick the current widget.
463 QTableWidget *mappingsTable = ui->tblNormalModeMappings;
464 if (ui->tabMappingModes->currentIndex() == 1) {
465 mappingsTable = ui->tblInsertModeMappings;
466 } else if (ui->tabMappingModes->currentIndex() == 2) {
467 mappingsTable = ui->tblVisualModeMappings;
468 }
469
470 // And add a new row.
471 int rows = mappingsTable->rowCount();
472 mappingsTable->insertRow(rows);
473 QTableWidgetItem *recursive = new QTableWidgetItem();
474 recursive->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
475 recursive->setCheckState(Qt::Unchecked);
476 mappingsTable->setItem(rows, 2, recursive);
477 mappingsTable->setCurrentCell(rows, 0);
478 mappingsTable->editItem(mappingsTable->currentItem());
479}
480
481void KateViInputModeConfigTab::removeSelectedMappingRows()
482{
483 // Pick the current widget.
484 QTableWidget *mappingsTable = ui->tblNormalModeMappings;
485 if (ui->tabMappingModes->currentIndex() == 1) {
486 mappingsTable = ui->tblInsertModeMappings;
487 } else if (ui->tabMappingModes->currentIndex() == 2) {
488 mappingsTable = ui->tblVisualModeMappings;
489 }
490
491 // And remove the selected rows.
492 QList<QTableWidgetSelectionRange> l = mappingsTable->selectedRanges();
493 foreach (const QTableWidgetSelectionRange &range, l) {
494 for (int i = 0; i < range.bottomRow() - range.topRow() + 1; i++) {
495 mappingsTable->removeRow(range.topRow());
496 }
497 }
498}
499
500void KateViInputModeConfigTab::importNormalMappingRow()
501{
502 QString fileName = KFileDialog::getOpenFileName();
503
504 if (fileName.isEmpty()) {
505 return;
506 }
507
508 QFile configFile(fileName);
509 if (! configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
510 KMessageBox::error(this, i18n("Unable to open the config file for reading."), i18n("Unable to open file"));
511 return;
512 }
513 QTextStream stream(&configFile);
514 while (! stream.atEnd()) {
515 QStringList line = stream.readLine().split(QLatin1String(" "));
516
517 // TODO - allow recursive mappings to be read.
518 if (line.size() > 2 && (line[0] == QLatin1String("noremap") || line[0] == QLatin1String("no")
519 || line[0] == QLatin1String("nnoremap") || line [0] == QLatin1String("nn"))) {
520 int rows = ui->tblNormalModeMappings->rowCount();
521 ui->tblNormalModeMappings->insertRow(rows);
522 ui->tblNormalModeMappings->setItem(rows, 0, new QTableWidgetItem(line[1]));
523 ui->tblNormalModeMappings->setItem(rows, 1, new QTableWidgetItem(line[2]));
524 QTableWidgetItem *recursive = new QTableWidgetItem();
525 recursive->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
526 recursive->setCheckState(Qt::Unchecked);
527 ui->tblNormalModeMappings->setItem(rows, 2, recursive);
528 }
529 }
530}
531//END KateViInputModeConfigTab
532
533//BEGIN KateSpellCheckConfigTab
534KateSpellCheckConfigTab::KateSpellCheckConfigTab(QWidget *parent)
535 : KateConfigPage(parent)
536{
537 // This will let us have more separation between this page and
538 // the KTabWidget edge (ereslibre)
539 QVBoxLayout *layout = new QVBoxLayout;
540 QWidget *newWidget = new QWidget(this);
541
542 ui = new Ui::SpellCheckConfigWidget();
543 ui->setupUi(newWidget);
544
545 // What's This? help can be found in the ui file
546 reload();
547
548 //
549 // after initial reload, connect the stuff for the changed () signal
550
551 m_sonnetConfigWidget = new Sonnet::ConfigWidget(KGlobal::config().data(), this);
552 connect(m_sonnetConfigWidget, SIGNAL(configChanged()), this, SLOT(slotChanged()));
553 layout->addWidget(m_sonnetConfigWidget);
554
555 layout->addWidget(newWidget);
556 setLayout(layout);
557}
558
559KateSpellCheckConfigTab::~KateSpellCheckConfigTab()
560{
561 delete ui;
562}
563
564void KateSpellCheckConfigTab::showWhatsThis(const QString& text)
565{
566 QWhatsThis::showText(QCursor::pos(), text);
567}
568
569void KateSpellCheckConfigTab::apply()
570{
571 if (!hasChanged()) {
572 // nothing changed, no need to apply stuff
573 return;
574 }
575 m_changed = false;
576
577 KateDocumentConfig::global()->configStart();
578 m_sonnetConfigWidget->save();
579 KateDocumentConfig::global()->configEnd();
580 foreach (KateDocument *doc, KateGlobal::self()->kateDocuments()) {
581 doc->refreshOnTheFlyCheck();
582 }
583}
584
585void KateSpellCheckConfigTab::reload()
586{
587 // does nothing
588}
589//END KateSpellCheckConfigTab
590
591//BEGIN KateNavigationConfigTab
592KateNavigationConfigTab::KateNavigationConfigTab(QWidget *parent)
593 : KateConfigPage(parent)
594{
595 // This will let us having more separation between this page and
596 // the KTabWidget edge (ereslibre)
597 QVBoxLayout *layout = new QVBoxLayout;
598 QWidget *newWidget = new QWidget(this);
599
600 ui = new Ui::NavigationConfigWidget();
601 ui->setupUi( newWidget );
602
603 // What's This? Help is in the ui-files
604
605 reload ();
606
607 //
608 // after initial reload, connect the stuff for the changed () signal
609 //
610
611 connect(ui->cbTextSelectionMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChanged()));
612 connect(ui->chkSmartHome, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
613 connect(ui->chkPagingMovesCursor, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
614 connect(ui->sbAutoCenterCursor, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
615 connect(ui->chkScrollPastEnd, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
616
617 layout->addWidget(newWidget);
618 setLayout(layout);
619}
620
621KateNavigationConfigTab::~KateNavigationConfigTab()
622{
623 delete ui;
624}
625
626void KateNavigationConfigTab::apply ()
627{
628 // nothing changed, no need to apply stuff
629 if (!hasChanged())
630 return;
631 m_changed = false;
632
633 KateViewConfig::global()->configStart ();
634 KateDocumentConfig::global()->configStart ();
635
636 KateDocumentConfig::global()->setSmartHome(ui->chkSmartHome->isChecked());
637
638 KateViewConfig::global()->setAutoCenterLines(qMax(0, ui->sbAutoCenterCursor->value()));
639 KateDocumentConfig::global()->setPageUpDownMovesCursor(ui->chkPagingMovesCursor->isChecked());
640
641 KateViewConfig::global()->setPersistentSelection (ui->cbTextSelectionMode->currentIndex() == 1);
642
643 KateViewConfig::global()->setScrollPastEnd(ui->chkScrollPastEnd->isChecked());
644
645 KateDocumentConfig::global()->configEnd ();
646 KateViewConfig::global()->configEnd ();
647}
648
649void KateNavigationConfigTab::reload ()
650{
651 ui->cbTextSelectionMode->setCurrentIndex( KateViewConfig::global()->persistentSelection() ? 1 : 0 );
652
653 ui->chkSmartHome->setChecked(KateDocumentConfig::global()->smartHome());
654 ui->chkPagingMovesCursor->setChecked(KateDocumentConfig::global()->pageUpDownMovesCursor());
655 ui->sbAutoCenterCursor->setValue(KateViewConfig::global()->autoCenterLines());
656 ui->chkScrollPastEnd->setChecked(KateViewConfig::global()->scrollPastEnd());
657}
658//END KateNavigationConfigTab
659
660//BEGIN KateEditGeneralConfigTab
661KateEditGeneralConfigTab::KateEditGeneralConfigTab(QWidget *parent)
662 : KateConfigPage(parent)
663{
664 QVBoxLayout *layout = new QVBoxLayout;
665 QWidget *newWidget = new QWidget(this);
666 ui = new Ui::EditConfigWidget();
667 ui->setupUi( newWidget );
668
669 reload();
670
671 connect(ui->chkStaticWordWrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
672 connect(ui->chkShowStaticWordWrapMarker, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
673 connect(ui->sbWordWrap, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
674 connect(ui->chkSmartCopyCut, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
675
676 // "What's this?" help is in the ui-file
677
678 layout->addWidget(newWidget);
679 setLayout(layout);
680}
681
682KateEditGeneralConfigTab::~KateEditGeneralConfigTab()
683{
684 delete ui;
685}
686
687void KateEditGeneralConfigTab::apply ()
688{
689 // nothing changed, no need to apply stuff
690 if (!hasChanged())
691 return;
692 m_changed = false;
693
694 KateViewConfig::global()->configStart ();
695 KateDocumentConfig::global()->configStart ();
696
697 KateDocumentConfig::global()->setWordWrapAt(ui->sbWordWrap->value());
698 KateDocumentConfig::global()->setWordWrap(ui->chkStaticWordWrap->isChecked());
699
700 KateRendererConfig::global()->setWordWrapMarker (ui->chkShowStaticWordWrapMarker->isChecked());
701
702 KateDocumentConfig::global()->configEnd ();
703 KateViewConfig::global()->setSmartCopyCut(ui->chkSmartCopyCut->isChecked());
704 KateViewConfig::global()->configEnd ();
705}
706
707void KateEditGeneralConfigTab::reload ()
708{
709 ui->chkStaticWordWrap->setChecked(KateDocumentConfig::global()->wordWrap());
710 ui->chkShowStaticWordWrapMarker->setChecked( KateRendererConfig::global()->wordWrapMarker() );
711 ui->sbWordWrap->setSuffix(ki18ncp("Wrap words at", " character", " characters"));
712 ui->sbWordWrap->setValue( KateDocumentConfig::global()->wordWrapAt() );
713 ui->chkSmartCopyCut->setChecked( KateViewConfig::global()->smartCopyCut() );
714}
715//END KateEditGeneralConfigTab
716
717
718//BEGIN KateEditConfigTab
719KateEditConfigTab::KateEditConfigTab(QWidget *parent)
720 : KateConfigPage(parent)
721 , editConfigTab(new KateEditGeneralConfigTab(this))
722 , navigationConfigTab(new KateNavigationConfigTab(this))
723 , indentConfigTab(new KateIndentConfigTab(this))
724 , completionConfigTab (new KateCompletionConfigTab(this))
725 , viInputModeConfigTab(new KateViInputModeConfigTab(this))
726 , spellCheckConfigTab(new KateSpellCheckConfigTab(this))
727{
728 QVBoxLayout *layout = new QVBoxLayout;
729 layout->setMargin(0);
730 KTabWidget *tabWidget = new KTabWidget(this);
731
732 // add all tabs
733 tabWidget->insertTab(0, editConfigTab, i18n("General"));
734 tabWidget->insertTab(1, navigationConfigTab, i18n("Text Navigation"));
735 tabWidget->insertTab(2, indentConfigTab, i18n("Indentation"));
736 tabWidget->insertTab(3, completionConfigTab, i18n("Auto Completion"));
737 tabWidget->insertTab(4, viInputModeConfigTab, i18n("Vi Input Mode"));
738 tabWidget->insertTab(5, spellCheckConfigTab, i18n("Spellcheck"));
739
740 connect(editConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
741 connect(navigationConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
742 connect(indentConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
743 connect(completionConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
744 connect(viInputModeConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
745 connect(spellCheckConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
746
747 layout->addWidget(tabWidget);
748 setLayout(layout);
749}
750
751KateEditConfigTab::~KateEditConfigTab()
752{
753}
754
755void KateEditConfigTab::apply ()
756{
757 // try to update the rest of tabs
758 editConfigTab->apply();
759 navigationConfigTab->apply();
760 indentConfigTab->apply();
761 completionConfigTab->apply();
762 viInputModeConfigTab->apply();
763 spellCheckConfigTab->apply();
764}
765
766void KateEditConfigTab::reload ()
767{
768 editConfigTab->reload();
769 navigationConfigTab->reload();
770 indentConfigTab->reload();
771 completionConfigTab->reload();
772 viInputModeConfigTab->reload();
773 spellCheckConfigTab->reload();
774}
775
776void KateEditConfigTab::reset ()
777{
778 editConfigTab->reset();
779 navigationConfigTab->reset();
780 indentConfigTab->reset();
781 completionConfigTab->reset();
782 viInputModeConfigTab->reset();
783 spellCheckConfigTab->reset();
784}
785
786void KateEditConfigTab::defaults ()
787{
788 editConfigTab->defaults();
789 navigationConfigTab->defaults();
790 indentConfigTab->defaults();
791 completionConfigTab->defaults();
792 viInputModeConfigTab->defaults();
793 spellCheckConfigTab->defaults();
794}
795//END KateEditConfigTab
796
797//BEGIN KateViewDefaultsConfig
798KateViewDefaultsConfig::KateViewDefaultsConfig(QWidget *parent)
799 : KateConfigPage(parent)
800 , textareaUi(new Ui::TextareaAppearanceConfigWidget())
801 , bordersUi(new Ui::BordersAppearanceConfigWidget())
802{
803 QLayout *layout = new QVBoxLayout( this );
804 QTabWidget *tabWidget = new QTabWidget( this );
805 layout->addWidget( tabWidget );
806 layout->setMargin( 0 );
807
808 QWidget *textareaTab = new QWidget( tabWidget );
809 textareaUi->setupUi( textareaTab );
810 tabWidget->addTab( textareaTab, i18n("General") );
811
812 QWidget *bordersTab = new QWidget( tabWidget );
813 bordersUi->setupUi( bordersTab );
814 tabWidget->addTab( bordersTab, i18n("Borders") );
815
816 if (KateDocument::simpleMode ())
817 bordersUi->gbSortBookmarks->hide ();
818
819 textareaUi->cmbDynamicWordWrapIndicator->addItem( i18n("Off") );
820 textareaUi->cmbDynamicWordWrapIndicator->addItem( i18n("Follow Line Numbers") );
821 textareaUi->cmbDynamicWordWrapIndicator->addItem( i18n("Always On") );
822
823 // hide power user mode if activated anyway
824 if (!KateGlobal::self()->simpleMode ())
825 textareaUi->chkDeveloperMode->hide ();
826
827 // What's This? help is in the ui-file
828
829 reload();
830
831 //
832 // after initial reload, connect the stuff for the changed () signal
833 //
834
835 connect(textareaUi->gbWordWrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
836 connect(textareaUi->cmbDynamicWordWrapIndicator, SIGNAL(activated(int)), this, SLOT(slotChanged()));
837 connect(textareaUi->sbDynamicWordWrapDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
838 connect(textareaUi->chkShowTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
839 connect(textareaUi->chkShowSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
840 connect(textareaUi->chkShowIndentationLines, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
841 connect(textareaUi->chkShowWholeBracketExpression, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
842 connect(textareaUi->chkAnimateBracketMatching, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
843 connect(textareaUi->chkDeveloperMode, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
844 connect(textareaUi->chkFoldFirstLine, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
845
846 connect(bordersUi->chkIconBorder, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
847 connect(bordersUi->chkScrollbarMarks, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
848 connect(bordersUi->chkScrollbarMiniMap, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
849 connect(bordersUi->chkScrollbarMiniMapAll, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
850 bordersUi->chkScrollbarMiniMapAll->hide(); // this is temporary until the feature is done
851 connect(bordersUi->spBoxMiniMapWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
852 connect(bordersUi->chkLineNumbers, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
853 connect(bordersUi->chkShowLineModification, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
854 connect(bordersUi->chkShowFoldingMarkers, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
855 connect(bordersUi->rbSortBookmarksByPosition, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
856 connect(bordersUi->rbSortBookmarksByCreation, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
857 connect(bordersUi->cmbShowScrollbars, SIGNAL(activated(int)), this, SLOT(slotChanged()));
858}
859
860KateViewDefaultsConfig::~KateViewDefaultsConfig()
861{
862 delete bordersUi;
863 delete textareaUi;
864}
865
866void KateViewDefaultsConfig::apply ()
867{
868 // nothing changed, no need to apply stuff
869 if (!hasChanged())
870 return;
871 m_changed = false;
872
873 KateViewConfig::global()->configStart ();
874 KateRendererConfig::global()->configStart ();
875
876 KateViewConfig::global()->setDynWordWrap (textareaUi->gbWordWrap->isChecked());
877 KateViewConfig::global()->setDynWordWrapIndicators (textareaUi->cmbDynamicWordWrapIndicator->currentIndex ());
878 KateViewConfig::global()->setDynWordWrapAlignIndent(textareaUi->sbDynamicWordWrapDepth->value());
879 KateDocumentConfig::global()->setShowTabs (textareaUi->chkShowTabs->isChecked());
880 KateDocumentConfig::global()->setShowSpaces (textareaUi->chkShowSpaces->isChecked());
881 KateViewConfig::global()->setLineNumbers (bordersUi->chkLineNumbers->isChecked());
882 KateViewConfig::global()->setIconBar (bordersUi->chkIconBorder->isChecked());
883 KateViewConfig::global()->setScrollBarMarks (bordersUi->chkScrollbarMarks->isChecked());
884 KateViewConfig::global()->setScrollBarMiniMap (bordersUi->chkScrollbarMiniMap->isChecked());
885 KateViewConfig::global()->setScrollBarMiniMapAll (bordersUi->chkScrollbarMiniMapAll->isChecked());
886 KateViewConfig::global()->setScrollBarMiniMapWidth (bordersUi->spBoxMiniMapWidth->value());
887 KateViewConfig::global()->setFoldingBar (bordersUi->chkShowFoldingMarkers->isChecked());
888 KateViewConfig::global()->setLineModification(bordersUi->chkShowLineModification->isChecked());
889 KateViewConfig::global()->setShowScrollbars( bordersUi->cmbShowScrollbars->currentIndex() );
890
891 KateViewConfig::global()->setBookmarkSort (bordersUi->rbSortBookmarksByPosition->isChecked()?0:1);
892 KateRendererConfig::global()->setShowIndentationLines(textareaUi->chkShowIndentationLines->isChecked());
893 KateRendererConfig::global()->setShowWholeBracketExpression(textareaUi->chkShowWholeBracketExpression->isChecked());
894 KateRendererConfig::global()->setAnimateBracketMatching(textareaUi->chkAnimateBracketMatching->isChecked());
895 KateViewConfig::global()->setFoldFirstLine(textareaUi->chkFoldFirstLine->isChecked());
896
897 // warn user that he needs restart the application
898 if (!textareaUi->chkDeveloperMode->isChecked() != KateDocumentConfig::global()->allowSimpleMode())
899 {
900 // inform...
901 KMessageBox::information(
902 this,
903 i18n("Changing the power user mode affects only newly opened / created documents. In KWrite a restart is recommended."),
904 i18n("Power user mode changed"));
905
906 KateDocumentConfig::global()->setAllowSimpleMode (!textareaUi->chkDeveloperMode->isChecked());
907 }
908
909 KateRendererConfig::global()->configEnd ();
910 KateViewConfig::global()->configEnd ();
911}
912
913void KateViewDefaultsConfig::reload ()
914{
915 textareaUi->gbWordWrap->setChecked(KateViewConfig::global()->dynWordWrap());
916 textareaUi->cmbDynamicWordWrapIndicator->setCurrentIndex( KateViewConfig::global()->dynWordWrapIndicators() );
917 textareaUi->sbDynamicWordWrapDepth->setValue(KateViewConfig::global()->dynWordWrapAlignIndent());
918 textareaUi->chkShowTabs->setChecked(KateDocumentConfig::global()->showTabs());
919 textareaUi->chkShowSpaces->setChecked(KateDocumentConfig::global()->showSpaces());
920 bordersUi->chkLineNumbers->setChecked(KateViewConfig::global()->lineNumbers());
921 bordersUi->chkIconBorder->setChecked(KateViewConfig::global()->iconBar());
922 bordersUi->chkScrollbarMarks->setChecked(KateViewConfig::global()->scrollBarMarks());
923 bordersUi->chkScrollbarMiniMap->setChecked(KateViewConfig::global()->scrollBarMiniMap());
924 bordersUi->chkScrollbarMiniMapAll->setChecked(KateViewConfig::global()->scrollBarMiniMapAll());
925 bordersUi->spBoxMiniMapWidth->setValue(KateViewConfig::global()->scrollBarMiniMapWidth());
926 bordersUi->chkShowFoldingMarkers->setChecked(KateViewConfig::global()->foldingBar());
927 bordersUi->chkShowLineModification->setChecked(KateViewConfig::global()->lineModification());
928 bordersUi->rbSortBookmarksByPosition->setChecked(KateViewConfig::global()->bookmarkSort()==0);
929 bordersUi->rbSortBookmarksByCreation->setChecked(KateViewConfig::global()->bookmarkSort()==1);
930 bordersUi->cmbShowScrollbars->setCurrentIndex( KateViewConfig::global()->showScrollbars() );
931 textareaUi->chkShowIndentationLines->setChecked(KateRendererConfig::global()->showIndentationLines());
932 textareaUi->chkShowWholeBracketExpression->setChecked(KateRendererConfig::global()->showWholeBracketExpression());
933 textareaUi->chkAnimateBracketMatching->setChecked(KateRendererConfig::global()->animateBracketMatching());
934 textareaUi->chkDeveloperMode->setChecked(!KateDocumentConfig::global()->allowSimpleMode());
935 textareaUi->chkFoldFirstLine->setChecked(KateViewConfig::global()->foldFirstLine());
936}
937
938void KateViewDefaultsConfig::reset () {;}
939
940void KateViewDefaultsConfig::defaults (){;}
941//END KateViewDefaultsConfig
942
943//BEGIN KateSaveConfigTab
944KateSaveConfigTab::KateSaveConfigTab( QWidget *parent )
945 : KateConfigPage( parent )
946 , modeConfigPage( new ModeConfigPage( this ) )
947{
948 // FIXME: Is really needed to move all this code below to another class,
949 // since it is another tab itself on the config dialog. This means we should
950 // initialize, add and work with as we do with modeConfigPage (ereslibre)
951 QVBoxLayout *layout = new QVBoxLayout;
952 layout->setMargin(0);
953 KTabWidget *tabWidget = new KTabWidget(this);
954
955 QWidget *tmpWidget = new QWidget(tabWidget);
956 QVBoxLayout *internalLayout = new QVBoxLayout;
957 QWidget *newWidget = new QWidget(tabWidget);
958 ui = new Ui::OpenSaveConfigWidget();
959 ui->setupUi( newWidget );
960
961 QWidget *tmpWidget2 = new QWidget(tabWidget);
962 QVBoxLayout *internalLayout2 = new QVBoxLayout;
963 QWidget *newWidget2 = new QWidget(tabWidget);
964 uiadv = new Ui::OpenSaveConfigAdvWidget();
965 uiadv->setupUi( newWidget2 );
966
967 // What's this help is added in ui/opensaveconfigwidget.ui
968 reload();
969
970 //
971 // after initial reload, connect the stuff for the changed () signal
972 //
973
974 connect( ui->cmbEncoding, SIGNAL(activated(int)), this, SLOT(slotChanged()));
975 connect( ui->cmbEncodingDetection, SIGNAL(activated(int)), this, SLOT(slotChanged()));
976 connect( ui->cmbEncodingFallback, SIGNAL(activated(int)), this, SLOT(slotChanged()));
977 connect( ui->cmbEOL, SIGNAL(activated(int)), this, SLOT(slotChanged()));
978 connect( ui->chkDetectEOL, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
979 connect( ui->chkEnableBOM, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
980 connect( ui->lineLengthLimit, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
981 connect( ui->cbRemoveTrailingSpaces, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChanged()));
982 connect( ui->chkNewLineAtEof, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
983 connect( uiadv->chkBackupLocalFiles, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
984 connect( uiadv->chkBackupRemoteFiles, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
985 connect( uiadv->sbConfigFileSearchDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
986 connect( uiadv->edtBackupPrefix, SIGNAL(textChanged(QString)), this, SLOT(slotChanged()) );
987 connect( uiadv->edtBackupSuffix, SIGNAL(textChanged(QString)), this, SLOT(slotChanged()) );
988 connect( uiadv->chkNoSync, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
989
990 internalLayout->addWidget(newWidget);
991 tmpWidget->setLayout(internalLayout);
992 internalLayout2->addWidget(newWidget2);
993 tmpWidget2->setLayout(internalLayout2);
994
995 // add all tabs
996 tabWidget->insertTab(0, tmpWidget, i18n("General"));
997 tabWidget->insertTab(1, tmpWidget2, i18n("Advanced"));
998 tabWidget->insertTab(2, modeConfigPage, i18n("Modes && Filetypes"));
999
1000 connect(modeConfigPage, SIGNAL(changed()), this, SLOT(slotChanged()));
1001
1002 layout->addWidget(tabWidget);
1003 setLayout(layout);
1004}
1005
1006KateSaveConfigTab::~KateSaveConfigTab()
1007{
1008 delete ui;
1009}
1010
1011void KateSaveConfigTab::apply()
1012{
1013 modeConfigPage->apply();
1014
1015 // nothing changed, no need to apply stuff
1016 if (!hasChanged())
1017 return;
1018 m_changed = false;
1019
1020 KateGlobalConfig::global()->configStart ();
1021 KateDocumentConfig::global()->configStart ();
1022
1023 if ( uiadv->edtBackupSuffix->text().isEmpty() && uiadv->edtBackupPrefix->text().isEmpty() ) {
1024 KMessageBox::information(
1025 this,
1026 i18n("You did not provide a backup suffix or prefix. Using default suffix: '~'"),
1027 i18n("No Backup Suffix or Prefix")
1028 );
1029 uiadv->edtBackupSuffix->setText( "~" );
1030 }
1031
1032 uint f( 0 );
1033 if ( uiadv->chkBackupLocalFiles->isChecked() )
1034 f |= KateDocumentConfig::LocalFiles;
1035 if ( uiadv->chkBackupRemoteFiles->isChecked() )
1036 f |= KateDocumentConfig::RemoteFiles;
1037
1038 KateDocumentConfig::global()->setBackupFlags(f);
1039 KateDocumentConfig::global()->setBackupPrefix(uiadv->edtBackupPrefix->text());
1040 KateDocumentConfig::global()->setBackupSuffix(uiadv->edtBackupSuffix->text());
1041
1042 KateDocumentConfig::global()->setSwapFileNoSync(uiadv->chkNoSync->isChecked());
1043
1044 KateDocumentConfig::global()->setSearchDirConfigDepth(uiadv->sbConfigFileSearchDepth->value());
1045
1046 KateDocumentConfig::global()->setRemoveSpaces(ui->cbRemoveTrailingSpaces->currentIndex());
1047
1048 KateDocumentConfig::global()->setNewLineAtEof(ui->chkNewLineAtEof->isChecked());
1049
1050 // set both standard and fallback encoding
1051 KateDocumentConfig::global()->setEncoding((ui->cmbEncoding->currentIndex() == 0) ? "" : KGlobal::charsets()->encodingForName(ui->cmbEncoding->currentText()));
1052
1053 KateGlobalConfig::global()->setProberType((KEncodingProber::ProberType)ui->cmbEncodingDetection->currentIndex());
1054 KateGlobalConfig::global()->setFallbackEncoding(KGlobal::charsets()->encodingForName(ui->cmbEncodingFallback->currentText()));
1055
1056 KateDocumentConfig::global()->setEol(ui->cmbEOL->currentIndex());
1057 KateDocumentConfig::global()->setAllowEolDetection(ui->chkDetectEOL->isChecked());
1058 KateDocumentConfig::global()->setBom(ui->chkEnableBOM->isChecked());
1059
1060 KateDocumentConfig::global()->setLineLengthLimit(ui->lineLengthLimit->value());
1061
1062 KateDocumentConfig::global()->configEnd ();
1063 KateGlobalConfig::global()->configEnd ();
1064}
1065
1066void KateSaveConfigTab::reload()
1067{
1068 modeConfigPage->reload();
1069
1070 // encodings
1071 ui->cmbEncoding->clear ();
1072 ui->cmbEncoding->addItem (i18n("KDE Default"));
1073 ui->cmbEncoding->setCurrentIndex(0);
1074 ui->cmbEncodingFallback->clear ();
1075 QStringList encodings (KGlobal::charsets()->descriptiveEncodingNames());
1076 int insert = 1;
1077 for (int i=0; i < encodings.count(); i++)
1078 {
1079 bool found = false;
1080 QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(KGlobal::charsets()->encodingForName(encodings[i]), found);
1081
1082 if (found)
1083 {
1084 ui->cmbEncoding->addItem (encodings[i]);
1085 ui->cmbEncodingFallback->addItem (encodings[i]);
1086
1087 if ( codecForEnc->name() == KateDocumentConfig::global()->encoding() )
1088 {
1089 ui->cmbEncoding->setCurrentIndex(insert);
1090 }
1091
1092 if ( codecForEnc == KateGlobalConfig::global()->fallbackCodec() )
1093 {
1094 // adjust index for fallback config, has no default!
1095 ui->cmbEncodingFallback->setCurrentIndex(insert-1);
1096 }
1097
1098 insert++;
1099 }
1100 }
1101
1102 // encoding detection
1103 ui->cmbEncodingDetection->clear ();
1104 bool found = false;
1105 for (int i = 0; !KEncodingProber::nameForProberType ((KEncodingProber::ProberType) i).isEmpty(); ++i) {
1106 ui->cmbEncodingDetection->addItem (KEncodingProber::nameForProberType ((KEncodingProber::ProberType) i));
1107 if (i == KateGlobalConfig::global()->proberType()) {
1108 ui->cmbEncodingDetection->setCurrentIndex(ui->cmbEncodingDetection->count()-1);
1109 found = true;
1110 }
1111 }
1112 if (!found)
1113 ui->cmbEncodingDetection->setCurrentIndex(KEncodingProber::Universal);
1114
1115
1116 // eol
1117 ui->cmbEOL->setCurrentIndex(KateDocumentConfig::global()->eol());
1118 ui->chkDetectEOL->setChecked(KateDocumentConfig::global()->allowEolDetection());
1119 ui->chkEnableBOM->setChecked(KateDocumentConfig::global()->bom());
1120 ui->lineLengthLimit->setValue(KateDocumentConfig::global()->lineLengthLimit());
1121
1122 ui->cbRemoveTrailingSpaces->setCurrentIndex(KateDocumentConfig::global()->removeSpaces());
1123 ui->chkNewLineAtEof->setChecked(KateDocumentConfig::global()->newLineAtEof());
1124 uiadv->sbConfigFileSearchDepth->setValue(KateDocumentConfig::global()->searchDirConfigDepth());
1125
1126 // other stuff
1127 uint f ( KateDocumentConfig::global()->backupFlags() );
1128 uiadv->chkBackupLocalFiles->setChecked( f & KateDocumentConfig::LocalFiles );
1129 uiadv->chkBackupRemoteFiles->setChecked( f & KateDocumentConfig::RemoteFiles );
1130 uiadv->edtBackupPrefix->setText( KateDocumentConfig::global()->backupPrefix() );
1131 uiadv->edtBackupSuffix->setText( KateDocumentConfig::global()->backupSuffix() );
1132 uiadv->chkNoSync->setChecked( KateDocumentConfig::global()->swapFileNoSync() );
1133}
1134
1135void KateSaveConfigTab::reset()
1136{
1137 modeConfigPage->reset();
1138}
1139
1140void KateSaveConfigTab::defaults()
1141{
1142 modeConfigPage->defaults();
1143
1144 ui->cbRemoveTrailingSpaces->setCurrentIndex(0);
1145
1146 uiadv->chkBackupLocalFiles->setChecked( true );
1147 uiadv->chkBackupRemoteFiles->setChecked( false );
1148 uiadv->edtBackupPrefix->setText( "" );
1149 uiadv->edtBackupSuffix->setText( "~" );
1150 uiadv->chkNoSync->setChecked( false );
1151}
1152
1153//END KateSaveConfigTab
1154
1155//BEGIN KatePartPluginConfigPage
1156KatePartPluginConfigPage::KatePartPluginConfigPage (QWidget *parent)
1157 : KateConfigPage (parent, "")
1158{
1159 QVBoxLayout *layout = new QVBoxLayout;
1160 layout->setMargin(0);
1161
1162 plugins.clear();
1163
1164 int i = 0;
1165 foreach (const KatePartPluginInfo &info, KatePartPluginManager::self()->pluginList())
1166 {
1167 KPluginInfo it(info.service());
1168 it.setPluginEnabled(info.load);
1169 plugins.append(it);
1170 i++;
1171 }
1172
1173 selector = new KPluginSelector(0);
1174
1175 connect(selector, SIGNAL(changed(bool)), this, SLOT(slotChanged()));
1176 connect(selector, SIGNAL(configCommitted(QByteArray)), this, SLOT(slotChanged()));
1177
1178 selector->addPlugins(plugins, KPluginSelector::IgnoreConfigFile, i18n("Editor Plugins"), "Editor");
1179
1180 layout->addWidget(selector);
1181 setLayout(layout);
1182}
1183
1184KatePartPluginConfigPage::~KatePartPluginConfigPage ()
1185{
1186}
1187
1188void KatePartPluginConfigPage::apply ()
1189{
1190 selector->updatePluginsState();
1191
1192 KatePartPluginList &katePluginList = KatePartPluginManager::self()->pluginList();
1193 for (int i=0; i < plugins.count(); i++) {
1194 if (plugins[i].isPluginEnabled()) {
1195 if (!katePluginList[i].load) {
1196 KatePartPluginManager::self()->loadPlugin(katePluginList[i]);
1197 KatePartPluginManager::self()->enablePlugin(katePluginList[i]);
1198 }
1199 } else {
1200 if (katePluginList[i].load) {
1201 KatePartPluginManager::self()->disablePlugin(katePluginList[i]);
1202 KatePartPluginManager::self()->unloadPlugin(katePluginList[i]);
1203 }
1204 }
1205 }
1206}
1207
1208void KatePartPluginConfigPage::reload ()
1209{
1210 selector->load();
1211}
1212
1213void KatePartPluginConfigPage::reset ()
1214{
1215 selector->load();
1216}
1217
1218void KatePartPluginConfigPage::defaults ()
1219{
1220 selector->defaults();
1221}
1222//END KatePartPluginConfigPage
1223
1224
1225//BEGIN KateHlDownloadDialog
1226KateHlDownloadDialog::KateHlDownloadDialog(QWidget *parent, const char *name, bool modal)
1227 : KDialog( parent )
1228{
1229 setCaption( i18n("Highlight Download") );
1230 setButtons( User1 | Close );
1231 setButtonGuiItem( User1, KGuiItem(i18n("&Install")) );
1232 setDefaultButton( User1 );
1233 setObjectName( name );
1234 setModal( modal );
1235
1236 KVBox* vbox = new KVBox(this);
1237 setMainWidget(vbox);
1238 vbox->setSpacing(-1);
1239 new QLabel(i18n("Select the syntax highlighting files you want to update:"), vbox);
1240 list = new QTreeWidget(vbox);
1241 list->setColumnCount(4);
1242 list->setHeaderLabels(QStringList() << "" << i18n("Name") << i18n("Installed") << i18n("Latest"));
1243 list->setSelectionMode(QAbstractItemView::MultiSelection);
1244 list->setAllColumnsShowFocus(true);
1245 list->setRootIsDecorated(false);
1246 list->setColumnWidth(0, 22);
1247
1248 new QLabel(i18n("<b>Note:</b> New versions are selected automatically."), vbox);
1249 setButtonIcon(User1, KIcon("dialog-ok"));
1250
1251 transferJob = KIO::get(
1252 KUrl(QString(HLDOWNLOADPATH)
1253 + QString("update-")
1254 + KateGlobal::katePartVersion()
1255 + QString(".xml")), KIO::Reload );
1256 connect(transferJob, SIGNAL(data(KIO::Job*,QByteArray)),
1257 this, SLOT(listDataReceived(KIO::Job*,QByteArray)));
1258// void data( KIO::Job *, const QByteArray &data);
1259 resize(450, 400);
1260 connect(this,SIGNAL(user1Clicked()),this,SLOT(slotUser1()));
1261}
1262
1263KateHlDownloadDialog::~KateHlDownloadDialog(){}
1264
1265/// Split typical version string (\c major.minor.patch) into
1266/// numeric components, convert 'em to \c unsigned and form a
1267/// single value that can be compared w/ other versions
1268/// using relation operators.
1269/// \note It takes into account only first 3 numbers
1270unsigned KateHlDownloadDialog::parseVersion(const QString& version_string)
1271{
1272 unsigned vn[3] = {0, 0, 0};
1273 unsigned idx = 0;
1274 foreach (const QString& n, version_string.split("."))
1275 {
1276 vn[idx++] = n.toUInt();
1277 if (idx == sizeof(vn))
1278 break;
1279 }
1280 return KDE_MAKE_VERSION(vn[0], vn[1], vn[2]);
1281}
1282
1283void KateHlDownloadDialog::listDataReceived(KIO::Job *, const QByteArray &data)
1284{
1285 if (!transferJob || transferJob->isErrorPage())
1286 {
1287 enableButton( User1, false );
1288 if (data.size()==0)
1289 KMessageBox::error(this,i18n("The list of highlightings could not be found on / retrieved from the server"));
1290 return;
1291 }
1292
1293 listData+=QString(data);
1294 kDebug(13000)<<QString("CurrentListData: ")<<listData;
1295 kDebug(13000)<<QString("Data length: %1").arg(data.size());
1296 kDebug(13000)<<QString("listData length: %1").arg(listData.length());
1297 if (data.size()==0)
1298 {
1299 if (listData.length()>0)
1300 {
1301 QString installedVersion;
1302 KateHlManager *hlm=KateHlManager::self();
1303 QDomDocument doc;
1304 doc.setContent(listData);
1305 QDomElement DocElem=doc.documentElement();
1306 QDomNode n=DocElem.firstChild();
1307 KateHighlighting *hl = 0;
1308
1309 if (n.isNull()) kDebug(13000)<<"There is no usable childnode";
1310 while (!n.isNull())
1311 {
1312 installedVersion=" --";
1313
1314 QDomElement e=n.toElement();
1315 if (!e.isNull())
1316 kDebug(13000)<<QString("NAME: ")<<e.tagName()<<QString(" - ")<<e.attribute("name");
1317 n=n.nextSibling();
1318
1319 QString Name=e.attribute("name");
1320
1321 for (int i=0;i<hlm->highlights();i++)
1322 {
1323 hl=hlm->getHl(i);
1324 if (hl && hl->name()==Name)
1325 {
1326 installedVersion=" "+hl->version();
1327 break;
1328 }
1329 else hl = 0;
1330 }
1331
1332 // autoselect entry if new or updated.
1333 QTreeWidgetItem* entry = new QTreeWidgetItem(list);
1334 entry->setText(0, "");
1335 entry->setText(1, e.attribute("name"));
1336 entry->setText(2, installedVersion);
1337 entry->setText(3, e.attribute("version"));
1338 entry->setText(4, e.attribute("url"));
1339
1340 bool is_fresh = false;
1341 if (hl)
1342 {
1343 unsigned prev_version = parseVersion(hl->version());
1344 unsigned next_version = parseVersion(e.attribute("version"));
1345 is_fresh = prev_version < next_version;
1346 }
1347 else is_fresh = true;
1348 if (is_fresh)
1349 {
1350 entry->treeWidget()->setItemSelected(entry, true);
1351 entry->setIcon(0, SmallIcon(("get-hot-new-stuff")));
1352 }
1353 }
1354 list->resizeColumnToContents(1);
1355 list->sortItems(1, Qt::AscendingOrder);
1356 }
1357 }
1358}
1359
1360void KateHlDownloadDialog::slotUser1()
1361{
1362 QString destdir=KGlobal::dirs()->saveLocation("data","katepart/syntax/");
1363 foreach (QTreeWidgetItem *it, list->selectedItems())
1364 {
1365 KUrl src(it->text(4));
1366 QString filename=src.fileName(KUrl::ObeyTrailingSlash);
1367 QString dest = destdir+filename;
1368
1369 KIO::NetAccess::download(src,dest, this);
1370 }
1371
1372 // update Config !!
1373 // this rewrites the cache....
1374 KateSyntaxDocument doc (KateHlManager::self()->getKConfig(), true);
1375}
1376//END KateHlDownloadDialog
1377
1378//BEGIN KateGotoBar
1379KateGotoBar::KateGotoBar(KTextEditor::View *view, QWidget *parent)
1380 : KateViewBarWidget( true, parent )
1381 , m_view( view )
1382{
1383 Q_ASSERT( m_view != 0 ); // this bar widget is pointless w/o a view
1384
1385 QHBoxLayout *topLayout = new QHBoxLayout( centralWidget() );
1386 topLayout->setMargin(0);
1387 gotoRange = new KIntSpinBox(centralWidget());
1388
1389 QLabel *label = new QLabel(i18n("&Go to line:"), centralWidget() );
1390 label->setBuddy(gotoRange);
1391
1392 QToolButton *btnOK = new QToolButton(centralWidget());
1393 btnOK->setAutoRaise(true);
1394 btnOK->setIcon(QIcon(SmallIcon("go-jump")));
1395 btnOK->setText(i18n("Go"));
1396 btnOK->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
1397 connect(btnOK, SIGNAL(clicked()), this, SLOT(gotoLine()));
1398
1399 topLayout->addWidget(label);
1400 topLayout->addWidget(gotoRange, 1);
1401 topLayout->setStretchFactor( gotoRange, 0 );
1402 topLayout->addWidget(btnOK);
1403 topLayout->addStretch();
1404
1405 setFocusProxy(gotoRange);
1406}
1407
1408void KateGotoBar::updateData()
1409{
1410 gotoRange->setMaximum(m_view->document()->lines());
1411 if (!isVisible())
1412 {
1413 gotoRange->setValue(m_view->cursorPosition().line() + 1);
1414 gotoRange->adjustSize(); // ### does not respect the range :-(
1415 }
1416 gotoRange->setFocus(Qt::OtherFocusReason);
1417 gotoRange->selectAll();
1418}
1419
1420void KateGotoBar::keyPressEvent(QKeyEvent* event)
1421{
1422 int key = event->key();
1423 if (key == Qt::Key_Return || key == Qt::Key_Enter) {
1424 gotoLine();
1425 return;
1426 }
1427 KateViewBarWidget::keyPressEvent(event);
1428}
1429
1430void KateGotoBar::gotoLine()
1431{
1432 KateView *kv = qobject_cast<KateView*>(m_view);
1433 if (kv && kv->selection() && !kv->config()->persistentSelection()) {
1434 kv->clearSelection();
1435 }
1436
1437 m_view->setCursorPosition( KTextEditor::Cursor(gotoRange->value() - 1, 0) );
1438 m_view->setFocus();
1439 emit hideMe();
1440}
1441//END KateGotoBar
1442
1443//BEGIN KateDictionaryBar
1444KateDictionaryBar::KateDictionaryBar(KateView* view, QWidget *parent)
1445 : KateViewBarWidget( true, parent )
1446 , m_view( view )
1447{
1448 Q_ASSERT(m_view != 0); // this bar widget is pointless w/o a view
1449
1450 QHBoxLayout *topLayout = new QHBoxLayout(centralWidget());
1451 topLayout->setMargin(0);
1452 //topLayout->setSpacing(spacingHint());
1453 m_dictionaryComboBox = new Sonnet::DictionaryComboBox(centralWidget());
1454 connect(m_dictionaryComboBox, SIGNAL(dictionaryChanged(QString)),
1455 this, SLOT(dictionaryChanged(QString)));
1456 connect(view->doc(), SIGNAL(defaultDictionaryChanged(KateDocument*)),
1457 this, SLOT(updateData()));
1458 QLabel *label = new QLabel(i18n("Dictionary:"), centralWidget());
1459 label->setBuddy(m_dictionaryComboBox);
1460
1461 topLayout->addWidget(label);
1462 topLayout->addWidget(m_dictionaryComboBox, 1);
1463 topLayout->setStretchFactor(m_dictionaryComboBox, 0);
1464 topLayout->addStretch();
1465}
1466
1467KateDictionaryBar::~KateDictionaryBar()
1468{
1469}
1470
1471void KateDictionaryBar::updateData()
1472{
1473 KateDocument *document = m_view->doc();
1474 QString dictionary = document->defaultDictionary();
1475 if(dictionary.isEmpty()) {
1476 dictionary = Sonnet::Speller().defaultLanguage();
1477 }
1478 m_dictionaryComboBox->setCurrentByDictionary(dictionary);
1479}
1480
1481void KateDictionaryBar::dictionaryChanged(const QString& dictionary)
1482{
1483 KTextEditor::Range selection = m_view->selectionRange();
1484 if(selection.isValid() && !selection.isEmpty()) {
1485 m_view->doc()->setDictionary(dictionary, selection);
1486 }
1487 else {
1488 m_view->doc()->setDefaultDictionary(dictionary);
1489 }
1490}
1491
1492//END KateGotoBar
1493
1494
1495//BEGIN KateModOnHdPrompt
1496KateModOnHdPrompt::KateModOnHdPrompt( KateDocument *doc,
1497 KTextEditor::ModificationInterface::ModifiedOnDiskReason modtype,
1498 const QString &reason,
1499 QWidget *parent )
1500 : KDialog( parent ),
1501 m_doc( doc ),
1502 m_modtype ( modtype ),
1503 m_proc( 0 ),
1504 m_diffFile( 0 )
1505{
1506 setButtons( Ok | Apply | Cancel | User1 );
1507
1508 QString title, okText, okIcon, okToolTip;
1509 if ( modtype == KTextEditor::ModificationInterface::OnDiskDeleted )
1510 {
1511 title = i18n("File Was Deleted on Disk");
1512 okText = i18n("&Save File As...");
1513 okIcon = "document-save-as";
1514 okToolTip = i18n("Lets you select a location and save the file again.");
1515 } else {
1516 title = i18n("File Changed on Disk");
1517 okText = i18n("&Reload File");
1518 okIcon = "view-refresh";
1519 okToolTip = i18n("Reload the file from disk. If you have unsaved changes, "
1520 "they will be lost.");
1521 }
1522
1523 setButtonText( Ok, okText );
1524 setButtonIcon( Ok, KIcon( okIcon ) );
1525 setButtonText( Apply, i18n("&Ignore Changes") );
1526 setButtonIcon( Apply, KIcon( "dialog-warning" ) );
1527
1528 setButtonToolTip( Ok, okToolTip );
1529 setButtonToolTip( Apply, i18n("Ignore the changes. You will not be prompted again.") );
1530 setButtonToolTip( Cancel, i18n("Do nothing. Next time you focus the file, "
1531 "or try to save it or close it, you will be prompted again.") );
1532
1533 setCaption( title );
1534
1535 QWidget *w = new QWidget(this);
1536 ui = new Ui::ModOnHdWidget();
1537 ui->setupUi( w );
1538 setMainWidget( w );
1539
1540 ui->lblIcon->setPixmap( DesktopIcon("dialog-warning" ) );
1541 ui->lblText->setText( reason + "\n\n" + i18n("What do you want to do?") );
1542
1543 // If the file isn't deleted, present a diff button, and a overwrite action.
1544 if ( modtype != KTextEditor::ModificationInterface::OnDiskDeleted )
1545 {
1546 setButtonGuiItem( User1, KStandardGuiItem::overwrite() );
1547 setButtonToolTip( User1, i18n("Overwrite the disk file with the editor content.") );
1548 connect( ui->btnDiff, SIGNAL(clicked()), this, SLOT(slotDiff()) );
1549 }
1550 else
1551 {
1552 ui->chkIgnoreWhiteSpaces->setVisible( false );
1553 ui->btnDiff->setVisible( false );
1554 showButton( User1, false );
1555 }
1556}
1557
1558KateModOnHdPrompt::~KateModOnHdPrompt()
1559{
1560 delete m_proc;
1561 m_proc = 0;
1562 if (m_diffFile) {
1563 m_diffFile->setAutoRemove(true);
1564 delete m_diffFile;
1565 m_diffFile = 0;
1566 }
1567 delete ui;
1568}
1569
1570void KateModOnHdPrompt::slotDiff()
1571{
1572 if (m_diffFile)
1573 return;
1574
1575 m_diffFile = new KTemporaryFile();
1576 m_diffFile->open();
1577
1578 // Start a KProcess that creates a diff
1579 m_proc = new KProcess( this );
1580 m_proc->setOutputChannelMode( KProcess::MergedChannels );
1581 qDebug() << "diff" << QString(ui->chkIgnoreWhiteSpaces->isChecked() ? "-ub" : "-u")
1582 << "-" << m_doc->url().toLocalFile();
1583 *m_proc << "diff" << QString(ui->chkIgnoreWhiteSpaces->isChecked() ? "-ub" : "-u")
1584 << "-" << m_doc->url().toLocalFile();
1585 connect( m_proc, SIGNAL(readyRead()), this, SLOT(slotDataAvailable()) );
1586 connect( m_proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotPDone()) );
1587
1588 setCursor( Qt::WaitCursor );
1589 // disable the button and checkbox, to hinder the user to run it twice.
1590 ui->chkIgnoreWhiteSpaces->setEnabled( false );
1591 ui->btnDiff->setEnabled( false );
1592
1593 m_proc->start();
1594
1595 QTextStream ts(m_proc);
1596 int lastln = m_doc->lines() - 1;
1597 for ( int l = 0; l < lastln; ++l ) {
1598 ts << m_doc->line( l ) << '\n';
1599 }
1600 ts << m_doc->line(lastln);
1601 ts.flush();
1602 m_proc->closeWriteChannel();
1603}
1604
1605void KateModOnHdPrompt::slotDataAvailable()
1606{
1607 m_diffFile->write(m_proc->readAll());
1608}
1609
1610void KateModOnHdPrompt::slotPDone()
1611{
1612 setCursor( Qt::ArrowCursor );
1613 ui->chkIgnoreWhiteSpaces->setEnabled( true );
1614 ui->btnDiff->setEnabled( true );
1615
1616 const QProcess::ExitStatus es = m_proc->exitStatus();
1617 delete m_proc;
1618 m_proc = 0;
1619
1620 if ( es != QProcess::NormalExit )
1621 {
1622 KMessageBox::sorry( this,
1623 i18n("The diff command failed. Please make sure that "
1624 "diff(1) is installed and in your PATH."),
1625 i18n("Error Creating Diff") );
1626 delete m_diffFile;
1627 m_diffFile = 0;
1628 return;
1629 }
1630
1631 if ( m_diffFile->size() == 0 )
1632 {
1633 if (ui->chkIgnoreWhiteSpaces->isChecked()) {
1634 KMessageBox::information( this,
1635 i18n("The files are identical."),
1636 i18n("Diff Output") );
1637 } else {
1638 KMessageBox::information( this,
1639 i18n("Ignoring amount of white space changed, the files are identical."),
1640 i18n("Diff Output") );
1641 }
1642 delete m_diffFile;
1643 m_diffFile = 0;
1644 return;
1645 }
1646
1647 m_diffFile->setAutoRemove(false);
1648 KUrl url = KUrl::fromPath(m_diffFile->fileName());
1649 delete m_diffFile;
1650 m_diffFile = 0;
1651
1652 // KRun::runUrl should delete the file, once the client exits
1653 KRun::runUrl( url, "text/x-patch", this, true );
1654}
1655
1656void KateModOnHdPrompt::slotButtonClicked(int button)
1657{
1658 switch(button)
1659 {
1660 case Default:
1661 case Ok:
1662 done( (m_modtype == KTextEditor::ModificationInterface::OnDiskDeleted) ?
1663 Save : Reload );
1664 break;
1665 case Apply:
1666 {
1667 if ( KMessageBox::warningContinueCancel(
1668 this,
1669 i18n("Ignoring means that you will not be warned again (unless "
1670 "the disk file changes once more): if you save the document, you "
1671 "will overwrite the file on disk; if you do not save then the disk "
1672 "file (if present) is what you have."),
1673 i18n("You Are on Your Own"),
1674 KStandardGuiItem::cont(),
1675 KStandardGuiItem::cancel(),
1676 "kate_ignore_modonhd" ) != KMessageBox::Continue )
1677 return;
1678 done( Ignore );
1679 break;
1680 }
1681 case User1:
1682 done( Overwrite );
1683 break;
1684 default:
1685 KDialog::slotButtonClicked(button);
1686 }
1687}
1688
1689//END KateModOnHdPrompt
1690
1691// kate: space-indent on; indent-width 2; replace-tabs on;
1692