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

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