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