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

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