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