kateconfigdialog.cpp
00001 /* This file is part of the KDE project 00002 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00003 Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "kateconfigdialog.h" 00021 #include "kateconfigdialog.moc" 00022 00023 #include "katemainwindow.h" 00024 00025 #include "kateconsole.h" 00026 #include "katedocmanager.h" 00027 #include "katepluginmanager.h" 00028 #include "kateconfigplugindialogpage.h" 00029 #include "kateviewmanager.h" 00030 #include "kateapp.h" 00031 #include "katefileselector.h" 00032 #include "katefilelist.h" 00033 #include "kateexternaltools.h" 00034 00035 #include <tqbuttongroup.h> 00036 #include <tqcheckbox.h> 00037 #include <tqhbox.h> 00038 #include <tqlabel.h> 00039 #include <tqlayout.h> 00040 #include <tqpushbutton.h> 00041 #include <tqradiobutton.h> 00042 #include <tqspinbox.h> 00043 #include <tqvbox.h> 00044 #include <tqwhatsthis.h> 00045 #include <tqcombobox.h> 00046 00047 #include <kinstance.h> 00048 #include <kdebug.h> 00049 #include <kdialogbase.h> 00050 #include <kglobalaccel.h> 00051 #include <kglobal.h> 00052 #include <kglobalsettings.h> 00053 #include <kiconloader.h> 00054 #include <kkeydialog.h> 00055 #include <klistbox.h> 00056 #include <klocale.h> 00057 #include <ksimpleconfig.h> 00058 #include <kstdaction.h> 00059 #include <kstandarddirs.h> 00060 #include <kwin.h> 00061 #include <kseparator.h> 00062 00063 KateConfigDialog::KateConfigDialog ( KateMainWindow *parent, Kate::View *view ) 00064 : KDialogBase ( KDialogBase::TreeList, 00065 i18n("Configure"), 00066 KDialogBase::Ok | KDialogBase::Apply|KDialogBase::Cancel | KDialogBase::Help, 00067 KDialogBase::Ok, 00068 parent, 00069 "configdialog" ) 00070 { 00071 KConfig *config = KateApp::self()->config(); 00072 00073 KWin::setIcons( winId(), KateApp::self()->icon(), KateApp::self()->miniIcon() ); 00074 00075 actionButton( KDialogBase::Apply)->setEnabled( false ); 00076 00077 mainWindow = parent; 00078 00079 setMinimumSize(600,400); 00080 00081 v = view; 00082 00083 pluginPages.setAutoDelete (false); 00084 editorPages.setAutoDelete (false); 00085 00086 TQStringList path; 00087 00088 setShowIconsInTreeList(true); 00089 00090 path.clear(); 00091 path << i18n("Application"); 00092 setFolderIcon (path, SmallIcon("kate", KIcon::SizeSmall)); 00093 00094 path.clear(); 00095 00096 //BEGIN General page 00097 path << i18n("Application") << i18n("General"); 00098 TQFrame* frGeneral = addPage(path, i18n("General Options"), BarIcon("gohome", KIcon::SizeSmall)); 00099 00100 TQVBoxLayout *lo = new TQVBoxLayout( frGeneral ); 00101 lo->setSpacing(KDialog::spacingHint()); 00102 config->setGroup("General"); 00103 00104 // GROUP with the one below: "Appearance" 00105 TQButtonGroup *bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("&Appearance"), frGeneral ); 00106 lo->addWidget( bgStartup ); 00107 00108 // show full path in title 00109 config->setGroup("General"); 00110 cb_fullPath = new TQCheckBox( i18n("&Show full path in title"), bgStartup); 00111 cb_fullPath->setChecked( mainWindow->viewManager()->getShowFullPath() ); 00112 TQWhatsThis::add(cb_fullPath,i18n("If this option is checked, the full document path will be shown in the window caption.")); 00113 connect( cb_fullPath, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00114 00115 // sort filelist if desired 00116 cb_sortFiles = new TQCheckBox(bgStartup); 00117 cb_sortFiles->setText(i18n("Sort &files alphabetically in the file list")); 00118 cb_sortFiles->setChecked(parent->filelist->sortType() == KateFileList::sortByName); 00119 TQWhatsThis::add( cb_sortFiles, i18n( 00120 "If this is checked, the files in the file list will be sorted alphabetically.") ); 00121 connect( cb_sortFiles, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00122 00123 // GROUP with the one below: "Behavior" 00124 bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("&Behavior"), frGeneral ); 00125 lo->addWidget( bgStartup ); 00126 00127 // number of recent files 00128 TQHBox *hbNrf = new TQHBox( bgStartup ); 00129 TQLabel *lNrf = new TQLabel( i18n("&Number of recent files:"), hbNrf ); 00130 sb_numRecentFiles = new TQSpinBox( 0, 1000, 1, hbNrf ); 00131 sb_numRecentFiles->setValue( mainWindow->fileOpenRecent->maxItems() ); 00132 lNrf->setBuddy( sb_numRecentFiles ); 00133 TQString numRecentFileHelpString ( i18n( 00134 "<qt>Sets the number of recent files remembered by Kate.<p><strong>NOTE: </strong>" 00135 "If you set this lower than the current value, the list will be truncated and " 00136 "some items forgotten.</qt>") ); 00137 TQWhatsThis::add( lNrf, numRecentFileHelpString ); 00138 TQWhatsThis::add( sb_numRecentFiles, numRecentFileHelpString ); 00139 connect( sb_numRecentFiles, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) ); 00140 00141 // sync the konsole ? 00142 cb_syncKonsole = new TQCheckBox(bgStartup); 00143 cb_syncKonsole->setText(i18n("Sync &terminal emulator with active document")); 00144 cb_syncKonsole->setChecked(parent->syncKonsole); 00145 TQWhatsThis::add( cb_syncKonsole, i18n( 00146 "If this is checked, the built in Konsole will <code>cd</code> to the directory " 00147 "of the active document when started and whenever the active document changes, " 00148 "if the document is a local file.") ); 00149 connect( cb_syncKonsole, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00150 00151 // modified files notification 00152 cb_modNotifications = new TQCheckBox( 00153 i18n("Wa&rn about files modified by foreign processes"), bgStartup ); 00154 cb_modNotifications->setChecked( parent->modNotification ); 00155 TQWhatsThis::add( cb_modNotifications, i18n( 00156 "If enabled, when Kate receives focus you will be asked what to do with " 00157 "files that have been modified on the hard disk. If not enabled, you will " 00158 "be asked what to do with a file that has been modified on the hard disk only " 00159 "when that file gains focus inside Kate.") ); 00160 connect( cb_modNotifications, TQT_SIGNAL( toggled( bool ) ), 00161 this, TQT_SLOT( slotChanged() ) ); 00162 00163 // GROUP with the one below: "Meta-informations" 00164 bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("Meta-Information"), frGeneral ); 00165 lo->addWidget( bgStartup ); 00166 00167 // save meta infos 00168 cb_saveMetaInfos = new TQCheckBox( bgStartup ); 00169 cb_saveMetaInfos->setText(i18n("Keep &meta-information past sessions")); 00170 cb_saveMetaInfos->setChecked(KateDocManager::self()->getSaveMetaInfos()); 00171 TQWhatsThis::add(cb_saveMetaInfos, i18n( 00172 "Check this if you want document configuration like for example " 00173 "bookmarks to be saved past editor sessions. The configuration will be " 00174 "restored if the document has not changed when reopened.")); 00175 connect( cb_saveMetaInfos, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00176 00177 // meta infos days 00178 TQHBox *hbDmf = new TQHBox( bgStartup ); 00179 hbDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos()); 00180 TQLabel *lDmf = new TQLabel( i18n("&Delete unused meta-information after:"), hbDmf ); 00181 sb_daysMetaInfos = new TQSpinBox( 0, 180, 1, hbDmf ); 00182 sb_daysMetaInfos->setSpecialValueText(i18n("(never)")); 00183 sb_daysMetaInfos->setSuffix(i18n(" day(s)")); 00184 sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() ); 00185 lDmf->setBuddy( sb_daysMetaInfos ); 00186 connect( cb_saveMetaInfos, TQT_SIGNAL( toggled( bool ) ), hbDmf, TQT_SLOT( setEnabled( bool ) ) ); 00187 connect( sb_daysMetaInfos, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) ); 00188 00189 lo->addStretch(1); // :-] works correct without autoadd 00190 //END General page 00191 00192 path.clear(); 00193 00194 //BEGIN Session page 00195 path << i18n("Application") << i18n("Sessions"); 00196 TQFrame* frSessions = addPage(path, i18n("Session Management"), BarIcon("history", KIcon::SizeSmall)); 00197 00198 lo = new TQVBoxLayout( frSessions ); 00199 lo->setSpacing(KDialog::spacingHint()); 00200 00201 // GROUP with the one below: "Startup" 00202 bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("Elements of Sessions"), frSessions ); 00203 lo->addWidget( bgStartup ); 00204 00205 // restore view config 00206 cb_restoreVC = new TQCheckBox( bgStartup ); 00207 cb_restoreVC->setText(i18n("Include &window configuration")); 00208 config->setGroup("General"); 00209 cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", true) ); 00210 TQWhatsThis::add(cb_restoreVC, i18n( 00211 "Check this if you want all your views and frames restored each time you open Kate")); 00212 connect( cb_restoreVC, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00213 00214 TQRadioButton *rb1, *rb2, *rb3; 00215 00216 sessions_start = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Startup"), frSessions ); 00217 lo->add (sessions_start); 00218 00219 sessions_start->setRadioButtonExclusive( true ); 00220 sessions_start->insert( rb1=new TQRadioButton( i18n("&Start new session"), sessions_start ), 0 ); 00221 sessions_start->insert( rb2=new TQRadioButton( i18n("&Load last-used session"), sessions_start ), 1 ); 00222 sessions_start->insert( rb3=new TQRadioButton( i18n("&Manually choose a session"), sessions_start ), 2 ); 00223 00224 config->setGroup("General"); 00225 TQString sesStart (config->readEntry ("Startup Session", "manual")); 00226 if (sesStart == "new") 00227 sessions_start->setButton (0); 00228 else if (sesStart == "last") 00229 sessions_start->setButton (1); 00230 else 00231 sessions_start->setButton (2); 00232 00233 connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00234 connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00235 connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00236 00237 sessions_exit = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Exit or Session Switch"), frSessions ); 00238 lo->add (sessions_exit); 00239 00240 sessions_exit->setRadioButtonExclusive( true ); 00241 sessions_exit->insert( rb1=new TQRadioButton( i18n("&Do not save session"), sessions_exit ), 0 ); 00242 sessions_exit->insert( rb2=new TQRadioButton( i18n("&Save session"), sessions_exit ), 1 ); 00243 sessions_exit->insert( rb3=new TQRadioButton( i18n("&Ask user"), sessions_exit ), 2 ); 00244 00245 config->setGroup("General"); 00246 TQString sesExit (config->readEntry ("Session Exit", "save")); 00247 if (sesExit == "discard") 00248 sessions_exit->setButton (0); 00249 else if (sesExit == "save") 00250 sessions_exit->setButton (1); 00251 else 00252 sessions_exit->setButton (2); 00253 00254 connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00255 connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00256 connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00257 00258 lo->addStretch(1); // :-] works correct without autoadd 00259 //END Session page 00260 00261 path.clear(); 00262 00263 // file selector page 00264 path << i18n("Application") << i18n("File Selector"); 00265 00266 TQVBox *page = addVBoxPage( path, i18n("File Selector Settings"), 00267 BarIcon("fileopen", KIcon::SizeSmall) ); 00268 fileSelConfigPage = new KFSConfigPage( page, "file selector config page", 00269 mainWindow->fileselector ); 00270 connect( fileSelConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); 00271 path.clear(); 00272 00273 path << i18n("Application") << i18n("Document List"); 00274 page = addVBoxPage( path, i18n("Document List Settings"), 00275 BarIcon("view_text", KIcon::SizeSmall) ); 00276 filelistConfigPage = new KFLConfigPage( page, "file list config page", 00277 mainWindow->filelist ); 00278 connect( filelistConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); 00279 path.clear(); 00280 00281 path << i18n("Application") << i18n("Plugins"); 00282 /*TQVBox **/page=addVBoxPage(path,i18n("Plugin Manager"), 00283 BarIcon("connect_established",KIcon::SizeSmall)); 00284 KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this); 00285 connect( configPluginPage, TQT_SIGNAL( changed() ), TQT_TQOBJECT(this), TQT_SLOT( slotChanged() ) ); 00286 00287 // Tools->External Tools menu 00288 path.clear(); 00289 path << i18n("Application") << i18n("External Tools"); 00290 page = addVBoxPage( path, i18n("External Tools"), 00291 BarIcon("configure", KIcon::SizeSmall) ); 00292 configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page"); 00293 connect( configExternalToolsPage, TQT_SIGNAL(changed()), TQT_TQOBJECT(this), TQT_SLOT(slotChanged()) ); 00294 00295 // editor widgets from kwrite/kwdialog 00296 path.clear(); 00297 path << i18n("Editor"); 00298 setFolderIcon (path, SmallIcon("edit", KIcon::SizeSmall)); 00299 00300 for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++) 00301 { 00302 path.clear(); 00303 path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i); 00304 /*TQVBox **/page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i), 00305 KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, KIcon::SizeSmall) ); 00306 00307 KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page); 00308 connect( cPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); 00309 editorPages.append (cPage); 00310 } 00311 00312 KatePluginList &pluginList (KatePluginManager::self()->pluginList()); 00313 for (unsigned int i=0; i < pluginList.size(); ++i) 00314 { 00315 if ( pluginList[i].load 00316 && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) ) 00317 addPluginPage (pluginList[i].plugin); 00318 } 00319 00320 enableButtonSeparator(true); 00321 dataChanged = false; 00322 unfoldTreeList (); 00323 } 00324 00325 KateConfigDialog::~KateConfigDialog() 00326 { 00327 } 00328 00329 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin) 00330 { 00331 if (!Kate::pluginConfigInterfaceExtension(plugin)) 00332 return; 00333 00334 for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++) 00335 { 00336 TQStringList path; 00337 path.clear(); 00338 path << i18n("Application")<<i18n("Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i); 00339 TQVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, KIcon::SizeSmall)); 00340 00341 PluginPageListItem *info=new PluginPageListItem; 00342 info->plugin = plugin; 00343 info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page); 00344 connect( info->page, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); 00345 pluginPages.append(info); 00346 } 00347 } 00348 00349 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin) 00350 { 00351 if (!Kate::pluginConfigInterfaceExtension(plugin)) 00352 return; 00353 00354 for (uint i=0; i<pluginPages.count(); i++) 00355 { 00356 if ( pluginPages.at(i)->plugin == plugin ) 00357 { 00358 TQWidget *w = pluginPages.at(i)->page->parentWidget(); 00359 delete pluginPages.at(i)->page; 00360 delete w; 00361 pluginPages.remove(pluginPages.at(i)); 00362 i--; 00363 } 00364 } 00365 } 00366 00367 void KateConfigDialog::slotOk() 00368 { 00369 slotApply(); 00370 accept(); 00371 } 00372 00373 void KateConfigDialog::slotApply() 00374 { 00375 KConfig *config = KateApp::self()->config(); 00376 00377 // if data changed apply the kate app stuff 00378 if( dataChanged ) 00379 { 00380 config->setGroup("General"); 00381 00382 config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked()); 00383 00384 int bu = sessions_start->id (sessions_start->selected()); 00385 00386 if (bu == 0) 00387 config->writeEntry ("Startup Session", "new"); 00388 else if (bu == 1) 00389 config->writeEntry ("Startup Session", "last"); 00390 else 00391 config->writeEntry ("Startup Session", "manual"); 00392 00393 bu = sessions_exit->id (sessions_exit->selected()); 00394 00395 if (bu == 0) 00396 config->writeEntry ("Session Exit", "discard"); 00397 else if (bu == 1) 00398 config->writeEntry ("Session Exit", "save"); 00399 else 00400 config->writeEntry ("Session Exit", "ask"); 00401 00402 config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked()); 00403 KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked()); 00404 00405 config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() ); 00406 KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value()); 00407 00408 config->writeEntry("Modified Notification", cb_modNotifications->isChecked()); 00409 mainWindow->modNotification = cb_modNotifications->isChecked(); 00410 00411 mainWindow->syncKonsole = cb_syncKonsole->isChecked(); 00412 mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID); 00413 00414 config->writeEntry( "Number of recent files", sb_numRecentFiles->value() ); 00415 mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() ); 00416 00417 fileSelConfigPage->apply(); 00418 00419 filelistConfigPage->apply(); 00420 00421 configExternalToolsPage->apply(); 00422 KateExternalToolsCommand::self()->reload(); 00423 for (uint i=0; i < KateApp::self()->mainWindows(); i++) 00424 { 00425 KateMainWindow *win = KateApp::self()->mainWindow (i); 00426 win->externalTools->reload(); 00427 } 00428 //mainWindow->externalTools->reload(); 00429 00430 mainWindow->viewManager()->setShowFullPath( cb_fullPath->isChecked() ); // hm, stored 2 places :( 00431 00432 mainWindow->saveOptions (); 00433 00434 // save plugin config !! 00435 KateApp::self()->pluginManager()->writeConfig (); 00436 } 00437 00438 // 00439 // editor config ! (the apply() methode will check the changed state internally) 00440 // 00441 for (uint i=0; i<editorPages.count(); i++) 00442 { 00443 editorPages.at(i)->apply(); 00444 } 00445 00446 v->getDoc()->writeConfig(config); 00447 00448 // 00449 // plugins config ! (the apply() methode SHOULD check the changed state internally) 00450 // 00451 for (uint i=0; i<pluginPages.count(); i++) 00452 { 00453 pluginPages.at(i)->page->apply(); 00454 } 00455 00456 config->sync(); 00457 00458 dataChanged = false; 00459 actionButton( KDialogBase::Apply)->setEnabled( false ); 00460 } 00461 00462 void KateConfigDialog::slotChanged() 00463 { 00464 dataChanged = true; 00465 actionButton( KDialogBase::Apply)->setEnabled( true ); 00466 }