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