kate Library API Documentation

katedialogs.cpp

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 00006 Based on work of: 00007 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Library General Public 00011 License version 2 as published by the Free Software Foundation. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 Boston, MA 02111-1307, USA. 00022 */ 00023 00024 //BEGIN Includes 00025 #include "katedialogs.h" 00026 #include "katedialogs.moc" 00027 00028 #include "katesyntaxdocument.h" 00029 #include "katedocument.h" 00030 #include "katefactory.h" 00031 #include "kateconfig.h" 00032 #include "kateschema.h" 00033 #include "kateautoindent.h" 00034 #include "kateview.h" 00035 #include "katebuffer.h" 00036 00037 #include <ktexteditor/plugin.h> 00038 #include <ktexteditor/configinterfaceextension.h> 00039 00040 #include <kio/job.h> 00041 #include <kio/jobclasses.h> 00042 #include <kio/netaccess.h> 00043 00044 #include <kapplication.h> 00045 #include <kspell.h> 00046 #include <kbuttonbox.h> 00047 #include <kcharsets.h> 00048 #include <kcolorcombo.h> 00049 #include <kcolordialog.h> 00050 #include <kcombobox.h> 00051 #include <kdebug.h> 00052 #include <kprocess.h> 00053 #include <kglobal.h> 00054 #include <kglobalsettings.h> 00055 #include <kiconloader.h> 00056 #include <klineedit.h> 00057 #include <klocale.h> 00058 #include <kmessagebox.h> 00059 #include <knuminput.h> 00060 #include <kpopupmenu.h> 00061 #include <krun.h> 00062 #include <kstandarddirs.h> 00063 #include <kaccel.h> 00064 #include <kcharsets.h> 00065 #include <kcolorbutton.h> 00066 #include <kglobal.h> 00067 #include <kkeybutton.h> 00068 #include <kkeydialog.h> 00069 #include <klistview.h> 00070 #include <klocale.h> 00071 #include <kmessagebox.h> 00072 #include <kparts/componentfactory.h> 00073 #include <kregexpeditorinterface.h> 00074 #include <kcombobox.h> 00075 #include <kconfig.h> 00076 #include <kfontdialog.h> 00077 #include <knuminput.h> 00078 #include <kmimetypechooser.h> 00079 00080 #include <qcheckbox.h> 00081 #include <qcombobox.h> 00082 #include <qgroupbox.h> 00083 #include <qhbox.h> 00084 #include <qheader.h> 00085 #include <qfile.h> 00086 #include <qhgroupbox.h> 00087 #include <qlabel.h> 00088 #include <qlayout.h> 00089 #include <qlineedit.h> 00090 #include <qlistview.h> 00091 #include <qmap.h> 00092 #include <qpainter.h> 00093 #include <qpointarray.h> 00094 #include <qpushbutton.h> 00095 #include <qtoolbutton.h> 00096 #include <qvbox.h> 00097 #include <qvgroupbox.h> 00098 #include <qwhatsthis.h> 00099 #include <qwidgetstack.h> 00100 #include <qbuttongroup.h> 00101 #include <qcheckbox.h> 00102 #include <qptrcollection.h> 00103 #include <qdialog.h> 00104 #include <qgrid.h> 00105 #include <qgroupbox.h> 00106 #include <qlabel.h> 00107 #include <qtextcodec.h> 00108 #include <qlayout.h> 00109 #include <qlineedit.h> 00110 #include <qlistbox.h> 00111 #include <qhbox.h> 00112 #include <qobjectlist.h> 00113 #include <qpushbutton.h> 00114 #include <qradiobutton.h> 00115 #include <qspinbox.h> 00116 #include <qstringlist.h> 00117 #include <qtabwidget.h> 00118 #include <qvbox.h> 00119 #include <qvgroupbox.h> 00120 #include <qwhatsthis.h> 00121 #include <qdom.h> 00122 #include <qslider.h> 00123 00124 // trailing slash is important 00125 #define HLDOWNLOADPATH "http://www.kde.org/apps/kate/syntax/" 00126 00127 //END 00128 00129 //BEGIN KateConfigPage 00130 KateConfigPage::KateConfigPage ( QWidget *parent, const char *name ) 00131 : Kate::ConfigPage (parent, name) 00132 , m_changed (false) 00133 { 00134 connect (this, SIGNAL(changed()), this, SLOT(somethingHasChanged ())); 00135 } 00136 00137 KateConfigPage::~KateConfigPage () 00138 { 00139 } 00140 00141 void KateConfigPage::somethingHasChanged () 00142 { 00143 m_changed = true; 00144 kdDebug (13000) << "TEST: something changed on the config page: " << this << endl; 00145 } 00146 //END KateConfigPage 00147 00148 //BEGIN KateSpellConfigPage 00149 KateSpellConfigPage::KateSpellConfigPage( QWidget* parent ) 00150 : KateConfigPage( parent) 00151 { 00152 QVBoxLayout* l = new QVBoxLayout( this ); 00153 cPage = new KSpellConfig( this, 0L, 0L, false ); 00154 l->addWidget( cPage ); 00155 connect( cPage, SIGNAL( configChanged() ), this, SLOT( slotChanged() ) ); 00156 } 00157 00158 void KateSpellConfigPage::apply () 00159 { 00160 // nothing changed, no need to apply stuff 00161 if (!changed()) 00162 return; 00163 00164 // kspell 00165 cPage->writeGlobalSettings (); 00166 } 00167 //END KateSpellConfigPage 00168 00169 //BEGIN KateIndentConfigTab 00170 const int KateIndentConfigTab::flags[] = {KateDocument::cfAutoIndent, KateDocument::cfSpaceIndent, 00171 KateDocument::cfKeepIndentProfile, KateDocument::cfKeepExtraSpaces, KateDocument::cfTabIndents, 00172 KateDocument::cfBackspaceIndents, KateDocumentConfig::cfDoxygenAutoTyping}; 00173 00174 KateIndentConfigTab::KateIndentConfigTab(QWidget *parent) 00175 : KateConfigPage(parent) 00176 { 00177 QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); 00178 int configFlags = KateDocumentConfig::global()->configFlags(); 00179 00180 QVGroupBox *gbAuto = new QVGroupBox(i18n("Automatic Indentation"), this); 00181 00182 opt[0] = new QCheckBox(i18n("A&ctivated"), gbAuto); 00183 00184 QHBox *indentLayout = new QHBox(gbAuto); 00185 QLabel *indentLabel = new QLabel(i18n("&Indentation mode:"), indentLayout); 00186 m_indentMode = new KComboBox (indentLayout); 00187 m_indentMode->insertStringList (KateAutoIndent::listModes()); 00188 indentLabel->setBuddy(m_indentMode); 00189 00190 opt[6] = new QCheckBox(i18n("Insert leading Doxygen \"*\" when typing"), gbAuto); 00191 00192 QVGroupBox *gbSpaces = new QVGroupBox(i18n("Indentation with Spaces"), this); 00193 QVBox *spaceLayout = new QVBox(gbSpaces); 00194 opt[1] = new QCheckBox(i18n("Use &spaces instead of tabs to indent"), spaceLayout ); 00195 00196 indentationWidth = new KIntNumInput(KateDocumentConfig::global()->indentationWidth(), spaceLayout); 00197 indentationWidth->setRange(1, 16, 1, false); 00198 indentationWidth->setLabel(i18n("Number of spaces:"), AlignVCenter); 00199 00200 opt[2] = new QCheckBox(i18n("Keep indent &profile"), this); 00201 opt[3] = new QCheckBox(i18n("&Keep extra spaces"), this); 00202 00203 QVGroupBox *keys = new QVGroupBox(i18n("Keys to Use"), this); 00204 opt[4] = new QCheckBox(i18n("&Tab key indents"), keys); 00205 opt[5] = new QCheckBox(i18n("&Backspace key indents"), keys); 00206 00207 QRadioButton *rb1, *rb2, *rb3; 00208 m_tabs = new QButtonGroup( 1, Qt::Horizontal, i18n("Tab Key Mode if Nothing Selected"), this ); 00209 m_tabs->setRadioButtonExclusive( true ); 00210 m_tabs->insert( rb1=new QRadioButton( i18n("Insert indent &characters"), m_tabs ), 0 ); 00211 m_tabs->insert( rb2=new QRadioButton( i18n("I&nsert tab character"), m_tabs ), 1 ); 00212 m_tabs->insert( rb3=new QRadioButton( i18n("Indent current &line"), m_tabs ), 2 ); 00213 00214 opt[0]->setChecked(configFlags & flags[0]); 00215 opt[1]->setChecked(configFlags & flags[1]); 00216 opt[2]->setChecked(configFlags & flags[2]); 00217 opt[3]->setChecked(configFlags & flags[3]); 00218 opt[4]->setChecked(configFlags & flags[4]); 00219 opt[5]->setChecked(configFlags & flags[5]); 00220 opt[6]->setChecked(configFlags & flags[6]); 00221 00222 layout->addWidget(gbAuto); 00223 layout->addWidget(gbSpaces); 00224 layout->addWidget(opt[2]); 00225 layout->addWidget(opt[3]); 00226 layout->addWidget(keys); 00227 layout->addWidget(m_tabs, 0); 00228 00229 layout->addStretch(); 00230 00231 // What is this? help 00232 QWhatsThis::add(opt[0], i18n( 00233 "When <b>Automatically indent</b> is on, KateView will indent new lines " 00234 "to equal the indentation on the previous line.<p>If the previous line " 00235 "is blank, the nearest line above with text is used.")); 00236 QWhatsThis::add(opt[1], i18n( 00237 "Check this if you want to indent with spaces rather than tabs.")); 00238 QWhatsThis::add(opt[3], i18n( 00239 "Indentations of more than the selected number of spaces will not be " 00240 "shortened.")); 00241 QWhatsThis::add(opt[4], i18n( 00242 "This allows the <b>Tab</b> key to be used to increase the indentation " 00243 "level.")); 00244 QWhatsThis::add(opt[5], i18n( 00245 "This allows the <b>Backspace</b> key to be used to decrease the " 00246 "indentation level.")); 00247 QWhatsThis::add(opt[6], i18n( 00248 "Automatically inserts a leading \"*\" while typing within a Doxygen " 00249 "style comment.")); 00250 QWhatsThis::add(indentationWidth, i18n("The number of spaces to indent with.")); 00251 00252 reload (); 00253 00254 // 00255 // after initial reload, connect the stuff for the changed () signal 00256 // 00257 00258 connect(m_indentMode, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00259 connect(m_indentMode, SIGNAL(activated(int)), this, SLOT(indenterSelected(int))); 00260 00261 connect( opt[0], SIGNAL(toggled(bool)), this, SLOT(somethingToggled())); 00262 connect( opt[1], SIGNAL(toggled(bool)), this, SLOT(somethingToggled())); 00263 00264 connect( opt[0], SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00265 connect( opt[1], SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00266 connect( opt[2], SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00267 connect( opt[3], SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00268 connect( opt[4], SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00269 connect( opt[5], SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00270 connect( opt[6], SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00271 00272 connect(indentationWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00273 00274 connect(rb1, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00275 connect(rb2, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00276 connect(rb3, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00277 } 00278 00279 void KateIndentConfigTab::somethingToggled() { 00280 m_indentMode->setEnabled(opt[0]->isChecked()); 00281 indentationWidth->setEnabled(opt[1]->isChecked()); 00282 } 00283 00284 void KateIndentConfigTab::indenterSelected (int index) 00285 { 00286 if (index == KateDocumentConfig::imCStyle) 00287 opt[6]->setEnabled(true); 00288 else 00289 opt[6]->setEnabled(false); 00290 } 00291 00292 void KateIndentConfigTab::apply () 00293 { 00294 // nothing changed, no need to apply stuff 00295 if (!changed()) 00296 return; 00297 00298 KateDocumentConfig::global()->configStart (); 00299 00300 int configFlags, z; 00301 00302 configFlags = KateDocumentConfig::global()->configFlags(); 00303 for (z = 0; z < numFlags; z++) { 00304 configFlags &= ~flags[z]; 00305 if (opt[z]->isChecked()) configFlags |= flags[z]; 00306 } 00307 00308 KateDocumentConfig::global()->setConfigFlags(configFlags); 00309 KateDocumentConfig::global()->setIndentationWidth(indentationWidth->value()); 00310 00311 KateDocumentConfig::global()->setIndentationMode(m_indentMode->currentItem()); 00312 00313 KateDocumentConfig::global()->setConfigFlags (KateDocumentConfig::cfTabIndentsMode, 2 == m_tabs->id (m_tabs->selected())); 00314 KateDocumentConfig::global()->setConfigFlags (KateDocumentConfig::cfTabInsertsTab, 1 == m_tabs->id (m_tabs->selected())); 00315 00316 KateDocumentConfig::global()->configEnd (); 00317 } 00318 00319 void KateIndentConfigTab::reload () 00320 { 00321 if (KateDocumentConfig::global()->configFlags() & KateDocumentConfig::cfTabIndentsMode) 00322 m_tabs->setButton (2); 00323 else if (KateDocumentConfig::global()->configFlags() & KateDocumentConfig::cfTabInsertsTab) 00324 m_tabs->setButton (1); 00325 else 00326 m_tabs->setButton (0); 00327 00328 m_indentMode->setCurrentItem (KateDocumentConfig::global()->indentationMode()); 00329 00330 somethingToggled (); 00331 indenterSelected (m_indentMode->currentItem()); 00332 } 00333 //END KateIndentConfigTab 00334 00335 //BEGIN KateSelectConfigTab 00336 KateSelectConfigTab::KateSelectConfigTab(QWidget *parent) 00337 : KateConfigPage(parent) 00338 { 00339 QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); 00340 00341 QRadioButton *rb1, *rb2; 00342 00343 m_tabs = new QButtonGroup( 1, Qt::Horizontal, i18n("Selection Mode"), this ); 00344 layout->add (m_tabs); 00345 00346 m_tabs->setRadioButtonExclusive( true ); 00347 m_tabs->insert( rb1=new QRadioButton( i18n("&Normal"), m_tabs ), 0 ); 00348 m_tabs->insert( rb2=new QRadioButton( i18n("&Persistent"), m_tabs ), 1 ); 00349 00350 00351 layout->addStretch(); 00352 00353 QWhatsThis::add(rb1, i18n( 00354 "Selections will be overwritten by typed text and will be lost on " 00355 "cursor movement.")); 00356 QWhatsThis::add(rb2, i18n( 00357 "Selections will stay even after cursor movement and typing.")); 00358 00359 reload (); 00360 00361 // 00362 // after initial reload, connect the stuff for the changed () signal 00363 // 00364 00365 connect(rb1, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00366 connect(rb2, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00367 } 00368 00369 void KateSelectConfigTab::apply () 00370 { 00371 // nothing changed, no need to apply stuff 00372 if (!changed()) 00373 return; 00374 00375 KateDocumentConfig::global()->configStart (); 00376 00377 int configFlags = KateDocumentConfig::global()->configFlags(); 00378 00379 configFlags &= ~KateDocumentConfig::cfPersistent; // clear persistent 00380 00381 if (m_tabs->id (m_tabs->selected()) == 1) 00382 configFlags |= KateDocumentConfig::cfPersistent; // set flag if checked 00383 00384 KateDocumentConfig::global()->setConfigFlags(configFlags); 00385 00386 KateDocumentConfig::global()->configEnd (); 00387 } 00388 00389 void KateSelectConfigTab::reload () 00390 { 00391 if (KateDocumentConfig::global()->configFlags() & KateDocumentConfig::cfPersistent) 00392 m_tabs->setButton (1); 00393 else 00394 m_tabs->setButton (0); 00395 } 00396 //END KateSelectConfigTab 00397 00398 //BEGIN KateEditConfigTab 00399 const int KateEditConfigTab::flags[] = {KateDocument::cfWordWrap, 00400 KateDocument::cfAutoBrackets, KateDocument::cfShowTabs, KateDocument::cfSmartHome, 00401 KateDocument::cfWrapCursor, KateDocumentConfig::cfReplaceTabsDyn, KateDocumentConfig::cfRemoveTrailingDyn}; 00402 00403 KateEditConfigTab::KateEditConfigTab(QWidget *parent) 00404 : KateConfigPage(parent) 00405 { 00406 QVBoxLayout *mainLayout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); 00407 int configFlags = KateDocumentConfig::global()->configFlags(); 00408 00409 QVGroupBox *gbWhiteSpace = new QVGroupBox(i18n("Tabulators"), this); 00410 00411 opt[2] = new QCheckBox(i18n("&Show tabs"), gbWhiteSpace); 00412 opt[2]->setChecked(configFlags & flags[2]); 00413 connect(opt[2], SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00414 00415 opt[5] = new QCheckBox( i18n("Replace tabs with spaces"), gbWhiteSpace ); 00416 opt[5]->setChecked( configFlags & KateDocumentConfig::cfReplaceTabsDyn ); 00417 connect( opt[5], SIGNAL(toggled(bool)), this, SLOT(slotChanged()) ); 00418 00419 e2 = new KIntNumInput(KateDocumentConfig::global()->tabWidth(), gbWhiteSpace); 00420 e2->setRange(1, 16, 1, false); 00421 e2->setLabel(i18n("Tab width:"), AlignVCenter); 00422 connect(e2, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00423 00424 mainLayout->addWidget(gbWhiteSpace); 00425 00426 QVGroupBox *gbWordWrap = new QVGroupBox(i18n("Static Word Wrap"), this); 00427 00428 opt[0] = new QCheckBox(i18n("Enable static &word wrap"), gbWordWrap); 00429 opt[0]->setChecked(KateDocumentConfig::global()->wordWrap()); 00430 connect(opt[0], SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00431 00432 e1 = new KIntNumInput(KateDocumentConfig::global()->wordWrapAt(), gbWordWrap); 00433 e1->setRange(20, 200, 1, false); 00434 e1->setLabel(i18n("Wrap words at:"), AlignVCenter); 00435 connect(e1, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00436 00437 mainLayout->addWidget(gbWordWrap); 00438 00439 QVGroupBox *gbCursor = new QVGroupBox(i18n("Text Cursor Movement"), this); 00440 00441 opt[3] = new QCheckBox(i18n("Smart ho&me"), gbCursor); 00442 opt[3]->setChecked(configFlags & flags[3]); 00443 connect(opt[3], SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00444 00445 opt[4] = new QCheckBox(i18n("Wrap c&ursor"), gbCursor); 00446 opt[4]->setChecked(configFlags & flags[4]); 00447 connect(opt[4], SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00448 00449 e6 = new QCheckBox(i18n("PageUp/PageDown moves cursor"), gbCursor); 00450 e6->setChecked(KateDocumentConfig::global()->pageUpDownMovesCursor()); 00451 connect(e6, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00452 00453 e4 = new KIntNumInput(KateViewConfig::global()->autoCenterLines(), gbCursor); 00454 e4->setRange(0, 1000000, 1, false); 00455 e4->setLabel(i18n("Autocenter cursor (lines):"), AlignVCenter); 00456 connect(e4, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00457 00458 mainLayout->addWidget(gbCursor); 00459 00460 opt[6] = new QCheckBox( i18n("Remove trailing spaces"), this ); 00461 mainLayout->addWidget( opt[6] ); 00462 opt[6]->setChecked( configFlags & KateDocumentConfig::cfRemoveTrailingDyn ); 00463 connect( opt[6], SIGNAL(toggled(bool)), this, SLOT(slotChanged()) ); 00464 00465 opt[1] = new QCheckBox(i18n("Auto &brackets"), this); 00466 mainLayout->addWidget(opt[1]); 00467 opt[1]->setChecked(configFlags & flags[1]); 00468 connect(opt[1], SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00469 00470 e3 = new KIntNumInput(e2, KateDocumentConfig::global()->undoSteps(), this); 00471 e3->setRange(0, 1000000, 1, false); 00472 e3->setSpecialValueText( i18n("Unlimited") ); 00473 e3->setLabel(i18n("Maximum undo steps:"), AlignVCenter); 00474 mainLayout->addWidget(e3); 00475 connect(e3, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00476 00477 QHBoxLayout *e5Layout = new QHBoxLayout(mainLayout); 00478 QLabel *e5Label = new QLabel(i18n("Smart search t&ext from:"), this); 00479 e5Layout->addWidget(e5Label); 00480 e5 = new KComboBox (this); 00481 e5->insertItem( i18n("Nowhere") ); 00482 e5->insertItem( i18n("Selection Only") ); 00483 e5->insertItem( i18n("Selection, then Current Word") ); 00484 e5->insertItem( i18n("Current Word Only") ); 00485 e5->insertItem( i18n("Current Word, then Selection") ); 00486 e5->setCurrentItem(KateViewConfig::global()->textToSearchMode()); 00487 e5Layout->addWidget(e5); 00488 e5Label->setBuddy(e5); 00489 connect(e5, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00490 00491 mainLayout->addStretch(); 00492 00493 // What is this? help 00494 QWhatsThis::add(opt[0], i18n( 00495 "Automatically start a new line of text when the current line exceeds " 00496 "the length specified by the <b>Wrap words at:</b> option." 00497 "<p>This option does not wrap existing lines of text - use the <b>Apply " 00498 "Static Word Wrap</b> option in the <b>Tools</b> menu for that purpose." 00499 "<p>If you want lines to be <i>visually wrapped</i> instead, according " 00500 "to the width of the view, enable <b>Dynamic Word Wrap</b> in the " 00501 "<b>View Defaults</b> config page.")); 00502 QWhatsThis::add(e1, i18n( 00503 "If the Word Wrap option is selected this entry determines the length " 00504 "(in characters) at which the editor will automatically start a new line.")); 00505 QWhatsThis::add(opt[1], i18n( 00506 "When the user types a left bracket ([,(, or {) KateView automatically " 00507 "enters the right bracket (}, ), or ]) to the right of the cursor.")); 00508 QWhatsThis::add(opt[2], i18n( 00509 "The editor will display a symbol to indicate the presence of a tab in " 00510 "the text.")); 00511 QWhatsThis::add(opt[3], i18n( 00512 "When selected, pressing the home key will cause the cursor to skip " 00513 "whitespace and go to the start of a line's text.")); 00514 QWhatsThis::add(e3, i18n( 00515 "Sets the number of undo/redo steps to record. More steps uses more memory.")); 00516 QWhatsThis::add(e4, i18n( 00517 "Sets the number of lines to maintain visible above and below the " 00518 "cursor when possible.")); 00519 QWhatsThis::add(opt[4], i18n( 00520 "When on, moving the insertion cursor using the <b>Left</b> and " 00521 "<b>Right</b> keys will go on to previous/next line at beginning/end of " 00522 "the line, similar to most editors.<p>When off, the insertion cursor " 00523 "cannot be moved left of the line start, but it can be moved off the " 00524 "line end, which can be very handy for programmers.")); 00525 QWhatsThis::add(e6, i18n("Selects whether the PageUp and PageDown keys should alter the vertical position of the cursor relative to the top of the view.")); 00526 QString gstfwt = i18n( 00527 "This determines where KateView will get the search text from " 00528 "(this will be automatically entered into the Find Text dialog): " 00529 "<br>" 00530 "<ul>" 00531 "<li><b>Nowhere:</b> Don't guess the search text." 00532 "</li>" 00533 "<li><b>Selection Only:</b> Use the current text selection, " 00534 "if available." 00535 "</li>" 00536 "<li><b>Selection, then Current Word:</b> Use the current " 00537 "selection if available, otherwise use the current word." 00538 "</li>" 00539 "<li><b>Current Word Only:</b> Use the word that the cursor " 00540 "is currently resting on, if available." 00541 "</li>" 00542 "<li><b>Current Word, then Selection:</b> Use the current " 00543 "word if available, otherwise use the current selection." 00544 "</li>" 00545 "</ul>" 00546 "Note that, in all the above modes, if a search string has " 00547 "not been or cannot be determined, then the Find Text Dialog " 00548 "will fall back to the last search text."); 00549 QWhatsThis::add(e5Label, gstfwt); 00550 QWhatsThis::add(e5, gstfwt); 00551 QWhatsThis::add( opt[5], i18n( 00552 "If this is enabled, the editor will calculate the number of spaces up to " 00553 "the next tab position as defined by the tab width, and insert that number " 00554 "of spaces instead of a TAB character." ) ); 00555 QWhatsThis::add( opt[6], i18n( 00556 "If this is enabled, the editor will remove any trailing whitespace on " 00557 "lines when they are left by the insertion cursor.") ); 00558 } 00559 00560 void KateEditConfigTab::apply () 00561 { 00562 // nothing changed, no need to apply stuff 00563 if (!changed()) 00564 return; 00565 00566 KateViewConfig::global()->configStart (); 00567 KateDocumentConfig::global()->configStart (); 00568 00569 int configFlags, z; 00570 00571 configFlags = KateDocumentConfig::global()->configFlags(); 00572 for (z = 1; z < numFlags; z++) { 00573 configFlags &= ~flags[z]; 00574 if (opt[z]->isChecked()) configFlags |= flags[z]; 00575 } 00576 KateDocumentConfig::global()->setConfigFlags(configFlags); 00577 00578 KateDocumentConfig::global()->setWordWrapAt(e1->value()); 00579 KateDocumentConfig::global()->setWordWrap (opt[0]->isChecked()); 00580 KateDocumentConfig::global()->setTabWidth(e2->value()); 00581 00582 if (e3->value() <= 0) 00583 KateDocumentConfig::global()->setUndoSteps(0); 00584 else 00585 KateDocumentConfig::global()->setUndoSteps(e3->value()); 00586 00587 KateViewConfig::global()->setAutoCenterLines(QMAX(0, e4->value())); 00588 KateViewConfig::global()->setTextToSearchMode(e5->currentItem()); 00589 KateDocumentConfig::global()->setPageUpDownMovesCursor(e6->isChecked()); 00590 00591 KateDocumentConfig::global()->configEnd (); 00592 KateViewConfig::global()->configEnd (); 00593 } 00594 00595 void KateEditConfigTab::reload () 00596 { 00597 00598 } 00599 //END KateEditConfigTab 00600 00601 //BEGIN KateViewDefaultsConfig 00602 KateViewDefaultsConfig::KateViewDefaultsConfig(QWidget *parent) 00603 :KateConfigPage(parent) 00604 { 00605 QRadioButton *rb1; 00606 QRadioButton *rb2; 00607 00608 QVBoxLayout *blay=new QVBoxLayout(this,0,KDialog::spacingHint()); 00609 00610 QVGroupBox *gbWordWrap = new QVGroupBox(i18n("Word Wrap"), this); 00611 00612 m_dynwrap=new QCheckBox(i18n("&Dynamic word wrap"),gbWordWrap); 00613 00614 QHBox *m_dynwrapIndicatorsLay = new QHBox (gbWordWrap); 00615 m_dynwrapIndicatorsLabel = new QLabel( i18n("Dynamic word wrap indicators (if applicable):"), m_dynwrapIndicatorsLay ); 00616 m_dynwrapIndicatorsCombo = new KComboBox( m_dynwrapIndicatorsLay ); 00617 m_dynwrapIndicatorsCombo->insertItem( i18n("Off") ); 00618 m_dynwrapIndicatorsCombo->insertItem( i18n("Follow Line Numbers") ); 00619 m_dynwrapIndicatorsCombo->insertItem( i18n("Always On") ); 00620 m_dynwrapIndicatorsLabel->setBuddy(m_dynwrapIndicatorsCombo); 00621 00622 m_dynwrapAlignLevel = new KIntNumInput(gbWordWrap); 00623 m_dynwrapAlignLevel->setLabel(i18n("Vertically align dynamically wrapped lines to indentation depth:")); 00624 m_dynwrapAlignLevel->setRange(0, 80, 10); 00625 // xgettext:no-c-format 00626 m_dynwrapAlignLevel->setSuffix(i18n("% of View Width")); 00627 m_dynwrapAlignLevel->setSpecialValueText(i18n("Disabled")); 00628 00629 m_wwmarker = new QCheckBox( i18n("Show static word wrap marker (if applicable)"), gbWordWrap ); 00630 00631 blay->addWidget(gbWordWrap); 00632 00633 QVGroupBox *gbFold = new QVGroupBox(i18n("Code Folding"), this); 00634 00635 m_folding=new QCheckBox(i18n("Show &folding markers (if available)"), gbFold ); 00636 m_collapseTopLevel = new QCheckBox( i18n("Collapse toplevel folding nodes"), gbFold ); 00637 m_collapseTopLevel->hide (); 00638 00639 blay->addWidget(gbFold); 00640 00641 QVGroupBox *gbBar = new QVGroupBox(i18n("Borders"), this); 00642 00643 m_icons=new QCheckBox(i18n("Show &icon border"),gbBar); 00644 m_line=new QCheckBox(i18n("Show &line numbers"),gbBar); 00645 m_scrollBarMarks=new QCheckBox(i18n("Show &scrollbar marks"),gbBar); 00646 00647 blay->addWidget(gbBar); 00648 00649 m_bmSort = new QButtonGroup( 1, Qt::Horizontal, i18n("Sort Bookmarks Menu"), this ); 00650 m_bmSort->setRadioButtonExclusive( true ); 00651 m_bmSort->insert( rb1=new QRadioButton( i18n("By &position"), m_bmSort ), 0 ); 00652 m_bmSort->insert( rb2=new QRadioButton( i18n("By c&reation"), m_bmSort ), 1 ); 00653 00654 blay->addWidget(m_bmSort, 0 ); 00655 blay->addStretch(1000); 00656 00657 QWhatsThis::add(m_dynwrap,i18n( 00658 "If this option is checked, the text lines will be wrapped at the view " 00659 "border on the screen.")); 00660 QString wtstr = i18n("Choose when the Dynamic Word Wrap Indicators should be displayed"); 00661 QWhatsThis::add(m_dynwrapIndicatorsLabel, wtstr); 00662 QWhatsThis::add(m_dynwrapIndicatorsCombo, wtstr); 00663 // xgettext:no-c-format 00664 QWhatsThis::add(m_dynwrapAlignLevel, i18n( 00665 "<p>Enables the start of dynamically wrapped lines to be aligned " 00666 "vertically to the indentation level of the first line. This can help " 00667 "to make code and markup more readable.</p><p>Additionally, this allows " 00668 "you to set a maximum width of the screen, as a percentage, after which " 00669 "dynamically wrapped lines will no longer be vertically aligned. For " 00670 "example, at 50%, lines whose indentation levels are deeper than 50% of " 00671 "the width of the screen will not have vertical alignment applied to " 00672 "subsequent wrapped lines.</p>")); 00673 QWhatsThis::add( m_wwmarker, i18n( 00674 "<p>If this option is checked, a vertical line will be drawn at the word " 00675 "wrap column as defined in the <strong>Editing</strong> properties." 00676 "<p>Note that the word wrap marker is only drawn if you use a fixed " 00677 "pitch font." )); 00678 QWhatsThis::add(m_line,i18n( 00679 "If this option is checked, every new view will display line numbers " 00680 "on the left hand side.")); 00681 QWhatsThis::add(m_icons,i18n( 00682 "If this option is checked, every new view will display an icon border " 00683 "on the left hand side.<br><br>The icon border shows bookmark signs, " 00684 "for instance.")); 00685 QWhatsThis::add(m_scrollBarMarks,i18n( 00686 "If this option is checked, every new view will show marks on the " 00687 "vertical scrollbar.<br><br>These marks will, for instance, show " 00688 "bookmarks.")); 00689 QWhatsThis::add(m_folding,i18n( 00690 "If this option is checked, every new view will display marks for code " 00691 "folding, if code folding is available.")); 00692 QWhatsThis::add(m_bmSort,i18n( 00693 "Choose how the bookmarks should be ordered in the <b>Bookmarks</b> menu.")); 00694 QWhatsThis::add(rb1,i18n( 00695 "The bookmarks will be ordered by the line numbers they are placed at.")); 00696 QWhatsThis::add(rb2,i18n( 00697 "Each new bookmark will be added to the bottom, independently from " 00698 "where it is placed in the document.")); 00699 00700 reload(); 00701 00702 // 00703 // after initial reload, connect the stuff for the changed () signal 00704 // 00705 00706 connect(m_dynwrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00707 connect(m_dynwrapIndicatorsCombo, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00708 connect(m_dynwrapAlignLevel, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00709 connect(m_wwmarker, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00710 connect(m_icons, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00711 connect(m_scrollBarMarks, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00712 connect(m_line, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00713 connect(m_folding, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00714 connect(m_collapseTopLevel, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) ); 00715 connect(rb1, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00716 connect(rb2, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00717 } 00718 00719 KateViewDefaultsConfig::~KateViewDefaultsConfig() 00720 { 00721 } 00722 00723 void KateViewDefaultsConfig::apply () 00724 { 00725 // nothing changed, no need to apply stuff 00726 if (!changed()) 00727 return; 00728 00729 KateViewConfig::global()->configStart (); 00730 KateRendererConfig::global()->configStart (); 00731 00732 KateViewConfig::global()->setDynWordWrap (m_dynwrap->isChecked()); 00733 KateViewConfig::global()->setDynWordWrapIndicators (m_dynwrapIndicatorsCombo->currentItem ()); 00734 KateViewConfig::global()->setDynWordWrapAlignIndent(m_dynwrapAlignLevel->value()); 00735 KateRendererConfig::global()->setWordWrapMarker (m_wwmarker->isChecked()); 00736 KateViewConfig::global()->setLineNumbers (m_line->isChecked()); 00737 KateViewConfig::global()->setIconBar (m_icons->isChecked()); 00738 KateViewConfig::global()->setScrollBarMarks (m_scrollBarMarks->isChecked()); 00739 KateViewConfig::global()->setFoldingBar (m_folding->isChecked()); 00740 KateViewConfig::global()->setBookmarkSort (m_bmSort->id (m_bmSort->selected())); 00741 00742 KateRendererConfig::global()->configEnd (); 00743 KateViewConfig::global()->configEnd (); 00744 } 00745 00746 void KateViewDefaultsConfig::reload () 00747 { 00748 m_dynwrap->setChecked(KateViewConfig::global()->dynWordWrap()); 00749 m_dynwrapIndicatorsCombo->setCurrentItem( KateViewConfig::global()->dynWordWrapIndicators() ); 00750 m_dynwrapAlignLevel->setValue(KateViewConfig::global()->dynWordWrapAlignIndent()); 00751 m_wwmarker->setChecked( KateRendererConfig::global()->wordWrapMarker() ); 00752 m_line->setChecked(KateViewConfig::global()->lineNumbers()); 00753 m_icons->setChecked(KateViewConfig::global()->iconBar()); 00754 m_scrollBarMarks->setChecked(KateViewConfig::global()->scrollBarMarks()); 00755 m_folding->setChecked(KateViewConfig::global()->foldingBar()); 00756 m_bmSort->setButton( KateViewConfig::global()->bookmarkSort() ); 00757 } 00758 00759 void KateViewDefaultsConfig::reset () {;} 00760 00761 void KateViewDefaultsConfig::defaults (){;} 00762 //END KateViewDefaultsConfig 00763 00764 //BEGIN KateEditKeyConfiguration 00765 00766 KateEditKeyConfiguration::KateEditKeyConfiguration( QWidget* parent, KateDocument* doc ) 00767 : KateConfigPage( parent ) 00768 { 00769 m_doc = doc; 00770 m_ready = false; 00771 } 00772 00773 void KateEditKeyConfiguration::showEvent ( QShowEvent * ) 00774 { 00775 if (!m_ready) 00776 { 00777 (new QVBoxLayout(this))->setAutoAdd(true); 00778 KateView* view = (KateView*)m_doc->views().at(0); 00779 m_ac = view->editActionCollection(); 00780 m_keyChooser = new KKeyChooser( m_ac, this, false ); 00781 connect( m_keyChooser, SIGNAL( keyChange() ), this, SLOT( slotChanged() ) ); 00782 m_keyChooser->show (); 00783 00784 m_ready = true; 00785 } 00786 00787 QWidget::show (); 00788 } 00789 00790 void KateEditKeyConfiguration::apply() 00791 { 00792 if (m_ready) 00793 { 00794 m_keyChooser->commitChanges(); 00795 m_ac->writeShortcutSettings( "Katepart Shortcuts" ); 00796 } 00797 } 00798 //END KateEditKeyConfiguration 00799 00800 //BEGIN KateSaveConfigTab 00801 KateSaveConfigTab::KateSaveConfigTab( QWidget *parent ) 00802 : KateConfigPage( parent ) 00803 { 00804 int configFlags = KateDocumentConfig::global()->configFlags(); 00805 QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); 00806 00807 QVGroupBox *gbEnc = new QVGroupBox(i18n("File Format"), this); 00808 layout->addWidget( gbEnc ); 00809 00810 QHBox *e5Layout = new QHBox(gbEnc); 00811 QLabel *e5Label = new QLabel(i18n("&Encoding:"), e5Layout); 00812 m_encoding = new KComboBox (e5Layout); 00813 e5Label->setBuddy(m_encoding); 00814 00815 e5Layout = new QHBox(gbEnc); 00816 e5Label = new QLabel(i18n("End &of line:"), e5Layout); 00817 m_eol = new KComboBox (e5Layout); 00818 e5Label->setBuddy(m_eol); 00819 00820 m_eol->insertItem (i18n("UNIX")); 00821 m_eol->insertItem (i18n("DOS/Windows")); 00822 m_eol->insertItem (i18n("Macintosh")); 00823 00824 QVGroupBox *gbMem = new QVGroupBox(i18n("Memory Usage"), this); 00825 layout->addWidget( gbMem ); 00826 00827 e5Layout = new QHBox(gbMem); 00828 e5Layout->setSpacing (32); 00829 blockCountLabel = new QLabel(e5Layout); 00830 blockCount = new QSlider (Qt::Horizontal, e5Layout); 00831 connect(blockCount, SIGNAL(valueChanged(int)), this, SLOT(blockCountChanged(int))); 00832 00833 blockCount->setRange(4, 512); 00834 blockCount->setValue (KateBuffer::maxLoadedBlocks()); 00835 blockCount->setSteps ( 4, 4 ); 00836 blockCountLabel->setBuddy(blockCount); 00837 00838 QVGroupBox *gbWhiteSpace = new QVGroupBox(i18n("Automatic Cleanups on Save"), this); 00839 layout->addWidget( gbWhiteSpace ); 00840 00841 replaceTabs = new QCheckBox(i18n("Replace &tabs with spaces"), gbWhiteSpace); 00842 replaceTabs->setChecked(configFlags & KateDocument::cfReplaceTabs); 00843 00844 removeSpaces = new QCheckBox(i18n("Re&move trailing spaces"), gbWhiteSpace); 00845 removeSpaces->setChecked(configFlags & KateDocument::cfRemoveSpaces); 00846 00847 QGroupBox *gb = new QGroupBox( 1, Qt::Horizontal, i18n("Backup on Save"), this ); 00848 layout->addWidget( gb ); 00849 cbLocalFiles = new QCheckBox( i18n("&Local files"), gb ); 00850 cbRemoteFiles = new QCheckBox( i18n("&Remote files"), gb ); 00851 00852 QHBox *hbBuPrefix = new QHBox( gb ); 00853 QLabel *lBuPrefix = new QLabel( i18n("&Prefix:"), hbBuPrefix ); 00854 leBuPrefix = new QLineEdit( hbBuPrefix ); 00855 lBuPrefix->setBuddy( leBuPrefix ); 00856 00857 QHBox *hbBuSuffix = new QHBox( gb ); 00858 QLabel *lBuSuffix = new QLabel( i18n("&Suffix:"), hbBuSuffix ); 00859 leBuSuffix = new QLineEdit( hbBuSuffix ); 00860 lBuSuffix->setBuddy( leBuSuffix ); 00861 00862 layout->addStretch(); 00863 00864 QWhatsThis::add(replaceTabs, i18n( 00865 "KateView will replace any tabs with the number of spaces indicated in " 00866 "the Tab Width: entry.")); 00867 QWhatsThis::add(removeSpaces, i18n( 00868 "KateView will automatically eliminate extra spaces at the ends of " 00869 "lines of text.")); 00870 QWhatsThis::add( gb, i18n( 00871 "<p>Backing up on save will cause Kate to copy the disk file to " 00872 "'&lt;prefix&gt;&lt;filename&gt;&lt;suffix&gt;' before saving changes." 00873 "<p>The suffix defaults to <strong>~</strong> and prefix is empty by default" ) ); 00874 QWhatsThis::add( cbLocalFiles, i18n( 00875 "Check this if you want backups of local files when saving") ); 00876 QWhatsThis::add( cbRemoteFiles, i18n( 00877 "Check this if you want backups of remote files when saving") ); 00878 QWhatsThis::add( leBuPrefix, i18n( 00879 "Enter the prefix to prepend to the backup file names" ) ); 00880 QWhatsThis::add( leBuSuffix, i18n( 00881 "Enter the suffix to add to the backup file names" ) ); 00882 00883 reload(); 00884 00885 // 00886 // after initial reload, connect the stuff for the changed () signal 00887 // 00888 00889 connect(m_encoding, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00890 connect(m_eol, SIGNAL(activated(int)), this, SLOT(slotChanged())); 00891 connect(blockCount, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); 00892 connect(replaceTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00893 connect(removeSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); 00894 connect( cbLocalFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00895 connect( cbRemoteFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) ); 00896 connect( leBuPrefix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) ); 00897 connect( leBuSuffix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) ); 00898 } 00899 00900 void KateSaveConfigTab::blockCountChanged (int value) 00901 { 00902 blockCountLabel->setText (i18n("Maximum loaded blocks per file: <b>%1</b>").arg (value)); 00903 } 00904 00905 void KateSaveConfigTab::apply() 00906 { 00907 // nothing changed, no need to apply stuff 00908 if (!changed()) 00909 return; 00910 00911 KateBuffer::setMaxLoadedBlocks (blockCount->value()); 00912 00913 KateDocumentConfig::global()->configStart (); 00914 00915 if ( leBuSuffix->text().isEmpty() && leBuPrefix->text().isEmpty() ) { 00916 KMessageBox::information( 00917 this, 00918 i18n("You did not provide a backup suffix or prefix. Using default suffix: '~'"), 00919 i18n("No Backup Suffix or Prefix") 00920 ); 00921 leBuSuffix->setText( "~" ); 00922 } 00923 00924 uint f( 0 ); 00925 if ( cbLocalFiles->isChecked() ) 00926 f |= KateDocumentConfig::LocalFiles; 00927 if ( cbRemoteFiles->isChecked() ) 00928 f |= KateDocumentConfig::RemoteFiles; 00929 00930 KateDocumentConfig::global()->setBackupFlags(f); 00931 KateDocumentConfig::global()->setBackupPrefix(leBuPrefix->text()); 00932 KateDocumentConfig::global()->setBackupSuffix(leBuSuffix->text()); 00933 00934 int configFlags = KateDocumentConfig::global()->configFlags(); 00935 00936 configFlags &= ~KateDocument::cfReplaceTabs; // clear flag 00937 if (replaceTabs->isChecked()) configFlags |= KateDocument::cfReplaceTabs; // set flag if checked 00938 00939 configFlags &= ~KateDocument::cfRemoveSpaces; // clear flag 00940 if (removeSpaces->isChecked()) configFlags |= KateDocument::cfRemoveSpaces; // set flag if checked 00941 00942 KateDocumentConfig::global()->setConfigFlags(configFlags); 00943 00944 KateDocumentConfig::global()->setEncoding(KGlobal::charsets()->encodingForName(m_encoding->currentText())); 00945 00946 KateDocumentConfig::global()->setEol(m_eol->currentItem()); 00947 00948 KateDocumentConfig::global()->configEnd (); 00949 } 00950 00951 void KateSaveConfigTab::reload() 00952 { 00953 // encoding 00954 m_encoding->clear (); 00955 QStringList encodings (KGlobal::charsets()->descriptiveEncodingNames()); 00956 int insert = 0; 00957 for (uint i=0; i < encodings.count(); i++) 00958 { 00959 bool found = false; 00960 QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(KGlobal::charsets()->encodingForName(encodings[i]), found); 00961 00962 if (found) 00963 { 00964 m_encoding->insertItem (encodings[i]); 00965 00966 if ( codecForEnc->name() == KateDocumentConfig::global()->encoding() ) 00967 { 00968 m_encoding->setCurrentItem(insert); 00969 } 00970 00971 insert++; 00972 } 00973 } 00974 00975 // eol 00976 m_eol->setCurrentItem(KateDocumentConfig::global()->eol()); 00977 00978 // other stuff 00979 uint f ( KateDocumentConfig::global()->backupFlags() ); 00980 cbLocalFiles->setChecked( f & KateDocumentConfig::LocalFiles ); 00981 cbRemoteFiles->setChecked( f & KateDocumentConfig::RemoteFiles ); 00982 leBuPrefix->setText( KateDocumentConfig::global()->backupPrefix() ); 00983 leBuSuffix->setText( KateDocumentConfig::global()->backupSuffix() ); 00984 } 00985 00986 void KateSaveConfigTab::reset() 00987 { 00988 } 00989 00990 void KateSaveConfigTab::defaults() 00991 { 00992 cbLocalFiles->setChecked( true ); 00993 cbRemoteFiles->setChecked( false ); 00994 leBuPrefix->setText( "" ); 00995 leBuSuffix->setText( "~" ); 00996 } 00997 00998 //END KateSaveConfigTab 00999 01000 //BEGIN PluginListItem 01001 class KatePartPluginListItem : public QCheckListItem 01002 { 01003 public: 01004 KatePartPluginListItem(bool checked, uint i, const QString &name, QListView *parent); 01005 uint pluginIndex () const { return index; } 01006 01007 protected: 01008 void stateChange(bool); 01009 01010 private: 01011 uint index; 01012 bool silentStateChange; 01013 }; 01014 01015 KatePartPluginListItem::KatePartPluginListItem(bool checked, uint i, const QString &name, QListView *parent) 01016 : QCheckListItem(parent, name, CheckBox) 01017 , index(i) 01018 , silentStateChange(false) 01019 { 01020 silentStateChange = true; 01021 setOn(checked); 01022 silentStateChange = false; 01023 } 01024 01025 void KatePartPluginListItem::stateChange(bool b) 01026 { 01027 if(!silentStateChange) 01028 static_cast<KatePartPluginListView *>(listView())->stateChanged(this, b); 01029 } 01030 //END 01031 01032 //BEGIN PluginListView 01033 KatePartPluginListView::KatePartPluginListView(QWidget *parent, const char *name) 01034 : KListView(parent, name) 01035 { 01036 } 01037 01038 void KatePartPluginListView::stateChanged(KatePartPluginListItem *item, bool b) 01039 { 01040 emit stateChange(item, b); 01041 } 01042 //END 01043 01044 //BEGIN KatePartPluginConfigPage 01045 KatePartPluginConfigPage::KatePartPluginConfigPage (QWidget *parent) : KateConfigPage (parent, "") 01046 { 01047 // sizemanagment 01048 QGridLayout *grid = new QGridLayout( this, 1, 1 ); 01049 grid->setSpacing( KDialogBase::spacingHint() ); 01050 01051 listView = new KatePartPluginListView(this); 01052 listView->addColumn(i18n("Name")); 01053 listView->addColumn(i18n("Comment")); 01054 01055 grid->addWidget( listView, 0, 0); 01056 01057 for (uint i=0; i<KateFactory::self()->plugins().count(); i++) 01058 { 01059 KatePartPluginListItem *item = new KatePartPluginListItem(KateDocumentConfig::global()->plugin(i), i, (KateFactory::self()->plugins())[i]->name(), listView); 01060 item->setText(0, (KateFactory::self()->plugins())[i]->name()); 01061 item->setText(1, (KateFactory::self()->plugins())[i]->comment()); 01062 01063 m_items.append (item); 01064 } 01065 01066 // configure button 01067 01068 btnConfigure = new QPushButton( i18n("Configure..."), this ); 01069 btnConfigure->setEnabled( false ); 01070 grid->addWidget( btnConfigure, 1, 0, Qt::AlignRight ); 01071 connect( btnConfigure, SIGNAL(clicked()), this, SLOT(slotConfigure()) ); 01072 01073 connect( listView, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(slotCurrentChanged(QListViewItem*)) ); 01074 connect( listView, SIGNAL(stateChange(KatePartPluginListItem *, bool)), 01075 this, SLOT(slotStateChanged(KatePartPluginListItem *, bool))); 01076 connect(listView, SIGNAL(stateChange(KatePartPluginListItem *, bool)), this, SLOT(slotChanged())); 01077 } 01078 01079 KatePartPluginConfigPage::~KatePartPluginConfigPage () 01080 { 01081 } 01082 01083 void KatePartPluginConfigPage::apply () 01084 { 01085 // nothing changed, no need to apply stuff 01086 if (!changed()) 01087 return; 01088 01089 KateDocumentConfig::global()->configStart (); 01090 01091 for (uint i=0; i < m_items.count(); i++) 01092 KateDocumentConfig::global()->setPlugin (m_items.at(i)->pluginIndex(), m_items.at(i)->isOn()); 01093 01094 KateDocumentConfig::global()->configEnd (); 01095 } 01096 01097 void KatePartPluginConfigPage::slotStateChanged( KatePartPluginListItem *item, bool b ) 01098 { 01099 if ( b ) 01100 slotCurrentChanged( (QListViewItem*)item ); 01101 } 01102 01103 void KatePartPluginConfigPage::slotCurrentChanged( QListViewItem* i ) 01104 { 01105 KatePartPluginListItem *item = static_cast<KatePartPluginListItem *>(i); 01106 if ( ! item ) return; 01107 01108 bool b = false; 01109 if ( item->isOn() ) 01110 { 01111 01112 // load this plugin, and see if it has config pages 01113 KTextEditor::Plugin *plugin = KTextEditor::createPlugin(QFile::encodeName((KateFactory::self()->plugins())[item->pluginIndex()]->library())); 01114 if ( plugin ) { 01115 KTextEditor::ConfigInterfaceExtension *cie = KTextEditor::configInterfaceExtension( plugin ); 01116 b = ( cie && cie->configPages() ); 01117 } 01118 01119 } 01120 btnConfigure->setEnabled( b ); 01121 } 01122 01123 void KatePartPluginConfigPage::slotConfigure() 01124 { 01125 KatePartPluginListItem *item = static_cast<KatePartPluginListItem*>(listView->currentItem()); 01126 KTextEditor::Plugin *plugin = 01127 KTextEditor::createPlugin(QFile::encodeName((KateFactory::self()->plugins())[item->pluginIndex()]->library())); 01128 01129 if ( ! plugin ) return; 01130 01131 KTextEditor::ConfigInterfaceExtension *cife = 01132 KTextEditor::configInterfaceExtension( plugin ); 01133 01134 if ( ! cife ) 01135 return; 01136 01137 if ( ! cife->configPages() ) 01138 return; 01139 01140 // If we have only one page, we use a simple dialog, else an icon list type 01141 KDialogBase::DialogType dt = 01142 cife->configPages() > 1 ? 01143 KDialogBase::IconList : // still untested 01144 KDialogBase::Plain; 01145 01146 QString name = (KateFactory::self()->plugins())[item->pluginIndex()]->name(); 01147 KDialogBase *kd = new KDialogBase ( dt, 01148 i18n("Configure %1").arg( name ), 01149 KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Help, 01150 KDialogBase::Ok, 01151 this ); 01152 01153 QPtrList<KTextEditor::ConfigPage> editorPages; 01154 01155 for (uint i = 0; i < cife->configPages (); i++) 01156 { 01157 QWidget *page; 01158 if ( dt == KDialogBase::IconList ) 01159 { 01160 QStringList path; 01161 path.clear(); 01162 path << cife->configPageName( i ); 01163 page = kd->addVBoxPage( path, cife->configPageFullName (i), 01164 cife->configPagePixmap(i, KIcon::SizeMedium) ); 01165 } 01166 else 01167 { 01168 page = kd->plainPage(); 01169 QVBoxLayout *_l = new QVBoxLayout( page ); 01170 _l->setAutoAdd( true ); 01171 } 01172 01173 editorPages.append( cife->configPage( i, page ) ); 01174 } 01175 01176 if (kd->exec()) 01177 { 01178 01179 for( uint i=0; i<editorPages.count(); i++ ) 01180 { 01181 editorPages.at( i )->apply(); 01182 } 01183 } 01184 01185 delete kd; 01186 } 01187 //END KatePartPluginConfigPage 01188 01189 //BEGIN KateHlConfigPage 01190 KateHlConfigPage::KateHlConfigPage (QWidget *parent) 01191 : KateConfigPage (parent, "") 01192 , hlData (0) 01193 { 01194 QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); 01195 01196 // hl chooser 01197 QHBox *hbHl = new QHBox( this ); 01198 layout->add (hbHl); 01199 01200 hbHl->setSpacing( KDialog::spacingHint() ); 01201 QLabel *lHl = new QLabel( i18n("H&ighlight:"), hbHl ); 01202 hlCombo = new QComboBox( false, hbHl ); 01203 lHl->setBuddy( hlCombo ); 01204 connect( hlCombo, SIGNAL(activated(int)), 01205 this, SLOT(hlChanged(int)) ); 01206 01207 for( int i = 0; i < KateHlManager::self()->highlights(); i++) { 01208 if (KateHlManager::self()->hlSection(i).length() > 0) 01209 hlCombo->insertItem(KateHlManager::self()->hlSection(i) + QString ("/") + KateHlManager::self()->hlNameTranslated(i)); 01210 else 01211 hlCombo->insertItem(KateHlManager::self()->hlNameTranslated(i)); 01212 } 01213 hlCombo->setCurrentItem(0); 01214 01215 QGroupBox *gbInfo = new QGroupBox( 1, Qt::Horizontal, i18n("Information"), this ); 01216 layout->add (gbInfo); 01217 01218 // author 01219 QHBox *hb1 = new QHBox( gbInfo); 01220 new QLabel( i18n("Author:"), hb1 ); 01221 author = new QLabel (hb1); 01222 author->setTextFormat (Qt::RichText); 01223 01224 // license 01225 QHBox *hb2 = new QHBox( gbInfo); 01226 new QLabel( i18n("License:"), hb2 ); 01227 license = new QLabel (hb2); 01228 01229 QGroupBox *gbProps = new QGroupBox( 1, Qt::Horizontal, i18n("Properties"), this ); 01230 layout->add (gbProps); 01231 01232 // file & mime types 01233 QHBox *hbFE = new QHBox( gbProps); 01234 QLabel *lFileExts = new QLabel( i18n("File e&xtensions:"), hbFE ); 01235 wildcards = new QLineEdit( hbFE ); 01236 lFileExts->setBuddy( wildcards ); 01237 01238 QHBox *hbMT = new QHBox( gbProps ); 01239 QLabel *lMimeTypes = new QLabel( i18n("MIME &types:"), hbMT); 01240 mimetypes = new QLineEdit( hbMT ); 01241 lMimeTypes->setBuddy( mimetypes ); 01242 01243 QHBox *hbMT2 = new QHBox( gbProps ); 01244 QLabel *lprio = new QLabel( i18n("Prio&rity:"), hbMT2); 01245 priority = new KIntNumInput( hbMT2 ); 01246 01247 lprio->setBuddy( priority ); 01248 01249 QToolButton *btnMTW = new QToolButton(hbMT); 01250 btnMTW->setIconSet(QIconSet(SmallIcon("wizard"))); 01251 connect(btnMTW, SIGNAL(clicked()), this, SLOT(showMTDlg())); 01252 01253 // download/new buttons 01254 QHBox *hbBtns = new QHBox( this ); 01255 layout->add (hbBtns); 01256 01257 ((QBoxLayout*)hbBtns->layout())->addStretch(1); // hmm. 01258 hbBtns->setSpacing( KDialog::spacingHint() ); 01259 QPushButton *btnDl = new QPushButton(i18n("Do&wnload..."), hbBtns); 01260 connect( btnDl, SIGNAL(clicked()), this, SLOT(hlDownload()) ); 01261 01262 hlCombo->setCurrentItem( 0 ); 01263 hlChanged(0); 01264 01265 QWhatsThis::add( hlCombo, i18n( 01266 "Choose a <em>Syntax Highlight mode</em> from this list to view its " 01267 "properties below.") ); 01268 QWhatsThis::add( wildcards, i18n( 01269 "The list of file extensions used to determine which files to highlight " 01270 "using the current syntax highlight mode.") ); 01271 QWhatsThis::add( mimetypes, i18n( 01272 "The list of Mime Types used to determine which files to highlight " 01273 "using the current highlight mode.<p>Click the wizard button on the " 01274 "left of the entry field to display the MimeType selection dialog.") ); 01275 QWhatsThis::add( btnMTW, i18n( 01276 "Display a dialog with a list of all available mime types to choose from." 01277 "<p>The <strong>File Extensions</strong> entry will automatically be " 01278 "edited as well.") ); 01279 QWhatsThis::add( btnDl, i18n( 01280 "Click this button to download new or updated syntax highlight " 01281 "descriptions from the Kate website.") ); 01282 01283 layout->addStretch (); 01284 01285 connect( wildcards, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) ); 01286 connect( mimetypes, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) ); 01287 connect( priority, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) ); 01288 } 01289 01290 KateHlConfigPage::~KateHlConfigPage () 01291 { 01292 } 01293 01294 void KateHlConfigPage::apply () 01295 { 01296 // nothing changed, no need to apply stuff 01297 if (!changed()) 01298 return; 01299 01300 writeback(); 01301 01302 for ( QIntDictIterator<KateHlData> it( hlDataDict ); it.current(); ++it ) 01303 KateHlManager::self()->getHl( it.currentKey() )->setData( it.current() ); 01304 01305 KateHlManager::self()->getKConfig()->sync (); 01306 } 01307 01308 void KateHlConfigPage::reload () 01309 { 01310 } 01311 01312 void KateHlConfigPage::hlChanged(int z) 01313 { 01314 writeback(); 01315 01316 KateHighlighting *hl = KateHlManager::self()->getHl( z ); 01317 01318 if (!hl) 01319 { 01320 hlData = 0; 01321 return; 01322 } 01323 01324 if ( !hlDataDict.find( z ) ) 01325 hlDataDict.insert( z, hl->getData() ); 01326 01327 hlData = hlDataDict.find( z ); 01328 wildcards->setText(hlData->wildcards); 01329 mimetypes->setText(hlData->mimetypes); 01330 priority->setValue(hlData->priority); 01331 01332 // split author string if needed into multiple lines ! 01333 QStringList l= QStringList::split (QRegExp("[,;]"), hl->author()); 01334 author->setText (l.join ("<br>")); 01335 01336 license->setText (hl->license()); 01337 } 01338 01339 void KateHlConfigPage::writeback() 01340 { 01341 if (hlData) 01342 { 01343 hlData->wildcards = wildcards->text(); 01344 hlData->mimetypes = mimetypes->text(); 01345 hlData->priority = priority->value(); 01346 } 01347 } 01348 01349 void KateHlConfigPage::hlDownload() 01350 { 01351 KateHlDownloadDialog diag(this,"hlDownload",true); 01352 diag.exec(); 01353 } 01354 01355 void KateHlConfigPage::showMTDlg() 01356 { 01357 QString text = i18n("Select the MimeTypes you want highlighted using the '%1' syntax highlight rules.\nPlease note that this will automatically edit the associated file extensions as well.").arg( hlCombo->currentText() ); 01358 QStringList list = QStringList::split( QRegExp("\\s*;\\s*"), mimetypes->text() ); 01359 KMimeTypeChooserDialog *d = new KMimeTypeChooserDialog( i18n("Select Mime Types"), text, list, "text", this ); 01360 01361 if ( d->exec() == KDialogBase::Accepted ) { 01362 // do some checking, warn user if mime types or patterns are removed. 01363 // if the lists are empty, and the fields not, warn. 01364 wildcards->setText(d->chooser()->patterns().join(";")); 01365 mimetypes->setText(d->chooser()->mimeTypes().join(";")); 01366 } 01367 } 01368 //END KateHlConfigPage 01369 01370 //BEGIN KateHlDownloadDialog 01371 KateHlDownloadDialog::KateHlDownloadDialog(QWidget *parent, const char *name, bool modal) 01372 :KDialogBase(KDialogBase::Swallow, i18n("Highlight Download"), User1|Close, User1, parent, name, modal, true, i18n("&Install")) 01373 { 01374 QVBox* vbox = new QVBox(this); 01375 setMainWidget(vbox); 01376 vbox->setSpacing(spacingHint()); 01377 new QLabel(i18n("Select the syntax highlighting files you want to update:"), vbox); 01378 list = new QListView(vbox); 01379 list->addColumn(""); 01380 list->addColumn(i18n("Name")); 01381 list->addColumn(i18n("Installed")); 01382 list->addColumn(i18n("Latest")); 01383 list->setSelectionMode(QListView::Multi); 01384 list->setAllColumnsShowFocus(true); 01385 01386 new QLabel(i18n("Note: New versions are selected automatically."), vbox); 01387 actionButton (User1)->setIconSet(SmallIconSet("ok")); 01388 01389 transferJob = KIO::get( 01390 KURL(QString(HLDOWNLOADPATH) 01391 + QString("update-") 01392 + QString(KATEPART_VERSION) 01393 + QString(".xml")), true, true ); 01394 connect(transferJob, SIGNAL(data(KIO::Job *, const QByteArray &)), 01395 this, SLOT(listDataReceived(KIO::Job *, const QByteArray &))); 01396 // void data( KIO::Job *, const QByteArray &data); 01397 resize(450, 400); 01398 } 01399 01400 KateHlDownloadDialog::~KateHlDownloadDialog(){} 01401 01402 void KateHlDownloadDialog::listDataReceived(KIO::Job *, const QByteArray &data) 01403 { 01404 if (!transferJob || transferJob->isErrorPage()) 01405 { 01406 actionButton(User1)->setEnabled(false); 01407 return; 01408 } 01409 01410 listData+=QString(data); 01411 kdDebug(13000)<<QString("CurrentListData: ")<<listData<<endl<<endl; 01412 kdDebug(13000)<<QString("Data length: %1").arg(data.size())<<endl; 01413 kdDebug(13000)<<QString("listData length: %1").arg(listData.length())<<endl; 01414 if (data.size()==0) 01415 { 01416 if (listData.length()>0) 01417 { 01418 QString installedVersion; 01419 KateHlManager *hlm=KateHlManager::self(); 01420 QDomDocument doc; 01421 doc.setContent(listData); 01422 QDomElement DocElem=doc.documentElement(); 01423 QDomNode n=DocElem.firstChild(); 01424 KateHighlighting *hl = 0; 01425 01426 if (n.isNull()) kdDebug(13000)<<"There is no usable childnode"<<endl; 01427 while (!n.isNull()) 01428 { 01429 installedVersion=" --"; 01430 01431 QDomElement e=n.toElement(); 01432 if (!e.isNull()) 01433 kdDebug(13000)<<QString("NAME: ")<<e.tagName()<<QString(" - ")<<e.attribute("name")<<endl; 01434 n=n.nextSibling(); 01435 01436 QString Name=e.attribute("name"); 01437 01438 for (int i=0;i<hlm->highlights();i++) 01439 { 01440 hl=hlm->getHl(i); 01441 if (hl && hl->name()==Name) 01442 { 01443 installedVersion=" "+hl->version(); 01444 break; 01445 } 01446 else hl = 0; 01447 } 01448 01449 // autoselect entry if new or updated. 01450 QListViewItem* entry = new QListViewItem( 01451 list, "", e.attribute("name"), installedVersion, 01452 e.attribute("version"),e.attribute("url")); 01453 if (!hl || hl->version() < e.attribute("version")) 01454 { 01455 entry->setSelected(true); 01456 entry->setPixmap(0, SmallIcon(("knewstuff"))); 01457 } 01458 } 01459 } 01460 } 01461 } 01462 01463 void KateHlDownloadDialog::slotUser1() 01464 { 01465 QString destdir=KGlobal::dirs()->saveLocation("data","katepart/syntax/"); 01466 for (QListViewItem *it=list->firstChild();it;it=it->nextSibling()) 01467 { 01468 if (list->isSelected(it)) 01469 { 01470 KURL src(it->text(4)); 01471 QString filename=src.fileName(false); 01472 QString dest = destdir+filename; 01473 01474 KIO::NetAccess::download(src,dest, this); 01475 } 01476 } 01477 01478 // update Config !! 01479 KateSyntaxDocument doc (true); 01480 } 01481 //END KateHlDownloadDialog 01482 01483 //BEGIN KateGotoLineDialog 01484 KateGotoLineDialog::KateGotoLineDialog(QWidget *parent, int line, int max) 01485 : KDialogBase(parent, 0L, true, i18n("Go to Line"), Ok | Cancel, Ok) { 01486 01487 QWidget *page = new QWidget(this); 01488 setMainWidget(page); 01489 01490 QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); 01491 e1 = new KIntNumInput(line, page); 01492 e1->setRange(1, max); 01493 e1->setEditFocus(true); 01494 01495 QLabel *label = new QLabel( e1,i18n("&Go to line:"), page ); 01496 topLayout->addWidget(label); 01497 topLayout->addWidget(e1); 01498 topLayout->addSpacing(spacingHint()); // A little bit extra space 01499 topLayout->addStretch(10); 01500 e1->setFocus(); 01501 } 01502 01503 int KateGotoLineDialog::getLine() { 01504 return e1->value(); 01505 } 01506 //END KateGotoLineDialog 01507 01508 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 17 11:35:12 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003