• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • app
kateconfigdialog.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kateconfigdialog.h"
21 #include "kateconfigdialog.moc"
22 
23 #include "katemainwindow.h"
24 
25 #include "kateconsole.h"
26 #include "katedocmanager.h"
27 #include "katepluginmanager.h"
28 #include "kateconfigplugindialogpage.h"
29 #include "kateviewmanager.h"
30 #include "kateapp.h"
31 #include "katefileselector.h"
32 #include "katefilelist.h"
33 #include "kateexternaltools.h"
34 
35 #include <tqbuttongroup.h>
36 #include <tqcheckbox.h>
37 #include <tqhbox.h>
38 #include <tqlabel.h>
39 #include <tqlayout.h>
40 #include <tqpushbutton.h>
41 #include <tqradiobutton.h>
42 #include <tqspinbox.h>
43 #include <tqvbox.h>
44 #include <tqwhatsthis.h>
45 #include <tqcombobox.h>
46 
47 #include <tdeinstance.h>
48 #include <kdebug.h>
49 #include <kdialogbase.h>
50 #include <tdeglobalaccel.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 <tdesimpleconfig.h>
58 #include <kstdaction.h>
59 #include <tdestandarddirs.h>
60 #include <twin.h>
61 #include <kseparator.h>
62 
63 KateConfigDialog::KateConfigDialog ( KateMainWindow *parent, Kate::View *view )
64  : KDialogBase ( KDialogBase::TreeList,
65  i18n("Configure"),
66  KDialogBase::Ok | KDialogBase::Apply|KDialogBase::Cancel | KDialogBase::Help,
67  KDialogBase::Ok,
68  parent,
69  "configdialog" )
70 {
71  TDEConfig *config = KateApp::self()->config();
72 
73  KWin::setIcons( winId(), KateApp::self()->icon(), KateApp::self()->miniIcon() );
74 
75  actionButton( KDialogBase::Apply)->setEnabled( false );
76 
77  mainWindow = parent;
78 
79  setMinimumSize(600,400);
80 
81  v = view;
82 
83  pluginPages.setAutoDelete (false);
84  editorPages.setAutoDelete (false);
85 
86  TQStringList path;
87 
88  setShowIconsInTreeList(true);
89 
90  path.clear();
91  path << i18n("Application");
92  setFolderIcon (path, SmallIcon("kate", TDEIcon::SizeSmall));
93 
94  path.clear();
95 
96  //BEGIN General page
97  path << i18n("Application") << i18n("General");
98  TQFrame* frGeneral = addPage(path, i18n("General Options"), BarIcon("go-home", TDEIcon::SizeSmall));
99 
100  TQVBoxLayout *lo = new TQVBoxLayout( frGeneral );
101  lo->setSpacing(KDialog::spacingHint());
102  config->setGroup("General");
103 
104  // GROUP with the one below: "Appearance"
105  TQButtonGroup *bgStartup = new TQButtonGroup( 1, TQt::Horizontal, i18n("&Appearance"), frGeneral );
106  lo->addWidget( bgStartup );
107 
108  // show full path in title
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()));
114 
115  // show session name in title
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()));
120 
121  // sort filelist if desired
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() ) );
128 
129  // GROUP with the one below: "Behavior"
130  bgStartup = new TQButtonGroup( 1, TQt::Horizontal, i18n("&Behavior"), frGeneral );
131  lo->addWidget( bgStartup );
132 
133  // number of recent files
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() ) );
146 
147  // Use only one instance of kate (MDI) ?
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() ) );
155 
156  // sync the konsole ?
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() ) );
165 
166  // modified files notification
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() ) );
177 
178  // GROUP with the one below: "Meta-informations"
179  bgStartup = new TQButtonGroup( 1, TQt::Horizontal, i18n("Meta-Information"), frGeneral );
180  lo->addWidget( bgStartup );
181 
182  // save meta infos
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() ) );
191 
192  // meta infos days
193  TQWidget *wDmf = new TQWidget( bgStartup );
194  wDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos());
195  TQLayout *layDmf = new TQHBoxLayout(wDmf);
196  TQLayout *layLabelDmf = new TQHBoxLayout(layDmf);
197  layLabelDmf->addItem(new TQSpacerItem(20,1, TQSizePolicy::Fixed));
198  TQLabel *lDmf = new TQLabel( i18n("&Delete unused meta-information after:"), wDmf);
199  layLabelDmf->add(lDmf);
200  sb_daysMetaInfos = new TQSpinBox( 0, 180, 1, wDmf );
201  sb_daysMetaInfos->setSpecialValueText(i18n("(never)"));
202  sb_daysMetaInfos->setSuffix(i18n(" day(s)"));
203  sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() );
204  layDmf->add(sb_daysMetaInfos);
205  lDmf->setBuddy( sb_daysMetaInfos );
206  connect( cb_saveMetaInfos, TQ_SIGNAL( toggled( bool ) ), wDmf, TQ_SLOT( setEnabled( bool ) ) );
207  connect( sb_daysMetaInfos, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( slotChanged() ) );
208 
209  lo->addStretch(1); // :-] works correct without autoadd
210  //END General page
211 
212  path.clear();
213 
214  //BEGIN Session page
215  path << i18n("Application") << i18n("Sessions");
216  TQFrame* frSessions = addPage(path, i18n("Session Management"), BarIcon("history", TDEIcon::SizeSmall));
217 
218  lo = new TQVBoxLayout( frSessions );
219  lo->setSpacing(KDialog::spacingHint());
220 
221  // GROUP with the one below: "Startup"
222  bgStartup = new TQButtonGroup( 1, TQt::Horizontal, i18n("Elements of Sessions"), frSessions );
223  lo->addWidget( bgStartup );
224 
225  // restore view config
226  cb_restoreVC = new TQCheckBox( bgStartup );
227  cb_restoreVC->setText(i18n("Include &window configuration"));
228  config->setGroup("General");
229  cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", true) );
230  TQWhatsThis::add(cb_restoreVC, i18n(
231  "Check this if you want all your views and frames restored each time you open Kate"));
232  connect( cb_restoreVC, TQ_SIGNAL( toggled( bool ) ), this, TQ_SLOT( slotChanged() ) );
233 
234  TQRadioButton *rb1, *rb2, *rb3;
235 
236  sessions_start = new TQButtonGroup( 1, TQt::Horizontal, i18n("Behavior on Application Startup"), frSessions );
237  lo->add (sessions_start);
238 
239  sessions_start->setRadioButtonExclusive( true );
240  sessions_start->insert( rb1=new TQRadioButton( i18n("&Start new session"), sessions_start ), 0 );
241  sessions_start->insert( rb2=new TQRadioButton( i18n("&Load last-used session"), sessions_start ), 1 );
242  sessions_start->insert( rb3=new TQRadioButton( i18n("&Manually choose a session"), sessions_start ), 2 );
243 
244  config->setGroup("General");
245  TQString sesStart (config->readEntry ("Startup Session", "manual"));
246  if (sesStart == "new")
247  sessions_start->setButton (0);
248  else if (sesStart == "last")
249  sessions_start->setButton (1);
250  else
251  sessions_start->setButton (2);
252 
253  connect(rb1, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotChanged()));
254  connect(rb2, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotChanged()));
255  connect(rb3, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotChanged()));
256 
257  sessions_exit = new TQButtonGroup( 1, TQt::Horizontal, i18n("Behavior on Application Exit or Session Switch"), frSessions );
258  lo->add (sessions_exit);
259 
260  sessions_exit->setRadioButtonExclusive( true );
261  sessions_exit->insert( rb1=new TQRadioButton( i18n("&Do not save session"), sessions_exit ), 0 );
262  sessions_exit->insert( rb2=new TQRadioButton( i18n("&Save session"), sessions_exit ), 1 );
263  sessions_exit->insert( rb3=new TQRadioButton( i18n("&Ask user"), sessions_exit ), 2 );
264 
265  config->setGroup("General");
266  TQString sesExit (config->readEntry ("Session Exit", "save"));
267  if (sesExit == "discard")
268  sessions_exit->setButton (0);
269  else if (sesExit == "save")
270  sessions_exit->setButton (1);
271  else
272  sessions_exit->setButton (2);
273 
274  connect(rb1, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotChanged()));
275  connect(rb2, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotChanged()));
276  connect(rb3, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotChanged()));
277 
278  lo->addStretch(1); // :-] works correct without autoadd
279  //END Session page
280 
281  path.clear();
282 
283  // file selector page
284  path << i18n("Application") << i18n("File Selector");
285 
286  TQVBox *page = addVBoxPage( path, i18n("File Selector Settings"),
287  BarIcon("document-open", TDEIcon::SizeSmall) );
288  fileSelConfigPage = new KFSConfigPage( page, "file selector config page",
289  mainWindow->fileselector );
290  connect( fileSelConfigPage, TQ_SIGNAL( changed() ), this, TQ_SLOT( slotChanged() ) );
291  path.clear();
292 
293  path << i18n("Application") << i18n("Document List");
294  page = addVBoxPage( path, i18n("Document List Settings"),
295  BarIcon("view_text", TDEIcon::SizeSmall) );
296  filelistConfigPage = new KFLConfigPage( page, "file list config page",
297  mainWindow->filelist );
298  connect( filelistConfigPage, TQ_SIGNAL( changed() ), this, TQ_SLOT( slotChanged() ) );
299  path.clear();
300 
301  path << i18n("Application") << i18n("Plugins");
302  /*TQVBox **/page=addVBoxPage(path,i18n("Plugin Manager"),
303  BarIcon("connect_established",TDEIcon::SizeSmall));
304  KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this);
305  connect( configPluginPage, TQ_SIGNAL( changed() ), this, TQ_SLOT( slotChanged() ) );
306 
307  // Tools->External Tools menu
308  path.clear();
309  path << i18n("Application") << i18n("External Tools");
310  page = addVBoxPage( path, i18n("External Tools"),
311  BarIcon("configure", TDEIcon::SizeSmall) );
312  configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page");
313  connect( configExternalToolsPage, TQ_SIGNAL(changed()), this, TQ_SLOT(slotChanged()) );
314 
315  // editor widgets from kwrite/kwdialog
316  path.clear();
317  path << i18n("Editor");
318  setFolderIcon (path, SmallIcon("edit", TDEIcon::SizeSmall));
319 
320  for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
321  {
322  path.clear();
323  path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
324  /*TQVBox **/page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
325  KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, TDEIcon::SizeSmall) );
326 
327  KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page);
328  connect( cPage, TQ_SIGNAL( changed() ), this, TQ_SLOT( slotChanged() ) );
329  editorPages.append (cPage);
330  }
331 
332  KatePluginList &pluginList (KatePluginManager::self()->pluginList());
333  for (unsigned int i=0; i < pluginList.size(); ++i)
334  {
335  if ( pluginList[i].load
336  && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) )
337  addPluginPage (pluginList[i].plugin);
338  }
339 
340  enableButtonSeparator(true);
341  dataChanged = false;
342  unfoldTreeList ();
343 }
344 
345 KateConfigDialog::~KateConfigDialog()
346 {
347 }
348 
349 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin)
350 {
351  if (!Kate::pluginConfigInterfaceExtension(plugin))
352  return;
353 
354  for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++)
355  {
356  TQStringList path;
357  path.clear();
358  path << i18n("Application")<<i18n("Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i);
359  TQVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, TDEIcon::SizeSmall));
360 
361  PluginPageListItem *info=new PluginPageListItem;
362  info->plugin = plugin;
363  info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page);
364  connect( info->page, TQ_SIGNAL( changed() ), this, TQ_SLOT( slotChanged() ) );
365  pluginPages.append(info);
366  }
367 }
368 
369 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin)
370 {
371  if (!Kate::pluginConfigInterfaceExtension(plugin))
372  return;
373 
374  for (uint i=0; i<pluginPages.count(); i++)
375  {
376  if ( pluginPages.at(i)->plugin == plugin )
377  {
378  TQWidget *w = pluginPages.at(i)->page->parentWidget();
379  delete pluginPages.at(i)->page;
380  delete w;
381  pluginPages.remove(pluginPages.at(i));
382  i--;
383  }
384  }
385 }
386 
387 void KateConfigDialog::slotOk()
388 {
389  slotApply();
390  accept();
391 }
392 
393 void KateConfigDialog::slotApply()
394 {
395  TDEConfig *config = KateApp::self()->config();
396 
397  // if data changed apply the kate app stuff
398  if( dataChanged )
399  {
400  config->setGroup("General");
401 
402  config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked());
403 
404  int bu = sessions_start->id (sessions_start->selected());
405 
406  if (bu == 0)
407  config->writeEntry ("Startup Session", "new");
408  else if (bu == 1)
409  config->writeEntry ("Startup Session", "last");
410  else
411  config->writeEntry ("Startup Session", "manual");
412 
413  bu = sessions_exit->id (sessions_exit->selected());
414 
415  if (bu == 0)
416  config->writeEntry ("Session Exit", "discard");
417  else if (bu == 1)
418  config->writeEntry ("Session Exit", "save");
419  else
420  config->writeEntry ("Session Exit", "ask");
421 
422  config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked());
423  KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked());
424 
425  config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() );
426  KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value());
427 
428  config->writeEntry("Modified Notification", cb_modNotifications->isChecked());
429  mainWindow->modNotification = cb_modNotifications->isChecked();
430 
431  mainWindow->showSessionName = cb_showSessionName->isChecked();
432  mainWindow->syncKonsole = cb_syncKonsole->isChecked();
433  mainWindow->useInstance = cb_useInstance->isChecked();
434  mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID);
435 
436  config->writeEntry( "Number of recent files", sb_numRecentFiles->value() );
437  mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() );
438 
439  fileSelConfigPage->apply();
440 
441  filelistConfigPage->apply();
442 
443  configExternalToolsPage->apply();
444  KateExternalToolsCommand::self()->reload();
445  for (uint i=0; i < KateApp::self()->mainWindows(); i++)
446  {
447  KateMainWindow *win = KateApp::self()->mainWindow (i);
448  win->externalTools->reload();
449  }
450  //mainWindow->externalTools->reload();
451 
452  mainWindow->viewManager()->setShowFullPath(cb_fullPath->isChecked());
453 
454  mainWindow->saveOptions ();
455 
456  // save plugin config !!
457  KateApp::self()->pluginManager()->writeConfig ();
458  }
459 
460  //
461  // editor config ! (the apply() methode will check the changed state internally)
462  //
463  for (uint i=0; i<editorPages.count(); i++)
464  {
465  editorPages.at(i)->apply();
466  }
467 
468  v->getDoc()->writeConfig(config);
469 
470  //
471  // plugins config ! (the apply() methode SHOULD check the changed state internally)
472  //
473  for (uint i=0; i<pluginPages.count(); i++)
474  {
475  pluginPages.at(i)->page->apply();
476  }
477 
478  config->sync();
479 
480  dataChanged = false;
481  actionButton( KDialogBase::Apply)->setEnabled( false );
482 }
483 
484 void KateConfigDialog::slotChanged()
485 {
486  dataChanged = true;
487  actionButton( KDialogBase::Apply)->setEnabled( true );
488 }
KateApp::mainWindow
KateMainWindow * mainWindow(uint n)
give back the window you want
Definition: kateapp.cpp:474
KateApp::self
static KateApp * self()
static accessor to avoid casting ;)
Definition: kateapp.cpp:113
KateApp::pluginManager
KatePluginManager * pluginManager()
other accessors for global unique instances
Definition: kateapp.cpp:366
KateApp::mainWindows
uint mainWindows() const
give back number of existing main windows
Definition: kateapp.cpp:469
KateExternalToolsConfigWidget
The config widget.
Definition: kateexternaltools.h:144

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kate

Skip menu "kate"
  • kate
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.9.1
This website is maintained by Timothy Pearson.