• 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 <kinstance.h>
48 #include <kdebug.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>
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, Qt::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, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) );
114 
115  // sort filelist if desired
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() ) );
122 
123  // GROUP with the one below: "Behavior"
124  bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("&Behavior"), frGeneral );
125  lo->addWidget( bgStartup );
126 
127  // number of recent files
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() ) );
140 
141  // Use only one instance of kate (MDI) ?
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() ) );
149 
150  // sync the konsole ?
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() ) );
159 
160  // modified files notification
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() ) );
171 
172  // GROUP with the one below: "Meta-informations"
173  bgStartup = new TQButtonGroup( 2, Qt::Horizontal, i18n("Meta-Information"), frGeneral );
174  lo->addWidget( bgStartup );
175 
176  // save meta infos
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() ) );
185 
186  // meta infos days
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() ) );
197 
198  lo->addStretch(1); // :-] works correct without autoadd
199  //END General page
200 
201  path.clear();
202 
203  //BEGIN Session page
204  path << i18n("Application") << i18n("Sessions");
205  TQFrame* frSessions = addPage(path, i18n("Session Management"), BarIcon("history", TDEIcon::SizeSmall));
206 
207  lo = new TQVBoxLayout( frSessions );
208  lo->setSpacing(KDialog::spacingHint());
209 
210  // GROUP with the one below: "Startup"
211  bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("Elements of Sessions"), frSessions );
212  lo->addWidget( bgStartup );
213 
214  // restore view config
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() ) );
222 
223  TQRadioButton *rb1, *rb2, *rb3;
224 
225  sessions_start = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Startup"), frSessions );
226  lo->add (sessions_start);
227 
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 );
232 
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);
239  else
240  sessions_start->setButton (2);
241 
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()));
245 
246  sessions_exit = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Exit or Session Switch"), frSessions );
247  lo->add (sessions_exit);
248 
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 );
253 
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);
260  else
261  sessions_exit->setButton (2);
262 
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()));
266 
267  lo->addStretch(1); // :-] works correct without autoadd
268  //END Session page
269 
270  path.clear();
271 
272  // file selector page
273  path << i18n("Application") << i18n("File Selector");
274 
275  TQVBox *page = addVBoxPage( path, i18n("File Selector Settings"),
276  BarIcon("document-open", TDEIcon::SizeSmall) );
277  fileSelConfigPage = new KFSConfigPage( page, "file selector config page",
278  mainWindow->fileselector );
279  connect( fileSelConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) );
280  path.clear();
281 
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",
286  mainWindow->filelist );
287  connect( filelistConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) );
288  path.clear();
289 
290  path << i18n("Application") << i18n("Plugins");
291  /*TQVBox **/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() ) );
295 
296  // Tools->External Tools menu
297  path.clear();
298  path << i18n("Application") << i18n("External Tools");
299  page = addVBoxPage( path, i18n("External Tools"),
300  BarIcon("configure", TDEIcon::SizeSmall) );
301  configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page");
302  connect( configExternalToolsPage, TQT_SIGNAL(changed()), TQT_TQOBJECT(this), TQT_SLOT(slotChanged()) );
303 
304  // editor widgets from kwrite/kwdialog
305  path.clear();
306  path << i18n("Editor");
307  setFolderIcon (path, SmallIcon("edit", TDEIcon::SizeSmall));
308 
309  for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
310  {
311  path.clear();
312  path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
313  /*TQVBox **/page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
314  KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, TDEIcon::SizeSmall) );
315 
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);
319  }
320 
321  KatePluginList &pluginList (KatePluginManager::self()->pluginList());
322  for (unsigned int i=0; i < pluginList.size(); ++i)
323  {
324  if ( pluginList[i].load
325  && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) )
326  addPluginPage (pluginList[i].plugin);
327  }
328 
329  enableButtonSeparator(true);
330  dataChanged = false;
331  unfoldTreeList ();
332 }
333 
334 KateConfigDialog::~KateConfigDialog()
335 {
336 }
337 
338 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin)
339 {
340  if (!Kate::pluginConfigInterfaceExtension(plugin))
341  return;
342 
343  for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++)
344  {
345  TQStringList path;
346  path.clear();
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));
349 
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);
355  }
356 }
357 
358 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin)
359 {
360  if (!Kate::pluginConfigInterfaceExtension(plugin))
361  return;
362 
363  for (uint i=0; i<pluginPages.count(); i++)
364  {
365  if ( pluginPages.at(i)->plugin == plugin )
366  {
367  TQWidget *w = pluginPages.at(i)->page->parentWidget();
368  delete pluginPages.at(i)->page;
369  delete w;
370  pluginPages.remove(pluginPages.at(i));
371  i--;
372  }
373  }
374 }
375 
376 void KateConfigDialog::slotOk()
377 {
378  slotApply();
379  accept();
380 }
381 
382 void KateConfigDialog::slotApply()
383 {
384  TDEConfig *config = KateApp::self()->config();
385 
386  // if data changed apply the kate app stuff
387  if( dataChanged )
388  {
389  config->setGroup("General");
390 
391  config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked());
392 
393  int bu = sessions_start->id (sessions_start->selected());
394 
395  if (bu == 0)
396  config->writeEntry ("Startup Session", "new");
397  else if (bu == 1)
398  config->writeEntry ("Startup Session", "last");
399  else
400  config->writeEntry ("Startup Session", "manual");
401 
402  bu = sessions_exit->id (sessions_exit->selected());
403 
404  if (bu == 0)
405  config->writeEntry ("Session Exit", "discard");
406  else if (bu == 1)
407  config->writeEntry ("Session Exit", "save");
408  else
409  config->writeEntry ("Session Exit", "ask");
410 
411  config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked());
412  KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked());
413 
414  config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() );
415  KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value());
416 
417  config->writeEntry("Modified Notification", cb_modNotifications->isChecked());
418  mainWindow->modNotification = cb_modNotifications->isChecked();
419 
420  mainWindow->syncKonsole = cb_syncKonsole->isChecked();
421  mainWindow->useInstance = cb_useInstance->isChecked();
422  mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID);
423 
424  config->writeEntry( "Number of recent files", sb_numRecentFiles->value() );
425  mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() );
426 
427  fileSelConfigPage->apply();
428 
429  filelistConfigPage->apply();
430 
431  configExternalToolsPage->apply();
432  KateExternalToolsCommand::self()->reload();
433  for (uint i=0; i < KateApp::self()->mainWindows(); i++)
434  {
435  KateMainWindow *win = KateApp::self()->mainWindow (i);
436  win->externalTools->reload();
437  }
438  //mainWindow->externalTools->reload();
439 
440  mainWindow->viewManager()->setShowFullPath( cb_fullPath->isChecked() ); // hm, stored 2 places :(
441 
442  mainWindow->saveOptions ();
443 
444  // save plugin config !!
445  KateApp::self()->pluginManager()->writeConfig ();
446  }
447 
448  //
449  // editor config ! (the apply() methode will check the changed state internally)
450  //
451  for (uint i=0; i<editorPages.count(); i++)
452  {
453  editorPages.at(i)->apply();
454  }
455 
456  v->getDoc()->writeConfig(config);
457 
458  //
459  // plugins config ! (the apply() methode SHOULD check the changed state internally)
460  //
461  for (uint i=0; i<pluginPages.count(); i++)
462  {
463  pluginPages.at(i)->page->apply();
464  }
465 
466  config->sync();
467 
468  dataChanged = false;
469  actionButton( KDialogBase::Apply)->setEnabled( false );
470 }
471 
472 void KateConfigDialog::slotChanged()
473 {
474  dataChanged = true;
475  actionButton( KDialogBase::Apply)->setEnabled( true );
476 }

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.8.1.2
This website is maintained by Timothy Pearson.