00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "katemainwindow.h"
00023 #include "katemainwindow.moc"
00024
00025 #include "kateconfigdialog.h"
00026 #include "kateconsole.h"
00027 #include "katedocmanager.h"
00028 #include "katepluginmanager.h"
00029 #include "kateconfigplugindialogpage.h"
00030 #include "kateviewmanager.h"
00031 #include "kateapp.h"
00032 #include "katefileselector.h"
00033 #include "katefilelist.h"
00034 #include "kategrepdialog.h"
00035 #include "katemailfilesdialog.h"
00036 #include "katemainwindowiface.h"
00037 #include "kateexternaltools.h"
00038 #include "katesavemodifieddialog.h"
00039 #include "katemwmodonhddialog.h"
00040 #include "katesession.h"
00041 #include "katetabwidget.h"
00042
00043 #include "../interfaces/mainwindow.h"
00044 #include "../interfaces/toolviewmanager.h"
00045
00046 #include <dcopclient.h>
00047 #include <kinstance.h>
00048 #include <kaboutdata.h>
00049 #include <kaction.h>
00050 #include <kcmdlineargs.h>
00051 #include <kdebug.h>
00052 #include <kdialogbase.h>
00053 #include <kdiroperator.h>
00054 #include <kdockwidget.h>
00055 #include <kedittoolbar.h>
00056 #include <kfiledialog.h>
00057 #include <kglobalaccel.h>
00058 #include <kglobal.h>
00059 #include <kglobalsettings.h>
00060 #include <kiconloader.h>
00061 #include <kkeydialog.h>
00062 #include <klocale.h>
00063 #include <kmessagebox.h>
00064 #include <kmimetype.h>
00065 #include <kopenwith.h>
00066 #include <kpopupmenu.h>
00067 #include <ksimpleconfig.h>
00068 #include <kstatusbar.h>
00069 #include <kstdaction.h>
00070 #include <kstandarddirs.h>
00071 #include <ktrader.h>
00072 #include <kuniqueapplication.h>
00073 #include <kurldrag.h>
00074 #include <kdesktopfile.h>
00075 #include <khelpmenu.h>
00076 #include <kmultitabbar.h>
00077 #include <ktip.h>
00078 #include <kmenubar.h>
00079 #include <kstringhandler.h>
00080 #include <qlayout.h>
00081 #include <qptrvector.h>
00082
00083 #include <assert.h>
00084 #include <unistd.h>
00085
00086
00087 uint KateMainWindow::uniqueID = 1;
00088
00089 KateMainWindow::KateMainWindow (KConfig *sconfig, const QString &sgroup)
00090 : KateMDI::MainWindow (0,(QString("__KateMainWindow#%1").arg(uniqueID)).latin1())
00091 {
00092
00093 myID = uniqueID;
00094 uniqueID++;
00095
00096 m_modignore = false;
00097
00098 console = 0;
00099 greptool = 0;
00100
00101
00102 if (!initialGeometrySet())
00103 {
00104 int scnum = QApplication::desktop()->screenNumber(parentWidget());
00105 QRect desk = QApplication::desktop()->screenGeometry(scnum);
00106
00107 QSize size;
00108
00109
00110 if (sconfig)
00111 {
00112 sconfig->setGroup (sgroup);
00113 size.setWidth (sconfig->readNumEntry( QString::fromLatin1("Width %1").arg(desk.width()), 0 ));
00114 size.setHeight (sconfig->readNumEntry( QString::fromLatin1("Height %1").arg(desk.height()), 0 ));
00115 }
00116
00117
00118 if (size.isEmpty())
00119 {
00120
00121 if (KateApp::self()->mainWindows () > 0)
00122 {
00123 KateMainWindow *win = KateApp::self()->activeMainWindow ();
00124
00125 if (!win)
00126 win = KateApp::self()->mainWindow (KateApp::self()->mainWindows ()-1);
00127
00128 size = win->size();
00129 }
00130 else
00131 {
00132
00133 KateApp::self()->config()->setGroup ("MainWindow");
00134 size.setWidth (KateApp::self()->config()->readNumEntry( QString::fromLatin1("Width %1").arg(desk.width()), 0 ));
00135 size.setHeight (KateApp::self()->config()->readNumEntry( QString::fromLatin1("Height %1").arg(desk.height()), 0 ));
00136
00137 if (size.isEmpty())
00138 size = QSize (kMin (700, desk.width()), kMin(480, desk.height()));
00139 }
00140
00141 resize (size);
00142 }
00143 }
00144
00145
00146 startRestore (sconfig, sgroup);
00147
00148 m_mainWindow = new Kate::MainWindow (this);
00149 m_toolViewManager = new Kate::ToolViewManager (this);
00150
00151 m_dcop = new KateMainWindowDCOPIface (this);
00152
00153
00154 setupMainWindow();
00155
00156
00157 setupActions();
00158
00159 setStandardToolBarMenuEnabled( true );
00160 setXMLFile( "kateui.rc" );
00161 createShellGUI ( true );
00162
00163 KatePluginManager::self()->enableAllPluginsGUI (this);
00164
00165 if ( KateApp::self()->authorize("shell_access") )
00166 Kate::Document::registerCommand(KateExternalToolsCommand::self());
00167
00168
00169 documentMenu = (QPopupMenu*)factory()->container("documents", this);
00170 connect(documentMenu, SIGNAL(aboutToShow()), this, SLOT(documentMenuAboutToShow()));
00171
00172
00173 for (uint i = 0; i < KateDocManager::self()->documents(); i++)
00174 slotDocumentCreated (KateDocManager::self()->document(i));
00175
00176 connect(KateDocManager::self(),SIGNAL(documentCreated(Kate::Document *)),this,SLOT(slotDocumentCreated(Kate::Document *)));
00177
00178 readOptions();
00179
00180 if (sconfig)
00181 m_viewManager->restoreViewConfiguration (sconfig, sgroup);
00182
00183 finishRestore ();
00184
00185 setAcceptDrops(true);
00186 }
00187
00188 KateMainWindow::~KateMainWindow()
00189 {
00190
00191 KateApp::self()->config()->setGroup ("MainWindow");
00192 saveWindowSize (KateApp::self()->config());
00193
00194
00195 saveOptions();
00196
00197 KateApp::self()->removeMainWindow (this);
00198
00199 KatePluginManager::self()->disableAllPluginsGUI (this);
00200
00201 delete m_dcop;
00202 }
00203
00204 void KateMainWindow::setupMainWindow ()
00205 {
00206 setToolViewStyle( KMultiTabBar::KDEV3ICON );
00207
00208 m_tabWidget = new KateTabWidget (centralWidget());
00209
00210 m_viewManager = new KateViewManager (this);
00211
00212 KateMDI::ToolView *ft = createToolView("kate_filelist", KMultiTabBar::Left, SmallIcon("kmultiple"), i18n("Documents"));
00213 filelist = new KateFileList (this, m_viewManager, ft, "filelist");
00214 filelist->readConfig(KateApp::self()->config(), "Filelist");
00215
00216 KateMDI::ToolView *t = createToolView("kate_fileselector", KMultiTabBar::Left, SmallIcon("fileopen"), i18n("Filesystem Browser"));
00217 fileselector = new KateFileSelector( this, m_viewManager, t, "operator");
00218 connect(fileselector->dirOperator(),SIGNAL(fileSelected(const KFileItem*)),this,SLOT(fileSelected(const KFileItem*)));
00219
00220
00221 if (KateApp::self()->authorize("shell_access"))
00222 {
00223 t = createToolView("kate_greptool", KMultiTabBar::Bottom, SmallIcon("filefind"), i18n("Find in Files") );
00224 greptool = new GrepTool( t, "greptool" );
00225 connect(greptool, SIGNAL(itemSelected(const QString &,int)), this, SLOT(slotGrepToolItemSelected(const QString &,int)));
00226 connect(t,SIGNAL(visibleChanged(bool)),this, SLOT(updateGrepDir (bool)));
00227
00228 greptool->show();
00229
00230 t = createToolView("kate_console", KMultiTabBar::Bottom, SmallIcon("konsole"), i18n("Terminal"));
00231 console = new KateConsole (this, t);
00232 }
00233
00234
00235 showToolView (ft);
00236 }
00237
00238 void KateMainWindow::setupActions()
00239 {
00240 KAction *a;
00241
00242 KStdAction::openNew( m_viewManager, SLOT( slotDocumentNew() ), actionCollection(), "file_new" )->setWhatsThis(i18n("Create a new document"));
00243 KStdAction::open( m_viewManager, SLOT( slotDocumentOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Open an existing document for editing"));
00244
00245 fileOpenRecent = KStdAction::openRecent (m_viewManager, SLOT(openURL (const KURL&)), actionCollection());
00246 fileOpenRecent->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
00247
00248 a=new KAction( i18n("Save A&ll"),"save_all", CTRL+Key_L, KateDocManager::self(), SLOT( saveAll() ), actionCollection(), "file_save_all" );
00249 a->setWhatsThis(i18n("Save all open, modified documents to disk."));
00250
00251 KStdAction::close( m_viewManager, SLOT( slotDocumentClose() ), actionCollection(), "file_close" )->setWhatsThis(i18n("Close the current document."));
00252
00253 a=new KAction( i18n( "Clos&e All" ), 0, this, SLOT( slotDocumentCloseAll() ), actionCollection(), "file_close_all" );
00254 a->setWhatsThis(i18n("Close all open documents."));
00255
00256 KStdAction::mail( this, SLOT(slotMail()), actionCollection() )->setWhatsThis(i18n("Send one or more of the open documents as email attachments."));
00257
00258 KStdAction::quit( this, SLOT( slotFileQuit() ), actionCollection(), "file_quit" )->setWhatsThis(i18n("Close this window"));
00259
00260 a=new KAction(i18n("&New Window"), "window_new", 0, this, SLOT(newWindow()), actionCollection(), "view_new_view");
00261 a->setWhatsThis(i18n("Create a new Kate view (a new window with the same document list)."));
00262
00263 if ( KateApp::self()->authorize("shell_access") )
00264 {
00265 externalTools = new KateExternalToolsMenuAction( i18n("External Tools"), actionCollection(), "tools_external", this );
00266 externalTools->setWhatsThis( i18n("Launch external helper applications") );
00267 }
00268
00269 KToggleAction* showFullScreenAction = KStdAction::fullScreen( 0, 0, actionCollection(),this);
00270 connect( showFullScreenAction,SIGNAL(toggled(bool)), this,SLOT(slotFullScreen(bool)));
00271
00272 documentOpenWith = new KActionMenu(i18n("Open W&ith"), actionCollection(), "file_open_with");
00273 documentOpenWith->setWhatsThis(i18n("Open the current document using another application registered for its file type, or an application of your choice."));
00274 connect(documentOpenWith->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(mSlotFixOpenWithMenu()));
00275 connect(documentOpenWith->popupMenu(), SIGNAL(activated(int)), this, SLOT(slotOpenWithMenuAction(int)));
00276
00277 a=KStdAction::keyBindings(this, SLOT(editKeys()), actionCollection());
00278 a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
00279
00280 a=KStdAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection());
00281 a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
00282
00283 KAction* settingsConfigure = KStdAction::preferences(this, SLOT(slotConfigure()), actionCollection(), "settings_configure");
00284 settingsConfigure->setWhatsThis(i18n("Configure various aspects of this application and the editing component."));
00285
00286
00287 if (KateApp::self()->authorize("shell_access"))
00288 new KAction(i18n("&Pipe to Console"), "pipe", 0, console, SLOT(slotPipeToConsole()), actionCollection(), "tools_pipe_to_terminal");
00289
00290
00291 KStdAction::tipOfDay( this, SLOT( tipOfTheDay() ), actionCollection() )->setWhatsThis(i18n("This shows useful tips on the use of this application."));
00292
00293 if (KatePluginManager::self()->pluginList().count() > 0)
00294 {
00295 a=new KAction(i18n("&Plugins Handbook"), 0, this, SLOT(pluginHelp()), actionCollection(), "help_plugins_contents");
00296 a->setWhatsThis(i18n("This shows help files for various available plugins."));
00297 }
00298
00299 connect(m_viewManager,SIGNAL(viewChanged()),this,SLOT(slotWindowActivated()));
00300 connect(m_viewManager,SIGNAL(viewChanged()),this,SLOT(slotUpdateOpenWith()));
00301
00302 slotWindowActivated ();
00303
00304
00305 new KAction(i18n("Menu entry Session->New", "&New"), "filenew", 0, KateSessionManager::self(), SLOT(sessionNew()), actionCollection(), "sessions_new");
00306 new KAction(i18n("&Open..."), "fileopen", 0, KateSessionManager::self(), SLOT(sessionOpen()), actionCollection(), "sessions_open");
00307 new KAction(i18n("&Save"), "filesave", 0, KateSessionManager::self(), SLOT(sessionSave()), actionCollection(), "sessions_save");
00308 new KAction(i18n("Save &As..."), "filesaveas", 0, KateSessionManager::self(), SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as");
00309 new KAction(i18n("&Manage..."), "view_choose", 0, KateSessionManager::self(), SLOT(sessionManage()), actionCollection(), "sessions_manage");
00310
00311
00312 new KateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list");
00313 }
00314
00315 KateTabWidget *KateMainWindow::tabWidget ()
00316 {
00317 return m_tabWidget;
00318 }
00319
00320 void KateMainWindow::slotDocumentCloseAll() {
00321 if (queryClose_internal())
00322 KateDocManager::self()->closeAllDocuments(false);
00323 }
00324
00325 bool KateMainWindow::queryClose_internal() {
00326 uint documentCount=KateDocManager::self()->documents();
00327
00328 if ( ! showModOnDiskPrompt() )
00329 return false;
00330
00331 QPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList();
00332 bool shutdown=(modifiedDocuments.count()==0);
00333
00334 if (!shutdown) {
00335 shutdown=KateSaveModifiedDialog::queryClose(this,modifiedDocuments);
00336 }
00337
00338 if ( KateDocManager::self()->documents() > documentCount ) {
00339 KMessageBox::information (this,
00340 i18n ("New file opened while trying to close Kate, closing aborted."),
00341 i18n ("Closing Aborted"));
00342 shutdown=false;
00343 }
00344
00345 return shutdown;
00346 }
00347
00351 bool KateMainWindow::queryClose()
00352 {
00353
00354
00355 if (KateApp::self()->sessionSaving())
00356 {
00357 return queryClose_internal ();
00358 }
00359
00360
00361
00362 if ( KateApp::self()->mainWindows () > 1 )
00363 return true;
00364
00365
00366
00367 if ( queryClose_internal () )
00368 {
00369 KateApp::self()->sessionManager()->saveActiveSession(true, true);
00370
00371
00372 KateApp::self()->dcopClient()->detach();
00373
00374 return true;
00375 }
00376
00377 return false;
00378 }
00379
00380 void KateMainWindow::newWindow ()
00381 {
00382 KateApp::self()->newMainWindow ();
00383 }
00384
00385 void KateMainWindow::slotEditToolbars()
00386 {
00387 saveMainWindowSettings( KateApp::self()->config(), "MainWindow" );
00388 KEditToolbar dlg( factory() );
00389 connect( &dlg, SIGNAL(newToolbarConfig()), this, SLOT(slotNewToolbarConfig()) );
00390 dlg.exec();
00391 }
00392
00393 void KateMainWindow::slotNewToolbarConfig()
00394 {
00395 applyMainWindowSettings( KateApp::self()->config(), "MainWindow" );
00396 }
00397
00398 void KateMainWindow::slotFileQuit()
00399 {
00400 KateApp::self()->shutdownKate (this);
00401 }
00402
00403 void KateMainWindow::readOptions ()
00404 {
00405 KConfig *config = KateApp::self()->config ();
00406
00407 config->setGroup("General");
00408 syncKonsole = config->readBoolEntry("Sync Konsole", true);
00409 modNotification = config->readBoolEntry("Modified Notification", false);
00410 KateDocManager::self()->setSaveMetaInfos(config->readBoolEntry("Save Meta Infos", true));
00411 KateDocManager::self()->setDaysMetaInfos(config->readNumEntry("Days Meta Infos", 30));
00412
00413 m_viewManager->setShowFullPath(config->readBoolEntry("Show Full Path in Title", false));
00414
00415 fileOpenRecent->loadEntries(config, "Recent Files");
00416
00417 fileselector->readConfig(config, "fileselector");
00418 }
00419
00420 void KateMainWindow::saveOptions ()
00421 {
00422 KConfig *config = KateApp::self()->config ();
00423
00424 config->setGroup("General");
00425
00426 if (console)
00427 config->writeEntry("Show Console", console->isVisible());
00428 else
00429 config->writeEntry("Show Console", false);
00430
00431 config->writeEntry("Save Meta Infos", KateDocManager::self()->getSaveMetaInfos());
00432
00433 config->writeEntry("Days Meta Infos", KateDocManager::self()->getDaysMetaInfos());
00434
00435 config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath());
00436
00437 config->writeEntry("Sync Konsole", syncKonsole);
00438
00439 fileOpenRecent->saveEntries(config, "Recent Files");
00440
00441 fileselector->writeConfig(config, "fileselector");
00442
00443 filelist->writeConfig(config, "Filelist");
00444 }
00445
00446 void KateMainWindow::slotWindowActivated ()
00447 {
00448 if (m_viewManager->activeView())
00449 {
00450 if (console && syncKonsole)
00451 {
00452 static QString path;
00453 QString newPath = m_viewManager->activeView()->getDoc()->url().directory();
00454
00455 if ( newPath != path )
00456 {
00457 path = newPath;
00458 console->cd (KURL( path ));
00459 }
00460 }
00461
00462 updateCaption (m_viewManager->activeView()->getDoc());
00463 }
00464
00465
00466 centralWidget()->setFocusProxy (m_viewManager->activeView());
00467 }
00468
00469 void KateMainWindow::slotUpdateOpenWith()
00470 {
00471 if (m_viewManager->activeView())
00472 documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty());
00473 else
00474 documentOpenWith->setEnabled(false);
00475 }
00476
00477 void KateMainWindow::documentMenuAboutToShow()
00478 {
00479
00480 while (documentMenu->count() > 3)
00481 documentMenu->removeItemAt (3);
00482
00483 QListViewItem * item = filelist->firstChild();
00484 while( item ) {
00485
00486 QString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 );
00487 Kate::Document* doc = ((KateFileListItem *)item)->document();
00488 documentMenu->insertItem (
00489 doc->isModified() ? i18n("'document name [*]', [*] means modified", "%1 [*]").arg(name) : name,
00490 m_viewManager, SLOT (activateView (int)), 0,
00491 ((KateFileListItem *)item)->documentNumber () );
00492
00493 item = item->nextSibling();
00494 }
00495 if (m_viewManager->activeView())
00496 documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true);
00497 }
00498
00499 void KateMainWindow::slotGrepToolItemSelected(const QString &filename,int linenumber)
00500 {
00501 KURL fileURL;
00502 fileURL.setPath( filename );
00503 m_viewManager->openURL( fileURL );
00504 if ( m_viewManager->activeView() == 0 ) return;
00505 m_viewManager->activeView()->gotoLineNumber( linenumber );
00506 raise();
00507 setActiveWindow();
00508 }
00509
00510 void KateMainWindow::dragEnterEvent( QDragEnterEvent *event )
00511 {
00512 event->accept(KURLDrag::canDecode(event));
00513 }
00514
00515 void KateMainWindow::dropEvent( QDropEvent *event )
00516 {
00517 slotDropEvent(event);
00518 }
00519
00520 void KateMainWindow::slotDropEvent( QDropEvent * event )
00521 {
00522 KURL::List textlist;
00523 if (!KURLDrag::decode(event, textlist)) return;
00524
00525 for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
00526 {
00527 m_viewManager->openURL (*i);
00528 }
00529 }
00530
00531 void KateMainWindow::editKeys()
00532 {
00533 KKeyDialog dlg ( false, this );
00534
00535 QPtrList<KXMLGUIClient> clients = guiFactory()->clients();
00536
00537 for( QPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
00538 dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() );
00539
00540 dlg.insert( externalTools->actionCollection(), i18n("External Tools") );
00541
00542 dlg.configure();
00543
00544 QPtrList<Kate::Document> l=KateDocManager::self()->documentList();
00545 for (uint i=0;i<l.count();i++) {
00546
00547 l.at(i)->reloadXML();
00548 QPtrList<class KTextEditor::View> l1=l.at(i)->views ();
00549 for (uint i1=0;i1<l1.count();i1++) {
00550 l1.at(i1)->reloadXML();
00551
00552 }
00553 }
00554
00555 externalTools->actionCollection()->writeShortcutSettings( "Shortcuts", new KConfig("externaltools", false, false, "appdata") );
00556 }
00557
00558 void KateMainWindow::openURL (const QString &name)
00559 {
00560 m_viewManager->openURL (KURL(name));
00561 }
00562
00563 void KateMainWindow::slotConfigure()
00564 {
00565 if (!m_viewManager->activeView())
00566 return;
00567
00568 KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView());
00569 dlg->exec();
00570
00571 delete dlg;
00572 }
00573
00574 KURL KateMainWindow::activeDocumentUrl()
00575 {
00576
00577
00578 Kate::View *v = m_viewManager->activeView();
00579 if ( v )
00580 return v->getDoc()->url();
00581 return KURL();
00582 }
00583
00584 void KateMainWindow::fileSelected(const KFileItem * )
00585 {
00586 const KFileItemList *list=fileselector->dirOperator()->selectedItems();
00587 KFileItem *tmp;
00588 for (KFileItemListIterator it(*list); (tmp = it.current()); ++it)
00589 {
00590 m_viewManager->openURL(tmp->url());
00591 fileselector->dirOperator()->view()->setSelected(tmp,false);
00592 }
00593 }
00594
00595
00596 void KateMainWindow::mSlotFixOpenWithMenu()
00597 {
00598
00599 documentOpenWith->popupMenu()->clear();
00600
00601 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00602
00603
00604 KTrader::OfferList offers = KTrader::self()->query(mime->name(), "Type == 'Application'");
00605
00606 for(KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) {
00607 if ((*it)->name() == "Kate") continue;
00608 documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
00609 }
00610
00611 documentOpenWith->popupMenu()->insertItem(i18n("&Other..."));
00612 }
00613
00614 void KateMainWindow::slotOpenWithMenuAction(int idx)
00615 {
00616 KURL::List list;
00617 list.append( m_viewManager->activeView()->getDoc()->url() );
00618 QString appname = documentOpenWith->popupMenu()->text(idx);
00619
00620 appname = appname.remove('&');
00621 if ( appname.compare(i18n("Other...")) == 0 ) {
00622
00623 KOpenWithDlg dlg(list);
00624 if (dlg.exec())
00625 KRun::run(*dlg.service(), list);
00626 return;
00627 }
00628
00629 QString qry = QString("((Type == 'Application') and (Name == '%1'))").arg( appname.latin1() );
00630 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00631 KTrader::OfferList offers = KTrader::self()->query(mime->name(), qry);
00632
00633 if (!offers.isEmpty()) {
00634 KService::Ptr app = offers.first();
00635 KRun::run(*app, list);
00636 }
00637 else
00638 KMessageBox::error(this, i18n("Application '%1' not found!").arg(appname.latin1()), i18n("Application Not Found!"));
00639 }
00640
00641 void KateMainWindow::pluginHelp()
00642 {
00643 KateApp::self()->invokeHelp (QString::null, "kate-plugins");
00644 }
00645
00646 void KateMainWindow::slotMail()
00647 {
00648 KateMailDialog *d = new KateMailDialog(this, this);
00649 if ( ! d->exec() )
00650 {
00651 delete d;
00652 return;
00653 }
00654 QPtrList<Kate::Document> attDocs = d->selectedDocs();
00655 delete d;
00656
00657 QStringList urls;
00658 Kate::Document *doc;
00659 QPtrListIterator<Kate::Document> it(attDocs);
00660 for ( ; it.current(); ++it ) {
00661 doc = it.current();
00662 if (!doc) continue;
00663 if ( doc->url().isEmpty() ) {
00664
00665 int r = KMessageBox::questionYesNo( this,
00666 i18n("<p>The current document has not been saved, and "
00667 "cannot be attached to an email message."
00668 "<p>Do you want to save it and proceed?"),
00669 i18n("Cannot Send Unsaved File"),KStdGuiItem::saveAs(),KStdGuiItem::cancel() );
00670 if ( r == KMessageBox::Yes ) {
00671 Kate::View *v = (Kate::View*)doc->views().first();
00672 int sr = v->saveAs();
00673 if ( sr == Kate::View::SAVE_OK ) { ;
00674 }
00675 else {
00676 if ( sr != Kate::View::SAVE_CANCEL )
00677 KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
00678 "if you have write permission.") );
00679 continue;
00680 }
00681 }
00682 else
00683 continue;
00684 }
00685 if ( doc->isModified() ) {
00686
00687 int r = KMessageBox::warningYesNoCancel( this,
00688 i18n("<p>The current file:<br><strong>%1</strong><br>has been "
00689 "modified. Modifications will not be available in the attachment."
00690 "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()),
00691 i18n("Save Before Sending?"), KStdGuiItem::save(), i18n("Do Not Save") );
00692 switch ( r ) {
00693 case KMessageBox::Cancel:
00694 continue;
00695 case KMessageBox::Yes:
00696 doc->save();
00697 if ( doc->isModified() ) {
00698 KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
00699 "if you have write permission.") );
00700 continue;
00701 }
00702 break;
00703 default:
00704 break;
00705 }
00706 }
00707
00708 urls << doc->url().url();
00709 }
00710 if ( ! urls.count() )
00711 return;
00712 KateApp::self()->invokeMailer( QString::null,
00713 QString::null,
00714 QString::null,
00715 QString::null,
00716 QString::null,
00717 QString::null,
00718 urls
00719 );
00720 }
00721 void KateMainWindow::tipOfTheDay()
00722 {
00723 KTipDialog::showTip( this, QString::null, true );
00724 }
00725
00726 void KateMainWindow::slotFullScreen(bool t)
00727 {
00728 if (t)
00729 showFullScreen();
00730 else
00731 showNormal();
00732 }
00733
00734 void KateMainWindow::updateGrepDir (bool visible)
00735 {
00736
00737 if (!visible)
00738 return;
00739
00740 if ( m_viewManager->activeView() )
00741 {
00742 if ( m_viewManager->activeView()->getDoc()->url().isLocalFile() )
00743 {
00744 greptool->updateDirName( m_viewManager->activeView()->getDoc()->url().directory() );
00745 }
00746 }
00747 }
00748
00749 bool KateMainWindow::event( QEvent *e )
00750 {
00751 uint type = e->type();
00752 if ( type == QEvent::WindowActivate && modNotification )
00753 {
00754 showModOnDiskPrompt();
00755 }
00756 return KateMDI::MainWindow::event( e );
00757 }
00758
00759 bool KateMainWindow::showModOnDiskPrompt()
00760 {
00761 Kate::Document *doc;
00762
00763 DocVector list( KateDocManager::self()->documents() );
00764 uint cnt = 0;
00765 for( doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() )
00766 {
00767 if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDisc )
00768 {
00769 list.insert( cnt, doc );
00770 cnt++;
00771 }
00772 }
00773
00774 if ( cnt && !m_modignore )
00775 {
00776 list.resize( cnt );
00777 KateMwModOnHdDialog mhdlg( list, this );
00778 m_modignore = true;
00779 bool res = mhdlg.exec();
00780 m_modignore = false;
00781
00782 return res;
00783 }
00784 return true;
00785 }
00786
00787 void KateMainWindow::slotDocumentCreated (Kate::Document *doc)
00788 {
00789 connect(doc,SIGNAL(modStateChanged(Kate::Document *)),this,SLOT(updateCaption(Kate::Document *)));
00790 connect(doc,SIGNAL(nameChanged(Kate::Document *)),this,SLOT(updateCaption(Kate::Document *)));
00791 connect(doc,SIGNAL(nameChanged(Kate::Document *)),this,SLOT(slotUpdateOpenWith()));
00792
00793 updateCaption (doc);
00794 }
00795
00796 void KateMainWindow::updateCaption (Kate::Document *doc)
00797 {
00798 if (!m_viewManager->activeView())
00799 {
00800 setCaption ("", false);
00801 return;
00802 }
00803
00804 if (!(m_viewManager->activeView()->getDoc() == doc))
00805 return;
00806
00807 QString c;
00808 if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath()))
00809 {
00810 c = m_viewManager->activeView()->getDoc()->docName();
00811 }
00812 else
00813 {
00814 c = m_viewManager->activeView()->getDoc()->url().prettyURL();
00815 }
00816
00817 QString sessName = KateApp::self()->sessionManager()->activeSession()->sessionName();
00818 if ( !sessName.isEmpty() )
00819 sessName = QString("%1: ").arg( sessName );
00820
00821 setCaption( sessName + KStringHandler::lsqueeze(c,64),
00822 m_viewManager->activeView()->getDoc()->isModified());
00823 }
00824
00825 void KateMainWindow::saveProperties(KConfig *config)
00826 {
00827 QString grp=config->group();
00828
00829 saveSession(config, grp);
00830 m_viewManager->saveViewConfiguration (config, grp);
00831
00832 config->setGroup(grp);
00833 }
00834
00835 void KateMainWindow::readProperties(KConfig *config)
00836 {
00837 QString grp=config->group();
00838
00839 startRestore(config, grp);
00840 finishRestore ();
00841 m_viewManager->restoreViewConfiguration (config, grp);
00842
00843 config->setGroup(grp);
00844 }
00845
00846 void KateMainWindow::saveGlobalProperties( KConfig* sessionConfig )
00847 {
00848 KateDocManager::self()->saveDocumentList (sessionConfig);
00849
00850 sessionConfig->setGroup("General");
00851 sessionConfig->writeEntry ("Last Session", KateApp::self()->sessionManager()->activeSession()->sessionFileRelative());
00852 }
00853
00854