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

kate

  • kate
  • app
katemainwindow.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
4  Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 //BEGIN Includes
22 #include "katemainwindow.h"
23 #include "katemainwindow.moc"
24 
25 #include "kateconfigdialog.h"
26 #include "kateconsole.h"
27 #include "katedocmanager.h"
28 #include "katepluginmanager.h"
29 #include "kateconfigplugindialogpage.h"
30 #include "kateviewmanager.h"
31 #include "kateapp.h"
32 #include "katefileselector.h"
33 #include "katefilelist.h"
34 #include "kategrepdialog.h"
35 #include "katemailfilesdialog.h"
36 #include "katemainwindowiface.h"
37 #include "kateexternaltools.h"
38 #include "katesavemodifieddialog.h"
39 #include "katemwmodonhddialog.h"
40 #include "katesession.h"
41 #include "katetabwidget.h"
42 
43 #include "../interfaces/mainwindow.h"
44 #include "../interfaces/toolviewmanager.h"
45 
46 #include <dcopclient.h>
47 #include <kinstance.h>
48 #include <tdeaboutdata.h>
49 #include <tdeaction.h>
50 #include <tdecmdlineargs.h>
51 #include <kdebug.h>
52 #include <kdialogbase.h>
53 #include <tdediroperator.h>
54 #include <kdockwidget.h>
55 #include <kedittoolbar.h>
56 #include <tdefiledialog.h>
57 #include <kglobalaccel.h>
58 #include <tdeglobal.h>
59 #include <tdeglobalsettings.h>
60 #include <kiconloader.h>
61 #include <kkeydialog.h>
62 #include <tdelocale.h>
63 #include <tdemessagebox.h>
64 #include <kmimetype.h>
65 #include <kopenwith.h>
66 #include <tdepopupmenu.h>
67 #include <ksimpleconfig.h>
68 #include <kstatusbar.h>
69 #include <kstdaction.h>
70 #include <kstandarddirs.h>
71 #include <ktrader.h>
72 #include <kuniqueapplication.h>
73 #include <kurldrag.h>
74 #include <kdesktopfile.h>
75 #include <khelpmenu.h>
76 #include <tdemultitabbar.h>
77 #include <ktip.h>
78 #include <tdemenubar.h>
79 #include <kstringhandler.h>
80 #include <tqlayout.h>
81 #include <tqptrvector.h>
82 
83 #include <assert.h>
84 #include <unistd.h>
85 //END
86 
87 uint KateMainWindow::uniqueID = 1;
88 
89 KateMainWindow::KateMainWindow (TDEConfig *sconfig, const TQString &sgroup)
90  : KateMDI::MainWindow (0,(TQString(TQString("__KateMainWindow#%1").arg(uniqueID))).latin1())
91 {
92  // first the very important id
93  myID = uniqueID;
94  uniqueID++;
95 
96  m_modignore = false;
97 
98  console = 0;
99  greptool = 0;
100 
101  // here we go, set some usable default sizes
102  if (!initialGeometrySet())
103  {
104  int scnum = TQApplication::desktop()->screenNumber(parentWidget());
105  TQRect desk = TQApplication::desktop()->screenGeometry(scnum);
106 
107  TQSize size;
108 
109  // try to load size
110  if (sconfig)
111  {
112  sconfig->setGroup (sgroup);
113  size.setWidth (sconfig->readNumEntry( TQString::fromLatin1("Width %1").arg(desk.width()), 0 ));
114  size.setHeight (sconfig->readNumEntry( TQString::fromLatin1("Height %1").arg(desk.height()), 0 ));
115  }
116 
117  // if thats fails, try to reuse size
118  if (size.isEmpty())
119  {
120  // first try to reuse size known from current or last created main window ;=)
121  if (KateApp::self()->mainWindows () > 0)
122  {
123  KateMainWindow *win = KateApp::self()->activeMainWindow ();
124 
125  if (!win)
126  win = KateApp::self()->mainWindow (KateApp::self()->mainWindows ()-1);
127 
128  size = win->size();
129  }
130  else // now fallback to hard defaults ;)
131  {
132  // first try global app config
133  KateApp::self()->config()->setGroup ("MainWindow");
134  size.setWidth (KateApp::self()->config()->readNumEntry( TQString::fromLatin1("Width %1").arg(desk.width()), 0 ));
135  size.setHeight (KateApp::self()->config()->readNumEntry( TQString::fromLatin1("Height %1").arg(desk.height()), 0 ));
136 
137  if (size.isEmpty())
138  size = TQSize (kMin (700, desk.width()), kMin(480, desk.height()));
139  }
140 
141  resize (size);
142  }
143  }
144 
145  // start session restore if needed
146  startRestore (sconfig, sgroup);
147 
148  m_mainWindow = new Kate::MainWindow (this);
149  m_toolViewManager = new Kate::ToolViewManager (this);
150 
151  m_dcop = new KateMainWindowDCOPIface (this);
152 
153  // setup the most important widgets
154  setupMainWindow();
155 
156  // setup the actions
157  setupActions();
158 
159  setStandardToolBarMenuEnabled( true );
160  setXMLFile( "kateui.rc" );
161  createShellGUI ( true );
162 
163  KatePluginManager::self()->enableAllPluginsGUI (this);
164 
165  if ( KateApp::self()->authorize("shell_access") )
166  Kate::Document::registerCommand(KateExternalToolsCommand::self());
167 
168  // connect documents menu aboutToshow
169  documentMenu = (TQPopupMenu*)factory()->container("documents", this);
170  connect(documentMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(documentMenuAboutToShow()));
171 
172  // caption update
173  for (uint i = 0; i < KateDocManager::self()->documents(); i++)
174  slotDocumentCreated (KateDocManager::self()->document(i));
175 
176  connect(KateDocManager::self(),TQT_SIGNAL(documentCreated(Kate::Document *)),this,TQT_SLOT(slotDocumentCreated(Kate::Document *)));
177 
178  readOptions();
179 
180  if (sconfig)
181  m_viewManager->restoreViewConfiguration (sconfig, sgroup);
182 
183  finishRestore ();
184 
185  setAcceptDrops(true);
186 }
187 
188 KateMainWindow::~KateMainWindow()
189 {
190  // first, save our fallback window size ;)
191  KateApp::self()->config()->setGroup ("MainWindow");
192  saveWindowSize (KateApp::self()->config());
193 
194  // save other options ;=)
195  saveOptions();
196 
197  KateApp::self()->removeMainWindow (this);
198 
199  KatePluginManager::self()->disableAllPluginsGUI (this);
200 
201  delete m_dcop;
202 }
203 
204 void KateMainWindow::setupMainWindow ()
205 {
206  setToolViewStyle( KMultiTabBar::KDEV3ICON );
207 
208  m_tabWidget = new KateTabWidget (centralWidget());
209 
210  m_viewManager = new KateViewManager (this);
211 
212  KateMDI::ToolView *ft = createToolView("kate_filelist", KMultiTabBar::Left, SmallIcon("application-vnd.tde.tdemultiple"), i18n("Documents"));
213  filelist = new KateFileList (this, m_viewManager, ft, "filelist");
214  filelist->readConfig(KateApp::self()->config(), "Filelist");
215 
216  KateMDI::ToolView *t = createToolView("kate_fileselector", KMultiTabBar::Left, SmallIcon("document-open"), i18n("Filesystem Browser"));
217  fileselector = new KateFileSelector( this, m_viewManager, t, "operator");
218  connect(fileselector->dirOperator(),TQT_SIGNAL(fileSelected(const KFileItem*)),this,TQT_SLOT(fileSelected(const KFileItem*)));
219 
220  // ONLY ALLOW SHELL ACCESS IF ALLOWED ;)
221  if (KateApp::self()->authorize("shell_access"))
222  {
223  t = createToolView("kate_greptool", KMultiTabBar::Bottom, SmallIcon("filefind"), i18n("Find in Files") );
224  greptool = new GrepTool( t, "greptool" );
225  connect(greptool, TQT_SIGNAL(itemSelected(const TQString &,int)), this, TQT_SLOT(slotGrepToolItemSelected(const TQString &,int)));
226  connect(t,TQT_SIGNAL(visibleChanged(bool)),this, TQT_SLOT(updateGrepDir (bool)));
227  // WARNING HACK - anders: showing the greptool seems to make the menu accels work
228  greptool->show();
229 
230  t = createToolView("kate_console", KMultiTabBar::Bottom, SmallIcon("konsole"), i18n("Terminal"));
231  console = new KateConsole (this, t);
232  }
233 
234  // make per default the filelist visible, if we are in session restore, katemdi will skip this ;)
235  showToolView (ft);
236 }
237 
238 void KateMainWindow::setupActions()
239 {
240  TDEAction *a;
241 
242  KStdAction::openNew( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentNew() ), actionCollection(), "file_new" )->setWhatsThis(i18n("Create a new document"));
243  KStdAction::open( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Open an existing document for editing"));
244 
245  fileOpenRecent = KStdAction::openRecent (TQT_TQOBJECT(m_viewManager), TQT_SLOT(openURL (const KURL&)), actionCollection());
246  fileOpenRecent->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
247 
248  a=new TDEAction( i18n("Save A&ll"),"save_all", CTRL+Key_L, KateDocManager::self(), TQT_SLOT( saveAll() ), actionCollection(), "file_save_all" );
249  a->setWhatsThis(i18n("Save all open, modified documents to disk."));
250 
251  KStdAction::close( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentClose() ), actionCollection(), "file_close" )->setWhatsThis(i18n("Close the current document."));
252 
253  a=new TDEAction( i18n( "Clos&e All" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotDocumentCloseAll() ), actionCollection(), "file_close_all" );
254  a->setWhatsThis(i18n("Close all open documents."));
255 
256  KStdAction::mail( TQT_TQOBJECT(this), TQT_SLOT(slotMail()), actionCollection() )->setWhatsThis(i18n("Send one or more of the open documents as email attachments."));
257 
258  KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT( slotFileQuit() ), actionCollection(), "file_quit" )->setWhatsThis(i18n("Close this window"));
259 
260  a=new TDEAction(i18n("&New Window"), "window-new", 0, TQT_TQOBJECT(this), TQT_SLOT(newWindow()), actionCollection(), "view_new_view");
261  a->setWhatsThis(i18n("Create a new Kate view (a new window with the same document list)."));
262 
263  if ( KateApp::self()->authorize("shell_access") )
264  {
265  externalTools = new KateExternalToolsMenuAction( i18n("External Tools"), actionCollection(), "tools_external", this );
266  externalTools->setWhatsThis( i18n("Launch external helper applications") );
267  }
268 
269  TDEToggleAction* showFullScreenAction = KStdAction::fullScreen( 0, 0, actionCollection(),this);
270  connect( showFullScreenAction,TQT_SIGNAL(toggled(bool)), this,TQT_SLOT(slotFullScreen(bool)));
271 
272  documentOpenWith = new TDEActionMenu(i18n("Open W&ith"), actionCollection(), "file_open_with");
273  documentOpenWith->setWhatsThis(i18n("Open the current document using another application registered for its file type, or an application of your choice."));
274  connect(documentOpenWith->popupMenu(), TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(mSlotFixOpenWithMenu()));
275  connect(documentOpenWith->popupMenu(), TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotOpenWithMenuAction(int)));
276 
277  a=KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(editKeys()), actionCollection());
278  a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
279 
280  a=KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotEditToolbars()), actionCollection());
281  a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
282 
283  TDEAction* settingsConfigure = KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotConfigure()), actionCollection(), "settings_configure");
284  settingsConfigure->setWhatsThis(i18n("Configure various aspects of this application and the editing component."));
285 
286  // pipe to terminal action
287  if (KateApp::self()->authorize("shell_access"))
288  new TDEAction(i18n("&Pipe to Console"), "pipe", 0, TQT_TQOBJECT(console), TQT_SLOT(slotPipeToConsole()), actionCollection(), "tools_pipe_to_terminal");
289 
290  // tip of the day :-)
291  KStdAction::tipOfDay( TQT_TQOBJECT(this), TQT_SLOT( tipOfTheDay() ), actionCollection() )->setWhatsThis(i18n("This shows useful tips on the use of this application."));
292 
293  if (KatePluginManager::self()->pluginList().count() > 0)
294  {
295  a=new TDEAction(i18n("&Plugins Handbook"), 0, TQT_TQOBJECT(this), TQT_SLOT(pluginHelp()), actionCollection(), "help_plugins_contents");
296  a->setWhatsThis(i18n("This shows help files for various available plugins."));
297  }
298 
299  connect(m_viewManager,TQT_SIGNAL(viewChanged()),TQT_TQOBJECT(this),TQT_SLOT(slotWindowActivated()));
300  connect(m_viewManager,TQT_SIGNAL(viewChanged()),TQT_TQOBJECT(this),TQT_SLOT(slotUpdateOpenWith()));
301 
302  slotWindowActivated ();
303 
304  // session actions
305  new TDEAction(i18n("Menu entry Session->New", "&New"), "document-new", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new");
306  new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open");
307  new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save");
308  new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as");
309  new TDEAction(i18n("&Manage..."), "view_choose", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionManage()), actionCollection(), "sessions_manage");
310 
311  // quick open menu ;)
312  new KateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list");
313 }
314 
315 KateTabWidget *KateMainWindow::tabWidget ()
316 {
317  return m_tabWidget;
318 }
319 
320 void KateMainWindow::slotDocumentCloseAll() {
321  if (queryClose_internal())
322  KateDocManager::self()->closeAllDocuments(false);
323 }
324 
325 bool KateMainWindow::queryClose_internal() {
326  uint documentCount=KateDocManager::self()->documents();
327 
328  if ( ! showModOnDiskPrompt() )
329  return false;
330 
331  TQPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList();
332  bool shutdown=(modifiedDocuments.count()==0);
333 
334  if (!shutdown) {
335  shutdown=KateSaveModifiedDialog::queryClose(this,modifiedDocuments);
336  }
337 
338  if ( KateDocManager::self()->documents() > documentCount ) {
339  KMessageBox::information (this,
340  i18n ("New file opened while trying to close Kate, closing aborted."),
341  i18n ("Closing Aborted"));
342  shutdown=false;
343  }
344 
345  return shutdown;
346 }
347 
351 bool KateMainWindow::queryClose()
352 {
353  // session saving, can we close all views ?
354  // just test, not close them actually
355  if (KateApp::self()->sessionSaving())
356  {
357  return queryClose_internal ();
358  }
359 
360  // normal closing of window
361  // allow to close all windows until the last without restrictions
362  if ( KateApp::self()->mainWindows () > 1 )
363  return true;
364 
365  // last one: check if we can close all documents, try run
366  // and save docs if we really close down !
367  if ( queryClose_internal () )
368  {
369  KateApp::self()->sessionManager()->saveActiveSession(true, true);
370 
371  // detach the dcopClient
372  KateApp::self()->dcopClient()->detach();
373 
374  return true;
375  }
376 
377  return false;
378 }
379 
380 void KateMainWindow::newWindow ()
381 {
382  KateApp::self()->newMainWindow ();
383 }
384 
385 void KateMainWindow::slotEditToolbars()
386 {
387  saveMainWindowSettings( KateApp::self()->config(), "MainWindow" );
388  KEditToolbar dlg( factory() );
389  connect( &dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(slotNewToolbarConfig()) );
390  dlg.exec();
391 }
392 
393 void KateMainWindow::slotNewToolbarConfig()
394 {
395  applyMainWindowSettings( KateApp::self()->config(), "MainWindow" );
396 }
397 
398 void KateMainWindow::slotFileQuit()
399 {
400  KateApp::self()->shutdownKate (this);
401 }
402 
403 void KateMainWindow::readOptions ()
404 {
405  TDEConfig *config = KateApp::self()->config ();
406 
407  config->setGroup("General");
408  syncKonsole = config->readBoolEntry("Sync Konsole", true);
409  useInstance = config->readBoolEntry("UseInstance", false);
410  modNotification = config->readBoolEntry("Modified Notification", false);
411  KateDocManager::self()->setSaveMetaInfos(config->readBoolEntry("Save Meta Infos", true));
412  KateDocManager::self()->setDaysMetaInfos(config->readNumEntry("Days Meta Infos", 30));
413 
414  m_viewManager->setShowFullPath(config->readBoolEntry("Show Full Path in Title", false));
415 
416  fileOpenRecent->setMaxItems( config->readNumEntry("Number of recent files", fileOpenRecent->maxItems() ) );
417  fileOpenRecent->loadEntries(config, "Recent Files");
418 
419  fileselector->readConfig(config, "fileselector");
420 }
421 
422 void KateMainWindow::saveOptions ()
423 {
424  TDEConfig *config = KateApp::self()->config ();
425  config->setGroup("General");
426 
427  if (console)
428  config->writeEntry("Show Console", console->isVisible());
429  else
430  config->writeEntry("Show Console", false);
431 
432  config->writeEntry("Save Meta Infos", KateDocManager::self()->getSaveMetaInfos());
433  config->writeEntry("Days Meta Infos", KateDocManager::self()->getDaysMetaInfos());
434  config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath());
435  config->writeEntry("Sync Konsole", syncKonsole);
436  config->writeEntry("UseInstance", useInstance);
437 
438  fileOpenRecent->saveEntries(config, "Recent Files");
439  fileselector->writeConfig(config, "fileselector");
440  filelist->writeConfig(config, "Filelist");
441 
442  config->sync();
443 }
444 
445 void KateMainWindow::slotWindowActivated ()
446 {
447  if (m_viewManager->activeView())
448  {
449  if (console && syncKonsole)
450  {
451  static TQString path;
452  TQString newPath = m_viewManager->activeView()->getDoc()->url().directory();
453 
454  if ( newPath != path )
455  {
456  path = newPath;
457  console->cd (KURL( path ));
458  }
459  }
460 
461  updateCaption (m_viewManager->activeView()->getDoc());
462  }
463 
464  // update proxy
465  centralWidget()->setFocusProxy (m_viewManager->activeView());
466 }
467 
468 void KateMainWindow::slotUpdateOpenWith()
469 {
470  if (m_viewManager->activeView())
471  documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty());
472  else
473  documentOpenWith->setEnabled(false);
474 }
475 
476 void KateMainWindow::documentMenuAboutToShow()
477 {
478  // remove documents
479  while (documentMenu->count() > 3)
480  documentMenu->removeItemAt (3);
481 
482  TQListViewItem * item = filelist->firstChild();
483  while( item ) {
484  // would it be saner to use the screen width as a limit that some random number??
485  TQString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 );
486  Kate::Document* doc = ((KateFileListItem *)item)->document();
487  documentMenu->insertItem (
488  doc->isModified() ? i18n("'document name [*]', [*] means modified", "%1 [*]").arg(name) : name,
489  m_viewManager, TQT_SLOT (activateView (int)), 0,
490  ((KateFileListItem *)item)->documentNumber () );
491 
492  item = item->nextSibling();
493  }
494  if (m_viewManager->activeView())
495  documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true);
496 }
497 
498 void KateMainWindow::slotGrepToolItemSelected(const TQString &filename,int linenumber)
499 {
500  KURL fileURL;
501  fileURL.setPath( filename );
502  m_viewManager->openURL( fileURL );
503  if ( m_viewManager->activeView() == 0 ) return;
504  m_viewManager->activeView()->gotoLineNumber( linenumber );
505  raise();
506  setActiveWindow();
507 }
508 
509 void KateMainWindow::dragEnterEvent( TQDragEnterEvent *event )
510 {
511  event->accept(KURLDrag::canDecode(event));
512 }
513 
514 void KateMainWindow::dropEvent( TQDropEvent *event )
515 {
516  slotDropEvent(event);
517 }
518 
519 void KateMainWindow::slotDropEvent( TQDropEvent * event )
520 {
521  KURL::List textlist;
522  if (!KURLDrag::decode(event, textlist)) return;
523 
524  for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
525  {
526  m_viewManager->openURL (*i);
527  }
528 }
529 
530 void KateMainWindow::editKeys()
531 {
532  KKeyDialog dlg ( false, this );
533 
534  TQPtrList<KXMLGUIClient> clients = guiFactory()->clients();
535 
536  for( TQPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
537  dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() );
538 
539  dlg.insert( externalTools->actionCollection(), i18n("External Tools") );
540 
541  dlg.configure();
542 
543  TQPtrList<Kate::Document> l=KateDocManager::self()->documentList();
544  for (uint i=0;i<l.count();i++) {
545 // kdDebug(13001)<<"reloading Keysettings for document "<<i<<endl;
546  l.at(i)->reloadXML();
547  TQPtrList<class KTextEditor::View> l1=l.at(i)->views ();//KTextEditor::Document
548  for (uint i1=0;i1<l1.count();i1++) {
549  l1.at(i1)->reloadXML();
550 // kdDebug(13001)<<"reloading Keysettings for view "<<i<<"/"<<i1<<endl;
551  }
552  }
553 
554  externalTools->actionCollection()->writeShortcutSettings( "Shortcuts", new TDEConfig("externaltools", false, false, "appdata") );
555 }
556 
557 void KateMainWindow::openURL (const TQString &name)
558 {
559  m_viewManager->openURL (KURL(name));
560 }
561 
562 void KateMainWindow::slotConfigure()
563 {
564  if (!m_viewManager->activeView())
565  return;
566 
567  KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView());
568  dlg->exec();
569 
570  delete dlg;
571 }
572 
573 KURL KateMainWindow::activeDocumentUrl()
574 {
575  // anders: i make this one safe, as it may be called during
576  // startup (by the file selector)
577  Kate::View *v = m_viewManager->activeView();
578  if ( v )
579  return v->getDoc()->url();
580  return KURL();
581 }
582 
583 void KateMainWindow::fileSelected(const KFileItem * /*file*/)
584 {
585  const KFileItemList *list=fileselector->dirOperator()->selectedItems();
586  KFileItem *tmp;
587  for (KFileItemListIterator it(*list); (tmp = it.current()); ++it)
588  {
589  m_viewManager->openURL(tmp->url());
590  fileselector->dirOperator()->view()->setSelected(tmp,false);
591  }
592 }
593 
594 // TODO make this work
595 void KateMainWindow::mSlotFixOpenWithMenu()
596 {
597  //kdDebug(13001)<<"13000"<<"fixing open with menu"<<endl;
598  documentOpenWith->popupMenu()->clear();
599  // get a list of appropriate services.
600  KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
601  //kdDebug(13001)<<"13000"<<"url: "<<m_viewManager->activeView()->getDoc()->url().prettyURL()<<"mime type: "<<mime->name()<<endl;
602  // some checking goes here...
603  TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), "Type == 'Application'");
604  // for each one, insert a menu item...
605  for(TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) {
606  if ((*it)->name() == "Kate") continue;
607  documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
608  }
609  // append "Other..." to call the TDE "open with" dialog.
610  documentOpenWith->popupMenu()->insertItem(i18n("&Other..."));
611 }
612 
613 void KateMainWindow::slotOpenWithMenuAction(int idx)
614 {
615  KURL::List list;
616  list.append( m_viewManager->activeView()->getDoc()->url() );
617  TQString appname = documentOpenWith->popupMenu()->text(idx);
618 
619  appname = appname.remove('&'); //Remove a possible accelerator ... otherwise the application might not get found.
620  if ( appname.compare(i18n("Other...")) == 0 ) {
621  // display "open with" dialog
622  KOpenWithDlg dlg(list);
623  if (dlg.exec())
624  KRun::run(*dlg.service(), list);
625  return;
626  }
627 
628  TQString qry = TQString("((Type == 'Application') and (Name == '%1'))").arg( appname.latin1() );
629  KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
630  TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), qry);
631 
632  if (!offers.isEmpty()) {
633  KService::Ptr app = offers.first();
634  KRun::run(*app, list);
635  }
636  else
637  KMessageBox::error(this, i18n("Application '%1' not found!").arg(appname.latin1()), i18n("Application Not Found!"));
638 }
639 
640 void KateMainWindow::pluginHelp()
641 {
642  KateApp::self()->invokeHelp (TQString::null, "kate-plugins");
643 }
644 
645 void KateMainWindow::slotMail()
646 {
647  KateMailDialog *d = new KateMailDialog(this, this);
648  if ( ! d->exec() )
649  {
650  delete d;
651  return;
652  }
653  TQPtrList<Kate::Document> attDocs = d->selectedDocs();
654  delete d;
655  // Check that all selected files are saved (or shouldn't be)
656  TQStringList urls; // to atthatch
657  Kate::Document *doc;
658  TQPtrListIterator<Kate::Document> it(attDocs);
659  for ( ; it.current(); ++it ) {
660  doc = it.current();
661  if (!doc) continue;
662  if ( doc->url().isEmpty() ) {
663  // unsaved document. back out unless it gets saved
664  int r = KMessageBox::questionYesNo( this,
665  i18n("<p>The current document has not been saved, and "
666  "cannot be attached to an email message."
667  "<p>Do you want to save it and proceed?"),
668  i18n("Cannot Send Unsaved File"),KStdGuiItem::saveAs(),KStdGuiItem::cancel() );
669  if ( r == KMessageBox::Yes ) {
670  Kate::View *v = (Kate::View*)doc->views().first();
671  int sr = v->saveAs();
672  if ( sr == Kate::View::SAVE_OK ) { ;
673  }
674  else {
675  if ( sr != Kate::View::SAVE_CANCEL ) // ERROR or RETRY(?)
676  KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
677  "if you have write permission.") );
678  continue;
679  }
680  }
681  else
682  continue;
683  }
684  if ( doc->isModified() ) {
685  // warn that document is modified and offer to save it before proceeding.
686  int r = KMessageBox::warningYesNoCancel( this,
687  i18n("<p>The current file:<br><strong>%1</strong><br>has been "
688  "modified. Modifications will not be available in the attachment."
689  "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()),
690  i18n("Save Before Sending?"), KStdGuiItem::save(), i18n("Do Not Save") );
691  switch ( r ) {
692  case KMessageBox::Cancel:
693  continue;
694  case KMessageBox::Yes:
695  doc->save();
696  if ( doc->isModified() ) { // read-only docs ends here, if modified. Hmm.
697  KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
698  "if you have write permission.") );
699  continue;
700  }
701  break;
702  default:
703  break;
704  }
705  }
706  // finally call the mailer
707  urls << doc->url().url();
708  } // check selected docs done
709  if ( ! urls.count() )
710  return;
711  KateApp::self()->invokeMailer( TQString::null, // to
712  TQString::null, // cc
713  TQString::null, // bcc
714  TQString::null, // subject
715  TQString::null, // body
716  TQString::null, // msgfile
717  urls // urls to atthatch
718  );
719 }
720 void KateMainWindow::tipOfTheDay()
721 {
722  KTipDialog::showTip( /*0*/this, TQString::null, true );
723 }
724 
725 void KateMainWindow::slotFullScreen(bool t)
726 {
727  if (t)
728  showFullScreen();
729  else
730  showNormal();
731 }
732 
733 void KateMainWindow::updateGrepDir (bool visible)
734 {
735  // grepdlg gets hidden
736  if (!visible)
737  return;
738 
739  if ( m_viewManager->activeView() )
740  {
741  if ( m_viewManager->activeView()->getDoc()->url().isLocalFile() )
742  {
743  greptool->updateDirName( m_viewManager->activeView()->getDoc()->url().directory() );
744  }
745  }
746 }
747 
748 bool KateMainWindow::event( TQEvent *e )
749 {
750  uint type = e->type();
751  if ( type == TQEvent::WindowActivate && modNotification )
752  {
753  showModOnDiskPrompt();
754  }
755  return KateMDI::MainWindow::event( e );
756 }
757 
758 bool KateMainWindow::showModOnDiskPrompt()
759 {
760  Kate::Document *doc;
761 
762  DocVector list( KateDocManager::self()->documents() );
763  uint cnt = 0;
764  for( doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() )
765  {
766  if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDisc )
767  {
768  list.insert( cnt, doc );
769  cnt++;
770  }
771  }
772 
773  if ( cnt && !m_modignore )
774  {
775  list.resize( cnt );
776  KateMwModOnHdDialog mhdlg( list, this );
777  m_modignore = true;
778  bool res = mhdlg.exec();
779  m_modignore = false;
780 
781  return res;
782  }
783  return true;
784 }
785 
786 void KateMainWindow::slotDocumentCreated (Kate::Document *doc)
787 {
788  connect(doc,TQT_SIGNAL(modStateChanged(Kate::Document *)),this,TQT_SLOT(updateCaption(Kate::Document *)));
789  connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotNameChanged(Kate::Document *)));
790  connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotUpdateOpenWith()));
791 
792  updateCaption (doc);
793 }
794 
795 void KateMainWindow::slotNameChanged(Kate::Document *doc)
796 {
797  updateCaption(doc);
798  if (!doc->url().isEmpty())
799  fileOpenRecent->addURL(doc->url());
800 }
801 
802 void KateMainWindow::updateCaption (Kate::Document *doc)
803 {
804  if (!m_viewManager->activeView())
805  {
806  setCaption ("", false);
807  return;
808  }
809 
810  if (!(m_viewManager->activeView()->getDoc() == doc))
811  return;
812 
813  TQString c;
814  if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath()))
815  {
816  c = m_viewManager->activeView()->getDoc()->docName();
817  }
818  else
819  {
820  c = m_viewManager->activeView()->getDoc()->url().prettyURL();
821  }
822 
823  TQString sessName = KateApp::self()->sessionManager()->activeSession()->sessionName();
824  if ( !sessName.isEmpty() )
825  sessName = TQString("%1: ").arg( sessName );
826 
827  setCaption( sessName + KStringHandler::lsqueeze(c,64),
828  m_viewManager->activeView()->getDoc()->isModified());
829 }
830 
831 void KateMainWindow::saveProperties(TDEConfig *config)
832 {
833  TQString grp=config->group();
834 
835  saveSession(config, grp);
836  m_viewManager->saveViewConfiguration (config, grp);
837 
838  config->setGroup(grp);
839 }
840 
841 void KateMainWindow::readProperties(TDEConfig *config)
842 {
843  TQString grp=config->group();
844 
845  startRestore(config, grp);
846  finishRestore ();
847  m_viewManager->restoreViewConfiguration (config, grp);
848 
849  config->setGroup(grp);
850 }
851 
852 void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig )
853 {
854  KateDocManager::self()->saveDocumentList (sessionConfig);
855 
856  sessionConfig->setGroup("General");
857  sessionConfig->writeEntry ("Last Session", KateApp::self()->sessionManager()->activeSession()->sessionFileRelative());
858 }

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.