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 <tdeglobal.h> 00052 #include <tdeglobalsettings.h> 00053 #include <kiconloader.h> 00054 #include <kkeydialog.h> 00055 #include <tdelistbox.h> 00056 #include <tdelocale.h> 00057 #include <ksimpleconfig.h> 00058 #include <kstdaction.h> 00059 #include <kstandarddirs.h> 00060 #include <twin.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 TDEConfig *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", TDEIcon::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("go-home", TDEIcon::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 // show session name in title 00116 cb_showSessionName = new TQCheckBox(i18n("Show s&ession name in title"), bgStartup); 00117 cb_showSessionName->setChecked(parent->showSessionName); 00118 TQWhatsThis::add(cb_showSessionName, i18n("If this option is checked, the session name will be shown in the window caption.")); 00119 connect(cb_showSessionName, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00120 00121 // sort filelist if desired 00122 cb_sortFiles = new TQCheckBox(bgStartup); 00123 cb_sortFiles->setText(i18n("Sort &files alphabetically in the file list")); 00124 cb_sortFiles->setChecked(parent->filelist->sortType() == KateFileList::sortByName); 00125 TQWhatsThis::add( cb_sortFiles, i18n( 00126 "If this is checked, the files in the file list will be sorted alphabetically.") ); 00127 connect( cb_sortFiles, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00128 00129 // GROUP with the one below: "Behavior" 00130 bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("&Behavior"), frGeneral ); 00131 lo->addWidget( bgStartup ); 00132 00133 // number of recent files 00134 TQHBox *hbNrf = new TQHBox( bgStartup ); 00135 TQLabel *lNrf = new TQLabel( i18n("&Number of recent files:"), hbNrf ); 00136 sb_numRecentFiles = new TQSpinBox( 0, 1000, 1, hbNrf ); 00137 sb_numRecentFiles->setValue( mainWindow->fileOpenRecent->maxItems() ); 00138 lNrf->setBuddy( sb_numRecentFiles ); 00139 TQString numRecentFileHelpString ( i18n( 00140 "<qt>Sets the number of recent files remembered by Kate.<p><strong>NOTE: </strong>" 00141 "If you set this lower than the current value, the list will be truncated and " 00142 "some items forgotten.</qt>") ); 00143 TQWhatsThis::add( lNrf, numRecentFileHelpString ); 00144 TQWhatsThis::add( sb_numRecentFiles, numRecentFileHelpString ); 00145 connect( sb_numRecentFiles, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) ); 00146 00147 // Use only one instance of kate (MDI) ? 00148 cb_useInstance = new TQCheckBox(bgStartup); 00149 cb_useInstance->setText(i18n("Always use the current instance of kate to open new files")); 00150 cb_useInstance->setChecked(parent->useInstance); 00151 TQWhatsThis::add( cb_useInstance, i18n( 00152 "When checked, all files opened from outside of Kate will only use the " 00153 "currently opened instance of Kate.") ); 00154 connect( cb_useInstance, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00155 00156 // sync the konsole ? 00157 cb_syncKonsole = new TQCheckBox(bgStartup); 00158 cb_syncKonsole->setText(i18n("Sync &terminal emulator with active document")); 00159 cb_syncKonsole->setChecked(parent->syncKonsole); 00160 TQWhatsThis::add( cb_syncKonsole, i18n( 00161 "If this is checked, the built in Konsole will <code>cd</code> to the directory " 00162 "of the active document when started and whenever the active document changes, " 00163 "if the document is a local file.") ); 00164 connect( cb_syncKonsole, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00165 00166 // modified files notification 00167 cb_modNotifications = new TQCheckBox( 00168 i18n("Wa&rn about files modified by foreign processes"), bgStartup ); 00169 cb_modNotifications->setChecked( parent->modNotification ); 00170 TQWhatsThis::add( cb_modNotifications, i18n( 00171 "If enabled, when Kate receives focus you will be asked what to do with " 00172 "files that have been modified on the hard disk. If not enabled, you will " 00173 "be asked what to do with a file that has been modified on the hard disk only " 00174 "when that file gains focus inside Kate.") ); 00175 connect( cb_modNotifications, TQT_SIGNAL( toggled( bool ) ), 00176 this, TQT_SLOT( slotChanged() ) ); 00177 00178 // GROUP with the one below: "Meta-informations" 00179 bgStartup = new TQButtonGroup( 2, Qt::Horizontal, i18n("Meta-Information"), frGeneral ); 00180 lo->addWidget( bgStartup ); 00181 00182 // save meta infos 00183 cb_saveMetaInfos = new TQCheckBox( bgStartup ); 00184 cb_saveMetaInfos->setText(i18n("Keep &meta-information past sessions")); 00185 cb_saveMetaInfos->setChecked(KateDocManager::self()->getSaveMetaInfos()); 00186 TQWhatsThis::add(cb_saveMetaInfos, i18n( 00187 "Check this if you want document configuration like for example " 00188 "bookmarks to be saved past editor sessions. The configuration will be " 00189 "restored if the document has not changed when reopened.")); 00190 connect( cb_saveMetaInfos, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00191 00192 // meta infos days 00193 TQHBox *hbDmf = new TQHBox( bgStartup ); 00194 hbDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos()); 00195 TQLabel *lDmf = new TQLabel( i18n("&Delete unused meta-information after:"), hbDmf ); 00196 sb_daysMetaInfos = new TQSpinBox( 0, 180, 1, hbDmf ); 00197 sb_daysMetaInfos->setSpecialValueText(i18n("(never)")); 00198 sb_daysMetaInfos->setSuffix(i18n(" day(s)")); 00199 sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() ); 00200 lDmf->setBuddy( sb_daysMetaInfos ); 00201 connect( cb_saveMetaInfos, TQT_SIGNAL( toggled( bool ) ), hbDmf, TQT_SLOT( setEnabled( bool ) ) ); 00202 connect( sb_daysMetaInfos, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) ); 00203 00204 lo->addStretch(1); // :-] works correct without autoadd 00205 //END General page 00206 00207 path.clear(); 00208 00209 //BEGIN Session page 00210 path << i18n("Application") << i18n("Sessions"); 00211 TQFrame* frSessions = addPage(path, i18n("Session Management"), BarIcon("history", TDEIcon::SizeSmall)); 00212 00213 lo = new TQVBoxLayout( frSessions ); 00214 lo->setSpacing(KDialog::spacingHint()); 00215 00216 // GROUP with the one below: "Startup" 00217 bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("Elements of Sessions"), frSessions ); 00218 lo->addWidget( bgStartup ); 00219 00220 // restore view config 00221 cb_restoreVC = new TQCheckBox( bgStartup ); 00222 cb_restoreVC->setText(i18n("Include &window configuration")); 00223 config->setGroup("General"); 00224 cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", true) ); 00225 TQWhatsThis::add(cb_restoreVC, i18n( 00226 "Check this if you want all your views and frames restored each time you open Kate")); 00227 connect( cb_restoreVC, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); 00228 00229 TQRadioButton *rb1, *rb2, *rb3; 00230 00231 sessions_start = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Startup"), frSessions ); 00232 lo->add (sessions_start); 00233 00234 sessions_start->setRadioButtonExclusive( true ); 00235 sessions_start->insert( rb1=new TQRadioButton( i18n("&Start new session"), sessions_start ), 0 ); 00236 sessions_start->insert( rb2=new TQRadioButton( i18n("&Load last-used session"), sessions_start ), 1 ); 00237 sessions_start->insert( rb3=new TQRadioButton( i18n("&Manually choose a session"), sessions_start ), 2 ); 00238 00239 config->setGroup("General"); 00240 TQString sesStart (config->readEntry ("Startup Session", "manual")); 00241 if (sesStart == "new") 00242 sessions_start->setButton (0); 00243 else if (sesStart == "last") 00244 sessions_start->setButton (1); 00245 else 00246 sessions_start->setButton (2); 00247 00248 connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00249 connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00250 connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00251 00252 sessions_exit = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Exit or Session Switch"), frSessions ); 00253 lo->add (sessions_exit); 00254 00255 sessions_exit->setRadioButtonExclusive( true ); 00256 sessions_exit->insert( rb1=new TQRadioButton( i18n("&Do not save session"), sessions_exit ), 0 ); 00257 sessions_exit->insert( rb2=new TQRadioButton( i18n("&Save session"), sessions_exit ), 1 ); 00258 sessions_exit->insert( rb3=new TQRadioButton( i18n("&Ask user"), sessions_exit ), 2 ); 00259 00260 config->setGroup("General"); 00261 TQString sesExit (config->readEntry ("Session Exit", "save")); 00262 if (sesExit == "discard") 00263 sessions_exit->setButton (0); 00264 else if (sesExit == "save") 00265 sessions_exit->setButton (1); 00266 else 00267 sessions_exit->setButton (2); 00268 00269 connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00270 connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00271 connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); 00272 00273 lo->addStretch(1); // :-] works correct without autoadd 00274 //END Session page 00275 00276 path.clear(); 00277 00278 // file selector page 00279 path << i18n("Application") << i18n("File Selector"); 00280 00281 TQVBox *page = addVBoxPage( path, i18n("File Selector Settings"), 00282 BarIcon("document-open", TDEIcon::SizeSmall) ); 00283 fileSelConfigPage = new KFSConfigPage( page, "file selector config page", 00284 mainWindow->fileselector ); 00285 connect( fileSelConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); 00286 path.clear(); 00287 00288 path << i18n("Application") << i18n("Document List"); 00289 page = addVBoxPage( path, i18n("Document List Settings"), 00290 BarIcon("view_text", TDEIcon::SizeSmall) ); 00291 filelistConfigPage = new KFLConfigPage( page, "file list config page", 00292 mainWindow->filelist ); 00293 connect( filelistConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); 00294 path.clear(); 00295 00296 path << i18n("Application") << i18n("Plugins"); 00297 /*TQVBox **/page=addVBoxPage(path,i18n("Plugin Manager"), 00298 BarIcon("connect_established",TDEIcon::SizeSmall)); 00299 KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this); 00300 connect( configPluginPage, TQT_SIGNAL( changed() ), TQT_TQOBJECT(this), TQT_SLOT( slotChanged() ) ); 00301 00302 // Tools->External Tools menu 00303 path.clear(); 00304 path << i18n("Application") << i18n("External Tools"); 00305 page = addVBoxPage( path, i18n("External Tools"), 00306 BarIcon("configure", TDEIcon::SizeSmall) ); 00307 configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page"); 00308 connect( configExternalToolsPage, TQT_SIGNAL(changed()), TQT_TQOBJECT(this), TQT_SLOT(slotChanged()) ); 00309 00310 // editor widgets from kwrite/kwdialog 00311 path.clear(); 00312 path << i18n("Editor"); 00313 setFolderIcon (path, SmallIcon("edit", TDEIcon::SizeSmall)); 00314 00315 for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++) 00316 { 00317 path.clear(); 00318 path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i); 00319 /*TQVBox **/page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i), 00320 KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, TDEIcon::SizeSmall) ); 00321 00322 KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page); 00323 connect( cPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); 00324 editorPages.append (cPage); 00325 } 00326 00327 KatePluginList &pluginList (KatePluginManager::self()->pluginList()); 00328 for (unsigned int i=0; i < pluginList.size(); ++i) 00329 { 00330 if ( pluginList[i].load 00331 && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) ) 00332 addPluginPage (pluginList[i].plugin); 00333 } 00334 00335 enableButtonSeparator(true); 00336 dataChanged = false; 00337 unfoldTreeList (); 00338 } 00339 00340 KateConfigDialog::~KateConfigDialog() 00341 { 00342 } 00343 00344 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin) 00345 { 00346 if (!Kate::pluginConfigInterfaceExtension(plugin)) 00347 return; 00348 00349 for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++) 00350 { 00351 TQStringList path; 00352 path.clear(); 00353 path << i18n("Application")<<i18n("Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i); 00354 TQVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, TDEIcon::SizeSmall)); 00355 00356 PluginPageListItem *info=new PluginPageListItem; 00357 info->plugin = plugin; 00358 info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page); 00359 connect( info->page, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); 00360 pluginPages.append(info); 00361 } 00362 } 00363 00364 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin) 00365 { 00366 if (!Kate::pluginConfigInterfaceExtension(plugin)) 00367 return; 00368 00369 for (uint i=0; i<pluginPages.count(); i++) 00370 { 00371 if ( pluginPages.at(i)->plugin == plugin ) 00372 { 00373 TQWidget *w = pluginPages.at(i)->page->parentWidget(); 00374 delete pluginPages.at(i)->page; 00375 delete w; 00376 pluginPages.remove(pluginPages.at(i)); 00377 i--; 00378 } 00379 } 00380 } 00381 00382 void KateConfigDialog::slotOk() 00383 { 00384 slotApply(); 00385 accept(); 00386 } 00387 00388 void KateConfigDialog::slotApply() 00389 { 00390 TDEConfig *config = KateApp::self()->config(); 00391 00392 // if data changed apply the kate app stuff 00393 if( dataChanged ) 00394 { 00395 config->setGroup("General"); 00396 00397 config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked()); 00398 00399 int bu = sessions_start->id (sessions_start->selected()); 00400 00401 if (bu == 0) 00402 config->writeEntry ("Startup Session", "new"); 00403 else if (bu == 1) 00404 config->writeEntry ("Startup Session", "last"); 00405 else 00406 config->writeEntry ("Startup Session", "manual"); 00407 00408 bu = sessions_exit->id (sessions_exit->selected()); 00409 00410 if (bu == 0) 00411 config->writeEntry ("Session Exit", "discard"); 00412 else if (bu == 1) 00413 config->writeEntry ("Session Exit", "save"); 00414 else 00415 config->writeEntry ("Session Exit", "ask"); 00416 00417 config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked()); 00418 KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked()); 00419 00420 config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() ); 00421 KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value()); 00422 00423 config->writeEntry("Modified Notification", cb_modNotifications->isChecked()); 00424 mainWindow->modNotification = cb_modNotifications->isChecked(); 00425 00426 mainWindow->showSessionName = cb_showSessionName->isChecked(); 00427 mainWindow->syncKonsole = cb_syncKonsole->isChecked(); 00428 mainWindow->useInstance = cb_useInstance->isChecked(); 00429 mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID); 00430 00431 config->writeEntry( "Number of recent files", sb_numRecentFiles->value() ); 00432 mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() ); 00433 00434 fileSelConfigPage->apply(); 00435 00436 filelistConfigPage->apply(); 00437 00438 configExternalToolsPage->apply(); 00439 KateExternalToolsCommand::self()->reload(); 00440 for (uint i=0; i < KateApp::self()->mainWindows(); i++) 00441 { 00442 KateMainWindow *win = KateApp::self()->mainWindow (i); 00443 win->externalTools->reload(); 00444 } 00445 //mainWindow->externalTools->reload(); 00446 00447 mainWindow->viewManager()->setShowFullPath(cb_fullPath->isChecked()); 00448 00449 mainWindow->saveOptions (); 00450 00451 // save plugin config !! 00452 KateApp::self()->pluginManager()->writeConfig (); 00453 } 00454 00455 // 00456 // editor config ! (the apply() methode will check the changed state internally) 00457 // 00458 for (uint i=0; i<editorPages.count(); i++) 00459 { 00460 editorPages.at(i)->apply(); 00461 } 00462 00463 v->getDoc()->writeConfig(config); 00464 00465 // 00466 // plugins config ! (the apply() methode SHOULD check the changed state internally) 00467 // 00468 for (uint i=0; i<pluginPages.count(); i++) 00469 { 00470 pluginPages.at(i)->page->apply(); 00471 } 00472 00473 config->sync(); 00474 00475 dataChanged = false; 00476 actionButton( KDialogBase::Apply)->setEnabled( false ); 00477 } 00478 00479 void KateConfigDialog::slotChanged() 00480 { 00481 dataChanged = true; 00482 actionButton( KDialogBase::Apply)->setEnabled( true ); 00483 }
Trinity API Reference