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 <qbuttongroup.h>
00036 #include <qcheckbox.h>
00037 #include <qhbox.h>
00038 #include <qlabel.h>
00039 #include <qlayout.h>
00040 #include <qpushbutton.h>
00041 #include <qradiobutton.h>
00042 #include <qspinbox.h>
00043 #include <qvbox.h>
00044 #include <qwhatsthis.h>
00045 #include <qcombobox.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 QStringList 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
00097 path << i18n("Application") << i18n("General");
00098 QFrame* frGeneral = addPage(path, i18n("General Options"), BarIcon("gohome", KIcon::SizeSmall));
00099
00100 QVBoxLayout *lo = new QVBoxLayout( frGeneral );
00101 lo->setSpacing(KDialog::spacingHint());
00102 config->setGroup("General");
00103
00104
00105 QButtonGroup *bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("&Appearance"), frGeneral );
00106 lo->addWidget( bgStartup );
00107
00108
00109 config->setGroup("General");
00110 cb_fullPath = new QCheckBox( i18n("&Show full path in title"), bgStartup);
00111 cb_fullPath->setChecked( mainWindow->viewManager()->getShowFullPath() );
00112 QWhatsThis::add(cb_fullPath,i18n("If this option is checked, the full document path will be shown in the window caption."));
00113 connect( cb_fullPath, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00114
00115
00116
00117 bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("&Behavior"), frGeneral );
00118 lo->addWidget( bgStartup );
00119
00120
00121 cb_syncKonsole = new QCheckBox(bgStartup);
00122 cb_syncKonsole->setText(i18n("Sync &terminal emulator with active document"));
00123 cb_syncKonsole->setChecked(parent->syncKonsole);
00124 QWhatsThis::add( cb_syncKonsole, i18n(
00125 "If this is checked, the built in Konsole will <code>cd</code> to the directory "
00126 "of the active document when started and whenever the active document changes, "
00127 "if the document is a local file.") );
00128 connect( cb_syncKonsole, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00129
00130
00131 cb_modNotifications = new QCheckBox(
00132 i18n("Wa&rn about files modified by foreign processes"), bgStartup );
00133 cb_modNotifications->setChecked( parent->modNotification );
00134 QWhatsThis::add( cb_modNotifications, i18n(
00135 "If enabled, when Kate receives focus you will be asked what to do with "
00136 "files that have been modified on the hard disk. If not enabled, you will "
00137 "be asked what to do with a file that has been modified on the hard disk only "
00138 "when that file gains focus inside Kate.") );
00139 connect( cb_modNotifications, SIGNAL( toggled( bool ) ),
00140 this, SLOT( slotChanged() ) );
00141
00142
00143 bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Meta-Information"), frGeneral );
00144 lo->addWidget( bgStartup );
00145
00146
00147 cb_saveMetaInfos = new QCheckBox( bgStartup );
00148 cb_saveMetaInfos->setText(i18n("Keep &meta-information past sessions"));
00149 cb_saveMetaInfos->setChecked(KateDocManager::self()->getSaveMetaInfos());
00150 QWhatsThis::add(cb_saveMetaInfos, i18n(
00151 "Check this if you want document configuration like for example "
00152 "bookmarks to be saved past editor sessions. The configuration will be "
00153 "restored if the document has not changed when reopened."));
00154 connect( cb_saveMetaInfos, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00155
00156
00157 QHBox *hbDmf = new QHBox( bgStartup );
00158 hbDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos());
00159 QLabel *lDmf = new QLabel( i18n("&Delete unused meta-information after:"), hbDmf );
00160 sb_daysMetaInfos = new QSpinBox( 0, 180, 1, hbDmf );
00161 sb_daysMetaInfos->setSpecialValueText(i18n("(never)"));
00162 sb_daysMetaInfos->setSuffix(i18n(" day(s)"));
00163 sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() );
00164 lDmf->setBuddy( sb_daysMetaInfos );
00165 connect( cb_saveMetaInfos, SIGNAL( toggled( bool ) ), hbDmf, SLOT( setEnabled( bool ) ) );
00166 connect( sb_daysMetaInfos, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
00167
00168 lo->addStretch(1);
00169
00170
00171 path.clear();
00172
00173
00174 path << i18n("Application") << i18n("Sessions");
00175 QFrame* frSessions = addPage(path, i18n("Session Management"), BarIcon("history", KIcon::SizeSmall));
00176
00177 lo = new QVBoxLayout( frSessions );
00178 lo->setSpacing(KDialog::spacingHint());
00179
00180
00181 bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Elements of Sessions"), frSessions );
00182 lo->addWidget( bgStartup );
00183
00184
00185 cb_restoreVC = new QCheckBox( bgStartup );
00186 cb_restoreVC->setText(i18n("Include &window configuration"));
00187 config->setGroup("General");
00188 cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", true) );
00189 QWhatsThis::add(cb_restoreVC, i18n(
00190 "Check this if you want all your views and frames restored each time you open Kate"));
00191 connect( cb_restoreVC, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00192
00193 QRadioButton *rb1, *rb2, *rb3;
00194
00195 sessions_start = new QButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Startup"), frSessions );
00196 lo->add (sessions_start);
00197
00198 sessions_start->setRadioButtonExclusive( true );
00199 sessions_start->insert( rb1=new QRadioButton( i18n("&Start new session"), sessions_start ), 0 );
00200 sessions_start->insert( rb2=new QRadioButton( i18n("&Load last-used session"), sessions_start ), 1 );
00201 sessions_start->insert( rb3=new QRadioButton( i18n("&Manually choose a session"), sessions_start ), 2 );
00202
00203 config->setGroup("General");
00204 QString sesStart (config->readEntry ("Startup Session", "manual"));
00205 if (sesStart == "new")
00206 sessions_start->setButton (0);
00207 else if (sesStart == "last")
00208 sessions_start->setButton (1);
00209 else
00210 sessions_start->setButton (2);
00211
00212 connect(rb1, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00213 connect(rb2, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00214 connect(rb3, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00215
00216 sessions_exit = new QButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Exit or Session Switch"), frSessions );
00217 lo->add (sessions_exit);
00218
00219 sessions_exit->setRadioButtonExclusive( true );
00220 sessions_exit->insert( rb1=new QRadioButton( i18n("&Do not save session"), sessions_exit ), 0 );
00221 sessions_exit->insert( rb2=new QRadioButton( i18n("&Save session"), sessions_exit ), 1 );
00222 sessions_exit->insert( rb3=new QRadioButton( i18n("&Ask user"), sessions_exit ), 2 );
00223
00224 config->setGroup("General");
00225 QString sesExit (config->readEntry ("Session Exit", "save"));
00226 if (sesExit == "discard")
00227 sessions_exit->setButton (0);
00228 else if (sesExit == "save")
00229 sessions_exit->setButton (1);
00230 else
00231 sessions_exit->setButton (2);
00232
00233 connect(rb1, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00234 connect(rb2, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00235 connect(rb3, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00236
00237 lo->addStretch(1);
00238
00239
00240 path.clear();
00241
00242
00243 path << i18n("Application") << i18n("File Selector");
00244
00245 QVBox *page = addVBoxPage( path, i18n("File Selector Settings"),
00246 BarIcon("fileopen", KIcon::SizeSmall) );
00247 fileSelConfigPage = new KFSConfigPage( page, "file selector config page",
00248 mainWindow->fileselector );
00249 connect( fileSelConfigPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00250 path.clear();
00251
00252 path << i18n("Application") << i18n("Document List");
00253 page = addVBoxPage( path, i18n("Document List Settings"),
00254 BarIcon("view_text", KIcon::SizeSmall) );
00255 filelistConfigPage = new KFLConfigPage( page, "file list config page",
00256 mainWindow->filelist );
00257 connect( filelistConfigPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00258 path.clear();
00259
00260 path << i18n("Application") << i18n("Plugins");
00261 page=addVBoxPage(path,i18n("Plugin Manager"),
00262 BarIcon("connect_established",KIcon::SizeSmall));
00263 KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this);
00264 connect( configPluginPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00265
00266
00267 path.clear();
00268 path << i18n("Application") << i18n("External Tools");
00269 page = addVBoxPage( path, i18n("External Tools"),
00270 BarIcon("configure", KIcon::SizeSmall) );
00271 configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page");
00272 connect( configExternalToolsPage, SIGNAL(changed()), this, SLOT(slotChanged()) );
00273
00274
00275 path.clear();
00276 path << i18n("Editor");
00277 setFolderIcon (path, SmallIcon("edit", KIcon::SizeSmall));
00278
00279 for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
00280 {
00281 path.clear();
00282 path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
00283 page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
00284 KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, KIcon::SizeSmall) );
00285
00286 KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page);
00287 connect( cPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00288 editorPages.append (cPage);
00289 }
00290
00291 KatePluginList &pluginList (KatePluginManager::self()->pluginList());
00292 for (unsigned int i=0; i < pluginList.size(); ++i)
00293 {
00294 if ( pluginList[i].load
00295 && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) )
00296 addPluginPage (pluginList[i].plugin);
00297 }
00298
00299 enableButtonSeparator(true);
00300 dataChanged = false;
00301 unfoldTreeList ();
00302 }
00303
00304 KateConfigDialog::~KateConfigDialog()
00305 {
00306 }
00307
00308 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin)
00309 {
00310 if (!Kate::pluginConfigInterfaceExtension(plugin))
00311 return;
00312
00313 for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++)
00314 {
00315 QStringList path;
00316 path.clear();
00317 path << i18n("Application")<<i18n("Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i);
00318 QVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, KIcon::SizeSmall));
00319
00320 PluginPageListItem *info=new PluginPageListItem;
00321 info->plugin = plugin;
00322 info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page);
00323 connect( info->page, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00324 pluginPages.append(info);
00325 }
00326 }
00327
00328 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin)
00329 {
00330 if (!Kate::pluginConfigInterfaceExtension(plugin))
00331 return;
00332
00333 for (uint i=0; i<pluginPages.count(); i++)
00334 {
00335 if ( pluginPages.at(i)->plugin == plugin )
00336 {
00337 QWidget *w = pluginPages.at(i)->page->parentWidget();
00338 delete pluginPages.at(i)->page;
00339 delete w;
00340 pluginPages.remove(pluginPages.at(i));
00341 i--;
00342 }
00343 }
00344 }
00345
00346 void KateConfigDialog::slotOk()
00347 {
00348 slotApply();
00349 accept();
00350 }
00351
00352 void KateConfigDialog::slotApply()
00353 {
00354 KConfig *config = KateApp::self()->config();
00355
00356
00357 if( dataChanged )
00358 {
00359 config->setGroup("General");
00360
00361 config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked());
00362
00363 int bu = sessions_start->id (sessions_start->selected());
00364
00365 if (bu == 0)
00366 config->writeEntry ("Startup Session", "new");
00367 else if (bu == 1)
00368 config->writeEntry ("Startup Session", "last");
00369 else
00370 config->writeEntry ("Startup Session", "manual");
00371
00372 bu = sessions_exit->id (sessions_exit->selected());
00373
00374 if (bu == 0)
00375 config->writeEntry ("Session Exit", "discard");
00376 else if (bu == 1)
00377 config->writeEntry ("Session Exit", "save");
00378 else
00379 config->writeEntry ("Session Exit", "ask");
00380
00381 config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked());
00382 KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked());
00383
00384 config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() );
00385 KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value());
00386
00387 config->writeEntry("Modified Notification", cb_modNotifications->isChecked());
00388 mainWindow->modNotification = cb_modNotifications->isChecked();
00389
00390 mainWindow->syncKonsole = cb_syncKonsole->isChecked();
00391
00392 fileSelConfigPage->apply();
00393
00394 filelistConfigPage->apply();
00395
00396 configExternalToolsPage->apply();
00397 KateExternalToolsCommand::self()->reload();
00398 for (uint i=0; i < KateApp::self()->mainWindows(); i++)
00399 {
00400 KateMainWindow *win = KateApp::self()->mainWindow (i);
00401 win->externalTools->reload();
00402 }
00403
00404
00405 mainWindow->viewManager()->setShowFullPath( cb_fullPath->isChecked() );
00406
00407 mainWindow->saveOptions ();
00408
00409
00410 KateApp::self()->pluginManager()->writeConfig ();
00411 }
00412
00413
00414
00415
00416 for (uint i=0; i<editorPages.count(); i++)
00417 {
00418 editorPages.at(i)->apply();
00419 }
00420
00421 v->getDoc()->writeConfig(config);
00422
00423
00424
00425
00426 for (uint i=0; i<pluginPages.count(); i++)
00427 {
00428 pluginPages.at(i)->page->apply();
00429 }
00430
00431 config->sync();
00432
00433 dataChanged = false;
00434 actionButton( KDialogBase::Apply)->setEnabled( false );
00435 }
00436
00437 void KateConfigDialog::slotChanged()
00438 {
00439 dataChanged = true;
00440 actionButton( KDialogBase::Apply)->setEnabled( true );
00441 }