20 #include "kateconfigdialog.h"
21 #include "kateconfigdialog.moc"
23 #include "katemainwindow.h"
25 #include "kateconsole.h"
26 #include "katedocmanager.h"
27 #include "katepluginmanager.h"
28 #include "kateconfigplugindialogpage.h"
29 #include "kateviewmanager.h"
31 #include "katefileselector.h"
32 #include "katefilelist.h"
33 #include "kateexternaltools.h"
35 #include <tqbuttongroup.h>
36 #include <tqcheckbox.h>
40 #include <tqpushbutton.h>
41 #include <tqradiobutton.h>
42 #include <tqspinbox.h>
44 #include <tqwhatsthis.h>
45 #include <tqcombobox.h>
47 #include <kinstance.h>
49 #include <kdialogbase.h>
50 #include <kglobalaccel.h>
51 #include <tdeglobal.h>
52 #include <tdeglobalsettings.h>
53 #include <kiconloader.h>
54 #include <kkeydialog.h>
55 #include <tdelistbox.h>
56 #include <tdelocale.h>
57 #include <ksimpleconfig.h>
58 #include <kstdaction.h>
59 #include <kstandarddirs.h>
61 #include <kseparator.h>
63 KateConfigDialog::KateConfigDialog ( KateMainWindow *parent, Kate::View *view )
64 : KDialogBase ( KDialogBase::TreeList,
66 KDialogBase::Ok | KDialogBase::Apply|KDialogBase::Cancel | KDialogBase::Help,
75 actionButton( KDialogBase::Apply)->setEnabled(
false );
79 setMinimumSize(600,400);
83 pluginPages.setAutoDelete (
false);
84 editorPages.setAutoDelete (
false);
88 setShowIconsInTreeList(
true);
91 path << i18n(
"Application");
92 setFolderIcon (path, SmallIcon(
"kate", TDEIcon::SizeSmall));
97 path << i18n(
"Application") << i18n(
"General");
98 TQFrame* frGeneral = addPage(path, i18n(
"General Options"), BarIcon(
"go-home", TDEIcon::SizeSmall));
100 TQVBoxLayout *lo =
new TQVBoxLayout( frGeneral );
101 lo->setSpacing(KDialog::spacingHint());
102 config->setGroup(
"General");
105 TQButtonGroup *bgStartup =
new TQButtonGroup( 1, Qt::Horizontal, i18n(
"&Appearance"), frGeneral );
106 lo->addWidget( bgStartup );
109 config->setGroup(
"General");
110 cb_fullPath =
new TQCheckBox( i18n(
"&Show full path in title"), bgStartup);
111 cb_fullPath->setChecked(
mainWindow->viewManager()->getShowFullPath() );
112 TQWhatsThis::add(cb_fullPath,i18n(
"If this option is checked, the full document path will be shown in the window caption."));
113 connect( cb_fullPath, TQT_SIGNAL( toggled(
bool ) ),
this, TQT_SLOT( slotChanged() ) );
116 cb_sortFiles =
new TQCheckBox(bgStartup);
117 cb_sortFiles->setText(i18n(
"Sort &files alphabetically in the file list"));
118 cb_sortFiles->setChecked(parent->filelist->sortType() == KateFileList::sortByName);
119 TQWhatsThis::add( cb_sortFiles, i18n(
120 "If this is checked, the files in the file list will be sorted alphabetically.") );
121 connect( cb_sortFiles, TQT_SIGNAL( toggled(
bool ) ),
this, TQT_SLOT( slotChanged() ) );
124 bgStartup =
new TQButtonGroup( 1, Qt::Horizontal, i18n(
"&Behavior"), frGeneral );
125 lo->addWidget( bgStartup );
128 TQHBox *hbNrf =
new TQHBox( bgStartup );
129 TQLabel *lNrf =
new TQLabel( i18n(
"&Number of recent files:"), hbNrf );
130 sb_numRecentFiles =
new TQSpinBox( 0, 1000, 1, hbNrf );
131 sb_numRecentFiles->setValue(
mainWindow->fileOpenRecent->maxItems() );
132 lNrf->setBuddy( sb_numRecentFiles );
133 TQString numRecentFileHelpString ( i18n(
134 "<qt>Sets the number of recent files remembered by Kate.<p><strong>NOTE: </strong>"
135 "If you set this lower than the current value, the list will be truncated and "
136 "some items forgotten.</qt>") );
137 TQWhatsThis::add( lNrf, numRecentFileHelpString );
138 TQWhatsThis::add( sb_numRecentFiles, numRecentFileHelpString );
139 connect( sb_numRecentFiles, TQT_SIGNAL( valueChanged (
int ) ),
this, TQT_SLOT( slotChanged() ) );
142 cb_useInstance =
new TQCheckBox(bgStartup);
143 cb_useInstance->setText(i18n(
"Always use the current instance of kate to open new files"));
144 cb_useInstance->setChecked(parent->useInstance);
145 TQWhatsThis::add( cb_useInstance, i18n(
146 "When checked, all files opened from outside of Kate will only use the "
147 "currently opened instance of Kate.") );
148 connect( cb_useInstance, TQT_SIGNAL( toggled(
bool ) ),
this, TQT_SLOT( slotChanged() ) );
151 cb_syncKonsole =
new TQCheckBox(bgStartup);
152 cb_syncKonsole->setText(i18n(
"Sync &terminal emulator with active document"));
153 cb_syncKonsole->setChecked(parent->syncKonsole);
154 TQWhatsThis::add( cb_syncKonsole, i18n(
155 "If this is checked, the built in Konsole will <code>cd</code> to the directory "
156 "of the active document when started and whenever the active document changes, "
157 "if the document is a local file.") );
158 connect( cb_syncKonsole, TQT_SIGNAL( toggled(
bool ) ),
this, TQT_SLOT( slotChanged() ) );
161 cb_modNotifications =
new TQCheckBox(
162 i18n(
"Wa&rn about files modified by foreign processes"), bgStartup );
163 cb_modNotifications->setChecked( parent->modNotification );
164 TQWhatsThis::add( cb_modNotifications, i18n(
165 "If enabled, when Kate receives focus you will be asked what to do with "
166 "files that have been modified on the hard disk. If not enabled, you will "
167 "be asked what to do with a file that has been modified on the hard disk only "
168 "when that file gains focus inside Kate.") );
169 connect( cb_modNotifications, TQT_SIGNAL( toggled(
bool ) ),
170 this, TQT_SLOT( slotChanged() ) );
173 bgStartup =
new TQButtonGroup( 2, Qt::Horizontal, i18n(
"Meta-Information"), frGeneral );
174 lo->addWidget( bgStartup );
177 cb_saveMetaInfos =
new TQCheckBox( bgStartup );
178 cb_saveMetaInfos->setText(i18n(
"Keep &meta-information past sessions"));
179 cb_saveMetaInfos->setChecked(KateDocManager::self()->getSaveMetaInfos());
180 TQWhatsThis::add(cb_saveMetaInfos, i18n(
181 "Check this if you want document configuration like for example "
182 "bookmarks to be saved past editor sessions. The configuration will be "
183 "restored if the document has not changed when reopened."));
184 connect( cb_saveMetaInfos, TQT_SIGNAL( toggled(
bool ) ),
this, TQT_SLOT( slotChanged() ) );
187 TQHBox *hbDmf =
new TQHBox( bgStartup );
188 hbDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos());
189 TQLabel *lDmf =
new TQLabel( i18n(
"&Delete unused meta-information after:"), hbDmf );
190 sb_daysMetaInfos =
new TQSpinBox( 0, 180, 1, hbDmf );
191 sb_daysMetaInfos->setSpecialValueText(i18n(
"(never)"));
192 sb_daysMetaInfos->setSuffix(i18n(
" day(s)"));
193 sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() );
194 lDmf->setBuddy( sb_daysMetaInfos );
195 connect( cb_saveMetaInfos, TQT_SIGNAL( toggled(
bool ) ), hbDmf, TQT_SLOT( setEnabled(
bool ) ) );
196 connect( sb_daysMetaInfos, TQT_SIGNAL( valueChanged (
int ) ),
this, TQT_SLOT( slotChanged() ) );
204 path << i18n(
"Application") << i18n(
"Sessions");
205 TQFrame* frSessions = addPage(path, i18n(
"Session Management"), BarIcon(
"history", TDEIcon::SizeSmall));
207 lo =
new TQVBoxLayout( frSessions );
208 lo->setSpacing(KDialog::spacingHint());
211 bgStartup =
new TQButtonGroup( 1, Qt::Horizontal, i18n(
"Elements of Sessions"), frSessions );
212 lo->addWidget( bgStartup );
215 cb_restoreVC =
new TQCheckBox( bgStartup );
216 cb_restoreVC->setText(i18n(
"Include &window configuration"));
217 config->setGroup(
"General");
218 cb_restoreVC->setChecked( config->readBoolEntry(
"Restore Window Configuration",
true) );
219 TQWhatsThis::add(cb_restoreVC, i18n(
220 "Check this if you want all your views and frames restored each time you open Kate"));
221 connect( cb_restoreVC, TQT_SIGNAL( toggled(
bool ) ),
this, TQT_SLOT( slotChanged() ) );
223 TQRadioButton *rb1, *rb2, *rb3;
225 sessions_start =
new TQButtonGroup( 1, Qt::Horizontal, i18n(
"Behavior on Application Startup"), frSessions );
226 lo->add (sessions_start);
228 sessions_start->setRadioButtonExclusive(
true );
229 sessions_start->insert( rb1=
new TQRadioButton( i18n(
"&Start new session"), sessions_start ), 0 );
230 sessions_start->insert( rb2=
new TQRadioButton( i18n(
"&Load last-used session"), sessions_start ), 1 );
231 sessions_start->insert( rb3=
new TQRadioButton( i18n(
"&Manually choose a session"), sessions_start ), 2 );
233 config->setGroup(
"General");
234 TQString sesStart (config->readEntry (
"Startup Session",
"manual"));
235 if (sesStart ==
"new")
236 sessions_start->setButton (0);
237 else if (sesStart ==
"last")
238 sessions_start->setButton (1);
240 sessions_start->setButton (2);
242 connect(rb1, TQT_SIGNAL(toggled(
bool)),
this, TQT_SLOT(slotChanged()));
243 connect(rb2, TQT_SIGNAL(toggled(
bool)),
this, TQT_SLOT(slotChanged()));
244 connect(rb3, TQT_SIGNAL(toggled(
bool)),
this, TQT_SLOT(slotChanged()));
246 sessions_exit =
new TQButtonGroup( 1, Qt::Horizontal, i18n(
"Behavior on Application Exit or Session Switch"), frSessions );
247 lo->add (sessions_exit);
249 sessions_exit->setRadioButtonExclusive(
true );
250 sessions_exit->insert( rb1=
new TQRadioButton( i18n(
"&Do not save session"), sessions_exit ), 0 );
251 sessions_exit->insert( rb2=
new TQRadioButton( i18n(
"&Save session"), sessions_exit ), 1 );
252 sessions_exit->insert( rb3=
new TQRadioButton( i18n(
"&Ask user"), sessions_exit ), 2 );
254 config->setGroup(
"General");
255 TQString sesExit (config->readEntry (
"Session Exit",
"save"));
256 if (sesExit ==
"discard")
257 sessions_exit->setButton (0);
258 else if (sesExit ==
"save")
259 sessions_exit->setButton (1);
261 sessions_exit->setButton (2);
263 connect(rb1, TQT_SIGNAL(toggled(
bool)),
this, TQT_SLOT(slotChanged()));
264 connect(rb2, TQT_SIGNAL(toggled(
bool)),
this, TQT_SLOT(slotChanged()));
265 connect(rb3, TQT_SIGNAL(toggled(
bool)),
this, TQT_SLOT(slotChanged()));
273 path << i18n(
"Application") << i18n(
"File Selector");
275 TQVBox *page = addVBoxPage( path, i18n(
"File Selector Settings"),
276 BarIcon(
"document-open", TDEIcon::SizeSmall) );
277 fileSelConfigPage =
new KFSConfigPage( page,
"file selector config page",
279 connect( fileSelConfigPage, TQT_SIGNAL( changed() ),
this, TQT_SLOT( slotChanged() ) );
282 path << i18n(
"Application") << i18n(
"Document List");
283 page = addVBoxPage( path, i18n(
"Document List Settings"),
284 BarIcon(
"view_text", TDEIcon::SizeSmall) );
285 filelistConfigPage =
new KFLConfigPage( page,
"file list config page",
287 connect( filelistConfigPage, TQT_SIGNAL( changed() ),
this, TQT_SLOT( slotChanged() ) );
290 path << i18n(
"Application") << i18n(
"Plugins");
291 page=addVBoxPage(path,i18n(
"Plugin Manager"),
292 BarIcon(
"connect_established",TDEIcon::SizeSmall));
293 KateConfigPluginPage *configPluginPage =
new KateConfigPluginPage(page,
this);
294 connect( configPluginPage, TQT_SIGNAL( changed() ), TQT_TQOBJECT(
this), TQT_SLOT( slotChanged() ) );
298 path << i18n(
"Application") << i18n(
"External Tools");
299 page = addVBoxPage( path, i18n(
"External Tools"),
300 BarIcon(
"configure", TDEIcon::SizeSmall) );
302 connect( configExternalToolsPage, TQT_SIGNAL(changed()), TQT_TQOBJECT(
this), TQT_SLOT(slotChanged()) );
306 path << i18n(
"Editor");
307 setFolderIcon (path, SmallIcon(
"edit", TDEIcon::SizeSmall));
309 for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
312 path << i18n(
"Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
313 page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
314 KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, TDEIcon::SizeSmall) );
316 KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page);
317 connect( cPage, TQT_SIGNAL( changed() ),
this, TQT_SLOT( slotChanged() ) );
318 editorPages.append (cPage);
321 KatePluginList &pluginList (KatePluginManager::self()->pluginList());
322 for (
unsigned int i=0; i < pluginList.size(); ++i)
324 if ( pluginList[i].load
325 && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) )
326 addPluginPage (pluginList[i].plugin);
329 enableButtonSeparator(
true);
334 KateConfigDialog::~KateConfigDialog()
338 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin)
340 if (!Kate::pluginConfigInterfaceExtension(plugin))
343 for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++)
347 path << i18n(
"Application")<<i18n(
"Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i);
348 TQVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, TDEIcon::SizeSmall));
350 PluginPageListItem *info=
new PluginPageListItem;
351 info->plugin = plugin;
352 info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page);
353 connect( info->page, TQT_SIGNAL( changed() ),
this, TQT_SLOT( slotChanged() ) );
354 pluginPages.append(info);
358 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin)
360 if (!Kate::pluginConfigInterfaceExtension(plugin))
363 for (uint i=0; i<pluginPages.count(); i++)
365 if ( pluginPages.at(i)->plugin == plugin )
367 TQWidget *w = pluginPages.at(i)->page->parentWidget();
368 delete pluginPages.at(i)->page;
370 pluginPages.remove(pluginPages.at(i));
376 void KateConfigDialog::slotOk()
382 void KateConfigDialog::slotApply()
389 config->setGroup(
"General");
391 config->writeEntry(
"Restore Window Configuration", cb_restoreVC->isChecked());
393 int bu = sessions_start->id (sessions_start->selected());
396 config->writeEntry (
"Startup Session",
"new");
398 config->writeEntry (
"Startup Session",
"last");
400 config->writeEntry (
"Startup Session",
"manual");
402 bu = sessions_exit->id (sessions_exit->selected());
405 config->writeEntry (
"Session Exit",
"discard");
407 config->writeEntry (
"Session Exit",
"save");
409 config->writeEntry (
"Session Exit",
"ask");
411 config->writeEntry(
"Save Meta Infos", cb_saveMetaInfos->isChecked());
412 KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked());
414 config->writeEntry(
"Days Meta Infos", sb_daysMetaInfos->value() );
415 KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value());
417 config->writeEntry(
"Modified Notification", cb_modNotifications->isChecked());
418 mainWindow->modNotification = cb_modNotifications->isChecked();
420 mainWindow->syncKonsole = cb_syncKonsole->isChecked();
421 mainWindow->useInstance = cb_useInstance->isChecked();
422 mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID);
424 config->writeEntry(
"Number of recent files", sb_numRecentFiles->value() );
425 mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() );
427 fileSelConfigPage->apply();
429 filelistConfigPage->apply();
431 configExternalToolsPage->apply();
432 KateExternalToolsCommand::self()->reload();
436 win->externalTools->reload();
440 mainWindow->viewManager()->setShowFullPath( cb_fullPath->isChecked() );
442 mainWindow->saveOptions ();
451 for (uint i=0; i<editorPages.count(); i++)
453 editorPages.at(i)->apply();
456 v->getDoc()->writeConfig(config);
461 for (uint i=0; i<pluginPages.count(); i++)
463 pluginPages.at(i)->page->apply();
469 actionButton( KDialogBase::Apply)->setEnabled(
false );
472 void KateConfigDialog::slotChanged()
475 actionButton( KDialogBase::Apply)->setEnabled(
true );