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_keyChooser = new KKeyChooser( view->editActionCollection(), this, false );
00671     connect( m_keyChooser, SIGNAL( keyChange() ), this, SLOT( slotChanged() ) );
00672     m_keyChooser->show ();
00673 
00674     m_ready = true;
00675   }
00676 
00677   QWidget::show ();
00678 }
00679 
00680 void EditKeyConfiguration::apply()
00681 {
00682   if (m_ready)
00683   {
00684     m_keyChooser->save();
00685   }
00686 }
00687 //END EditKeyConfiguration
00688 
00689 //BEGIN SaveConfigTab
00690 SaveConfigTab::SaveConfigTab( QWidget *parent )
00691   : KateConfigPage( parent )
00692 {
00693   int configFlags = KateDocumentConfig::global()->configFlags();
00694   QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() );
00695 
00696   QVGroupBox *gbEnc = new QVGroupBox(i18n("File Format"), this);
00697   layout->addWidget( gbEnc );
00698 
00699   QHBox *e5Layout = new QHBox(gbEnc);
00700   QLabel *e5Label = new QLabel(i18n("&Encoding:"), e5Layout);
00701   m_encoding = new KComboBox (e5Layout);
00702   e5Label->setBuddy(m_encoding);
00703 
00704 
00705   e5Layout = new QHBox(gbEnc);
00706   e5Label = new QLabel(i18n("End &of line:"), e5Layout);
00707   m_eol = new KComboBox (e5Layout);
00708   e5Label->setBuddy(m_eol);
00709 
00710   m_eol->insertItem (i18n("Unix"));
00711   m_eol->insertItem (i18n("Dos/Windows"));
00712   m_eol->insertItem (i18n("Macintosh"));
00713 
00714   QVGroupBox *gbWhiteSpace = new QVGroupBox(i18n("Automatic Cleanups on Save"), this);
00715   layout->addWidget( gbWhiteSpace );
00716 
00717   replaceTabs = new QCheckBox(i18n("Replace &tabs with spaces"), gbWhiteSpace);
00718   replaceTabs->setChecked(configFlags & KateDocument::cfReplaceTabs);
00719 
00720 
00721   removeSpaces = new QCheckBox(i18n("Re&move trailing spaces"), gbWhiteSpace);
00722   removeSpaces->setChecked(configFlags & KateDocument::cfRemoveSpaces);
00723 
00724   QGroupBox *gb = new QGroupBox( 1, Qt::Horizontal, i18n("Backup on Save"), this );
00725   layout->addWidget( gb );
00726   cbLocalFiles = new QCheckBox( i18n("&Local files"), gb );
00727   cbRemoteFiles = new QCheckBox( i18n("&Remote files"), gb );
00728   QHBox *hbBuSuffix = new QHBox( gb );
00729   QLabel *lBuSuffix = new QLabel( i18n("&Suffix:"), hbBuSuffix );
00730   leBuSuffix = new QLineEdit( hbBuSuffix );
00731   lBuSuffix->setBuddy( leBuSuffix );
00732 
00733   layout->addStretch();
00734 
00735   QWhatsThis::add(replaceTabs, i18n("KateView will replace any tabs with the number of spaces indicated in the Tab Width: entry."));
00736   QWhatsThis::add(removeSpaces, i18n("KateView will automatically eliminate extra spaces at the ends of lines of text."));
00737 
00738   QWhatsThis::add( gb, i18n(
00739         "<p>Backing up on save will cause Kate to copy the disk file to "
00740         "'&lt;filename&gt;&lt;suffix&gt;' before saving changes."
00741         "<p>The suffix defaults to <strong>~</strong>" ) );
00742   QWhatsThis::add( cbLocalFiles, i18n(
00743         "Check this if you want backups of local files when saving") );
00744   QWhatsThis::add( cbRemoteFiles, i18n(
00745         "Check this if you want backups of remote files when saving") );
00746   QWhatsThis::add( leBuSuffix, i18n(
00747         "Enter the suffix to add to the backup file names" ) );
00748 
00749   reload();
00750   
00751   //
00752   // after initial reload, connect the stuff for the changed () signal
00753   //
00754     
00755   connect(m_encoding, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00756   connect(m_eol, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00757   connect(replaceTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00758   connect(removeSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00759   connect( cbLocalFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
00760   connect( cbRemoteFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
00761   connect( leBuSuffix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00762 }
00763 
00764 void SaveConfigTab::apply()
00765 {
00766   // nothing changed, no need to apply stuff
00767   if (!changed())
00768     return;
00769 
00770   KateDocumentConfig::global()->configStart ();
00771 
00772   if ( leBuSuffix->text().isEmpty() ) {
00773     KMessageBox::information(
00774                 this,
00775                 i18n("You didn't provide a backup suffix. Using default: '~'"),
00776                 i18n("No Backup Suffix")
00777                         );
00778     leBuSuffix->setText( "~" );
00779   }
00780 
00781   uint f( 0 );
00782   if ( cbLocalFiles->isChecked() )
00783     f |= KateDocumentConfig::LocalFiles;
00784   if ( cbRemoteFiles->isChecked() )
00785     f |= KateDocumentConfig::RemoteFiles;
00786 
00787   KateDocumentConfig::global()->setBackupFlags(f);
00788   KateDocumentConfig::global()->setBackupSuffix(leBuSuffix->text());
00789 
00790   int configFlags = KateDocumentConfig::global()->configFlags();
00791 
00792   configFlags &= ~KateDocument::cfReplaceTabs; // clear flag
00793   if (replaceTabs->isChecked()) configFlags |= KateDocument::cfReplaceTabs; // set flag if checked
00794 
00795   configFlags &= ~KateDocument::cfRemoveSpaces; // clear flag
00796   if (removeSpaces->isChecked()) configFlags |= KateDocument::cfRemoveSpaces; // set flag if checked
00797 
00798   KateDocumentConfig::global()->setConfigFlags(configFlags);
00799 
00800   KateDocumentConfig::global()->setEncoding(KGlobal::charsets()->encodingForName(m_encoding->currentText()));
00801 
00802   KateDocumentConfig::global()->setEol(m_eol->currentItem());
00803   
00804   KateDocumentConfig::global()->configEnd ();
00805 }
00806 
00807 void SaveConfigTab::reload()
00808 {
00809   // encoding
00810   m_encoding->clear ();
00811   QStringList encodings (KGlobal::charsets()->descriptiveEncodingNames());
00812   int insert = 0;
00813   for (uint i=0; i < encodings.count(); i++)
00814   {
00815     bool found = false;
00816     QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(KGlobal::charsets()->encodingForName(encodings[i]), found);
00817 
00818     if (found)
00819     {
00820       m_encoding->insertItem (encodings[i]);
00821 
00822       if ( codecForEnc->name() == KateDocumentConfig::global()->encoding() )
00823       {
00824         m_encoding->setCurrentItem(insert);
00825       }
00826 
00827       insert++;
00828     }
00829   }
00830 
00831   // eol
00832   m_eol->setCurrentItem(KateDocumentConfig::global()->eol());
00833 
00834   // other stuff
00835   uint f ( KateDocumentConfig::global()->backupFlags() );
00836   cbLocalFiles->setChecked( f & KateDocumentConfig::LocalFiles );
00837   cbRemoteFiles->setChecked( f & KateDocumentConfig::RemoteFiles );
00838   leBuSuffix->setText( KateDocumentConfig::global()->backupSuffix() );
00839 }
00840 
00841 void SaveConfigTab::reset()
00842 {
00843 }
00844 
00845 void SaveConfigTab::defaults()
00846 {
00847   cbLocalFiles->setChecked( true );
00848   cbRemoteFiles->setChecked( false );
00849   leBuSuffix->setText( "~" );
00850 }
00851 
00852 //END SaveConfigTab
00853 
00854 //BEGIN PluginListItem
00855 class KatePartPluginListItem : public QCheckListItem
00856 {
00857   public:
00858     KatePartPluginListItem(bool checked, uint i, const QString &name, QListView *parent);
00859     uint pluginIndex () const { return index; }
00860   
00861   protected:        
00862     void stateChange(bool);
00863     
00864   private:
00865     uint index;
00866     bool silentStateChange;
00867 };
00868          
00869 KatePartPluginListItem::KatePartPluginListItem(bool checked, uint i, const QString &name, QListView *parent)
00870   : QCheckListItem(parent, name, CheckBox)
00871   , index(i)
00872   , silentStateChange(false)
00873 {
00874   silentStateChange = true;
00875   setOn(checked);
00876   silentStateChange = false;
00877 }
00878 
00879 void KatePartPluginListItem::stateChange(bool b)
00880 {
00881   if(!silentStateChange)
00882     static_cast<KatePartPluginListView *>(listView())->stateChanged(this, b);
00883 }
00884 //END
00885 
00886 //BEGIN PluginListView
00887 KatePartPluginListView::KatePartPluginListView(QWidget *parent, const char *name)
00888   : KListView(parent, name)
00889 {
00890 }
00891 
00892 void KatePartPluginListView::stateChanged(KatePartPluginListItem *item, bool b)
00893 {
00894   emit stateChange(item, b);
00895 }
00896 //END
00897 
00898 //BEGIN PluginConfigPage
00899 PluginConfigPage::PluginConfigPage (QWidget *parent) : KateConfigPage (parent, "")
00900 {
00901   // sizemanagment
00902   QGridLayout *grid = new QGridLayout( this, 1, 1 );
00903 
00904   listView = new KatePartPluginListView(this);
00905   listView->addColumn(i18n("Name"));
00906   listView->addColumn(i18n("Comment"));
00907 
00908   grid->addWidget( listView, 0, 0);
00909 
00910   for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
00911   {
00912     KatePartPluginListItem *item = new KatePartPluginListItem(KateDocumentConfig::global()->plugin(i), i, (KateFactory::self()->plugins())[i]->name(), listView);
00913     item->setText(0, (KateFactory::self()->plugins())[i]->name());
00914     item->setText(1, (KateFactory::self()->plugins())[i]->comment());
00915     
00916     m_items.append (item);
00917   }
00918   
00919   connect(listView, SIGNAL(stateChange(KatePartPluginListItem *, bool)), this, SLOT(slotChanged()));
00920 }
00921 
00922 PluginConfigPage::~PluginConfigPage ()
00923 {
00924 }
00925 
00926 void PluginConfigPage::apply ()
00927 {
00928   // nothing changed, no need to apply stuff
00929   if (!changed())
00930     return;
00931     
00932   KateDocumentConfig::global()->configStart ();
00933     
00934   for (uint i=0; i < m_items.count(); i++)
00935     KateDocumentConfig::global()->setPlugin (m_items.at(i)->pluginIndex(), m_items.at(i)->isOn());
00936   
00937   KateDocumentConfig::global()->configEnd ();
00938 }
00939 //END
00940 
00941 //BEGIN HlConfigPage
00942 HlConfigPage::HlConfigPage (QWidget *parent)
00943  : KateConfigPage (parent, "")
00944  , hlData (0)
00945 {
00946   QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() );
00947 
00948   // hl chooser
00949   QHBox *hbHl = new QHBox( this );
00950   layout->add (hbHl);
00951 
00952   hbHl->setSpacing( KDialog::spacingHint() );
00953   QLabel *lHl = new QLabel( i18n("H&ighlight:"), hbHl );
00954   hlCombo = new QComboBox( false, hbHl );
00955   lHl->setBuddy( hlCombo );
00956   connect( hlCombo, SIGNAL(activated(int)),
00957            this, SLOT(hlChanged(int)) );
00958 
00959   for( int i = 0; i < HlManager::self()->highlights(); i++) {
00960     if (HlManager::self()->hlSection(i).length() > 0)
00961       hlCombo->insertItem(HlManager::self()->hlSection(i) + QString ("/") + HlManager::self()->hlName(i));
00962     else
00963       hlCombo->insertItem(HlManager::self()->hlName(i));
00964   }
00965   hlCombo->setCurrentItem(0);
00966 
00967   QGroupBox *gbProps = new QGroupBox( 1, Qt::Horizontal, i18n("Properties"), this );
00968   layout->add (gbProps);
00969 
00970   // file & mime types
00971   QHBox *hbFE = new QHBox( gbProps);
00972   QLabel *lFileExts = new QLabel( i18n("File e&xtensions:"), hbFE );
00973   wildcards  = new QLineEdit( hbFE );
00974   lFileExts->setBuddy( wildcards );
00975 
00976   QHBox *hbMT = new QHBox( gbProps );
00977   QLabel *lMimeTypes = new QLabel( i18n("MIME &types:"), hbMT);
00978   mimetypes = new QLineEdit( hbMT );
00979   lMimeTypes->setBuddy( mimetypes );
00980 
00981   QHBox *hbMT2 = new QHBox( gbProps );
00982   QLabel *lprio = new QLabel( i18n("Prio&rity:"), hbMT2);
00983   priority = new KIntNumInput( hbMT2 );
00984 
00985   lprio->setBuddy( priority );
00986 
00987   QToolButton *btnMTW = new QToolButton(hbMT);
00988   btnMTW->setIconSet(QIconSet(SmallIcon("wizard")));
00989   connect(btnMTW, SIGNAL(clicked()), this, SLOT(showMTDlg()));
00990 
00991   // download/new buttons
00992   QHBox *hbBtns = new QHBox( this );
00993   layout->add (hbBtns);
00994 
00995   ((QBoxLayout*)hbBtns->layout())->addStretch(1); // hmm.
00996   hbBtns->setSpacing( KDialog::spacingHint() );
00997   QPushButton *btnDl = new QPushButton(i18n("Do&wnload..."), hbBtns);
00998   connect( btnDl, SIGNAL(clicked()), this, SLOT(hlDownload()) );
00999 
01000   hlCombo->setCurrentItem( 0 );
01001   hlChanged(0);
01002 
01003   QWhatsThis::add( hlCombo,   i18n("Choose a <em>Syntax Highlight mode</em> from this list to view its properties below.") );
01004   QWhatsThis::add( wildcards, i18n("The list of file extensions used to determine which files to highlight using the current syntax highlight mode.") );
01005   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.") );
01006   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.") );
01007   QWhatsThis::add( btnDl,     i18n("Click this button to download new or updated syntax highlight descriptions from the Kate website.") );
01008 
01009   layout->addStretch ();
01010 
01011   connect( wildcards, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
01012   connect( mimetypes, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
01013   connect( priority, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
01014 }
01015 
01016 HlConfigPage::~HlConfigPage ()
01017 {
01018 }
01019 
01020 void HlConfigPage::apply ()
01021 {
01022   // nothing changed, no need to apply stuff
01023   if (!changed())
01024     return;
01025 
01026   writeback();
01027 
01028   for ( QIntDictIterator<HlData> it( hlDataDict ); it.current(); ++it )
01029     HlManager::self()->getHl( it.currentKey() )->setData( it.current() );
01030 
01031   HlManager::self()->getKConfig()->sync ();
01032 }
01033 
01034 void HlConfigPage::reload ()
01035 {
01036 }
01037 
01038 void HlConfigPage::hlChanged(int z)
01039 {
01040   writeback();
01041 
01042   if ( ! hlDataDict.find( z ) )
01043     hlDataDict.insert( z, HlManager::self()->getHl( z )->getData() );
01044 
01045   hlData = hlDataDict.find( z );
01046   wildcards->setText(hlData->wildcards);
01047   mimetypes->setText(hlData->mimetypes);
01048   priority->setValue(hlData->priority);
01049 }
01050 
01051 void HlConfigPage::writeback()
01052 {
01053   if (hlData)
01054   {
01055     hlData->wildcards = wildcards->text();
01056     hlData->mimetypes = mimetypes->text();
01057     hlData->priority = priority->value();
01058   }
01059 }
01060 
01061 void HlConfigPage::hlDownload()
01062 {
01063   HlDownloadDialog diag(this,"hlDownload",true);
01064   diag.exec();
01065 }
01066 
01067 void HlConfigPage::showMTDlg()
01068 {
01069   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() );
01070   QStringList list = QStringList::split( QRegExp("\\s*;\\s*"), mimetypes->text() );
01071   KMimeTypeChooserDlg *d = new KMimeTypeChooserDlg( this, i18n("Select Mime Types"), text, list );
01072 
01073   if ( d->exec() == KDialogBase::Accepted ) {
01074     // do some checking, warn user if mime types or patterns are removed.
01075     // if the lists are empty, and the fields not, warn.
01076     wildcards->setText(d->patterns().join(";"));
01077     mimetypes->setText(d->mimeTypes().join(";"));
01078   }
01079 }
01080 //END HlConfigPage
01081 
01082 //BEGIN KMimeTypeChooser
01083 /*********************************************************************/
01084 /*               KMimeTypeChooser Implementation                     */
01085 /*********************************************************************/
01086 KMimeTypeChooser::KMimeTypeChooser( QWidget *parent, const QString &text, const QStringList &selectedMimeTypes, bool editbutton, bool showcomment, bool showpatterns)
01087     : QVBox( parent )
01088 {
01089   setSpacing( KDialogBase::spacingHint() );
01090 
01091 /* HATE!!!! geometry management seems BADLY broken :(((((((((((
01092    Problem: if richtext is used (or Qt::WordBreak is on in the label),
01093    the list view is NOT resized when the parent box is.
01094    No richtext :(((( */
01095   if ( !text.isEmpty() ) {
01096     new QLabel( text, this );
01097   }
01098 
01099   lvMimeTypes = new QListView( this );
01100   lvMimeTypes->addColumn( i18n("Mime Type") );
01101   if ( showcomment )
01102     lvMimeTypes->addColumn( i18n("Comment") );
01103   if ( showpatterns )
01104     lvMimeTypes->addColumn( i18n("Patterns") );
01105   lvMimeTypes->setRootIsDecorated( true );
01106 
01107   //lvMimeTypes->clear(); WHY?!
01108   QMap<QString,QListViewItem*> groups;
01109   // thanks to kdebase/kcontrol/filetypes/filetypesview
01110   KMimeType::List mimetypes = KMimeType::allMimeTypes();
01111   QValueListIterator<KMimeType::Ptr> it(mimetypes.begin());
01112 
01113   QListViewItem *groupItem;
01114   bool agroupisopen = false;
01115   QListViewItem *idefault = 0; //open this, if all other fails
01116   for (; it != mimetypes.end(); ++it) {
01117     QString mimetype = (*it)->name();
01118     int index = mimetype.find("/");
01119     QString maj = mimetype.left(index);
01120     QString min = mimetype.right(mimetype.length() - (index+1));
01121 
01122     QMapIterator<QString,QListViewItem*> mit = groups.find( maj );
01123     if ( mit == groups.end() ) {
01124         groupItem = new QListViewItem( lvMimeTypes, maj );
01125         groups.insert( maj, groupItem );
01126         if (maj == "text")
01127           idefault = groupItem;
01128     }
01129     else
01130         groupItem = mit.data();
01131 
01132     QCheckListItem *item = new QCheckListItem( groupItem, min, QCheckListItem::CheckBox );
01133     item->setPixmap( 0, SmallIcon( (*it)->icon(QString::null,false) ) );
01134     int cl = 1;
01135     if ( showcomment ) {
01136       item->setText( cl, (*it)->comment(QString::null, false) );
01137       cl++;
01138     }
01139     if ( showpatterns )
01140       item->setText( cl, (*it)->patterns().join("; ") );
01141     if ( selectedMimeTypes.contains(mimetype) ) {
01142       item->setOn( true );
01143       groupItem->setOpen( true );
01144       agroupisopen = true;
01145       lvMimeTypes->ensureItemVisible( item );// actually, i should do this for the first item only.
01146     }
01147   }
01148 
01149   if (! agroupisopen)
01150     idefault->setOpen( true );
01151 
01152   if (editbutton) {
01153     QHBox *btns = new QHBox( this );
01154     ((QBoxLayout*)btns->layout())->addStretch(1); // hmm.
01155     btnEditMimeType = new QPushButton( i18n("&Edit..."), btns );
01156     connect( btnEditMimeType, SIGNAL(clicked()), this, SLOT(editMimeType()) );
01157     btnEditMimeType->setEnabled( false );
01158     connect( lvMimeTypes, SIGNAL( doubleClicked ( QListViewItem * )), this, SLOT( editMimeType()));
01159     connect( lvMimeTypes, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(slotCurrentChanged(QListViewItem*)) );
01160     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.") );
01161   }
01162 }
01163 
01164 void KMimeTypeChooser::editMimeType()
01165 {
01166   if ( !(lvMimeTypes->currentItem() && (lvMimeTypes->currentItem())->parent()) ) return;
01167   QString mt = (lvMimeTypes->currentItem()->parent())->text( 0 ) + "/" + (lvMimeTypes->currentItem())->text( 0 );
01168   // thanks to libkonq/konq_operations.cc
01169   QString keditfiletype = QString::fromLatin1("keditfiletype");
01170   KRun::runCommand( keditfiletype + " " + KProcess::quote(mt),
01171                     keditfiletype, keditfiletype /*unused*/);
01172 }
01173 
01174 void KMimeTypeChooser::slotCurrentChanged(QListViewItem* i)
01175 {
01176   btnEditMimeType->setEnabled( i->parent() );
01177 }
01178 
01179 QStringList KMimeTypeChooser::selectedMimeTypesStringList()
01180 {
01181   QStringList l;
01182   QListViewItemIterator it( lvMimeTypes );
01183   for (; it.current(); ++it) {
01184     if ( it.current()->parent() && ((QCheckListItem*)it.current())->isOn() )
01185       l << it.current()->parent()->text(0) + "/" + it.current()->text(0); // FIXME: uncecked, should be Ok unless someone changes mimetypes during this!
01186   }
01187   return l;
01188 }
01189 
01190 QStringList KMimeTypeChooser::patterns()
01191 {
01192   QStringList l;
01193   KMimeType::Ptr p;
01194   QString defMT = KMimeType::defaultMimeType();
01195   QListViewItemIterator it( lvMimeTypes );
01196   for (; it.current(); ++it) {
01197     if ( it.current()->parent() && ((QCheckListItem*)it.current())->isOn() ) {
01198       p = KMimeType::mimeType( it.current()->parent()->text(0) + "/" + it.current()->text(0) );
01199       if ( p->name() != defMT )
01200         l += p->patterns();
01201     }
01202   }
01203   return l;
01204 }
01205 //END
01206 
01207 //BEGIN KMimeTypeChooserDlg
01208 /*********************************************************************/
01209 /*               KMimeTypeChooserDlg Implementation                  */
01210 /*********************************************************************/
01211 KMimeTypeChooserDlg::KMimeTypeChooserDlg(QWidget *parent,
01212                          const QString &caption, const QString& text,
01213                          const QStringList &selectedMimeTypes,
01214                          bool editbutton, bool showcomment, bool showpatterns )
01215     : KDialogBase(parent, 0, true, caption, Cancel|Ok, Ok)
01216 {
01217   KConfig *config = kapp->config();
01218 
01219   chooser = new KMimeTypeChooser( this, text, selectedMimeTypes, editbutton, showcomment, showpatterns);
01220   setMainWidget(chooser);
01221 
01222   config->setGroup("KMimeTypeChooserDlg");
01223   resize( config->readSizeEntry("size", new QSize(400,300)) );
01224 }
01225 
01226 KMimeTypeChooserDlg::~KMimeTypeChooserDlg()
01227 {
01228   KConfig *config = kapp->config();
01229   config->setGroup("KMimeTypeChooserDlg");
01230   config->writeEntry("size", size());
01231 }
01232 
01233 QStringList KMimeTypeChooserDlg::mimeTypes()
01234 {
01235   return chooser->selectedMimeTypesStringList();
01236 }
01237 
01238 QStringList KMimeTypeChooserDlg::patterns()
01239 {
01240   return chooser->patterns();
01241 }
01242 //END
01243 
01244 HlDownloadDialog::HlDownloadDialog(QWidget *parent, const char *name, bool modal)
01245   :KDialogBase(KDialogBase::Swallow, i18n("Highlight Download"), User1|Cancel, User1, parent, name, modal,false,i18n("&Install"))
01246 {
01247   setMainWidget( list=new QListView(this));
01248   list->addColumn(i18n("Name"));
01249   list->addColumn(i18n("Installed"));
01250   list->addColumn(i18n("Latest"));
01251   list->addColumn(i18n("Release Date"));
01252   list->setSelectionMode(QListView::Multi);
01253   KIO::TransferJob *getIt=KIO::get(KURL(HLDOWNLOADPATH), true, true );
01254   connect(getIt,SIGNAL(data(KIO::Job *, const QByteArray &)),
01255     this, SLOT(listDataReceived(KIO::Job *, const QByteArray &)));
01256 //        void data( KIO::Job *, const QByteArray &data);
01257 
01258 }
01259 
01260 HlDownloadDialog::~HlDownloadDialog(){}
01261 
01262 void HlDownloadDialog::listDataReceived(KIO::Job *, const QByteArray &data)
01263 {
01264   listData+=QString(data);
01265   kdDebug(13000)<<QString("CurrentListData: ")<<listData<<endl<<endl;
01266   kdDebug(13000)<<QString("Data length: %1").arg(data.size())<<endl;
01267   kdDebug(13000)<<QString("listData length: %1").arg(listData.length())<<endl;
01268   if (data.size()==0)
01269   {
01270     if (listData.length()>0)
01271     {
01272       QString installedVersion;
01273       HlManager *hlm=HlManager::self();
01274       QDomDocument doc;
01275       doc.setContent(listData);
01276       QDomElement DocElem=doc.documentElement();
01277       QDomNode n=DocElem.firstChild();
01278       Highlight *hl;
01279 
01280       if (n.isNull()) kdDebug(13000)<<"There is no usable childnode"<<endl;
01281       while (!n.isNull())
01282       {
01283         installedVersion="    --";
01284 
01285         QDomElement e=n.toElement();
01286         if (!e.isNull())
01287         kdDebug(13000)<<QString("NAME: ")<<e.tagName()<<QString(" - ")<<e.attribute("name")<<endl;
01288         n=n.nextSibling();
01289 
01290         QString Name=e.attribute("name");
01291 
01292         for (int i=0;i<hlm->highlights();i++)
01293         {
01294           hl=hlm->getHl(i);
01295           if (hl->name()==Name)
01296           {
01297             installedVersion="    "+hl->version();
01298             break;
01299           }
01300         }
01301 
01302         (void) new QListViewItem(list,e.attribute("name"),installedVersion,e.attribute("version"),e.attribute("date"),e.attribute("url"));
01303       }
01304     }
01305   }
01306 }
01307 
01308 void HlDownloadDialog::slotUser1()
01309 {
01310   QString destdir=KGlobal::dirs()->saveLocation("data","katepart/syntax/");
01311   for (QListViewItem *it=list->firstChild();it;it=it->nextSibling())
01312   {
01313     if (list->isSelected(it))
01314     {
01315       KURL src(it->text(4));
01316       QString filename=src.fileName(false);
01317       QString dest = destdir+filename;
01318 
01319       KIO::NetAccess::download(src,dest, this);
01320     }
01321   }
01322 
01323   // update Config !!
01324   SyntaxDocument doc (true);
01325 }
01326 
01327 //BEGIN GotoLineDialog
01328 GotoLineDialog::GotoLineDialog(QWidget *parent, int line, int max)
01329   : KDialogBase(parent, 0L, true, i18n("Go to Line"), Ok | Cancel, Ok) {
01330 
01331   QWidget *page = new QWidget(this);
01332   setMainWidget(page);
01333 
01334   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
01335   e1 = new KIntNumInput(line, page);
01336   e1->setRange(1, max);
01337   e1->setEditFocus(true);
01338 
01339   QLabel *label = new QLabel( e1,i18n("&Go to line:"), page );
01340   topLayout->addWidget(label);
01341   topLayout->addWidget(e1);
01342   topLayout->addSpacing(spacingHint()); // A little bit extra space
01343   topLayout->addStretch(10);
01344   e1->setFocus();
01345 }
01346 
01347 int GotoLineDialog::getLine() {
01348   return e1->value();
01349 }
01350 //END GotoLineDialog
01351 
01352 // 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.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:37:40 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003