• 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 <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 <ksimpleconfig.h>
69#include <kstatusbar.h>
70#include <kstdaction.h>
71#include <tdestandarddirs.h>
72#include <ktrader.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
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 (queryClose_internal())
343 KateDocManager::self()->closeAllDocuments(false);
344}
345
346bool KateMainWindow::queryClose_internal() {
347 uint documentCount=KateDocManager::self()->documents();
348
349 if ( !showModOnDiskPrompt() )
350 {
351 return false;
352 }
353
354 TQPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList();
355 bool shutdown = (modifiedDocuments.count() == 0);
356
357 if (!shutdown)
358 {
359 shutdown = KateSaveModifiedDialog::queryClose(this,modifiedDocuments);
360 }
361
362 if ( KateDocManager::self()->documents() > documentCount ) {
363 KMessageBox::information (this,
364 i18n ("New file opened while trying to close Kate, closing aborted."),
365 i18n ("Closing Aborted"));
366 return false;
367 }
368
369 if (!shutdown)
370 {
371 return false;
372 }
373
374 return KateApp::self()->query_session_close();
375}
376
380bool KateMainWindow::queryClose()
381{
382 // session saving, can we close all views ?
383 // just test, not close them actually
384 if (KateApp::self()->sessionSaving())
385 {
386 return queryClose_internal();
387 }
388
389 // normal closing of window
390 // allow to close all windows until the last without restrictions
391 if (KateApp::self()->mainWindows() > 1)
392 {
393 return true;
394 }
395
396 // last one: check if we can close all documents and sessions, try run
397 // and save docs if we really close down !
398 if (queryClose_internal())
399 {
400 // detach the dcopClient
401 KateApp::self()->dcopClient()->detach();
402 return true;
403 }
404
405 return false;
406}
407
408void KateMainWindow::newWindow ()
409{
410 KateApp::self()->newMainWindow ();
411}
412
413void KateMainWindow::slotEditToolbars()
414{
415 saveMainWindowSettings( KateApp::self()->config(), "MainWindow" );
416 KEditToolbar dlg( factory() );
417 connect( &dlg, TQ_SIGNAL(newToolbarConfig()), this, TQ_SLOT(slotNewToolbarConfig()) );
418 dlg.exec();
419}
420
421void KateMainWindow::slotNewToolbarConfig()
422{
423 applyMainWindowSettings( KateApp::self()->config(), "MainWindow" );
424}
425
426void KateMainWindow::slotFileQuit()
427{
428 KateApp::self()->shutdownKate(this);
429}
430
431void KateMainWindow::readOptions ()
432{
433 TDEConfig *config = KateApp::self()->config ();
434
435 config->setGroup("General");
436 showSessionName = config->readBoolEntry("Show session name", false);
437 syncKonsole = config->readBoolEntry("Sync Konsole", true);
438 useInstance = config->readBoolEntry("UseInstance", false);
439 modNotification = config->readBoolEntry("Modified Notification", false);
440 KateDocManager::self()->setSaveMetaInfos(config->readBoolEntry("Save Meta Infos", true));
441 KateDocManager::self()->setDaysMetaInfos(config->readNumEntry("Days Meta Infos", 30));
442
443 m_viewManager->setShowFullPath(config->readBoolEntry("Show Full Path in Title", false));
444
445 fileOpenRecent->setMaxItems( config->readNumEntry("Number of recent files", fileOpenRecent->maxItems() ) );
446 fileOpenRecent->loadEntries(config, "Recent Files");
447
448 fileselector->readConfig(config, "fileselector");
449}
450
451void KateMainWindow::saveOptions ()
452{
453 TDEConfig *config = KateApp::self()->config ();
454 config->setGroup("General");
455
456 if (console)
457 config->writeEntry("Show Console", console->isVisible());
458 else
459 config->writeEntry("Show Console", false);
460
461 config->writeEntry("Show session name", showSessionName);
462 config->writeEntry("Save Meta Infos", KateDocManager::self()->getSaveMetaInfos());
463 config->writeEntry("Days Meta Infos", KateDocManager::self()->getDaysMetaInfos());
464 config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath());
465 config->writeEntry("Sync Konsole", syncKonsole);
466 config->writeEntry("UseInstance", useInstance);
467
468 fileOpenRecent->saveEntries(config, "Recent Files");
469 fileselector->writeConfig(config, "fileselector");
470 filelist->writeConfig(config, "Filelist");
471
472 config->sync();
473}
474
475void KateMainWindow::slotWindowActivated ()
476{
477 if (m_viewManager->activeView())
478 {
479 if (console && syncKonsole)
480 {
481 static TQString path;
482 TQString newPath = m_viewManager->activeView()->getDoc()->url().directory();
483
484 if ( newPath != path )
485 {
486 path = newPath;
487 console->cd (KURL( path ));
488 }
489 }
490
491 updateCaption (m_viewManager->activeView()->getDoc());
492 }
493
494 // update proxy
495 centralWidget()->setFocusProxy (m_viewManager->activeView());
496}
497
498void KateMainWindow::slotUpdateOpenWith()
499{
500 if (m_viewManager->activeView())
501 documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty());
502 else
503 documentOpenWith->setEnabled(false);
504}
505
506void KateMainWindow::documentMenuAboutToShow()
507{
508 // remove documents
509 while (documentMenu->count() > 3)
510 documentMenu->removeItemAt (3);
511
512 TQListViewItem * item = filelist->firstChild();
513 while( item ) {
514 // would it be saner to use the screen width as a limit that some random number??
515 TQString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 );
516 Kate::Document* doc = ((KateFileListItem *)item)->document();
517 documentMenu->insertItem (
518 doc->isModified() ? i18n("'document name [*]', [*] means modified", "%1 [*]").arg(name) : name,
519 m_viewManager, TQ_SLOT (activateView (int)), 0,
520 ((KateFileListItem *)item)->documentNumber () );
521
522 item = item->nextSibling();
523 }
524 if (m_viewManager->activeView())
525 documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true);
526}
527
528void KateMainWindow::slotGrepToolItemSelected(const TQString &filename,int linenumber)
529{
530 KURL fileURL;
531 fileURL.setPath( filename );
532 m_viewManager->openURL( fileURL );
533 if ( m_viewManager->activeView() == 0 ) return;
534 m_viewManager->activeView()->gotoLineNumber( linenumber );
535 raise();
536 setActiveWindow();
537}
538
539void KateMainWindow::dragEnterEvent( TQDragEnterEvent *event )
540{
541 event->accept(KURLDrag::canDecode(event));
542}
543
544void KateMainWindow::dropEvent( TQDropEvent *event )
545{
546 slotDropEvent(event);
547}
548
549void KateMainWindow::slotDropEvent( TQDropEvent * event )
550{
551 KURL::List textlist;
552 if (!KURLDrag::decode(event, textlist)) return;
553
554 for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
555 {
556 m_viewManager->openURL (*i);
557 }
558}
559
560void KateMainWindow::editKeys()
561{
562 KKeyDialog dlg ( false, this );
563
564 TQPtrList<KXMLGUIClient> clients = guiFactory()->clients();
565
566 for( TQPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
567 dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() );
568
569 dlg.insert( externalTools->actionCollection(), i18n("External Tools") );
570
571 dlg.configure();
572
573 TQPtrList<Kate::Document> l=KateDocManager::self()->documentList();
574 for (uint i=0;i<l.count();i++) {
575// kdDebug(13001)<<"reloading Keysettings for document "<<i<<endl;
576 l.at(i)->reloadXML();
577 TQPtrList<class KTextEditor::View> l1=l.at(i)->views ();//KTextEditor::Document
578 for (uint i1=0;i1<l1.count();i1++) {
579 l1.at(i1)->reloadXML();
580// kdDebug(13001)<<"reloading Keysettings for view "<<i<<"/"<<i1<<endl;
581 }
582 }
583
584 externalTools->actionCollection()->writeShortcutSettings( "Shortcuts", new TDEConfig("externaltools", false, false, "appdata") );
585}
586
587void KateMainWindow::openURL (const TQString &name)
588{
589 m_viewManager->openURL (KURL(name));
590}
591
592void KateMainWindow::slotConfigure()
593{
594 if (!m_viewManager->activeView())
595 return;
596
597 KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView());
598 dlg->exec();
599
600 delete dlg;
601
602 // Inform Kate that options may have been changed
603 KateApp::self()->reparse_config();
604}
605
606KURL KateMainWindow::activeDocumentUrl()
607{
608 // anders: i make this one safe, as it may be called during
609 // startup (by the file selector)
610 Kate::View *v = m_viewManager->activeView();
611 if ( v )
612 return v->getDoc()->url();
613 return KURL();
614}
615
616void KateMainWindow::fileSelected(const KFileItem * /*file*/)
617{
618 const KFileItemList *list=fileselector->dirOperator()->selectedItems();
619 KFileItem *tmp;
620 for (KFileItemListIterator it(*list); (tmp = it.current()); ++it)
621 {
622 m_viewManager->openURL(tmp->url());
623 fileselector->dirOperator()->view()->setSelected(tmp,false);
624 }
625}
626
627// TODO make this work
628void KateMainWindow::mSlotFixOpenWithMenu()
629{
630 //kdDebug(13001)<<"13000"<<"fixing open with menu"<<endl;
631 documentOpenWith->popupMenu()->clear();
632 // get a list of appropriate services.
633 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
634 //kdDebug(13001)<<"13000"<<"url: "<<m_viewManager->activeView()->getDoc()->url().prettyURL()<<"mime type: "<<mime->name()<<endl;
635 // some checking goes here...
636 TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), "Type == 'Application'");
637 // for each one, insert a menu item...
638 for(TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) {
639 if ((*it)->name() == "Kate") continue;
640 documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
641 }
642 // append "Other..." to call the TDE "open with" dialog.
643 documentOpenWith->popupMenu()->insertItem(i18n("&Other..."));
644}
645
646void KateMainWindow::slotOpenWithMenuAction(int idx)
647{
648 KURL::List list;
649 list.append( m_viewManager->activeView()->getDoc()->url() );
650 TQString appname = documentOpenWith->popupMenu()->text(idx);
651
652 appname = appname.remove('&'); //Remove a possible accelerator ... otherwise the application might not get found.
653 if ( appname.compare(i18n("Other...")) == 0 ) {
654 // display "open with" dialog
655 KOpenWithDlg dlg(list);
656 if (dlg.exec())
657 KRun::run(*dlg.service(), list);
658 return;
659 }
660
661 TQString qry = TQString("((Type == 'Application') and (Name == '%1'))").arg( appname.latin1() );
662 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
663 TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), qry);
664
665 if (!offers.isEmpty()) {
666 KService::Ptr app = offers.first();
667 KRun::run(*app, list);
668 }
669 else
670 KMessageBox::error(this, i18n("Application '%1' not found!").arg(appname.latin1()), i18n("Application Not Found!"));
671}
672
673void KateMainWindow::pluginHelp()
674{
675 KateApp::self()->invokeHelp (TQString::null, "kate-plugins");
676}
677
678void KateMainWindow::slotMail()
679{
680 KateMailDialog *d = new KateMailDialog(this, this);
681 if ( ! d->exec() )
682 {
683 delete d;
684 return;
685 }
686 TQPtrList<Kate::Document> attDocs = d->selectedDocs();
687 delete d;
688 // Check that all selected files are saved (or shouldn't be)
689 TQStringList urls; // to atthatch
690 Kate::Document *doc;
691 TQPtrListIterator<Kate::Document> it(attDocs);
692 for ( ; it.current(); ++it ) {
693 doc = it.current();
694 if (!doc) continue;
695 if ( doc->url().isEmpty() ) {
696 // unsaved document. back out unless it gets saved
697 int r = KMessageBox::questionYesNo( this,
698 i18n("<p>The current document has not been saved, and "
699 "cannot be attached to an email message."
700 "<p>Do you want to save it and proceed?"),
701 i18n("Cannot Send Unsaved File"),KStdGuiItem::saveAs(),KStdGuiItem::cancel() );
702 if ( r == KMessageBox::Yes ) {
703 Kate::View *v = (Kate::View*)doc->views().first();
704 int sr = v->saveAs();
705 if ( sr == Kate::View::SAVE_OK ) { ;
706 }
707 else {
708 if ( sr != Kate::View::SAVE_CANCEL ) // ERROR or RETRY(?)
709 KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
710 "if you have write permission.") );
711 continue;
712 }
713 }
714 else
715 continue;
716 }
717 if ( doc->isModified() ) {
718 // warn that document is modified and offer to save it before proceeding.
719 int r = KMessageBox::warningYesNoCancel( this,
720 i18n("<p>The current file:<br><strong>%1</strong><br>has been "
721 "modified. Modifications will not be available in the attachment."
722 "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()),
723 i18n("Save Before Sending?"), KStdGuiItem::save(), i18n("Do Not Save") );
724 switch ( r ) {
725 case KMessageBox::Cancel:
726 continue;
727 case KMessageBox::Yes:
728 doc->save();
729 if ( doc->isModified() ) { // read-only docs ends here, if modified. Hmm.
730 KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
731 "if you have write permission.") );
732 continue;
733 }
734 break;
735 default:
736 break;
737 }
738 }
739 // finally call the mailer
740 urls << doc->url().url();
741 } // check selected docs done
742 if ( ! urls.count() )
743 return;
744 KateApp::self()->invokeMailer( TQString::null, // to
745 TQString::null, // cc
746 TQString::null, // bcc
747 TQString::null, // subject
748 TQString::null, // body
749 TQString::null, // msgfile
750 urls // urls to atthatch
751 );
752}
753void KateMainWindow::tipOfTheDay()
754{
755 KTipDialog::showTip( /*0*/this, TQString::null, true );
756}
757
758void KateMainWindow::slotFullScreen(bool t)
759{
760 if (t)
761 showFullScreen();
762 else
763 showNormal();
764}
765
766void KateMainWindow::updateGrepDir (bool visible)
767{
768 // grepdlg gets hidden
769 if (!visible)
770 return;
771
772 if ( m_viewManager->activeView() )
773 {
774 if ( m_viewManager->activeView()->getDoc()->url().isLocalFile() )
775 {
776 greptool->updateDirName( m_viewManager->activeView()->getDoc()->url().directory() );
777 }
778 }
779}
780
781bool KateMainWindow::event( TQEvent *e )
782{
783 uint type = e->type();
784 if ( type == TQEvent::WindowActivate && modNotification )
785 {
786 showModOnDiskPrompt();
787 }
788 return KateMDI::MainWindow::event( e );
789}
790
791bool KateMainWindow::showModOnDiskPrompt()
792{
793 Kate::Document *doc;
794
795 DocVector list( KateDocManager::self()->documents() );
796 uint cnt = 0;
797 for( doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() )
798 {
799 if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDisc )
800 {
801 list.insert( cnt, doc );
802 cnt++;
803 }
804 }
805
806 if ( cnt && !m_modignore )
807 {
808 list.resize( cnt );
809 KateMwModOnHdDialog mhdlg( list, this );
810 m_modignore = true;
811 bool res = mhdlg.exec();
812 m_modignore = false;
813
814 return res;
815 }
816 return true;
817}
818
819void KateMainWindow::slotDocumentCreated (Kate::Document *doc)
820{
821 connect(doc,TQ_SIGNAL(modStateChanged(Kate::Document *)),this,TQ_SLOT(updateCaption(Kate::Document *)));
822 connect(doc,TQ_SIGNAL(nameChanged(Kate::Document *)),this,TQ_SLOT(slotNameChanged(Kate::Document *)));
823 connect(doc,TQ_SIGNAL(nameChanged(Kate::Document *)),this,TQ_SLOT(slotUpdateOpenWith()));
824
825 updateCaption (doc);
826}
827
828void KateMainWindow::slotNameChanged(Kate::Document *doc)
829{
830 updateCaption(doc);
831 if (!doc->url().isEmpty())
832 fileOpenRecent->addURL(doc->url());
833}
834
835void KateMainWindow::updateCaption(Kate::Document *doc)
836{
837 if (!m_viewManager->activeView())
838 {
839 setCaption ("", false);
840 return;
841 }
842
843 if (!(m_viewManager->activeView()->getDoc() == doc))
844 return;
845
846 TQString c;
847 if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath()))
848 {
849 c = m_viewManager->activeView()->getDoc()->docName();
850 }
851 else
852 {
853 c = m_viewManager->activeView()->getDoc()->url().pathOrURL();
854 }
855
856 if (showSessionName)
857 {
858 TQString sessName = KateApp::self()->sessionManager()->getActiveSessionName();
859 if (!sessName.isEmpty())
860 {
861 sessName = TQString("%1: ").arg(sessName);
862 }
863 setCaption(KStringHandler::lsqueeze(sessName,32) + KStringHandler::lsqueeze(c,64),
864 m_viewManager->activeView()->getDoc()->isModified());
865 }
866 else
867 {
868 setCaption(KStringHandler::lsqueeze(c,64), m_viewManager->activeView()->getDoc()->isModified());
869 }
870}
871
872void KateMainWindow::saveProperties(TDEConfig *config)
873{
874 TQString grp=config->group();
875
876 saveSession(config, grp);
877 m_viewManager->saveViewConfiguration (config, grp);
878
879 config->setGroup(grp);
880}
881
882void KateMainWindow::readProperties(TDEConfig *config)
883{
884 TQString grp=config->group();
885
886 startRestore(config, grp);
887 finishRestore ();
888 m_viewManager->restoreViewConfiguration (config, grp);
889
890 config->setGroup(grp);
891}
892
893bool KateMainWindow::eventFilter(TQObject *obj, TQEvent *ev)
894{
895 if (ev->type() == TQEvent::MouseButtonRelease)
896 {
897 TQMouseEvent *mouseEvent = static_cast<TQMouseEvent *>(ev);
898 switch (mouseEvent->button())
899 {
900 case TQMouseEvent::HistoryBackButton:
901 filelist->slotPrevDocument();
902 return true;
903 case TQMouseEvent::HistoryForwardButton:
904 filelist->slotNextDocument();
905 return true;
906 }
907 }
908 return false;
909}
910
911//-------------------------------------------
912void KateMainWindow::slotSelectionChanged()
913{
914 TDEActionCollection *mwac = actionCollection(); // Main Window Action Collection
915 TDEActionPtrList actionList = m_sessionpanel->m_actionCollection->actions();
916 TDEActionPtrList::ConstIterator spa_it;
917 for (spa_it = actionList.begin(); spa_it != actionList.end(); ++spa_it)
918 {
919 TDEAction *a = mwac->action((*spa_it)->name());
920 TDEToggleAction *ta = dynamic_cast<TDEToggleAction*>(a);
921 if (ta)
922 {
923 ta->setChecked((dynamic_cast<TDEToggleAction*>(*spa_it))->isChecked());
924 }
925 if (a)
926 {
927 a->setEnabled((*spa_it)->isEnabled());
928 }
929 }
930}
931
932//-------------------------------------------
933void KateMainWindow::activateSession(int sessionId)
934{
935 if (sessionId < 0 || sessionId == KateApp::self()->sessionManager()->getActiveSessionId())
936 {
937 return;
938 }
939
940 // Select the required session in the session panel's listview
941 TQListViewItem *item = m_sessionpanel->m_listview->firstChild();
942 int idx = 0;
943 while (item && idx < sessionId)
944 {
945 item = item->nextSibling();
946 ++idx;
947 }
948 if (idx == sessionId && item)
949 {
950 // Required session item found, switch session with consistent behavior
951 m_sessionpanel->m_listview->setSelected(item, true);
952 m_sessionpanel->slotActivateSession();
953 }
954}
955
956//-------------------------------------------
957KateSessionListActionMenu::KateSessionListActionMenu(KateMainWindow *mw, const TQString &text, TQObject *parent, const char *name)
958 : TDEActionMenu(text, parent, name), m_mainWindow(mw)
959{
960 connect(popupMenu(), TQ_SIGNAL(aboutToShow()), this, TQ_SLOT(slotAboutToShow()));
961}
962
963//-------------------------------------------
964void KateSessionListActionMenu::slotAboutToShow()
965{
966 popupMenu()->clear();
967
968 TQPtrList<KateSession> &sessions = KateApp::self()->sessionManager()->getSessionsList();
969 for (int idx = 0; idx < (int)sessions.count(); ++idx)
970 {
971 popupMenu()->insertItem(sessions[idx]->getSessionName(), m_mainWindow, TQ_SLOT(activateSession(int)), 0, idx);
972 }
973}
KateApp::query_session_close
bool query_session_close()
to be called when the application is about to quit
Definition: kateapp.cpp:313
KateApp::reparse_config
void reparse_config()
called after the config dialog has been closed.
Definition: kateapp.cpp:362
KateApp::newMainWindow
KateMainWindow * newMainWindow(TDEConfig *sconfig=0, const TQString &sgroup="")
window management
Definition: kateapp.cpp:435
KateApp::shutdownKate
void shutdownKate(KateMainWindow *win)
kate shutdown
Definition: kateapp.cpp:298
KateApp::mainWindow
KateMainWindow * mainWindow(uint n)
give back the window you want
Definition: kateapp.cpp:475
KateApp::self
static KateApp * self()
static accessor to avoid casting ;)
Definition: kateapp.cpp:114
KateApp::activeMainWindow
KateMainWindow * activeMainWindow()
give back current active main window can only be 0 at app start or exit
Definition: kateapp.cpp:457
KateApp::sessionManager
KateSessionManager * sessionManager()
accessor to session manager
Definition: kateapp.cpp:377
KateApp::removeMainWindow
void removeMainWindow(KateMainWindow *mainWindow)
removes the mainwindow given, DOES NOT DELETE IT
Definition: kateapp.cpp:452
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.