Kate
katedialogs.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk> 00003 Copyright (C) 2003 Christoph Cullmann <cullmann@kde.org> 00004 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00005 Copyright (C) 2006 Dominik Haumann <dhdev@gmx.de> 00006 Copyright (C) 2007 Mirko Stocker <me@misto.ch> 00007 Copyright (C) 2009 Michel Ludwig <michel.ludwig@kdemail.net> 00008 Copyright (C) 2009 Erlend Hamberg <ehamberg@gmail.com> 00009 00010 Based on work of: 00011 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 00012 00013 This library is free software; you can redistribute it and/or 00014 modify it under the terms of the GNU Library General Public 00015 License version 2 as published by the Free Software Foundation. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Library General Public License for more details. 00021 00022 You should have received a copy of the GNU Library General Public License 00023 along with this library; see the file COPYING.LIB. If not, write to 00024 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00025 Boston, MA 02110-1301, USA. 00026 */ 00027 00028 //BEGIN Includes 00029 #include "katedialogs.h" 00030 #include "katedialogs.moc" 00031 00032 #include "kateautoindent.h" 00033 #include "katebuffer.h" 00034 #include "kateconfig.h" 00035 #include "katedocument.h" 00036 #include "kateglobal.h" 00037 #include "kateviglobal.h" 00038 #include "katevikeyparser.h" 00039 #include "kateschema.h" 00040 #include "katesyntaxdocument.h" 00041 #include "katemodeconfigpage.h" 00042 #include "kateview.h" 00043 #include "katepartpluginmanager.h" 00044 #include "kpluginselector.h" 00045 #include "spellcheck/spellcheck.h" 00046 00047 // auto generated ui files 00048 #include "ui_modonhdwidget.h" 00049 #include "ui_textareaappearanceconfigwidget.h" 00050 #include "ui_bordersappearanceconfigwidget.h" 00051 #include "ui_cursorconfigwidget.h" 00052 #include "ui_editconfigwidget.h" 00053 #include "ui_indentationconfigwidget.h" 00054 #include "ui_completionconfigtab.h" 00055 #include "ui_opensaveconfigwidget.h" 00056 #include "ui_opensaveconfigadvwidget.h" 00057 #include "ui_viinputmodeconfigwidget.h" 00058 #include "ui_spellcheckconfigwidget.h" 00059 00060 #include <ktexteditor/plugin.h> 00061 00062 #include <kio/job.h> 00063 #include <kio/jobclasses.h> 00064 #include <kio/netaccess.h> 00065 00066 #include <kapplication.h> 00067 #include <kcharsets.h> 00068 #include <kcolorbutton.h> 00069 #include <kcolorcombo.h> 00070 #include <kcolordialog.h> 00071 #include <kcombobox.h> 00072 #include <kconfig.h> 00073 #include <kdebug.h> 00074 #include <kfontdialog.h> 00075 #include <kglobal.h> 00076 #include <kglobalsettings.h> 00077 #include <kiconloader.h> 00078 #include <kshortcutsdialog.h> 00079 #include <klineedit.h> 00080 #include <klocale.h> 00081 #include <kmessagebox.h> 00082 #include <kmimetypechooser.h> 00083 #include <knuminput.h> 00084 #include <kmenu.h> 00085 #include <kprocess.h> 00086 #include <krun.h> 00087 #include <kseparator.h> 00088 #include <kstandarddirs.h> 00089 #include <ktemporaryfile.h> 00090 #include <kpushbutton.h> 00091 #include <kvbox.h> 00092 #include <kactioncollection.h> 00093 #include <kplugininfo.h> 00094 #include <ktabwidget.h> 00095 00096 //#include <knewstuff/knewstuff.h> 00097 #include <QtGui/QCheckBox> 00098 #include <QtGui/QComboBox> 00099 #include <QtGui/QDialog> 00100 #include <QtCore/QFile> 00101 #include <QtGui/QGroupBox> 00102 #include <QtGui/QLabel> 00103 #include <QtGui/QLayout> 00104 #include <QtCore/QMap> 00105 #include <QtCore/QObject> 00106 #include <QtGui/QPainter> 00107 #include <QtGui/QRadioButton> 00108 #include <QtGui/QSlider> 00109 #include <QtCore/QStringList> 00110 #include <QtGui/QTabWidget> 00111 #include <QtCore/QTextCodec> 00112 #include <QtCore/QTextStream> 00113 #include <QtGui/QToolButton> 00114 #include <QtGui/QWhatsThis> 00115 #include <QtGui/QKeyEvent> 00116 #include <QtXml/QDomDocument> 00117 00118 // trailing slash is important 00119 #define HLDOWNLOADPATH "http://kate.kde.org/syntax/" 00120 00121 //END 00122 00123 //BEGIN KateConfigPage 00124 KateConfigPage::KateConfigPage ( QWidget *parent, const char * ) 00125 : KTextEditor::ConfigPage (parent) 00126 , m_changed (false) 00127 { 00128 connect (this, SIGNAL(changed()), this, SLOT(somethingHasChanged ())); 00129 } 00130 00131 KateConfigPage::~KateConfigPage () 00132 { 00133 } 00134 00135 void KateConfigPage::slotChanged() 00136 { 00137 emit changed(); 00138 } 00139 00140 void KateConfigPage::somethingHasChanged () 00141 { 00142 m_changed = true; 00143 kDebug (13000) << "TEST: something changed on the config page: " << this; 00144 } 00145 //END KateConfigPage 00146 00147 //BEGIN KateIndentConfigTab 00148 KateIndentConfigTab::KateIndentConfigTab(QWidget *parent) 00149 : KateConfigPage(parent) 00150 { 00151 // This will let us have more separation between this page and 00152 // the KTabWidget edge (ereslibre) 00153 QVBoxLayout *layout = new QVBoxLayout; 00154 QWidget *newWidget = new QWidget(this); 00155 00156 ui = new Ui::IndentationConfigWidget(); 00157 ui->setupUi( newWidget ); 00158 00159 ui->cmbMode->addItems (KateAutoIndent::listModes()); 00160 00161 ui->label->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard); 00162 connect(ui->label, SIGNAL(linkActivated(const QString&)), this, SLOT(showWhatsThis(const QString&))); 00163 00164 // What's This? help can be found in the ui file 00165 00166 reload (); 00167 00168 // 00169 // after initial reload, connect the stuff for the changed () signal 00170 // 00171 00172 connect(ui->cmbMode, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00173 connect(ui->rbIndentWithTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00174 connect(ui->rbIndentWithSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00175 connect(ui->rbIndentMixed, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00176 connect(ui->rbIndentWithTabs, SIGNAL(toggled(bool)), ui->sbIndentWidth, SLOT(setDisabled(bool))); 00177 00178 connect(ui->chkKeepExtraSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00179 connect(ui->chkIndentPaste, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00180 connect(ui->chkBackspaceUnindents, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00181 00182 connect(ui->sbTabWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00183 connect(ui->sbIndentWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00184 00185 connect(ui->rbTabAdvances, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00186 connect(ui->rbTabIndents, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00187 connect(ui->rbTabSmart, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00188 00189 layout->addWidget(newWidget); 00190 setLayout(layout); 00191 } 00192 00193 KateIndentConfigTab::~KateIndentConfigTab() 00194 { 00195 delete ui; 00196 } 00197 00198 void KateIndentConfigTab::slotChanged() 00199 { 00200 if (ui->rbIndentWithTabs->isChecked()) 00201 ui->sbIndentWidth->setValue(ui->sbTabWidth->value()); 00202 00203 KateConfigPage::slotChanged(); 00204 } 00205 00206 void KateIndentConfigTab::showWhatsThis(const QString& text) 00207 { 00208 QWhatsThis::showText(QCursor::pos(), text); 00209 } 00210 00211 void KateIndentConfigTab::apply () 00212 { 00213 // nothing changed, no need to apply stuff 00214 if (!hasChanged()) 00215 return; 00216 m_changed = false; 00217 00218 KateDocumentConfig::global()->configStart (); 00219 00220 KateDocumentConfig::global()->setKeepExtraSpaces(ui->chkKeepExtraSpaces->isChecked()); 00221 KateDocumentConfig::global()->setBackspaceIndents(ui->chkBackspaceUnindents->isChecked()); 00222 KateDocumentConfig::global()->setIndentPastedText(ui->chkIndentPaste->isChecked()); 00223 KateDocumentConfig::global()->setIndentationWidth(ui->sbIndentWidth->value()); 00224 KateDocumentConfig::global()->setIndentationMode(KateAutoIndent::modeName(ui->cmbMode->currentIndex())); 00225 KateDocumentConfig::global()->setTabWidth(ui->sbTabWidth->value()); 00226 KateDocumentConfig::global()->setReplaceTabsDyn(ui->rbIndentWithSpaces->isChecked()); 00227 00228 if (ui->rbTabAdvances->isChecked()) 00229 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabInsertsTab ); 00230 else if (ui->rbTabIndents->isChecked()) 00231 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabIndents ); 00232 else 00233 KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabSmart ); 00234 00235 KateDocumentConfig::global()->configEnd (); 00236 } 00237 00238 void KateIndentConfigTab::reload () 00239 { 00240 ui->sbTabWidth->setSuffix(ki18np(" character", " characters")); 00241 ui->sbTabWidth->setValue(KateDocumentConfig::global()->tabWidth()); 00242 ui->sbIndentWidth->setSuffix(ki18np(" character", " characters")); 00243 ui->sbIndentWidth->setValue(KateDocumentConfig::global()->indentationWidth()); 00244 ui->chkKeepExtraSpaces->setChecked(KateDocumentConfig::global()->keepExtraSpaces()); 00245 ui->chkIndentPaste->setChecked(KateDocumentConfig::global()->indentPastedText()); 00246 ui->chkBackspaceUnindents->setChecked(KateDocumentConfig::global()->backspaceIndents()); 00247 00248 ui->rbTabAdvances->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabInsertsTab ); 00249 ui->rbTabIndents->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabIndents ); 00250 ui->rbTabSmart->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabSmart ); 00251 00252 ui->cmbMode->setCurrentIndex (KateAutoIndent::modeNumber (KateDocumentConfig::global()->indentationMode())); 00253 00254 if (KateDocumentConfig::global()->replaceTabsDyn()) 00255 ui->rbIndentWithSpaces->setChecked (true); 00256 else 00257 { 00258 if (KateDocumentConfig::global()->indentationWidth() == KateDocumentConfig::global()->tabWidth()) 00259 ui->rbIndentWithTabs->setChecked (true); 00260 else 00261 ui->rbIndentMixed->setChecked (true); 00262 } 00263 00264 ui->sbIndentWidth->setEnabled(!ui->rbIndentWithTabs->isChecked()); 00265 } 00266 //END KateIndentConfigTab 00267 00268 //BEGIN KateCompletionConfigTab 00269 KateCompletionConfigTab::KateCompletionConfigTab(QWidget *parent) 00270 : KateConfigPage(parent) 00271 { 00272 // This will let us have more separation between this page and 00273 // the KTabWidget edge (ereslibre) 00274 QVBoxLayout *layout = new QVBoxLayout; 00275 QWidget *newWidget = new QWidget(this); 00276 00277 ui = new Ui::CompletionConfigTab (); 00278 ui->setupUi( newWidget ); 00279 00280 // What's This? help can be found in the ui file 00281 00282 reload (); 00283 00284 // 00285 // after initial reload, connect the stuff for the changed () signal 00286 // 00287 00288 connect(ui->chkAutoCompletionEnabled, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00289 connect(ui->gbWordCompletion, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00290 connect(ui->minimalWordLength, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00291 00292 layout->addWidget(newWidget); 00293 setLayout(layout); 00294 } 00295 00296 KateCompletionConfigTab::~KateCompletionConfigTab() 00297 { 00298 delete ui; 00299 } 00300 00301 void KateCompletionConfigTab::showWhatsThis(const QString& text) 00302 { 00303 QWhatsThis::showText(QCursor::pos(), text); 00304 } 00305 00306 void KateCompletionConfigTab::apply () 00307 { 00308 // nothing changed, no need to apply stuff 00309 if (!hasChanged()) 00310 return; 00311 m_changed = false; 00312 00313 KateViewConfig::global()->configStart (); 00314 KateViewConfig::global()->setAutomaticCompletionInvocation (ui->chkAutoCompletionEnabled->isChecked()); 00315 KateViewConfig::global()->setWordCompletion (ui->gbWordCompletion->isChecked()); 00316 KateViewConfig::global()->setWordCompletionMinimalWordLength (ui->minimalWordLength->value()); 00317 KateViewConfig::global()->configEnd (); 00318 } 00319 00320 void KateCompletionConfigTab::reload () 00321 { 00322 ui->chkAutoCompletionEnabled->setChecked( KateViewConfig::global()->automaticCompletionInvocation () ); 00323 ui->gbWordCompletion->setChecked( KateViewConfig::global()->wordCompletion () ); 00324 ui->minimalWordLength->setValue (KateViewConfig::global()->wordCompletionMinimalWordLength ()); 00325 } 00326 //END KateCompletionConfigTab 00327 00328 //BEGIN KateViInputModeConfigTab 00329 KateViInputModeConfigTab::KateViInputModeConfigTab(QWidget *parent) 00330 : KateConfigPage(parent) 00331 { 00332 // This will let us have more separation between this page and 00333 // the KTabWidget edge (ereslibre) 00334 QVBoxLayout *layout = new QVBoxLayout; 00335 QWidget *newWidget = new QWidget(this); 00336 00337 ui = new Ui::ViInputModeConfigWidget (); 00338 ui->setupUi( newWidget ); 00339 00340 // What's This? help can be found in the ui file 00341 00342 reload (); 00343 00344 // 00345 // after initial reload, connect the stuff for the changed () signal 00346 // 00347 00348 connect(ui->chkViInputModeDefault, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00349 connect(ui->chkViCommandsOverride, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00350 connect(ui->chkViStatusBarHide, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00351 connect(ui->tblNormalModeMappings, SIGNAL(cellChanged(int, int)), this, SLOT(slotChanged())); 00352 connect(ui->btnAddNewNormal, SIGNAL(clicked()), this, SLOT(addNewNormalModeMappingRow())); 00353 connect(ui->btnRemoveSelectedNormal, SIGNAL(clicked()), this, SLOT(removeSelectedNormalMappingRow())); 00354 00355 layout->addWidget(newWidget); 00356 setLayout(layout); 00357 } 00358 00359 KateViInputModeConfigTab::~KateViInputModeConfigTab() 00360 { 00361 delete ui; 00362 } 00363 00364 void KateViInputModeConfigTab::showWhatsThis(const QString& text) 00365 { 00366 QWhatsThis::showText(QCursor::pos(), text); 00367 } 00368 00369 void KateViInputModeConfigTab::apply () 00370 { 00371 // nothing changed, no need to apply stuff 00372 if (!hasChanged()) 00373 return; 00374 m_changed = false; 00375 00376 KateViewConfig::global()->configStart (); 00377 KateViewConfig::global()->setViInputMode (ui->chkViInputModeDefault->isChecked()); 00378 KateViewConfig::global()->setViInputModeStealKeys (ui->chkViCommandsOverride->isChecked()); 00379 KateViewConfig::global()->setViInputModeHideStatusBar (ui->chkViStatusBarHide->isChecked()); 00380 KateGlobal::self()->viInputModeGlobal()->clearMappings( NormalMode ); 00381 for ( int i = 0; i < ui->tblNormalModeMappings->rowCount(); i++ ) { 00382 QTableWidgetItem* from = ui->tblNormalModeMappings->item( i, 0 ); 00383 QTableWidgetItem* to = ui->tblNormalModeMappings->item( i, 1 ); 00384 00385 if ( from && to ) { 00386 KateGlobal::self()->viInputModeGlobal()->addMapping( NormalMode, from->text(), to->text() ); 00387 } 00388 } 00389 KateViewConfig::global()->configEnd (); 00390 } 00391 00392 void KateViInputModeConfigTab::reload () 00393 { 00394 ui->chkViInputModeDefault->setChecked( KateViewConfig::global()->viInputMode () ); 00395 ui->chkViCommandsOverride->setChecked( KateViewConfig::global()->viInputModeStealKeys () ); 00396 ui->chkViStatusBarHide->setChecked( KateViewConfig::global()->viInputModeHideStatusBar () ); 00397 00398 ui->chkViCommandsOverride->setEnabled(ui->chkViInputModeDefault->isChecked()); 00399 ui->chkViStatusBarHide->setEnabled(ui->chkViInputModeDefault->isChecked()); 00400 00401 QStringList l = KateGlobal::self()->viInputModeGlobal()->getMappings( NormalMode ); 00402 ui->tblNormalModeMappings->setRowCount( l.size() ); 00403 00404 // make the two columns fill the entire table width 00405 ui->tblNormalModeMappings->setColumnWidth( 0, ui->tblNormalModeMappings->width()/3 ); 00406 ui->tblNormalModeMappings->horizontalHeader()->setStretchLastSection( true ); 00407 00408 int i = 0; 00409 foreach( const QString &f, l ) { 00410 QTableWidgetItem *from 00411 = new QTableWidgetItem( KateViKeyParser::getInstance()->decodeKeySequence( f ) ); 00412 QString s = KateGlobal::self()->viInputModeGlobal()->getMapping( NormalMode, f ); 00413 QTableWidgetItem *to = 00414 new QTableWidgetItem( KateViKeyParser::getInstance()->decodeKeySequence( s ) ); 00415 00416 ui->tblNormalModeMappings->setItem(i, 0, from); 00417 ui->tblNormalModeMappings->setItem(i++, 1, to); 00418 } 00419 } 00420 00421 void KateViInputModeConfigTab::addNewNormalModeMappingRow() 00422 { 00423 int rows = ui->tblNormalModeMappings->rowCount(); 00424 ui->tblNormalModeMappings->insertRow( rows ); 00425 ui->tblNormalModeMappings->setCurrentCell( rows, 0 ); 00426 ui->tblNormalModeMappings->editItem( ui->tblNormalModeMappings->currentItem() ); 00427 } 00428 00429 void KateViInputModeConfigTab::removeSelectedNormalMappingRow() 00430 { 00431 QList<QTableWidgetSelectionRange> l = ui->tblNormalModeMappings->selectedRanges(); 00432 00433 foreach( const QTableWidgetSelectionRange &range, l ) { 00434 for ( int i = 0; i < range.bottomRow()-range.topRow()+1; i++ ) { 00435 ui->tblNormalModeMappings->removeRow( range.topRow() ); 00436 } 00437 } 00438 } 00439 //END KateViInputModeConfigTab 00440 00441 //BEGIN KateSpellCheckConfigTab 00442 KateSpellCheckConfigTab::KateSpellCheckConfigTab(QWidget *parent) 00443 : KateConfigPage(parent) 00444 { 00445 // This will let us have more separation between this page and 00446 // the KTabWidget edge (ereslibre) 00447 QVBoxLayout *layout = new QVBoxLayout; 00448 QWidget *newWidget = new QWidget(this); 00449 00450 ui = new Ui::SpellCheckConfigWidget(); 00451 ui->setupUi(newWidget); 00452 00453 // What's This? help can be found in the ui file 00454 reload(); 00455 00456 // 00457 // after initial reload, connect the stuff for the changed () signal 00458 00459 m_sonnetConfigWidget = new Sonnet::ConfigWidget(KGlobal::config().data(), this); 00460 connect(m_sonnetConfigWidget, SIGNAL(configChanged()), this, SLOT(slotChanged())); 00461 layout->addWidget(m_sonnetConfigWidget); 00462 00463 layout->addWidget(newWidget); 00464 setLayout(layout); 00465 } 00466 00467 KateSpellCheckConfigTab::~KateSpellCheckConfigTab() 00468 { 00469 delete ui; 00470 } 00471 00472 void KateSpellCheckConfigTab::showWhatsThis(const QString& text) 00473 { 00474 QWhatsThis::showText(QCursor::pos(), text); 00475 } 00476 00477 void KateSpellCheckConfigTab::apply() 00478 { 00479 if (!hasChanged()) { 00480 // nothing changed, no need to apply stuff 00481 return; 00482 } 00483 m_changed = false; 00484 00485 KateDocumentConfig::global()->configStart(); 00486 m_sonnetConfigWidget->save(); 00487 KateDocumentConfig::global()->configEnd(); 00488 foreach (KateDocument *doc, KateGlobal::self()->kateDocuments()) { 00489 doc->refreshOnTheFlyCheck(); 00490 } 00491 } 00492 00493 void KateSpellCheckConfigTab::reload() 00494 { 00495 // does nothing 00496 } 00497 //END KateSpellCheckConfigTab 00498 00499 //BEGIN KateSelectConfigTab 00500 KateSelectConfigTab::KateSelectConfigTab(QWidget *parent) 00501 : KateConfigPage(parent) 00502 { 00503 // This will let us having more separation between this page and 00504 // the KTabWidget edge (ereslibre) 00505 QVBoxLayout *layout = new QVBoxLayout; 00506 QWidget *newWidget = new QWidget(this); 00507 00508 ui = new Ui::CursorConfigWidget(); 00509 ui->setupUi( newWidget ); 00510 00511 // What's This? Help is in the ui-files 00512 00513 reload (); 00514 00515 // 00516 // after initial reload, connect the stuff for the changed () signal 00517 // 00518 00519 connect(ui->rbNormal, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00520 connect(ui->rbPersistent, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00521 connect(ui->chkSmartHome, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00522 connect(ui->chkWrapCursor, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00523 connect(ui->chkPagingMovesCursor, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00524 connect(ui->sbAutoCenterCursor, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00525 00526 layout->addWidget(newWidget); 00527 setLayout(layout); 00528 } 00529 00530 KateSelectConfigTab::~KateSelectConfigTab() 00531 { 00532 delete ui; 00533 } 00534 00535 void KateSelectConfigTab::apply () 00536 { 00537 // nothing changed, no need to apply stuff 00538 if (!hasChanged()) 00539 return; 00540 m_changed = false; 00541 00542 KateViewConfig::global()->configStart (); 00543 KateDocumentConfig::global()->configStart (); 00544 00545 KateDocumentConfig::global()->setSmartHome(ui->chkSmartHome->isChecked()); 00546 KateDocumentConfig::global()->setWrapCursor(ui->chkWrapCursor->isChecked()); 00547 00548 KateViewConfig::global()->setAutoCenterLines(qMax(0, ui->sbAutoCenterCursor->value())); 00549 KateDocumentConfig::global()->setPageUpDownMovesCursor(ui->chkPagingMovesCursor->isChecked()); 00550 00551 KateViewConfig::global()->setPersistentSelection (ui->rbPersistent->isChecked()); 00552 00553 KateDocumentConfig::global()->configEnd (); 00554 KateViewConfig::global()->configEnd (); 00555 } 00556 00557 void KateSelectConfigTab::reload () 00558 { 00559 ui->rbNormal->setChecked( ! KateViewConfig::global()->persistentSelection() ); 00560 ui->rbPersistent->setChecked( KateViewConfig::global()->persistentSelection() ); 00561 00562 ui->chkSmartHome->setChecked(KateDocumentConfig::global()->smartHome()); 00563 ui->chkWrapCursor->setChecked(KateDocumentConfig::global()->wrapCursor()); 00564 ui->chkPagingMovesCursor->setChecked(KateDocumentConfig::global()->pageUpDownMovesCursor()); 00565 ui->sbAutoCenterCursor->setValue(KateViewConfig::global()->autoCenterLines()); 00566 } 00567 //END KateSelectConfigTab 00568 00569 //BEGIN KateEditGeneralConfigTab 00570 KateEditGeneralConfigTab::KateEditGeneralConfigTab(QWidget *parent) 00571 : KateConfigPage(parent) 00572 { 00573 QVBoxLayout *layout = new QVBoxLayout; 00574 QWidget *newWidget = new QWidget(this); 00575 ui = new Ui::EditConfigWidget(); 00576 ui->setupUi( newWidget ); 00577 00578 reload(); 00579 00580 connect(ui->chkStaticWordWrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00581 connect(ui->chkShowStaticWordWrapMarker, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00582 connect(ui->sbWordWrap, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00583 connect( ui->chkRemoveTrailingSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) ); 00584 connect(ui->chkAutoBrackets, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00585 connect(ui->chkSmartCopyCut, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00586 connect(ui->chkScrollPastEnd, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00587 00588 // "What's this?" help is in the ui-file 00589 00590 layout->addWidget(newWidget); 00591 setLayout(layout); 00592 } 00593 00594 KateEditGeneralConfigTab::~KateEditGeneralConfigTab() 00595 { 00596 delete ui; 00597 } 00598 00599 void KateEditGeneralConfigTab::apply () 00600 { 00601 // nothing changed, no need to apply stuff 00602 if (!hasChanged()) 00603 return; 00604 m_changed = false; 00605 00606 KateViewConfig::global()->configStart (); 00607 KateDocumentConfig::global()->configStart (); 00608 00609 KateDocumentConfig::global()->setAutoBrackets(ui->chkAutoBrackets->isChecked()); 00610 KateDocumentConfig::global()->setRemoveTrailingDyn(ui->chkRemoveTrailingSpaces->isChecked()); 00611 00612 KateDocumentConfig::global()->setWordWrapAt(ui->sbWordWrap->value()); 00613 KateDocumentConfig::global()->setWordWrap(ui->chkStaticWordWrap->isChecked()); 00614 00615 KateRendererConfig::global()->setWordWrapMarker (ui->chkShowStaticWordWrapMarker->isChecked()); 00616 00617 KateDocumentConfig::global()->configEnd (); 00618 KateViewConfig::global()->setSmartCopyCut(ui->chkSmartCopyCut->isChecked()); 00619 KateViewConfig::global()->setScrollPastEnd(ui->chkScrollPastEnd->isChecked()); 00620 KateViewConfig::global()->configEnd (); 00621 } 00622 00623 void KateEditGeneralConfigTab::reload () 00624 { 00625 ui->chkStaticWordWrap->setChecked(KateDocumentConfig::global()->wordWrap()); 00626 ui->chkShowStaticWordWrapMarker->setChecked( KateRendererConfig::global()->wordWrapMarker() ); 00627 ui->sbWordWrap->setSuffix(ki18ncp("Wrap words at", " character", " characters")); 00628 ui->sbWordWrap->setValue( KateDocumentConfig::global()->wordWrapAt() ); 00629 ui->chkRemoveTrailingSpaces->setChecked( KateDocumentConfig::global()->removeTrailingDyn() ); 00630 ui->chkAutoBrackets->setChecked( KateDocumentConfig::global()->autoBrackets() ); 00631 ui->chkSmartCopyCut->setChecked( KateViewConfig::global()->smartCopyCut() ); 00632 ui->chkScrollPastEnd->setChecked( KateViewConfig::global()->scrollPastEnd() ); 00633 } 00634 //END KateEditGeneralConfigTab 00635 00636 00637 //BEGIN KateEditConfigTab 00638 KateEditConfigTab::KateEditConfigTab(QWidget *parent) 00639 : KateConfigPage(parent) 00640 , editConfigTab(new KateEditGeneralConfigTab(this)) 00641 , selectConfigTab(new KateSelectConfigTab(this)) 00642 , indentConfigTab(new KateIndentConfigTab(this)) 00643 , completionConfigTab (new KateCompletionConfigTab(this)) 00644 , viInputModeConfigTab(new KateViInputModeConfigTab(this)) 00645 , spellCheckConfigTab(new KateSpellCheckConfigTab(this)) 00646 { 00647 QVBoxLayout *layout = new QVBoxLayout; 00648 layout->setMargin(0); 00649 KTabWidget *tabWidget = new KTabWidget(this); 00650 00651 // add all tabs 00652 tabWidget->insertTab(0, editConfigTab, i18n("General")); 00653 tabWidget->insertTab(1, selectConfigTab, i18n("Cursor && Selection")); 00654 tabWidget->insertTab(2, indentConfigTab, i18n("Indentation")); 00655 tabWidget->insertTab(3, completionConfigTab, i18n("Auto Completion")); 00656 tabWidget->insertTab(4, viInputModeConfigTab, i18n("Vi Input Mode")); 00657 tabWidget->insertTab(5, spellCheckConfigTab, i18n("Spellcheck")); 00658 00659 connect(editConfigTab, SIGNAL(changed()), this, SLOT(slotChanged())); 00660 connect(selectConfigTab, SIGNAL(changed()), this, SLOT(slotChanged())); 00661 connect(indentConfigTab, SIGNAL(changed()), this, SLOT(slotChanged())); 00662 connect(completionConfigTab, SIGNAL(changed()), this, SLOT(slotChanged())); 00663 connect(viInputModeConfigTab, SIGNAL(changed()), this, SLOT(slotChanged())); 00664 connect(spellCheckConfigTab, SIGNAL(changed()), this, SLOT(slotChanged())); 00665 00666 layout->addWidget(tabWidget); 00667 setLayout(layout); 00668 } 00669 00670 KateEditConfigTab::~KateEditConfigTab() 00671 { 00672 } 00673 00674 void KateEditConfigTab::apply () 00675 { 00676 // try to update the rest of tabs 00677 editConfigTab->apply(); 00678 selectConfigTab->apply(); 00679 indentConfigTab->apply(); 00680 completionConfigTab->apply(); 00681 viInputModeConfigTab->apply(); 00682 spellCheckConfigTab->apply(); 00683 } 00684 00685 void KateEditConfigTab::reload () 00686 { 00687 editConfigTab->reload(); 00688 selectConfigTab->reload(); 00689 indentConfigTab->reload(); 00690 completionConfigTab->reload(); 00691 viInputModeConfigTab->reload(); 00692 spellCheckConfigTab->reload(); 00693 } 00694 00695 void KateEditConfigTab::reset () 00696 { 00697 editConfigTab->reset(); 00698 selectConfigTab->reset(); 00699 indentConfigTab->reset(); 00700 completionConfigTab->reset(); 00701 viInputModeConfigTab->reset(); 00702 spellCheckConfigTab->reset(); 00703 } 00704 00705 void KateEditConfigTab::defaults () 00706 { 00707 editConfigTab->defaults(); 00708 selectConfigTab->defaults(); 00709 indentConfigTab->defaults(); 00710 completionConfigTab->defaults(); 00711 viInputModeConfigTab->defaults(); 00712 spellCheckConfigTab->defaults(); 00713 } 00714 //END KateEditConfigTab 00715 00716 //BEGIN KateViewDefaultsConfig 00717 KateViewDefaultsConfig::KateViewDefaultsConfig(QWidget *parent) 00718 : KateConfigPage(parent) 00719 , textareaUi(new Ui::TextareaAppearanceConfigWidget()) 00720 , bordersUi(new Ui::BordersAppearanceConfigWidget()) 00721 { 00722 QLayout *layout = new QVBoxLayout( this ); 00723 QTabWidget *tabWidget = new QTabWidget( this ); 00724 layout->addWidget( tabWidget ); 00725 layout->setMargin( 0 ); 00726 00727 QWidget *textareaTab = new QWidget( tabWidget ); 00728 textareaUi->setupUi( textareaTab ); 00729 tabWidget->addTab( textareaTab, i18n("General") ); 00730 00731 QWidget *bordersTab = new QWidget( tabWidget ); 00732 bordersUi->setupUi( bordersTab ); 00733 tabWidget->addTab( bordersTab, i18n("Borders") ); 00734 00735 if (KateDocument::simpleMode ()) 00736 bordersUi->gbSortBookmarks->hide (); 00737 00738 textareaUi->cmbDynamicWordWrapIndicator->addItem( i18n("Off") ); 00739 textareaUi->cmbDynamicWordWrapIndicator->addItem( i18n("Follow Line Numbers") ); 00740 textareaUi->cmbDynamicWordWrapIndicator->addItem( i18n("Always On") ); 00741 00742 // hide power user mode if activated anyway 00743 if (!KateGlobal::self()->simpleMode ()) 00744 textareaUi->chkDeveloperMode->hide (); 00745 00746 // What's This? help is in the ui-file 00747 00748 reload(); 00749 00750 // 00751 // after initial reload, connect the stuff for the changed () signal 00752 // 00753 00754 connect(textareaUi->gbWordWrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00755 connect(textareaUi->cmbDynamicWordWrapIndicator, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00756 connect(textareaUi->sbDynamicWordWrapDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00757 connect(textareaUi->chkShowTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00758 connect(textareaUi->chkShowSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00759 connect(textareaUi->chkShowIndentationLines, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00760 connect(textareaUi->chkShowWholeBracketExpression, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00761 connect(textareaUi->chkDeveloperMode, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00762 00763 connect(bordersUi->chkIconBorder, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00764 connect(bordersUi->chkScrollbarMarks, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00765 connect(bordersUi->chkLineNumbers, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00766 connect(bordersUi->chkShowFoldingMarkers, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00767 connect(bordersUi->rbSortBookmarksByPosition, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00768 connect(bordersUi->rbSortBookmarksByCreation, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00769 } 00770 00771 KateViewDefaultsConfig::~KateViewDefaultsConfig() 00772 { 00773 delete bordersUi; 00774 delete textareaUi; 00775 } 00776 00777 void KateViewDefaultsConfig::apply () 00778 { 00779 // nothing changed, no need to apply stuff 00780 if (!hasChanged()) 00781 return; 00782 m_changed = false; 00783 00784 KateViewConfig::global()->configStart (); 00785 KateRendererConfig::global()->configStart (); 00786 00787 KateViewConfig::global()->setDynWordWrap (textareaUi->gbWordWrap->isChecked()); 00788 KateViewConfig::global()->setDynWordWrapIndicators (textareaUi->cmbDynamicWordWrapIndicator->currentIndex ()); 00789 KateViewConfig::global()->setDynWordWrapAlignIndent(textareaUi->sbDynamicWordWrapDepth->value()); 00790 KateDocumentConfig::global()->setShowTabs (textareaUi->chkShowTabs->isChecked()); 00791 KateDocumentConfig::global()->setShowSpaces (textareaUi->chkShowSpaces->isChecked()); 00792 KateViewConfig::global()->setLineNumbers (bordersUi->chkLineNumbers->isChecked()); 00793 KateViewConfig::global()->setIconBar (bordersUi->chkIconBorder->isChecked()); 00794 KateViewConfig::global()->setScrollBarMarks (bordersUi->chkScrollbarMarks->isChecked()); 00795 KateViewConfig::global()->setFoldingBar (bordersUi->chkShowFoldingMarkers->isChecked()); 00796 00797 KateViewConfig::global()->setBookmarkSort (bordersUi->rbSortBookmarksByPosition->isChecked()?0:1); 00798 KateRendererConfig::global()->setShowIndentationLines(textareaUi->chkShowIndentationLines->isChecked()); 00799 KateRendererConfig::global()->setShowWholeBracketExpression(textareaUi->chkShowWholeBracketExpression->isChecked()); 00800 00801 // warn user that he needs restart the application 00802 if (!textareaUi->chkDeveloperMode->isChecked() != KateDocumentConfig::global()->allowSimpleMode()) 00803 { 00804 // inform... 00805 KMessageBox::information( 00806 this, 00807 i18n("Changing the power user mode affects only newly opened / created documents. In KWrite a restart is recommended."), 00808 i18n("Power user mode changed")); 00809 00810 KateDocumentConfig::global()->setAllowSimpleMode (!textareaUi->chkDeveloperMode->isChecked()); 00811 } 00812 00813 KateRendererConfig::global()->configEnd (); 00814 KateViewConfig::global()->configEnd (); 00815 } 00816 00817 void KateViewDefaultsConfig::reload () 00818 { 00819 textareaUi->gbWordWrap->setChecked(KateViewConfig::global()->dynWordWrap()); 00820 textareaUi->cmbDynamicWordWrapIndicator->setCurrentIndex( KateViewConfig::global()->dynWordWrapIndicators() ); 00821 textareaUi->sbDynamicWordWrapDepth->setValue(KateViewConfig::global()->dynWordWrapAlignIndent()); 00822 textareaUi->chkShowTabs->setChecked(KateDocumentConfig::global()->showTabs()); 00823 textareaUi->chkShowSpaces->setChecked(KateDocumentConfig::global()->showSpaces()); 00824 bordersUi->chkLineNumbers->setChecked(KateViewConfig::global()->lineNumbers()); 00825 bordersUi->chkIconBorder->setChecked(KateViewConfig::global()->iconBar()); 00826 bordersUi->chkScrollbarMarks->setChecked(KateViewConfig::global()->scrollBarMarks()); 00827 bordersUi->chkShowFoldingMarkers->setChecked(KateViewConfig::global()->foldingBar()); 00828 bordersUi->rbSortBookmarksByPosition->setChecked(KateViewConfig::global()->bookmarkSort()==0); 00829 bordersUi->rbSortBookmarksByCreation->setChecked(KateViewConfig::global()->bookmarkSort()==1); 00830 textareaUi->chkShowIndentationLines->setChecked(KateRendererConfig::global()->showIndentationLines()); 00831 textareaUi->chkShowWholeBracketExpression->setChecked(KateRendererConfig::global()->showWholeBracketExpression()); 00832 textareaUi->chkDeveloperMode->setChecked(!KateDocumentConfig::global()->allowSimpleMode()); 00833 } 00834 00835 void KateViewDefaultsConfig::reset () {;} 00836 00837 void KateViewDefaultsConfig::defaults (){;} 00838 //END KateViewDefaultsConfig 00839 00840 //BEGIN KateSaveConfigTab 00841 KateSaveConfigTab::KateSaveConfigTab( QWidget *parent ) 00842 : KateConfigPage( parent ) 00843 , modeConfigPage( new ModeConfigPage( this ) ) 00844 { 00845 // FIXME: Is really needed to move all this code below to another class, 00846 // since it is another tab itself on the config dialog. This means we should 00847 // initialize, add and work with as we do with modeConfigPage (ereslibre) 00848 QVBoxLayout *layout = new QVBoxLayout; 00849 layout->setMargin(0); 00850 KTabWidget *tabWidget = new KTabWidget(this); 00851 00852 QWidget *tmpWidget = new QWidget(tabWidget); 00853 QVBoxLayout *internalLayout = new QVBoxLayout; 00854 QWidget *newWidget = new QWidget(tabWidget); 00855 ui = new Ui::OpenSaveConfigWidget(); 00856 ui->setupUi( newWidget ); 00857 00858 QWidget *tmpWidget2 = new QWidget(tabWidget); 00859 QVBoxLayout *internalLayout2 = new QVBoxLayout; 00860 QWidget *newWidget2 = new QWidget(tabWidget); 00861 uiadv = new Ui::OpenSaveConfigAdvWidget(); 00862 uiadv->setupUi( newWidget2 ); 00863 00864 // What's this help is added in ui/opensaveconfigwidget.ui 00865 reload(); 00866 00867 // 00868 // after initial reload, connect the stuff for the changed () signal 00869 // 00870 00871 connect( ui->cmbEncoding, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00872 connect( ui->cmbEncodingDetection, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00873 connect( ui->cmbEncodingFallback, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00874 connect( ui->cmbEOL, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00875 connect( ui->chkDetectEOL, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00876 connect( ui->chkEnableBOM, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00877 connect( ui->chkRemoveTrailingSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00878 connect( uiadv->chkBackupLocalFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00879 connect( uiadv->chkBackupRemoteFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00880 connect( uiadv->sbConfigFileSearchDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00881 connect( uiadv->edtBackupPrefix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) ); 00882 connect( uiadv->edtBackupSuffix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) ); 00883 connect( uiadv->chkNoSync, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00884 00885 internalLayout->addWidget(newWidget); 00886 tmpWidget->setLayout(internalLayout); 00887 internalLayout2->addWidget(newWidget2); 00888 tmpWidget2->setLayout(internalLayout2); 00889 00890 // add all tabs 00891 tabWidget->insertTab(0, tmpWidget, i18n("General")); 00892 tabWidget->insertTab(1, tmpWidget2, i18n("Advanced")); 00893 tabWidget->insertTab(2, modeConfigPage, i18n("Modes && Filetypes")); 00894 00895 connect(modeConfigPage, SIGNAL(changed()), this, SLOT(slotChanged())); 00896 00897 layout->addWidget(tabWidget); 00898 setLayout(layout); 00899 } 00900 00901 KateSaveConfigTab::~KateSaveConfigTab() 00902 { 00903 delete ui; 00904 } 00905 00906 void KateSaveConfigTab::apply() 00907 { 00908 modeConfigPage->apply(); 00909 00910 // nothing changed, no need to apply stuff 00911 if (!hasChanged()) 00912 return; 00913 m_changed = false; 00914 00915 KateGlobalConfig::global()->configStart (); 00916 KateDocumentConfig::global()->configStart (); 00917 00918 if ( uiadv->edtBackupSuffix->text().isEmpty() && uiadv->edtBackupPrefix->text().isEmpty() ) { 00919 KMessageBox::information( 00920 this, 00921 i18n("You did not provide a backup suffix or prefix. Using default suffix: '~'"), 00922 i18n("No Backup Suffix or Prefix") 00923 ); 00924 uiadv->edtBackupSuffix->setText( "~" ); 00925 } 00926 00927 uint f( 0 ); 00928 if ( uiadv->chkBackupLocalFiles->isChecked() ) 00929 f |= KateDocumentConfig::LocalFiles; 00930 if ( uiadv->chkBackupRemoteFiles->isChecked() ) 00931 f |= KateDocumentConfig::RemoteFiles; 00932 00933 KateDocumentConfig::global()->setBackupFlags(f); 00934 KateDocumentConfig::global()->setBackupPrefix(uiadv->edtBackupPrefix->text()); 00935 KateDocumentConfig::global()->setBackupSuffix(uiadv->edtBackupSuffix->text()); 00936 00937 KateDocumentConfig::global()->setSwapFileNoSync(uiadv->chkNoSync->isChecked()); 00938 00939 KateDocumentConfig::global()->setSearchDirConfigDepth(uiadv->sbConfigFileSearchDepth->value()); 00940 00941 KateDocumentConfig::global()->setRemoveSpaces(ui->chkRemoveTrailingSpaces->isChecked()); 00942 00943 // set both standard and fallback encoding 00944 KateDocumentConfig::global()->setEncoding((ui->cmbEncoding->currentIndex() == 0) ? "" : KGlobal::charsets()->encodingForName(ui->cmbEncoding->currentText())); 00945 00946 KateGlobalConfig::global()->setProberType((KEncodingProber::ProberType)ui->cmbEncodingDetection->currentIndex()); 00947 KateGlobalConfig::global()->setFallbackEncoding(KGlobal::charsets()->encodingForName(ui->cmbEncodingFallback->currentText())); 00948 00949 KateDocumentConfig::global()->setEol(ui->cmbEOL->currentIndex()); 00950 KateDocumentConfig::global()->setAllowEolDetection(ui->chkDetectEOL->isChecked()); 00951 KateDocumentConfig::global()->setBom(ui->chkEnableBOM->isChecked()); 00952 00953 KateDocumentConfig::global()->configEnd (); 00954 KateGlobalConfig::global()->configEnd (); 00955 } 00956 00957 void KateSaveConfigTab::reload() 00958 { 00959 modeConfigPage->reload(); 00960 00961 // encodings 00962 ui->cmbEncoding->clear (); 00963 ui->cmbEncoding->addItem (i18n("KDE Default")); 00964 ui->cmbEncoding->setCurrentIndex(0); 00965 ui->cmbEncodingFallback->clear (); 00966 QStringList encodings (KGlobal::charsets()->descriptiveEncodingNames()); 00967 int insert = 1; 00968 for (int i=0; i < encodings.count(); i++) 00969 { 00970 bool found = false; 00971 QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(KGlobal::charsets()->encodingForName(encodings[i]), found); 00972 00973 if (found) 00974 { 00975 ui->cmbEncoding->addItem (encodings[i]); 00976 ui->cmbEncodingFallback->addItem (encodings[i]); 00977 00978 if ( codecForEnc->name() == KateDocumentConfig::global()->encoding() ) 00979 { 00980 ui->cmbEncoding->setCurrentIndex(insert); 00981 } 00982 00983 if ( codecForEnc == KateGlobalConfig::global()->fallbackCodec() ) 00984 { 00985 // adjust index for fallback config, has no default! 00986 ui->cmbEncodingFallback->setCurrentIndex(insert-1); 00987 } 00988 00989 insert++; 00990 } 00991 } 00992 00993 // encoding detection 00994 ui->cmbEncodingDetection->clear (); 00995 bool found = false; 00996 for (int i = 0; !KEncodingProber::nameForProberType ((KEncodingProber::ProberType) i).isEmpty(); ++i) { 00997 ui->cmbEncodingDetection->addItem (KEncodingProber::nameForProberType ((KEncodingProber::ProberType) i)); 00998 if (i == KateGlobalConfig::global()->proberType()) { 00999 ui->cmbEncodingDetection->setCurrentIndex(ui->cmbEncodingDetection->count()-1); 01000 found = true; 01001 } 01002 } 01003 if (!found) 01004 ui->cmbEncodingDetection->setCurrentIndex(KEncodingProber::Universal); 01005 01006 01007 // eol 01008 ui->cmbEOL->setCurrentIndex(KateDocumentConfig::global()->eol()); 01009 ui->chkDetectEOL->setChecked(KateDocumentConfig::global()->allowEolDetection()); 01010 ui->chkEnableBOM->setChecked(KateDocumentConfig::global()->bom()); 01011 01012 ui->chkRemoveTrailingSpaces->setChecked(KateDocumentConfig::global()->removeSpaces()); 01013 uiadv->sbConfigFileSearchDepth->setValue(KateDocumentConfig::global()->searchDirConfigDepth()); 01014 01015 // other stuff 01016 uint f ( KateDocumentConfig::global()->backupFlags() ); 01017 uiadv->chkBackupLocalFiles->setChecked( f & KateDocumentConfig::LocalFiles ); 01018 uiadv->chkBackupRemoteFiles->setChecked( f & KateDocumentConfig::RemoteFiles ); 01019 uiadv->edtBackupPrefix->setText( KateDocumentConfig::global()->backupPrefix() ); 01020 uiadv->edtBackupSuffix->setText( KateDocumentConfig::global()->backupSuffix() ); 01021 uiadv->chkNoSync->setChecked( KateDocumentConfig::global()->swapFileNoSync() ); 01022 } 01023 01024 void KateSaveConfigTab::reset() 01025 { 01026 modeConfigPage->reset(); 01027 } 01028 01029 void KateSaveConfigTab::defaults() 01030 { 01031 modeConfigPage->defaults(); 01032 01033 uiadv->chkBackupLocalFiles->setChecked( true ); 01034 uiadv->chkBackupRemoteFiles->setChecked( false ); 01035 uiadv->edtBackupPrefix->setText( "" ); 01036 uiadv->edtBackupSuffix->setText( "~" ); 01037 uiadv->chkNoSync->setChecked( false ); 01038 } 01039 01040 //END KateSaveConfigTab 01041 01042 //BEGIN KatePartPluginConfigPage 01043 KatePartPluginConfigPage::KatePartPluginConfigPage (QWidget *parent) 01044 : KateConfigPage (parent, "") 01045 , scriptConfigPage (new KateScriptConfigPage(this)) 01046 { 01047 // FIXME: Is really needed to move all this code below to another class, 01048 // since it is another tab itself on the config dialog. This means we should 01049 // initialize, add and work with as we do with scriptConfigPage (ereslibre) 01050 QVBoxLayout *generalLayout = new QVBoxLayout; 01051 generalLayout->setMargin(0); 01052 KTabWidget *tabWidget = new KTabWidget(this); 01053 01054 QWidget *tmpWidget = new QWidget(tabWidget); 01055 QVBoxLayout *internalLayout = new QVBoxLayout; 01056 QWidget *newWidget = new QWidget(tabWidget); 01057 QVBoxLayout *layout = new QVBoxLayout; 01058 newWidget->setLayout(layout); 01059 layout->setMargin(0); 01060 01061 plugins.clear(); 01062 01063 int i = 0; 01064 foreach (const KatePartPluginInfo &info, KatePartPluginManager::self()->pluginList()) 01065 { 01066 KPluginInfo it(info.service()); 01067 it.setPluginEnabled(info.load); 01068 plugins.append(it); 01069 i++; 01070 } 01071 01072 selector = new KPluginSelector(0); 01073 01074 connect(selector, SIGNAL(changed(bool)), this, SLOT(slotChanged())); 01075 connect(selector, SIGNAL(configCommitted(QByteArray)), this, SLOT(slotChanged())); 01076 01077 selector->addPlugins(plugins, KPluginSelector::IgnoreConfigFile, i18n("Editor Plugins"), "Editor"); 01078 layout->addWidget(selector); 01079 01080 internalLayout->addWidget(newWidget); 01081 tmpWidget->setLayout(internalLayout); 01082 01083 // add all tabs 01084 tabWidget->insertTab(0, tmpWidget, i18n("Plugins")); 01085 tabWidget->insertTab(1, scriptConfigPage, i18n("Scripts")); 01086 01087 generalLayout->addWidget(tabWidget); 01088 setLayout(generalLayout); 01089 } 01090 01091 KatePartPluginConfigPage::~KatePartPluginConfigPage () 01092 { 01093 } 01094 01095 void KatePartPluginConfigPage::apply () 01096 { 01097 scriptConfigPage->apply(); 01098 01099 selector->updatePluginsState(); 01100 01101 KatePartPluginList &katePluginList = KatePartPluginManager::self()->pluginList(); 01102 for (int i=0; i < plugins.count(); i++) { 01103 if (plugins[i].isPluginEnabled()) { 01104 if (!katePluginList[i].load) { 01105 KatePartPluginManager::self()->loadPlugin(katePluginList[i]); 01106 KatePartPluginManager::self()->enablePlugin(katePluginList[i]); 01107 } 01108 } else { 01109 if (katePluginList[i].load) { 01110 KatePartPluginManager::self()->disablePlugin(katePluginList[i]); 01111 KatePartPluginManager::self()->unloadPlugin(katePluginList[i]); 01112 } 01113 } 01114 } 01115 } 01116 01117 void KatePartPluginConfigPage::reload () 01118 { 01119 scriptConfigPage->reload(); 01120 01121 selector->load(); 01122 } 01123 01124 void KatePartPluginConfigPage::reset () 01125 { 01126 scriptConfigPage->reset(); 01127 01128 selector->load(); 01129 } 01130 01131 void KatePartPluginConfigPage::defaults () 01132 { 01133 scriptConfigPage->defaults(); 01134 01135 selector->defaults(); 01136 } 01137 //END KatePartPluginConfigPage 01138 01139 class KateScriptNewStuff {}; 01140 01141 /* 01142 class KateScriptNewStuff: public KNewStuff { 01143 public: 01144 KateScriptNewStuff(QWidget *parent):KNewStuff("kate/scripts",parent) {} 01145 virtual ~KateScriptNewStuff() {} 01146 virtual bool install( const QString &fileName ) {return false;} 01147 virtual bool createUploadFile( const QString &fileName ) {return false;} 01148 }; 01149 */ 01150 //BEGIN KateScriptConfigPage 01151 KateScriptConfigPage::KateScriptConfigPage(QWidget *parent): KateConfigPage(parent,""), m_newStuff(new KateScriptNewStuff()) 01152 { 01153 // TODO: Please look at KateSelectConfigTab or ModeConfigPage to add 01154 // a layout like we do there, to be consistent and have on all config 01155 // pages the same distance to the KTabWidget edge (ereslibre) 01156 01157 //m_newStuff->download(); 01158 } 01159 01160 KateScriptConfigPage::~KateScriptConfigPage() 01161 { 01162 delete m_newStuff; 01163 m_newStuff=0; 01164 } 01165 01166 void KateScriptConfigPage::apply () { 01167 } 01168 void KateScriptConfigPage::reload () { 01169 } 01170 01171 //END KateScriptConfigPage 01172 01173 //BEGIN KateHlDownloadDialog 01174 KateHlDownloadDialog::KateHlDownloadDialog(QWidget *parent, const char *name, bool modal) 01175 : KDialog( parent ) 01176 { 01177 setCaption( i18n("Highlight Download") ); 01178 setButtons( User1 | Close ); 01179 setButtonGuiItem( User1, KGuiItem(i18n("&Install")) ); 01180 setDefaultButton( User1 ); 01181 setObjectName( name ); 01182 setModal( modal ); 01183 01184 KVBox* vbox = new KVBox(this); 01185 setMainWidget(vbox); 01186 vbox->setSpacing(-1); 01187 new QLabel(i18n("Select the syntax highlighting files you want to update:"), vbox); 01188 list = new QTreeWidget(vbox); 01189 list->setColumnCount(4); 01190 list->setHeaderLabels(QStringList() << "" << i18n("Name") << i18n("Installed") << i18n("Latest")); 01191 list->setSelectionMode(QAbstractItemView::MultiSelection); 01192 list->setAllColumnsShowFocus(true); 01193 list->setRootIsDecorated(false); 01194 list->setColumnWidth(0, 22); 01195 01196 new QLabel(i18n("<b>Note:</b> New versions are selected automatically."), vbox); 01197 setButtonIcon(User1, KIcon("dialog-ok")); 01198 01199 transferJob = KIO::get( 01200 KUrl(QString(HLDOWNLOADPATH) 01201 + QString("update-") 01202 + KateGlobal::katePartVersion() 01203 + QString(".xml")), KIO::Reload ); 01204 connect(transferJob, SIGNAL(data(KIO::Job *, const QByteArray &)), 01205 this, SLOT(listDataReceived(KIO::Job *, const QByteArray &))); 01206 // void data( KIO::Job *, const QByteArray &data); 01207 resize(450, 400); 01208 connect(this,SIGNAL(user1Clicked()),this,SLOT(slotUser1())); 01209 } 01210 01211 KateHlDownloadDialog::~KateHlDownloadDialog(){} 01212 01213 void KateHlDownloadDialog::listDataReceived(KIO::Job *, const QByteArray &data) 01214 { 01215 if (!transferJob || transferJob->isErrorPage()) 01216 { 01217 enableButton( User1, false ); 01218 if (data.size()==0) 01219 KMessageBox::error(this,i18n("The list of highlightings could not be found on / retrieved from the server")); 01220 return; 01221 } 01222 01223 listData+=QString(data); 01224 kDebug(13000)<<QString("CurrentListData: ")<<listData; 01225 kDebug(13000)<<QString("Data length: %1").arg(data.size()); 01226 kDebug(13000)<<QString("listData length: %1").arg(listData.length()); 01227 if (data.size()==0) 01228 { 01229 if (listData.length()>0) 01230 { 01231 QString installedVersion; 01232 KateHlManager *hlm=KateHlManager::self(); 01233 QDomDocument doc; 01234 doc.setContent(listData); 01235 QDomElement DocElem=doc.documentElement(); 01236 QDomNode n=DocElem.firstChild(); 01237 KateHighlighting *hl = 0; 01238 01239 if (n.isNull()) kDebug(13000)<<"There is no usable childnode"; 01240 while (!n.isNull()) 01241 { 01242 installedVersion=" --"; 01243 01244 QDomElement e=n.toElement(); 01245 if (!e.isNull()) 01246 kDebug(13000)<<QString("NAME: ")<<e.tagName()<<QString(" - ")<<e.attribute("name"); 01247 n=n.nextSibling(); 01248 01249 QString Name=e.attribute("name"); 01250 01251 for (int i=0;i<hlm->highlights();i++) 01252 { 01253 hl=hlm->getHl(i); 01254 if (hl && hl->name()==Name) 01255 { 01256 installedVersion=" "+hl->version(); 01257 break; 01258 } 01259 else hl = 0; 01260 } 01261 01262 // autoselect entry if new or updated. 01263 QTreeWidgetItem* entry = new QTreeWidgetItem(list); 01264 entry->setText(0, ""); 01265 entry->setText(1, e.attribute("name")); 01266 entry->setText(2, installedVersion); 01267 entry->setText(3, e.attribute("version")); 01268 entry->setText(4, e.attribute("url")); 01269 01270 if (!hl || hl->version() < e.attribute("version")) 01271 { 01272 entry->treeWidget()->setItemSelected(entry, true); 01273 entry->setIcon(0, SmallIcon(("get-hot-new-stuff"))); 01274 } 01275 } 01276 list->resizeColumnToContents(1); 01277 } 01278 } 01279 } 01280 01281 void KateHlDownloadDialog::slotUser1() 01282 { 01283 QString destdir=KGlobal::dirs()->saveLocation("data","katepart/syntax/"); 01284 foreach (QTreeWidgetItem *it, list->selectedItems()) 01285 { 01286 KUrl src(it->text(4)); 01287 QString filename=src.fileName(KUrl::ObeyTrailingSlash); 01288 QString dest = destdir+filename; 01289 01290 KIO::NetAccess::download(src,dest, this); 01291 } 01292 01293 // update Config !! 01294 // this rewrites the cache.... 01295 KateSyntaxDocument doc (KateHlManager::self()->getKConfig(), true); 01296 } 01297 //END KateHlDownloadDialog 01298 01299 //BEGIN KateGotoBar 01300 KateGotoBar::KateGotoBar(KTextEditor::View *view, QWidget *parent) 01301 : KateViewBarWidget( true, parent ) 01302 , m_view( view ) 01303 { 01304 Q_ASSERT( m_view != 0 ); // this bar widget is pointless w/o a view 01305 01306 QHBoxLayout *topLayout = new QHBoxLayout( centralWidget() ); 01307 topLayout->setMargin(0); 01308 gotoRange = new KIntSpinBox(centralWidget()); 01309 01310 QLabel *label = new QLabel(i18n("&Go to line:"), centralWidget() ); 01311 label->setBuddy(gotoRange); 01312 01313 QToolButton *btnOK = new QToolButton(centralWidget()); 01314 btnOK->setAutoRaise(true); 01315 btnOK->setIcon(QIcon(SmallIcon("go-jump"))); 01316 btnOK->setText(i18n("Go")); 01317 btnOK->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 01318 connect(btnOK, SIGNAL(clicked()), this, SLOT(gotoLine())); 01319 01320 topLayout->addWidget(label); 01321 topLayout->addWidget(gotoRange, 1); 01322 topLayout->setStretchFactor( gotoRange, 0 ); 01323 topLayout->addWidget(btnOK); 01324 topLayout->addStretch(); 01325 01326 setFocusProxy(gotoRange); 01327 } 01328 01329 void KateGotoBar::updateData() 01330 { 01331 gotoRange->setMaximum(m_view->document()->lines()); 01332 if (!isVisible()) 01333 { 01334 gotoRange->setValue(m_view->cursorPosition().line() + 1); 01335 gotoRange->adjustSize(); // ### does not respect the range :-( 01336 } 01337 gotoRange->setFocus(Qt::OtherFocusReason); 01338 gotoRange->selectAll(); 01339 } 01340 01341 void KateGotoBar::keyPressEvent(QKeyEvent* event) 01342 { 01343 int key = event->key(); 01344 if (key == Qt::Key_Return || key == Qt::Key_Enter) { 01345 gotoLine(); 01346 return; 01347 } 01348 KateViewBarWidget::keyPressEvent(event); 01349 } 01350 01351 void KateGotoBar::gotoLine() 01352 { 01353 m_view->setCursorPosition( KTextEditor::Cursor(gotoRange->value() - 1, 0) ); 01354 m_view->setFocus(); 01355 emit hideMe(); 01356 } 01357 //END KateGotoBar 01358 01359 //BEGIN KateDictionaryBar 01360 KateDictionaryBar::KateDictionaryBar(KateView* view, QWidget *parent) 01361 : KateViewBarWidget( true, parent ) 01362 , m_view( view ) 01363 { 01364 Q_ASSERT(m_view != 0); // this bar widget is pointless w/o a view 01365 01366 QHBoxLayout *topLayout = new QHBoxLayout(centralWidget()); 01367 topLayout->setMargin(0); 01368 //topLayout->setSpacing(spacingHint()); 01369 m_dictionaryComboBox = new Sonnet::DictionaryComboBox(centralWidget()); 01370 connect(m_dictionaryComboBox, SIGNAL(dictionaryChanged(const QString&)), 01371 this, SLOT(dictionaryChanged(const QString&))); 01372 connect(view->doc(), SIGNAL(defaultDictionaryChanged(KateDocument*)), 01373 this, SLOT(updateData())); 01374 QLabel *label = new QLabel(i18n("Dictionary:"), centralWidget()); 01375 label->setBuddy(m_dictionaryComboBox); 01376 01377 topLayout->addWidget(label); 01378 topLayout->addWidget(m_dictionaryComboBox, 1); 01379 topLayout->setStretchFactor(m_dictionaryComboBox, 0); 01380 topLayout->addStretch(); 01381 } 01382 01383 KateDictionaryBar::~KateDictionaryBar() 01384 { 01385 } 01386 01387 void KateDictionaryBar::updateData() 01388 { 01389 KateDocument *document = m_view->doc(); 01390 QString dictionary = document->defaultDictionary(); 01391 if(dictionary.isEmpty()) { 01392 dictionary = Sonnet::Speller().defaultLanguage(); 01393 } 01394 m_dictionaryComboBox->setCurrentByDictionary(dictionary); 01395 } 01396 01397 void KateDictionaryBar::dictionaryChanged(const QString& dictionary) 01398 { 01399 KTextEditor::Range selection = m_view->selectionRange(); 01400 if(selection.isValid() && !selection.isEmpty()) { 01401 m_view->doc()->setDictionary(dictionary, selection); 01402 } 01403 else { 01404 m_view->doc()->setDefaultDictionary(dictionary); 01405 } 01406 } 01407 01408 //END KateGotoBar 01409 01410 01411 //BEGIN KateModOnHdPrompt 01412 KateModOnHdPrompt::KateModOnHdPrompt( KateDocument *doc, 01413 KTextEditor::ModificationInterface::ModifiedOnDiskReason modtype, 01414 const QString &reason, 01415 QWidget *parent ) 01416 : KDialog( parent ), 01417 m_doc( doc ), 01418 m_modtype ( modtype ), 01419 m_proc( 0 ), 01420 m_diffFile( 0 ) 01421 { 01422 setButtons( Ok | Apply | Cancel | User1 ); 01423 01424 QString title, btnOK, whatisok; 01425 if ( modtype == KTextEditor::ModificationInterface::OnDiskDeleted ) 01426 { 01427 title = i18n("File Was Deleted on Disk"); 01428 btnOK = i18n("&Save File As..."); 01429 whatisok = i18n("Lets you select a location and save the file again."); 01430 } else { 01431 title = i18n("File Changed on Disk"); 01432 btnOK = i18n("&Reload File"); 01433 whatisok = i18n("Reload the file from disk. If you have unsaved changes, " 01434 "they will be lost."); 01435 } 01436 01437 setButtonText( Ok, btnOK ); 01438 setButtonText( Apply, i18n("&Ignore") ); 01439 01440 setButtonWhatsThis( Ok, whatisok ); 01441 setButtonWhatsThis( Apply, i18n("Ignore the changes. You will not be prompted again.") ); 01442 setButtonWhatsThis( Cancel, i18n("Do nothing. Next time you focus the file, " 01443 "or try to save it or close it, you will be prompted again.") ); 01444 01445 setCaption( title ); 01446 01447 QWidget *w = new QWidget(this); 01448 ui = new Ui::ModOnHdWidget(); 01449 ui->setupUi( w ); 01450 setMainWidget( w ); 01451 01452 ui->lblIcon->setPixmap( DesktopIcon("dialog-warning" ) ); 01453 ui->lblText->setText( reason + "\n\n" + i18n("What do you want to do?") ); 01454 01455 // If the file isn't deleted, present a diff button, and a overwrite action. 01456 if ( modtype != KTextEditor::ModificationInterface::OnDiskDeleted ) 01457 { 01458 setButtonText( User1, i18n("Overwrite") ); 01459 setButtonWhatsThis( User1, i18n("Overwrite the disk file with the editor content.") ); 01460 connect( ui->btnDiff, SIGNAL(clicked()), this, SLOT(slotDiff()) ); 01461 } 01462 else 01463 { 01464 ui->chkIgnoreWhiteSpaces->setVisible( false ); 01465 ui->btnDiff->setVisible( false ); 01466 showButton( User1, false ); 01467 } 01468 } 01469 01470 KateModOnHdPrompt::~KateModOnHdPrompt() 01471 { 01472 delete m_proc; 01473 m_proc = 0; 01474 if (m_diffFile) { 01475 m_diffFile->setAutoRemove(true); 01476 delete m_diffFile; 01477 m_diffFile = 0; 01478 } 01479 delete ui; 01480 } 01481 01482 void KateModOnHdPrompt::slotDiff() 01483 { 01484 if (m_diffFile) 01485 return; 01486 01487 m_diffFile = new KTemporaryFile(); 01488 m_diffFile->open(); 01489 01490 // Start a KProcess that creates a diff 01491 m_proc = new KProcess( this ); 01492 m_proc->setOutputChannelMode( KProcess::MergedChannels ); 01493 *m_proc << "diff" << QString(ui->chkIgnoreWhiteSpaces->isChecked() ? "-ub" : "-u") 01494 << "-" << m_doc->url().toLocalFile(); 01495 connect( m_proc, SIGNAL(readyRead()), this, SLOT(slotDataAvailable()) ); 01496 connect( m_proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPDone()) ); 01497 01498 setCursor( Qt::WaitCursor ); 01499 // disable the button and checkbox, to hinder the user to run it twice. 01500 ui->chkIgnoreWhiteSpaces->setEnabled( false ); 01501 ui->btnDiff->setEnabled( false ); 01502 01503 m_proc->start(); 01504 01505 QTextStream ts(m_proc); 01506 int lastln = m_doc->lines(); 01507 for ( int l = 0; l < lastln; ++l ) 01508 ts << m_doc->line( l ) << '\n'; 01509 ts.flush(); 01510 m_proc->closeWriteChannel(); 01511 } 01512 01513 void KateModOnHdPrompt::slotDataAvailable() 01514 { 01515 m_diffFile->write(m_proc->readAll()); 01516 } 01517 01518 void KateModOnHdPrompt::slotPDone() 01519 { 01520 setCursor( Qt::ArrowCursor ); 01521 ui->chkIgnoreWhiteSpaces->setEnabled( true ); 01522 ui->btnDiff->setEnabled( true ); 01523 01524 const QProcess::ExitStatus es = m_proc->exitStatus(); 01525 delete m_proc; 01526 m_proc = 0; 01527 01528 if ( es != QProcess::NormalExit ) 01529 { 01530 KMessageBox::sorry( this, 01531 i18n("The diff command failed. Please make sure that " 01532 "diff(1) is installed and in your PATH."), 01533 i18n("Error Creating Diff") ); 01534 delete m_diffFile; 01535 m_diffFile = 0; 01536 return; 01537 } 01538 01539 if ( m_diffFile->size() == 0 ) 01540 { 01541 KMessageBox::information( this, 01542 i18n("Besides white space changes, the files are identical."), 01543 i18n("Diff Output") ); 01544 delete m_diffFile; 01545 m_diffFile = 0; 01546 return; 01547 } 01548 01549 m_diffFile->setAutoRemove(false); 01550 KUrl url = KUrl::fromPath(m_diffFile->fileName()); 01551 delete m_diffFile; 01552 m_diffFile = 0; 01553 01554 // KRun::runUrl should delete the file, once the client exits 01555 KRun::runUrl( url, "text/x-patch", this, true ); 01556 } 01557 01558 void KateModOnHdPrompt::slotButtonClicked(int button) 01559 { 01560 switch(button) 01561 { 01562 case Default: 01563 case Ok: 01564 done( (m_modtype == KTextEditor::ModificationInterface::OnDiskDeleted) ? 01565 Save : Reload ); 01566 break; 01567 case Apply: 01568 { 01569 if ( KMessageBox::warningContinueCancel( 01570 this, 01571 i18n("Ignoring means that you will not be warned again (unless " 01572 "the disk file changes once more): if you save the document, you " 01573 "will overwrite the file on disk; if you do not save then the disk " 01574 "file (if present) is what you have."), 01575 i18n("You Are on Your Own"), 01576 KStandardGuiItem::cont(), 01577 KStandardGuiItem::cancel(), 01578 "kate_ignore_modonhd" ) != KMessageBox::Continue ) 01579 return; 01580 done( Ignore ); 01581 break; 01582 } 01583 case User1: 01584 done( Overwrite ); 01585 break; 01586 default: 01587 KDialog::slotButtonClicked(button); 01588 } 01589 } 01590 01591 //END KateModOnHdPrompt 01592 01593 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference