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, TQt::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, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged()));
116 cb_showSessionName =
new TQCheckBox(i18n(
"Show s&ession name in title"), bgStartup);
117 cb_showSessionName->setChecked(parent->showSessionName);
118 TQWhatsThis::add(cb_showSessionName, i18n(
"If this option is checked, the session name will be shown in the window caption."));
119 connect(cb_showSessionName, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged()));
122 cb_sortFiles =
new TQCheckBox(bgStartup);
123 cb_sortFiles->setText(i18n(
"Sort &files alphabetically in the file list"));
124 cb_sortFiles->setChecked(parent->filelist->sortType() == KateFileList::sortByName);
125 TQWhatsThis::add( cb_sortFiles, i18n(
126 "If this is checked, the files in the file list will be sorted alphabetically.") );
127 connect( cb_sortFiles, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotChanged() ) );
130 bgStartup =
new TQButtonGroup( 1, TQt::Horizontal, i18n(
"&Behavior"), frGeneral );
131 lo->addWidget( bgStartup );
134 TQHBox *hbNrf =
new TQHBox( bgStartup );
135 TQLabel *lNrf =
new TQLabel( i18n(
"&Number of recent files:"), hbNrf );
136 sb_numRecentFiles =
new TQSpinBox( 0, 1000, 1, hbNrf );
137 sb_numRecentFiles->setValue( mainWindow->fileOpenRecent->maxItems() );
138 lNrf->setBuddy( sb_numRecentFiles );
139 TQString numRecentFileHelpString ( i18n(
140 "<qt>Sets the number of recent files remembered by Kate.<p><strong>NOTE: </strong>"
141 "If you set this lower than the current value, the list will be truncated and "
142 "some items forgotten.</qt>") );
143 TQWhatsThis::add( lNrf, numRecentFileHelpString );
144 TQWhatsThis::add( sb_numRecentFiles, numRecentFileHelpString );
145 connect( sb_numRecentFiles, TQ_SIGNAL( valueChanged (
int ) ),
this, TQ_SLOT( slotChanged() ) );
148 cb_useInstance =
new TQCheckBox(bgStartup);
149 cb_useInstance->setText(i18n(
"Always use the current instance of kate to open new files"));
150 cb_useInstance->setChecked(parent->useInstance);
151 TQWhatsThis::add( cb_useInstance, i18n(
152 "When checked, all files opened from outside of Kate will only use the "
153 "currently opened instance of Kate.") );
154 connect( cb_useInstance, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotChanged() ) );
157 cb_syncKonsole =
new TQCheckBox(bgStartup);
158 cb_syncKonsole->setText(i18n(
"Sync &terminal emulator with active document"));
159 cb_syncKonsole->setChecked(parent->syncKonsole);
160 TQWhatsThis::add( cb_syncKonsole, i18n(
161 "If this is checked, the built in Konsole will <code>cd</code> to the directory "
162 "of the active document when started and whenever the active document changes, "
163 "if the document is a local file.") );
164 connect( cb_syncKonsole, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotChanged() ) );
167 cb_modNotifications =
new TQCheckBox(
168 i18n(
"Wa&rn about files modified by foreign processes"), bgStartup );
169 cb_modNotifications->setChecked( parent->modNotification );
170 TQWhatsThis::add( cb_modNotifications, i18n(
171 "If enabled, when Kate receives focus you will be asked what to do with "
172 "files that have been modified on the hard disk. If not enabled, you will "
173 "be asked what to do with a file that has been modified on the hard disk only "
174 "when that file gains focus inside Kate.") );
175 connect( cb_modNotifications, TQ_SIGNAL( toggled(
bool ) ),
176 this, TQ_SLOT( slotChanged() ) );
179 bgStartup =
new TQButtonGroup( 2, TQt::Horizontal, i18n(
"Meta-Information"), frGeneral );
180 lo->addWidget( bgStartup );
183 cb_saveMetaInfos =
new TQCheckBox( bgStartup );
184 cb_saveMetaInfos->setText(i18n(
"Keep &meta-information past sessions"));
185 cb_saveMetaInfos->setChecked(KateDocManager::self()->getSaveMetaInfos());
186 TQWhatsThis::add(cb_saveMetaInfos, i18n(
187 "Check this if you want document configuration like for example "
188 "bookmarks to be saved past editor sessions. The configuration will be "
189 "restored if the document has not changed when reopened."));
190 connect( cb_saveMetaInfos, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotChanged() ) );
193 TQHBox *hbDmf =
new TQHBox( bgStartup );
194 hbDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos());
195 TQLabel *lDmf =
new TQLabel( i18n(
"&Delete unused meta-information after:"), hbDmf );
196 sb_daysMetaInfos =
new TQSpinBox( 0, 180, 1, hbDmf );
197 sb_daysMetaInfos->setSpecialValueText(i18n(
"(never)"));
198 sb_daysMetaInfos->setSuffix(i18n(
" day(s)"));
199 sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() );
200 lDmf->setBuddy( sb_daysMetaInfos );
201 connect( cb_saveMetaInfos, TQ_SIGNAL( toggled(
bool ) ), hbDmf, TQ_SLOT( setEnabled(
bool ) ) );
202 connect( sb_daysMetaInfos, TQ_SIGNAL( valueChanged (
int ) ),
this, TQ_SLOT( slotChanged() ) );
210 path << i18n(
"Application") << i18n(
"Sessions");
211 TQFrame* frSessions = addPage(path, i18n(
"Session Management"), BarIcon(
"history", TDEIcon::SizeSmall));
213 lo =
new TQVBoxLayout( frSessions );
214 lo->setSpacing(KDialog::spacingHint());
217 bgStartup =
new TQButtonGroup( 1, TQt::Horizontal, i18n(
"Elements of Sessions"), frSessions );
218 lo->addWidget( bgStartup );
221 cb_restoreVC =
new TQCheckBox( bgStartup );
222 cb_restoreVC->setText(i18n(
"Include &window configuration"));
223 config->setGroup(
"General");
224 cb_restoreVC->setChecked( config->readBoolEntry(
"Restore Window Configuration",
true) );
225 TQWhatsThis::add(cb_restoreVC, i18n(
226 "Check this if you want all your views and frames restored each time you open Kate"));
227 connect( cb_restoreVC, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotChanged() ) );
229 TQRadioButton *rb1, *rb2, *rb3;
231 sessions_start =
new TQButtonGroup( 1, TQt::Horizontal, i18n(
"Behavior on Application Startup"), frSessions );
232 lo->add (sessions_start);
234 sessions_start->setRadioButtonExclusive(
true );
235 sessions_start->insert( rb1=
new TQRadioButton( i18n(
"&Start new session"), sessions_start ), 0 );
236 sessions_start->insert( rb2=
new TQRadioButton( i18n(
"&Load last-used session"), sessions_start ), 1 );
237 sessions_start->insert( rb3=
new TQRadioButton( i18n(
"&Manually choose a session"), sessions_start ), 2 );
239 config->setGroup(
"General");
240 TQString sesStart (config->readEntry (
"Startup Session",
"manual"));
241 if (sesStart ==
"new")
242 sessions_start->setButton (0);
243 else if (sesStart ==
"last")
244 sessions_start->setButton (1);
246 sessions_start->setButton (2);
248 connect(rb1, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged()));
249 connect(rb2, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged()));
250 connect(rb3, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged()));
252 sessions_exit =
new TQButtonGroup( 1, TQt::Horizontal, i18n(
"Behavior on Application Exit or Session Switch"), frSessions );
253 lo->add (sessions_exit);
255 sessions_exit->setRadioButtonExclusive(
true );
256 sessions_exit->insert( rb1=
new TQRadioButton( i18n(
"&Do not save session"), sessions_exit ), 0 );
257 sessions_exit->insert( rb2=
new TQRadioButton( i18n(
"&Save session"), sessions_exit ), 1 );
258 sessions_exit->insert( rb3=
new TQRadioButton( i18n(
"&Ask user"), sessions_exit ), 2 );
260 config->setGroup(
"General");
261 TQString sesExit (config->readEntry (
"Session Exit",
"save"));
262 if (sesExit ==
"discard")
263 sessions_exit->setButton (0);
264 else if (sesExit ==
"save")
265 sessions_exit->setButton (1);
267 sessions_exit->setButton (2);
269 connect(rb1, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged()));
270 connect(rb2, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged()));
271 connect(rb3, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged()));
279 path << i18n(
"Application") << i18n(
"File Selector");
281 TQVBox *page = addVBoxPage( path, i18n(
"File Selector Settings"),
282 BarIcon(
"document-open", TDEIcon::SizeSmall) );
283 fileSelConfigPage =
new KFSConfigPage( page,
"file selector config page",
284 mainWindow->fileselector );
285 connect( fileSelConfigPage, TQ_SIGNAL( changed() ),
this, TQ_SLOT( slotChanged() ) );
288 path << i18n(
"Application") << i18n(
"Document List");
289 page = addVBoxPage( path, i18n(
"Document List Settings"),
290 BarIcon(
"view_text", TDEIcon::SizeSmall) );
291 filelistConfigPage =
new KFLConfigPage( page,
"file list config page",
292 mainWindow->filelist );
293 connect( filelistConfigPage, TQ_SIGNAL( changed() ),
this, TQ_SLOT( slotChanged() ) );
296 path << i18n(
"Application") << i18n(
"Plugins");
297 page=addVBoxPage(path,i18n(
"Plugin Manager"),
298 BarIcon(
"connect_established",TDEIcon::SizeSmall));
299 KateConfigPluginPage *configPluginPage =
new KateConfigPluginPage(page,
this);
300 connect( configPluginPage, TQ_SIGNAL( changed() ),
this, TQ_SLOT( slotChanged() ) );
304 path << i18n(
"Application") << i18n(
"External Tools");
305 page = addVBoxPage( path, i18n(
"External Tools"),
306 BarIcon(
"configure", TDEIcon::SizeSmall) );
308 connect( configExternalToolsPage, TQ_SIGNAL(changed()),
this, TQ_SLOT(slotChanged()) );
312 path << i18n(
"Editor");
313 setFolderIcon (path, SmallIcon(
"edit", TDEIcon::SizeSmall));
315 for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
318 path << i18n(
"Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
319 page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
320 KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, TDEIcon::SizeSmall) );
322 KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page);
323 connect( cPage, TQ_SIGNAL( changed() ),
this, TQ_SLOT( slotChanged() ) );
324 editorPages.append (cPage);
327 KatePluginList &pluginList (KatePluginManager::self()->pluginList());
328 for (
unsigned int i=0; i < pluginList.size(); ++i)
330 if ( pluginList[i].load
331 && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) )
332 addPluginPage (pluginList[i].plugin);
335 enableButtonSeparator(
true);
340 KateConfigDialog::~KateConfigDialog()
344 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin)
346 if (!Kate::pluginConfigInterfaceExtension(plugin))
349 for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++)
353 path << i18n(
"Application")<<i18n(
"Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i);
354 TQVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, TDEIcon::SizeSmall));
356 PluginPageListItem *info=
new PluginPageListItem;
357 info->plugin = plugin;
358 info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page);
359 connect( info->page, TQ_SIGNAL( changed() ),
this, TQ_SLOT( slotChanged() ) );
360 pluginPages.append(info);
364 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin)
366 if (!Kate::pluginConfigInterfaceExtension(plugin))
369 for (uint i=0; i<pluginPages.count(); i++)
371 if ( pluginPages.at(i)->plugin == plugin )
373 TQWidget *w = pluginPages.at(i)->page->parentWidget();
374 delete pluginPages.at(i)->page;
376 pluginPages.remove(pluginPages.at(i));
382 void KateConfigDialog::slotOk()
388 void KateConfigDialog::slotApply()
395 config->setGroup(
"General");
397 config->writeEntry(
"Restore Window Configuration", cb_restoreVC->isChecked());
399 int bu = sessions_start->id (sessions_start->selected());
402 config->writeEntry (
"Startup Session",
"new");
404 config->writeEntry (
"Startup Session",
"last");
406 config->writeEntry (
"Startup Session",
"manual");
408 bu = sessions_exit->id (sessions_exit->selected());
411 config->writeEntry (
"Session Exit",
"discard");
413 config->writeEntry (
"Session Exit",
"save");
415 config->writeEntry (
"Session Exit",
"ask");
417 config->writeEntry(
"Save Meta Infos", cb_saveMetaInfos->isChecked());
418 KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked());
420 config->writeEntry(
"Days Meta Infos", sb_daysMetaInfos->value() );
421 KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value());
423 config->writeEntry(
"Modified Notification", cb_modNotifications->isChecked());
424 mainWindow->modNotification = cb_modNotifications->isChecked();
426 mainWindow->showSessionName = cb_showSessionName->isChecked();
427 mainWindow->syncKonsole = cb_syncKonsole->isChecked();
428 mainWindow->useInstance = cb_useInstance->isChecked();
429 mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID);
431 config->writeEntry(
"Number of recent files", sb_numRecentFiles->value() );
432 mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() );
434 fileSelConfigPage->apply();
436 filelistConfigPage->apply();
438 configExternalToolsPage->apply();
439 KateExternalToolsCommand::self()->reload();
443 win->externalTools->reload();
447 mainWindow->viewManager()->setShowFullPath(cb_fullPath->isChecked());
449 mainWindow->saveOptions ();
458 for (uint i=0; i<editorPages.count(); i++)
460 editorPages.at(i)->apply();
463 v->getDoc()->writeConfig(config);
468 for (uint i=0; i<pluginPages.count(); i++)
470 pluginPages.at(i)->page->apply();
476 actionButton( KDialogBase::Apply)->setEnabled(
false );
479 void KateConfigDialog::slotChanged()
482 actionButton( KDialogBase::Apply)->setEnabled(
true );
KateMainWindow * mainWindow(uint n)
give back the window you want
static KateApp * self()
static accessor to avoid casting ;)
KatePluginManager * pluginManager()
other accessors for global unique instances
uint mainWindows() const
give back number of existing main windows