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