00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "katedialogs.h"
00028 #include "katedialogs.moc"
00029
00030 #include "kateautoindent.h"
00031 #include "katebuffer.h"
00032 #include "kateconfig.h"
00033 #include "katedocument.h"
00034 #include "kateglobal.h"
00035 #include "kateschema.h"
00036 #include "katesyntaxdocument.h"
00037 #include "katemodeconfigpage.h"
00038 #include "kateview.h"
00039 #include "katepartpluginmanager.h"
00040 #include "kpluginselector.h"
00041
00042
00043 #include "ui_modonhdwidget.h"
00044 #include "ui_appearanceconfigwidget.h"
00045 #include "ui_cursorconfigwidget.h"
00046 #include "ui_editconfigwidget.h"
00047 #include "ui_indentationconfigwidget.h"
00048 #include "ui_completionconfigtab.h"
00049 #include "ui_opensaveconfigwidget.h"
00050 #include "ui_opensaveconfigadvwidget.h"
00051
00052 #include <ktexteditor/plugin.h>
00053
00054 #include <kio/job.h>
00055 #include <kio/jobclasses.h>
00056 #include <kio/netaccess.h>
00057
00058 #include <kapplication.h>
00059 #include <kcharsets.h>
00060 #include <kcolorbutton.h>
00061 #include <kcolorcombo.h>
00062 #include <kcolordialog.h>
00063 #include <kcombobox.h>
00064 #include <kconfig.h>
00065 #include <kdebug.h>
00066 #include <kfontdialog.h>
00067 #include <kglobal.h>
00068 #include <kglobalsettings.h>
00069 #include <kiconloader.h>
00070 #include <kshortcutsdialog.h>
00071 #include <klineedit.h>
00072 #include <klocale.h>
00073 #include <kmessagebox.h>
00074 #include <kmimetypechooser.h>
00075 #include <knuminput.h>
00076 #include <kmenu.h>
00077 #include <kprocess.h>
00078 #include <krun.h>
00079 #include <kseparator.h>
00080 #include <kstandarddirs.h>
00081 #include <ktemporaryfile.h>
00082 #include <kpushbutton.h>
00083 #include <kvbox.h>
00084 #include <kactioncollection.h>
00085 #include <kplugininfo.h>
00086
00087 #include <ktabwidget.h>
00088
00089 #include <QtGui/QCheckBox>
00090 #include <QtGui/QComboBox>
00091 #include <QtGui/QDialog>
00092 #include <QtCore/QFile>
00093 #include <QtGui/QGroupBox>
00094 #include <QtGui/QLabel>
00095 #include <QtGui/QLayout>
00096 #include <QtGui/QLineEdit>
00097 #include <QtCore/QMap>
00098 #include <QtCore/QObject>
00099 #include <QtGui/QPainter>
00100 #include <QtGui/QRadioButton>
00101 #include <QtGui/QSlider>
00102 #include <QtGui/QSpinBox>
00103 #include <QtCore/QStringList>
00104 #include <QtGui/QTabWidget>
00105 #include <QtCore/QTextCodec>
00106 #include <QtCore/QTextStream>
00107 #include <QtGui/QToolButton>
00108 #include <QtGui/QWhatsThis>
00109 #include <QtGui/QKeyEvent>
00110 #include <QtXml/QDomDocument>
00111
00112
00113 #define HLDOWNLOADPATH "http://kate.kde.org/syntax/"
00114
00115
00116
00117
00118 KateConfigPage::KateConfigPage ( QWidget *parent, const char * )
00119 : KTextEditor::ConfigPage (parent)
00120 , m_changed (false)
00121 {
00122 connect (this, SIGNAL(changed()), this, SLOT(somethingHasChanged ()));
00123 }
00124
00125 KateConfigPage::~KateConfigPage ()
00126 {
00127 }
00128
00129 void KateConfigPage::slotChanged()
00130 {
00131 emit changed();
00132 }
00133
00134 void KateConfigPage::somethingHasChanged ()
00135 {
00136 m_changed = true;
00137 kDebug (13000) << "TEST: something changed on the config page: " << this;
00138 }
00139
00140
00141
00142 KateIndentConfigTab::KateIndentConfigTab(QWidget *parent)
00143 : KateConfigPage(parent)
00144 {
00145
00146
00147 QVBoxLayout *layout = new QVBoxLayout;
00148 QWidget *newWidget = new QWidget(this);
00149
00150 ui = new Ui::IndentationConfigWidget();
00151 ui->setupUi( newWidget );
00152
00153 ui->cmbMode->addItems (KateAutoIndent::listModes());
00154
00155 ui->label->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
00156 connect(ui->label, SIGNAL(linkActivated(const QString&)), this, SLOT(showWhatsThis(const QString&)));
00157
00158
00159
00160 reload ();
00161
00162
00163
00164
00165
00166 connect(ui->cmbMode, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00167
00168 connect(ui->chkKeepExtraSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00169 connect(ui->chkIndentPaste, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00170 connect(ui->chkBackspaceUnindents, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00171
00172 connect(ui->sbIndentWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00173
00174 connect(ui->rbTabAdvances, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00175 connect(ui->rbTabIndents, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00176 connect(ui->rbTabSmart, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00177
00178 layout->addWidget(newWidget);
00179 setLayout(layout);
00180 }
00181
00182 KateIndentConfigTab::~KateIndentConfigTab()
00183 {
00184 delete ui;
00185 }
00186
00187 void KateIndentConfigTab::showWhatsThis(const QString& text)
00188 {
00189 QWhatsThis::showText(QCursor::pos(), text);
00190 }
00191
00192 void KateIndentConfigTab::apply ()
00193 {
00194
00195 if (!hasChanged())
00196 return;
00197 m_changed = false;
00198
00199 KateDocumentConfig::global()->configStart ();
00200
00201 uint configFlags = KateDocumentConfig::global()->configFlags();
00202
00203 configFlags &= ~KateDocumentConfig::cfKeepExtraSpaces;
00204 configFlags &= ~KateDocumentConfig::cfIndentPastedText;
00205 configFlags &= ~KateDocumentConfig::cfBackspaceIndents;
00206
00207 if (ui->chkKeepExtraSpaces->isChecked()) configFlags |= KateDocumentConfig::cfKeepExtraSpaces;
00208 if (ui->chkIndentPaste->isChecked()) configFlags |= KateDocumentConfig::cfIndentPastedText;
00209 if (ui->chkBackspaceUnindents->isChecked()) configFlags |= KateDocumentConfig::cfBackspaceIndents;
00210
00211 KateDocumentConfig::global()->setConfigFlags(configFlags);
00212 KateDocumentConfig::global()->setIndentationWidth(ui->sbIndentWidth->value());
00213 KateDocumentConfig::global()->setIndentationMode(KateAutoIndent::modeName(ui->cmbMode->currentIndex()));
00214
00215 if (ui->rbTabAdvances->isChecked())
00216 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabInsertsTab );
00217 else if (ui->rbTabIndents->isChecked())
00218 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabIndents );
00219 else
00220 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabSmart );
00221
00222 KateDocumentConfig::global()->configEnd ();
00223 }
00224
00225 void KateIndentConfigTab::reload ()
00226 {
00227 uint configFlags = KateDocumentConfig::global()->configFlags();
00228
00229 ui->sbIndentWidth->setValue(KateDocumentConfig::global()->indentationWidth());
00230 ui->chkKeepExtraSpaces->setChecked(configFlags & KateDocumentConfig::cfKeepExtraSpaces);
00231 ui->chkIndentPaste->setChecked(configFlags & KateDocumentConfig::cfIndentPastedText);
00232 ui->chkBackspaceUnindents->setChecked(configFlags & KateDocumentConfig::cfBackspaceIndents);
00233
00234 ui->rbTabAdvances->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabInsertsTab );
00235 ui->rbTabIndents->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabIndents );
00236 ui->rbTabSmart->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabSmart );
00237
00238 ui->cmbMode->setCurrentIndex (KateAutoIndent::modeNumber (KateDocumentConfig::global()->indentationMode()));
00239 }
00240
00241
00242
00243 KateCompletionConfigTab::KateCompletionConfigTab(QWidget *parent)
00244 : KateConfigPage(parent)
00245 {
00246
00247
00248 QVBoxLayout *layout = new QVBoxLayout;
00249 QWidget *newWidget = new QWidget(this);
00250
00251 ui = new Ui::CompletionConfigTab ();
00252 ui->setupUi( newWidget );
00253
00254
00255
00256 reload ();
00257
00258
00259
00260
00261
00262 connect(ui->chkAutoCompletionEnabled, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00263
00264 layout->addWidget(newWidget);
00265 setLayout(layout);
00266 }
00267
00268 KateCompletionConfigTab::~KateCompletionConfigTab()
00269 {
00270 delete ui;
00271 }
00272
00273 void KateCompletionConfigTab::showWhatsThis(const QString& text)
00274 {
00275 QWhatsThis::showText(QCursor::pos(), text);
00276 }
00277
00278 void KateCompletionConfigTab::apply ()
00279 {
00280
00281 if (!hasChanged())
00282 return;
00283 m_changed = false;
00284
00285 KateViewConfig::global()->configStart ();
00286 KateViewConfig::global()->setAutomaticCompletionInvocation (ui->chkAutoCompletionEnabled->isChecked());
00287 KateViewConfig::global()->configEnd ();
00288 }
00289
00290 void KateCompletionConfigTab::reload ()
00291 {
00292 ui->chkAutoCompletionEnabled->setChecked( KateViewConfig::global()->automaticCompletionInvocation () );
00293 }
00294
00295
00296
00297 KateSelectConfigTab::KateSelectConfigTab(QWidget *parent)
00298 : KateConfigPage(parent)
00299 {
00300
00301
00302 QVBoxLayout *layout = new QVBoxLayout;
00303 QWidget *newWidget = new QWidget(this);
00304
00305 uint configFlags = KateDocumentConfig::global()->configFlags();
00306
00307 ui = new Ui::CursorConfigWidget();
00308 ui->setupUi( newWidget );
00309
00310 ui->chkSmartHome->setChecked(configFlags & KateDocumentConfig::cfSmartHome);
00311 connect(ui->chkSmartHome, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00312
00313 ui->chkWrapCursor->setChecked(configFlags & KateDocumentConfig::cfWrapCursor);
00314 connect(ui->chkWrapCursor, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00315
00316 ui->chkPagingMovesCursor->setChecked(KateDocumentConfig::global()->pageUpDownMovesCursor());
00317 connect(ui->chkPagingMovesCursor, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00318
00319 ui->sbAutoCenterCursor->setValue(KateViewConfig::global()->autoCenterLines());
00320 connect(ui->sbAutoCenterCursor, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00321
00322
00323
00324 reload ();
00325
00326
00327
00328
00329
00330 connect(ui->rbNormal, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00331 connect(ui->rbPersistent, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00332
00333 layout->addWidget(newWidget);
00334 setLayout(layout);
00335 }
00336
00337 KateSelectConfigTab::~KateSelectConfigTab()
00338 {
00339 delete ui;
00340 }
00341
00342 void KateSelectConfigTab::apply ()
00343 {
00344
00345 if (!hasChanged())
00346 return;
00347 m_changed = false;
00348
00349 KateViewConfig::global()->configStart ();
00350 KateDocumentConfig::global()->configStart ();
00351
00352 uint configFlags = KateDocumentConfig::global()->configFlags();
00353
00354 configFlags &= ~KateDocumentConfig::cfSmartHome;
00355 configFlags &= ~KateDocumentConfig::cfWrapCursor;
00356
00357 if (ui->chkSmartHome->isChecked()) configFlags |= KateDocumentConfig::cfSmartHome;
00358 if (ui->chkWrapCursor->isChecked()) configFlags |= KateDocumentConfig::cfWrapCursor;
00359
00360 KateDocumentConfig::global()->setConfigFlags(configFlags);
00361
00362 KateViewConfig::global()->setAutoCenterLines(qMax(0, ui->sbAutoCenterCursor->value()));
00363 KateDocumentConfig::global()->setPageUpDownMovesCursor(ui->chkPagingMovesCursor->isChecked());
00364
00365 KateViewConfig::global()->setPersistentSelection (ui->rbPersistent->isChecked());
00366
00367 KateDocumentConfig::global()->configEnd ();
00368 KateViewConfig::global()->configEnd ();
00369 }
00370
00371 void KateSelectConfigTab::reload ()
00372 {
00373 ui->rbNormal->setChecked( ! KateViewConfig::global()->persistentSelection() );
00374 ui->rbPersistent->setChecked( KateViewConfig::global()->persistentSelection() );
00375 }
00376
00377
00378
00379 KateEditConfigTab::KateEditConfigTab(QWidget *parent)
00380 : KateConfigPage(parent)
00381 , selectConfigTab(new KateSelectConfigTab(this))
00382 , indentConfigTab(new KateIndentConfigTab(this))
00383 , completionConfigTab (new KateCompletionConfigTab(this))
00384 {
00385
00386
00387
00388
00389 QVBoxLayout *layout = new QVBoxLayout;
00390 layout->setMargin(0);
00391 KTabWidget *tabWidget = new KTabWidget(this);
00392 uint configFlags = KateDocumentConfig::global()->configFlags();
00393
00394 QWidget *tmpWidget = new QWidget(tabWidget);
00395 QVBoxLayout *internalLayout = new QVBoxLayout;
00396 QWidget *newWidget = new QWidget(tabWidget);
00397 ui = new Ui::EditConfigWidget();
00398 ui->setupUi( newWidget );
00399
00400 ui->chkReplaceTabs->setChecked( configFlags & KateDocumentConfig::cfReplaceTabsDyn );
00401 connect( ui->chkReplaceTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
00402
00403 ui->chkShowTabs->setChecked( configFlags & KateDocumentConfig::cfShowTabs );
00404 connect(ui->chkShowTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00405
00406 ui->chkShowSpaces->setChecked( configFlags & KateDocumentConfig::cfShowSpaces );
00407 connect(ui->chkShowSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00408
00409 ui->sbTabWidth->setValue( KateDocumentConfig::global()->tabWidth() );
00410 connect(ui->sbTabWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00411
00412
00413 ui->chkStaticWordWrap->setChecked(KateDocumentConfig::global()->wordWrap());
00414 connect(ui->chkStaticWordWrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00415
00416 ui->chkShowStaticWordWrapMarker->setChecked( KateRendererConfig::global()->wordWrapMarker() );
00417 connect(ui->chkShowStaticWordWrapMarker, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00418
00419 ui->sbWordWrap->setValue( KateDocumentConfig::global()->wordWrapAt() );
00420 connect(ui->sbWordWrap, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00421
00422
00423 ui->chkRemoveTrailingSpaces->setChecked( configFlags & KateDocumentConfig::cfRemoveTrailingDyn );
00424 connect( ui->chkRemoveTrailingSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
00425
00426 ui->chkAutoBrackets->setChecked( configFlags & KateDocumentConfig::cfAutoBrackets );
00427 connect(ui->chkAutoBrackets, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00428
00429
00430
00431 internalLayout->addWidget(newWidget);
00432 tmpWidget->setLayout(internalLayout);
00433
00434
00435 tabWidget->insertTab(0, tmpWidget, i18n("General"));
00436 tabWidget->insertTab(1, selectConfigTab, i18n("Cursor & Selection"));
00437 tabWidget->insertTab(2, indentConfigTab, i18n("Indentation"));
00438 tabWidget->insertTab(3, completionConfigTab, i18n("Auto Completion"));
00439
00440 connect(selectConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
00441 connect(indentConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
00442 connect(completionConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
00443
00444 layout->addWidget(tabWidget);
00445 setLayout(layout);
00446 }
00447
00448 KateEditConfigTab::~KateEditConfigTab()
00449 {
00450 delete ui;
00451 }
00452
00453 void KateEditConfigTab::apply ()
00454 {
00455
00456 selectConfigTab->apply();
00457 indentConfigTab->apply();
00458 completionConfigTab->apply();
00459
00460
00461 if (!hasChanged())
00462 return;
00463 m_changed = false;
00464
00465 KateViewConfig::global()->configStart ();
00466 KateDocumentConfig::global()->configStart ();
00467
00468 uint configFlags = KateDocumentConfig::global()->configFlags();
00469
00470 configFlags &= ~KateDocumentConfig::cfAutoBrackets;
00471 configFlags &= ~KateDocumentConfig::cfShowTabs;
00472 configFlags &= ~KateDocumentConfig::cfShowSpaces;
00473 configFlags &= ~KateDocumentConfig::cfReplaceTabsDyn;
00474 configFlags &= ~KateDocumentConfig::cfRemoveTrailingDyn;
00475
00476 if (ui->chkAutoBrackets->isChecked()) configFlags |= KateDocumentConfig::cfAutoBrackets;
00477 if (ui->chkShowTabs->isChecked()) configFlags |= KateDocumentConfig::cfShowTabs;
00478 if (ui->chkShowSpaces->isChecked()) configFlags |= KateDocumentConfig::cfShowSpaces;
00479 if (ui->chkReplaceTabs->isChecked()) configFlags |= KateDocumentConfig::cfReplaceTabsDyn;
00480 if (ui->chkRemoveTrailingSpaces->isChecked()) configFlags |= KateDocumentConfig::cfRemoveTrailingDyn;
00481
00482 KateDocumentConfig::global()->setConfigFlags(configFlags);
00483
00484 KateDocumentConfig::global()->setWordWrapAt(ui->sbWordWrap->value());
00485 KateDocumentConfig::global()->setWordWrap(ui->chkStaticWordWrap->isChecked());
00486 KateDocumentConfig::global()->setTabWidth(ui->sbTabWidth->value());
00487
00488 KateRendererConfig::global()->setWordWrapMarker (ui->chkShowStaticWordWrapMarker->isChecked());
00489
00490 KateDocumentConfig::global()->configEnd ();
00491 KateViewConfig::global()->configEnd ();
00492 }
00493
00494 void KateEditConfigTab::reload ()
00495 {
00496 selectConfigTab->reload();
00497 indentConfigTab->reload();
00498 completionConfigTab->reload();
00499 }
00500
00501 void KateEditConfigTab::reset ()
00502 {
00503 selectConfigTab->reset();
00504 indentConfigTab->reset();
00505 completionConfigTab->reset();
00506 }
00507
00508 void KateEditConfigTab::defaults ()
00509 {
00510 selectConfigTab->defaults();
00511 indentConfigTab->defaults();
00512 completionConfigTab->defaults();
00513 }
00514
00515
00516
00517 KateViewDefaultsConfig::KateViewDefaultsConfig(QWidget *parent)
00518 :KateConfigPage(parent)
00519 {
00520 ui = new Ui::AppearanceConfigWidget();
00521 ui->setupUi( this );
00522
00523 if (KateDocument::simpleMode ())
00524 ui->gbSortBookmarks->hide ();
00525
00526 ui->cmbDynamicWordWrapIndicator->addItem( i18n("Off") );
00527 ui->cmbDynamicWordWrapIndicator->addItem( i18n("Follow Line Numbers") );
00528 ui->cmbDynamicWordWrapIndicator->addItem( i18n("Always On") );
00529
00530 ui->chkShowIndentationLines->setChecked(KateRendererConfig::global()->showIndentationLines());
00531 ui->chkShowWholeBracketExpression->setChecked(KateRendererConfig::global()->showWholeBracketExpression());
00532
00533
00534
00535 reload();
00536
00537
00538
00539
00540
00541 connect(ui->chkDynamicWordWrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00542 connect(ui->cmbDynamicWordWrapIndicator, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00543 connect(ui->sbDynamicWordWrapDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00544 connect(ui->chkIconBorder, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00545 connect(ui->chkScrollbarMarks, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00546 connect(ui->chkLineNumbers, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00547 connect(ui->chkShowFoldingMarkers, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00548 connect(ui->rbSortBookmarksByPosition, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00549 connect(ui->rbSortBookmarksByCreation, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00550 connect(ui->chkShowIndentationLines, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00551 connect(ui->chkShowWholeBracketExpression, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00552 connect(ui->chkDeveloperMode, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00553 }
00554
00555 KateViewDefaultsConfig::~KateViewDefaultsConfig()
00556 {
00557 delete ui;
00558 }
00559
00560 void KateViewDefaultsConfig::apply ()
00561 {
00562
00563 if (!hasChanged())
00564 return;
00565 m_changed = false;
00566
00567 KateViewConfig::global()->configStart ();
00568 KateRendererConfig::global()->configStart ();
00569
00570 KateViewConfig::global()->setDynWordWrap (ui->chkDynamicWordWrap->isChecked());
00571 KateViewConfig::global()->setDynWordWrapIndicators (ui->cmbDynamicWordWrapIndicator->currentIndex ());
00572 KateViewConfig::global()->setDynWordWrapAlignIndent(ui->sbDynamicWordWrapDepth->value());
00573 KateViewConfig::global()->setLineNumbers (ui->chkLineNumbers->isChecked());
00574 KateViewConfig::global()->setIconBar (ui->chkIconBorder->isChecked());
00575 KateViewConfig::global()->setScrollBarMarks (ui->chkScrollbarMarks->isChecked());
00576 KateViewConfig::global()->setFoldingBar (ui->chkShowFoldingMarkers->isChecked());
00577
00578 KateViewConfig::global()->setBookmarkSort (ui->rbSortBookmarksByPosition->isChecked()?0:1);
00579 KateRendererConfig::global()->setShowIndentationLines(ui->chkShowIndentationLines->isChecked());
00580 KateRendererConfig::global()->setShowWholeBracketExpression(ui->chkShowWholeBracketExpression->isChecked());
00581
00582 KateDocumentConfig::global()->setAllowSimpleMode (!ui->chkDeveloperMode->isChecked());
00583
00584 KateRendererConfig::global()->configEnd ();
00585 KateViewConfig::global()->configEnd ();
00586 }
00587
00588 void KateViewDefaultsConfig::reload ()
00589 {
00590 ui->chkDynamicWordWrap->setChecked(KateViewConfig::global()->dynWordWrap());
00591 ui->cmbDynamicWordWrapIndicator->setCurrentIndex( KateViewConfig::global()->dynWordWrapIndicators() );
00592 ui->sbDynamicWordWrapDepth->setValue(KateViewConfig::global()->dynWordWrapAlignIndent());
00593 ui->chkLineNumbers->setChecked(KateViewConfig::global()->lineNumbers());
00594 ui->chkIconBorder->setChecked(KateViewConfig::global()->iconBar());
00595 ui->chkScrollbarMarks->setChecked(KateViewConfig::global()->scrollBarMarks());
00596 ui->chkShowFoldingMarkers->setChecked(KateViewConfig::global()->foldingBar());
00597 ui->rbSortBookmarksByPosition->setChecked(KateViewConfig::global()->bookmarkSort()==0);
00598 ui->rbSortBookmarksByCreation->setChecked(KateViewConfig::global()->bookmarkSort()==1);
00599 ui->chkShowIndentationLines->setChecked(KateRendererConfig::global()->showIndentationLines());
00600 ui->chkShowWholeBracketExpression->setChecked(KateRendererConfig::global()->showWholeBracketExpression());
00601 ui->chkDeveloperMode->setChecked(!KateDocumentConfig::global()->allowSimpleMode());
00602 }
00603
00604 void KateViewDefaultsConfig::reset () {;}
00605
00606 void KateViewDefaultsConfig::defaults (){;}
00607
00608
00609
00610
00611 KateEditKeyConfiguration::KateEditKeyConfiguration( QWidget* parent)
00612 : KateConfigPage( parent )
00613 , m_ready(false)
00614 {
00615 m_doc = new KateDocument();
00616 m_view = new KateView(m_doc, 0);
00617 }
00618
00619 KateEditKeyConfiguration::~KateEditKeyConfiguration()
00620 {
00621 delete m_view;
00622 delete m_doc;
00623 }
00624
00625 void KateEditKeyConfiguration::showEvent ( QShowEvent * )
00626 {
00627 if (!m_ready)
00628 {
00629 m_actionCollection = m_view->editActionCollection();
00630
00631 QVBoxLayout *layout = new QVBoxLayout(this);
00632 layout->addWidget(m_shortcutsEditor = new KShortcutsEditor( m_actionCollection, this, false ));
00633 connect( m_shortcutsEditor, SIGNAL( keyChange() ), this, SLOT( slotChanged() ) );
00634
00635 m_shortcutsEditor->show ();
00636
00637 m_ready = true;
00638 }
00639
00640 QWidget::show ();
00641 }
00642
00643 void KateEditKeyConfiguration::apply()
00644 {
00645 if(!hasChanged())
00646 return;
00647 m_changed = false;
00648
00649 if (m_ready)
00650 {
00651 KateViewConfig::global()->configStart ();
00652 m_actionCollection->writeSettings();
00653 KateViewConfig::global()->configEnd ();
00654 }
00655 }
00656
00657
00658
00659 KateSaveConfigTab::KateSaveConfigTab( QWidget *parent )
00660 : KateConfigPage( parent )
00661 , modeConfigPage( new ModeConfigPage( this ) )
00662 {
00663
00664
00665
00666 QVBoxLayout *layout = new QVBoxLayout;
00667 layout->setMargin(0);
00668 KTabWidget *tabWidget = new KTabWidget(this);
00669
00670 QWidget *tmpWidget = new QWidget(tabWidget);
00671 QVBoxLayout *internalLayout = new QVBoxLayout;
00672 QWidget *newWidget = new QWidget(tabWidget);
00673 ui = new Ui::OpenSaveConfigWidget();
00674 ui->setupUi( newWidget );
00675
00676 QWidget *tmpWidget2 = new QWidget(tabWidget);
00677 QVBoxLayout *internalLayout2 = new QVBoxLayout;
00678 QWidget *newWidget2 = new QWidget(tabWidget);
00679 uiadv = new Ui::OpenSaveConfigAdvWidget();
00680 uiadv->setupUi( newWidget2 );
00681
00682
00683 reload();
00684
00685
00686
00687
00688
00689 connect( ui->cmbEncoding, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00690 connect( ui->cmbEncodingDetection, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00691 connect( ui->cmbEOL, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00692 connect( ui->chkDetectEOL, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
00693 connect( ui->chkRemoveTrailingSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00694 connect( uiadv->chkBackupLocalFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
00695 connect( uiadv->chkBackupRemoteFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
00696 connect( uiadv->sbConfigFileSearchDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00697 connect( uiadv->edtBackupPrefix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00698 connect( uiadv->edtBackupSuffix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00699
00700 internalLayout->addWidget(newWidget);
00701 tmpWidget->setLayout(internalLayout);
00702 internalLayout2->addWidget(newWidget2);
00703 tmpWidget2->setLayout(internalLayout2);
00704
00705
00706 tabWidget->insertTab(0, tmpWidget, i18n("General"));
00707 tabWidget->insertTab(1, tmpWidget2, i18n("Advanced"));
00708 tabWidget->insertTab(2, modeConfigPage, i18n("Modes & Filetypes"));
00709
00710 connect(modeConfigPage, SIGNAL(changed()), this, SLOT(slotChanged()));
00711
00712 layout->addWidget(tabWidget);
00713 setLayout(layout);
00714 }
00715
00716 KateSaveConfigTab::~KateSaveConfigTab()
00717 {
00718 delete ui;
00719 }
00720
00721 void KateSaveConfigTab::apply()
00722 {
00723 modeConfigPage->apply();
00724
00725
00726 if (!hasChanged())
00727 return;
00728 m_changed = false;
00729
00730 KateDocumentConfig::global()->configStart ();
00731
00732 if ( uiadv->edtBackupSuffix->text().isEmpty() && uiadv->edtBackupPrefix->text().isEmpty() ) {
00733 KMessageBox::information(
00734 this,
00735 i18n("You did not provide a backup suffix or prefix. Using default suffix: '~'"),
00736 i18n("No Backup Suffix or Prefix")
00737 );
00738 uiadv->edtBackupSuffix->setText( "~" );
00739 }
00740
00741 uint f( 0 );
00742 if ( uiadv->chkBackupLocalFiles->isChecked() )
00743 f |= KateDocumentConfig::LocalFiles;
00744 if ( uiadv->chkBackupRemoteFiles->isChecked() )
00745 f |= KateDocumentConfig::RemoteFiles;
00746
00747 KateDocumentConfig::global()->setBackupFlags(f);
00748 KateDocumentConfig::global()->setBackupPrefix(uiadv->edtBackupPrefix->text());
00749 KateDocumentConfig::global()->setBackupSuffix(uiadv->edtBackupSuffix->text());
00750
00751 KateDocumentConfig::global()->setSearchDirConfigDepth(uiadv->sbConfigFileSearchDepth->value());
00752
00753 uint configFlags = KateDocumentConfig::global()->configFlags();
00754
00755 configFlags &= ~KateDocumentConfig::cfRemoveSpaces;
00756 if (ui->chkRemoveTrailingSpaces->isChecked()) configFlags |= KateDocumentConfig::cfRemoveSpaces;
00757
00758 KateDocumentConfig::global()->setConfigFlags(configFlags);
00759
00760 KateDocumentConfig::global()->setEncoding((ui->cmbEncoding->currentIndex() == 0) ? "" : KGlobal::charsets()->encodingForName(ui->cmbEncoding->currentText()));
00761 KateDocumentConfig::global()->setEncodingAutoDetectionScript(
00762 (KEncodingDetector::AutoDetectScript)ui->cmbEncodingDetection->itemData(ui->cmbEncodingDetection->currentIndex()).toUInt());
00763
00764 KateDocumentConfig::global()->setEol(ui->cmbEOL->currentIndex());
00765 KateDocumentConfig::global()->setAllowEolDetection(ui->chkDetectEOL->isChecked());
00766
00767 KateDocumentConfig::global()->configEnd ();
00768 }
00769
00770 void KateSaveConfigTab::reload()
00771 {
00772 modeConfigPage->reload();
00773
00774
00775 ui->cmbEncoding->clear ();
00776 ui->cmbEncoding->addItem (i18n("KDE Default"));
00777 ui->cmbEncoding->setCurrentIndex(0);
00778 QStringList encodings (KGlobal::charsets()->descriptiveEncodingNames());
00779 int insert = 1;
00780 for (int i=0; i < encodings.count(); i++)
00781 {
00782 bool found = false;
00783 QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(KGlobal::charsets()->encodingForName(encodings[i]), found);
00784
00785 if (found)
00786 {
00787 ui->cmbEncoding->addItem (encodings[i]);
00788
00789 if ( codecForEnc->name() == KateDocumentConfig::global()->encoding() )
00790 {
00791 ui->cmbEncoding->setCurrentIndex(insert);
00792 }
00793
00794 insert++;
00795 }
00796 }
00797
00798
00799 ui->cmbEncodingDetection->clear ();
00800 ui->cmbEncodingDetection->addItem (i18n("Disabled"));
00801 ui->cmbEncodingDetection->setCurrentIndex(0);
00802
00803 foreach(const QStringList &encodingsForScript, KGlobal::charsets()->encodingsByScript())
00804 {
00805 KEncodingDetector::AutoDetectScript scri=KEncodingDetector::scriptForName(encodingsForScript.at(0));
00806 if (KEncodingDetector::hasAutoDetectionForScript(scri))
00807 {
00808 ui->cmbEncodingDetection->addItem (encodingsForScript.at(0),QVariant((uint)scri));
00809 if (scri==KateDocumentConfig::global()->encodingAutoDetectionScript())
00810 ui->cmbEncodingDetection->setCurrentIndex(ui->cmbEncodingDetection->count()-1);
00811 }
00812 }
00813
00814
00815 ui->cmbEOL->setCurrentIndex(KateDocumentConfig::global()->eol());
00816 ui->chkDetectEOL->setChecked(KateDocumentConfig::global()->allowEolDetection());
00817
00818 const uint configFlags = KateDocumentConfig::global()->configFlags();
00819 ui->chkRemoveTrailingSpaces->setChecked(configFlags & KateDocumentConfig::cfRemoveSpaces);
00820 uiadv->sbConfigFileSearchDepth->setValue(KateDocumentConfig::global()->searchDirConfigDepth());
00821
00822
00823 uint f ( KateDocumentConfig::global()->backupFlags() );
00824 uiadv->chkBackupLocalFiles->setChecked( f & KateDocumentConfig::LocalFiles );
00825 uiadv->chkBackupRemoteFiles->setChecked( f & KateDocumentConfig::RemoteFiles );
00826 uiadv->edtBackupPrefix->setText( KateDocumentConfig::global()->backupPrefix() );
00827 uiadv->edtBackupSuffix->setText( KateDocumentConfig::global()->backupSuffix() );
00828 }
00829
00830 void KateSaveConfigTab::reset()
00831 {
00832 modeConfigPage->reset();
00833 }
00834
00835 void KateSaveConfigTab::defaults()
00836 {
00837 modeConfigPage->defaults();
00838
00839 uiadv->chkBackupLocalFiles->setChecked( true );
00840 uiadv->chkBackupRemoteFiles->setChecked( false );
00841 uiadv->edtBackupPrefix->setText( "" );
00842 uiadv->edtBackupSuffix->setText( "~" );
00843 }
00844
00845
00846
00847
00848 KatePartPluginConfigPage::KatePartPluginConfigPage (QWidget *parent)
00849 : KateConfigPage (parent, "")
00850 , scriptConfigPage (new KateScriptConfigPage(this))
00851 {
00852
00853
00854
00855 QVBoxLayout *generalLayout = new QVBoxLayout;
00856 generalLayout->setMargin(0);
00857 KTabWidget *tabWidget = new KTabWidget(this);
00858
00859 QWidget *tmpWidget = new QWidget(tabWidget);
00860 QVBoxLayout *internalLayout = new QVBoxLayout;
00861 QWidget *newWidget = new QWidget(tabWidget);
00862 QVBoxLayout *layout = new QVBoxLayout;
00863 newWidget->setLayout(layout);
00864 layout->setMargin(0);
00865
00866 plugins.clear();
00867
00868 int i = 0;
00869 foreach (const KatePartPluginInfo &info, KatePartPluginManager::self()->pluginList())
00870 {
00871 KPluginInfo it(info.service);
00872 it.setPluginEnabled(info.load);
00873 plugins.append(it);
00874 i++;
00875 }
00876
00877 selector = new KPluginSelector(0);
00878
00879 connect(selector, SIGNAL(changed(bool)), this, SLOT(slotChanged()));
00880 connect(selector, SIGNAL(configCommitted(QByteArray)), this, SLOT(slotChanged()));
00881
00882 selector->addPlugins(plugins, KPluginSelector::IgnoreConfigFile, i18n("Editor Plugins"), "Editor");
00883 layout->addWidget(selector);
00884
00885 internalLayout->addWidget(newWidget);
00886 tmpWidget->setLayout(internalLayout);
00887
00888
00889 tabWidget->insertTab(0, tmpWidget, i18n("Plugins"));
00890 tabWidget->insertTab(1, scriptConfigPage, i18n("Scripts"));
00891
00892 generalLayout->addWidget(tabWidget);
00893 setLayout(generalLayout);
00894 }
00895
00896 KatePartPluginConfigPage::~KatePartPluginConfigPage ()
00897 {
00898 }
00899
00900 void KatePartPluginConfigPage::apply ()
00901 {
00902 scriptConfigPage->apply();
00903
00904 selector->updatePluginsState();
00905
00906 KatePartPluginList &katePluginList = KatePartPluginManager::self()->pluginList();
00907 for (int i=0; i < plugins.count(); i++) {
00908 if (plugins[i].isPluginEnabled()) {
00909 if (!katePluginList[i].load) {
00910 KatePartPluginManager::self()->loadPlugin(katePluginList[i]);
00911 KatePartPluginManager::self()->enablePlugin(katePluginList[i]);
00912 }
00913 } else {
00914 if (katePluginList[i].load) {
00915 KatePartPluginManager::self()->disablePlugin(katePluginList[i]);
00916 KatePartPluginManager::self()->unloadPlugin(katePluginList[i]);
00917 }
00918 }
00919 }
00920 }
00921
00922 void KatePartPluginConfigPage::reload ()
00923 {
00924 scriptConfigPage->reload();
00925
00926 selector->load();
00927 }
00928
00929 void KatePartPluginConfigPage::reset ()
00930 {
00931 scriptConfigPage->reset();
00932
00933 selector->load();
00934 }
00935
00936 void KatePartPluginConfigPage::defaults ()
00937 {
00938 scriptConfigPage->defaults();
00939
00940 selector->defaults();
00941 }
00942
00943
00944 class KateScriptNewStuff {};
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956 KateScriptConfigPage::KateScriptConfigPage(QWidget *parent): KateConfigPage(parent,""), m_newStuff(new KateScriptNewStuff())
00957 {
00958
00959
00960
00961
00962
00963 }
00964
00965 KateScriptConfigPage::~KateScriptConfigPage()
00966 {
00967 delete m_newStuff;
00968 m_newStuff=0;
00969 }
00970
00971 void KateScriptConfigPage::apply () {
00972 }
00973 void KateScriptConfigPage::reload () {
00974 }
00975
00976
00977
00978
00979 KateHlDownloadDialog::KateHlDownloadDialog(QWidget *parent, const char *name, bool modal)
00980 : KDialog( parent )
00981 {
00982 setCaption( i18n("Highlight Download") );
00983 setButtons( User1 | Close );
00984 setButtonGuiItem( User1, KGuiItem(i18n("&Install")) );
00985 setDefaultButton( User1 );
00986 setObjectName( name );
00987 setModal( modal );
00988 showButtonSeparator( true );
00989
00990 KVBox* vbox = new KVBox(this);
00991 setMainWidget(vbox);
00992 vbox->setSpacing(spacingHint());
00993 new QLabel(i18n("Select the syntax highlighting files you want to update:"), vbox);
00994 list = new QTreeWidget(vbox);
00995 list->setColumnCount(4);
00996 list->setHeaderLabels(QStringList() << "" << i18n("Name") << i18n("Installed") << i18n("Latest"));
00997 list->setSelectionMode(QAbstractItemView::MultiSelection);
00998 list->setAllColumnsShowFocus(true);
00999 list->setRootIsDecorated(false);
01000 list->setColumnWidth(0, 22);
01001
01002 new QLabel(i18n("<b>Note:</b> New versions are selected automatically."), vbox);
01003 setButtonIcon(User1, KIcon("dialog-ok"));
01004
01005 transferJob = KIO::get(
01006 KUrl(QString(HLDOWNLOADPATH)
01007 + QString("update-")
01008 + QString(KATEPART_VERSION)
01009 + QString(".xml")), KIO::Reload );
01010 connect(transferJob, SIGNAL(data(KIO::Job *, const QByteArray &)),
01011 this, SLOT(listDataReceived(KIO::Job *, const QByteArray &)));
01012
01013 resize(450, 400);
01014 connect(this,SIGNAL(user1Clicked()),this,SLOT(slotUser1()));
01015 }
01016
01017 KateHlDownloadDialog::~KateHlDownloadDialog(){}
01018
01019 void KateHlDownloadDialog::listDataReceived(KIO::Job *, const QByteArray &data)
01020 {
01021 if (!transferJob || transferJob->isErrorPage())
01022 {
01023 enableButton( User1, false );
01024 return;
01025 }
01026
01027 listData+=QString(data);
01028 kDebug(13000)<<QString("CurrentListData: ")<<listData;
01029 kDebug(13000)<<QString("Data length: %1").arg(data.size());
01030 kDebug(13000)<<QString("listData length: %1").arg(listData.length());
01031 if (data.size()==0)
01032 {
01033 if (listData.length()>0)
01034 {
01035 QString installedVersion;
01036 KateHlManager *hlm=KateHlManager::self();
01037 QDomDocument doc;
01038 doc.setContent(listData);
01039 QDomElement DocElem=doc.documentElement();
01040 QDomNode n=DocElem.firstChild();
01041 KateHighlighting *hl = 0;
01042
01043 if (n.isNull()) kDebug(13000)<<"There is no usable childnode";
01044 while (!n.isNull())
01045 {
01046 installedVersion=" --";
01047
01048 QDomElement e=n.toElement();
01049 if (!e.isNull())
01050 kDebug(13000)<<QString("NAME: ")<<e.tagName()<<QString(" - ")<<e.attribute("name");
01051 n=n.nextSibling();
01052
01053 QString Name=e.attribute("name");
01054
01055 for (int i=0;i<hlm->highlights();i++)
01056 {
01057 hl=hlm->getHl(i);
01058 if (hl && hl->name()==Name)
01059 {
01060 installedVersion=" "+hl->version();
01061 break;
01062 }
01063 else hl = 0;
01064 }
01065
01066
01067 QTreeWidgetItem* entry = new QTreeWidgetItem(list);
01068 entry->setText(0, "");
01069 entry->setText(1, e.attribute("name"));
01070 entry->setText(2, installedVersion);
01071 entry->setText(3, e.attribute("version"));
01072 entry->setText(4, e.attribute("url"));
01073
01074 if (!hl || hl->version() < e.attribute("version"))
01075 {
01076 entry->treeWidget()->setItemSelected(entry, true);
01077 entry->setIcon(0, SmallIcon(("get-hot-new-stuff")));
01078 }
01079 }
01080 list->resizeColumnToContents(1);
01081 }
01082 }
01083 }
01084
01085 void KateHlDownloadDialog::slotUser1()
01086 {
01087 QString destdir=KGlobal::dirs()->saveLocation("data","katepart/syntax/");
01088 foreach (QTreeWidgetItem *it, list->selectedItems())
01089 {
01090 KUrl src(it->text(4));
01091 QString filename=src.fileName(KUrl::ObeyTrailingSlash);
01092 QString dest = destdir+filename;
01093
01094 KIO::NetAccess::download(src,dest, this);
01095 }
01096
01097
01098
01099 KateSyntaxDocument doc (KateHlManager::self()->getKConfig(), true);
01100 }
01101
01102
01103
01104 KateGotoBar::KateGotoBar(KateViewBar *parent)
01105 : KateViewBarWidget( parent )
01106 {
01107 QHBoxLayout *topLayout = new QHBoxLayout( centralWidget() );
01108 topLayout->setMargin(0);
01109
01110 gotoRange = new QSpinBox(centralWidget());
01111
01112 QLabel *label = new QLabel(i18n("&Go to line:"), centralWidget() );
01113 label->setBuddy(gotoRange);
01114
01115 btnOK = new QToolButton();
01116 btnOK->setAutoRaise(true);
01117 btnOK->setIcon(QIcon(SmallIcon("go-jump")));
01118 btnOK->setText(i18n("Go"));
01119 btnOK->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
01120 connect(btnOK, SIGNAL(clicked()), this, SLOT(gotoLine()));
01121
01122 topLayout->addWidget(label);
01123 topLayout->addWidget(gotoRange, 1);
01124 topLayout->setStretchFactor( gotoRange, 0 );
01125 topLayout->addWidget(btnOK);
01126 topLayout->addStretch();
01127 }
01128
01129 void KateGotoBar::showBar()
01130 {
01131 KateView* view = viewBar()->view();
01132 gotoRange->setMaximum(view->doc()->lines());
01133 if (!isVisible())
01134 {
01135 gotoRange->setValue(view->cursorPosition().line() + 1);
01136 gotoRange->adjustSize();
01137 }
01138 gotoRange->setFocus(Qt::OtherFocusReason);
01139 gotoRange->selectAll();
01140
01141 KateViewBarWidget::showBar();
01142 }
01143
01144 void KateGotoBar::keyPressEvent(QKeyEvent* event)
01145 {
01146 int key = event->key();
01147 if (key == Qt::Key_Return || key == Qt::Key_Enter) {
01148 gotoLine();
01149 return;
01150 }
01151 KateViewBarWidget::keyPressEvent(event);
01152 }
01153
01154 void KateGotoBar::gotoLine()
01155 {
01156 viewBar()->view()->setCursorPosition( KTextEditor::Cursor(gotoRange->value() - 1, 0) );
01157 viewBar()->view()->setFocus();
01158 hideBar();
01159 }
01160
01161
01162
01163 KateModOnHdPrompt::KateModOnHdPrompt( KateDocument *doc,
01164 KTextEditor::ModificationInterface::ModifiedOnDiskReason modtype,
01165 const QString &reason,
01166 QWidget *parent )
01167 : KDialog( parent ),
01168 m_doc( doc ),
01169 m_modtype ( modtype ),
01170 m_proc( 0 ),
01171 m_diffFile( 0 )
01172 {
01173 setButtons( Ok | Apply | Cancel | User1 );
01174
01175 QString title, btnOK, whatisok;
01176 if ( modtype == KTextEditor::ModificationInterface::OnDiskDeleted )
01177 {
01178 title = i18n("File Was Deleted on Disk");
01179 btnOK = i18n("&Save File As...");
01180 whatisok = i18n("Lets you select a location and save the file again.");
01181 } else {
01182 title = i18n("File Changed on Disk");
01183 btnOK = i18n("&Reload File");
01184 whatisok = i18n("Reload the file from disk. If you have unsaved changes, "
01185 "they will be lost.");
01186 }
01187
01188 setButtonText( Ok, btnOK );
01189 setButtonText( Apply, i18n("&Ignore") );
01190
01191 setButtonWhatsThis( Ok, whatisok );
01192 setButtonWhatsThis( Apply, i18n("Ignore the changes. You will not be prompted again.") );
01193 setButtonWhatsThis( Cancel, i18n("Do nothing. Next time you focus the file, "
01194 "or try to save it or close it, you will be prompted again.") );
01195
01196 showButtonSeparator( true );
01197 setCaption( title );
01198
01199 QWidget *w = new QWidget(this);
01200 ui = new Ui::ModOnHdWidget();
01201 ui->setupUi( w );
01202 setMainWidget( w );
01203
01204 ui->lblIcon->setPixmap( DesktopIcon("dialog-warning" ) );
01205 ui->lblText->setText( reason + "\n\n" + i18n("What do you want to do?") );
01206
01207
01208 if ( modtype != KTextEditor::ModificationInterface::OnDiskDeleted )
01209 {
01210 setButtonText( User1, i18n("Overwrite") );
01211 setButtonWhatsThis( User1, i18n("Overwrite the disk file with the editor content.") );
01212 connect( ui->btnDiff, SIGNAL(clicked()), this, SLOT(slotDiff()) );
01213 }
01214 else
01215 {
01216 ui->chkIgnoreWhiteSpaces->setVisible( false );
01217 ui->btnDiff->setVisible( false );
01218 showButton( User1, false );
01219 }
01220 }
01221
01222 KateModOnHdPrompt::~KateModOnHdPrompt()
01223 {
01224 delete m_proc;
01225 m_proc = 0;
01226 if (m_diffFile) {
01227 m_diffFile->setAutoRemove(true);
01228 delete m_diffFile;
01229 m_diffFile = 0;
01230 }
01231 delete ui;
01232 }
01233
01234 void KateModOnHdPrompt::slotDiff()
01235 {
01236 if (m_diffFile)
01237 return;
01238
01239 m_diffFile = new KTemporaryFile();
01240 m_diffFile->open();
01241
01242
01243 m_proc = new KProcess( this );
01244 m_proc->setOutputChannelMode( KProcess::MergedChannels );
01245 *m_proc << "diff" << QString(ui->chkIgnoreWhiteSpaces->isChecked() ? "-ub" : "-u")
01246 << "-" << m_doc->url().path();
01247 connect( m_proc, SIGNAL(readyRead()), this, SLOT(slotDataAvailable()) );
01248 connect( m_proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPDone()) );
01249
01250 setCursor( Qt::WaitCursor );
01251
01252 ui->chkIgnoreWhiteSpaces->setEnabled( false );
01253 ui->btnDiff->setEnabled( false );
01254
01255 m_proc->start();
01256
01257 QTextStream ts(m_proc);
01258 int lastln = m_doc->lines();
01259 for ( int l = 0; l < lastln; ++l )
01260 ts << m_doc->line( l ) << '\n';
01261 ts.flush();
01262 m_proc->closeWriteChannel();
01263 }
01264
01265 void KateModOnHdPrompt::slotDataAvailable()
01266 {
01267 m_diffFile->write(m_proc->readAll());
01268 }
01269
01270 void KateModOnHdPrompt::slotPDone()
01271 {
01272 setCursor( Qt::ArrowCursor );
01273 ui->chkIgnoreWhiteSpaces->setEnabled( true );
01274 ui->btnDiff->setEnabled( true );
01275
01276 const QProcess::ExitStatus es = m_proc->exitStatus();
01277 delete m_proc;
01278 m_proc = 0;
01279
01280 if ( es != QProcess::NormalExit )
01281 {
01282 KMessageBox::sorry( this,
01283 i18n("The diff command failed. Please make sure that "
01284 "diff(1) is installed and in your PATH."),
01285 i18n("Error Creating Diff") );
01286 delete m_diffFile;
01287 m_diffFile = 0;
01288 return;
01289 }
01290
01291 if ( m_diffFile->size() == 0 )
01292 {
01293 KMessageBox::information( this,
01294 i18n("Besides white space changes, the files are identical."),
01295 i18n("Diff Output") );
01296 delete m_diffFile;
01297 m_diffFile = 0;
01298 return;
01299 }
01300
01301 m_diffFile->setAutoRemove(false);
01302 KUrl url = KUrl::fromPath(m_diffFile->fileName());
01303 delete m_diffFile;
01304 m_diffFile = 0;
01305
01306
01307 KRun::runUrl( url, "text/x-patch", this, true );
01308 }
01309
01310 void KateModOnHdPrompt::slotButtonClicked(int button)
01311 {
01312 switch(button)
01313 {
01314 case Default:
01315 case Ok:
01316 done( (m_modtype == KTextEditor::ModificationInterface::OnDiskDeleted) ?
01317 Save : Reload );
01318 break;
01319 case Apply:
01320 {
01321 if ( KMessageBox::warningContinueCancel(
01322 this,
01323 i18n("Ignoring means that you will not be warned again (unless "
01324 "the disk file changes once more): if you save the document, you "
01325 "will overwrite the file on disk; if you do not save then the disk "
01326 "file (if present) is what you have."),
01327 i18n("You Are on Your Own"),
01328 KStandardGuiItem::cont(),
01329 KStandardGuiItem::cancel(),
01330 "kate_ignore_modonhd" ) != KMessageBox::Continue )
01331 return;
01332 done( Ignore );
01333 break;
01334 }
01335 case User1:
01336 done( Overwrite );
01337 break;
01338 default:
01339 KDialog::slotButtonClicked(button);
01340 }
01341 }
01342
01343
01344
01345