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 documentMenu->insertItem (
00486 KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 ),
00487 m_viewManager, SLOT (activateView (int)), 0,
00488 ((KateFileListItem *)item)->documentNumber () );
00489
00490 item = item->nextSibling();
00491 }
00492 if (m_viewManager->activeView())
00493 documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true);
00494 }
00495
00496 void KateMainWindow::slotGrepToolItemSelected(const QString &filename,int linenumber)
00497 {
00498 KURL fileURL;
00499 fileURL.setPath( filename );
00500 m_viewManager->openURL( fileURL );
00501 if ( m_viewManager->activeView() == 0 ) return;
00502 m_viewManager->activeView()->gotoLineNumber( linenumber );
00503 raise();
00504 setActiveWindow();
00505 }
00506
00507 void KateMainWindow::dragEnterEvent( QDragEnterEvent *event )
00508 {
00509 event->accept(KURLDrag::canDecode(event));
00510 }
00511
00512 void KateMainWindow::dropEvent( QDropEvent *event )
00513 {
00514 slotDropEvent(event);
00515 }
00516
00517 void KateMainWindow::slotDropEvent( QDropEvent * event )
00518 {
00519 KURL::List textlist;
00520 if (!KURLDrag::decode(event, textlist)) return;
00521
00522 for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
00523 {
00524 m_viewManager->openURL (*i);
00525 }
00526 }
00527
00528 void KateMainWindow::editKeys()
00529 {
00530 KKeyDialog dlg ( false, this );
00531
00532 QPtrList<KXMLGUIClient> clients = guiFactory()->clients();
00533
00534 for( QPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
00535 dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() );
00536
00537 dlg.insert( externalTools->actionCollection(), i18n("External Tools") );
00538
00539 dlg.configure();
00540
00541 QPtrList<Kate::Document> l=KateDocManager::self()->documentList();
00542 for (uint i=0;i<l.count();i++) {
00543
00544 l.at(i)->reloadXML();
00545 QPtrList<class KTextEditor::View> l1=l.at(i)->views ();
00546 for (uint i1=0;i1<l1.count();i1++) {
00547 l1.at(i1)->reloadXML();
00548
00549 }
00550 }
00551
00552 externalTools->actionCollection()->writeShortcutSettings( "Shortcuts", new KConfig("externaltools", false, false, "appdata") );
00553 }
00554
00555 void KateMainWindow::openURL (const QString &name)
00556 {
00557 m_viewManager->openURL (KURL(name));
00558 }
00559
00560 void KateMainWindow::slotConfigure()
00561 {
00562 if (!m_viewManager->activeView())
00563 return;
00564
00565 KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView());
00566 dlg->exec();
00567
00568 delete dlg;
00569 }
00570
00571 KURL KateMainWindow::activeDocumentUrl()
00572 {
00573
00574
00575 Kate::View *v = m_viewManager->activeView();
00576 if ( v )
00577 return v->getDoc()->url();
00578 return KURL();
00579 }
00580
00581 void KateMainWindow::fileSelected(const KFileItem * )
00582 {
00583 const KFileItemList *list=fileselector->dirOperator()->selectedItems();
00584 KFileItem *tmp;
00585 for (KFileItemListIterator it(*list); (tmp = it.current()); ++it)
00586 {
00587 m_viewManager->openURL(tmp->url());
00588 fileselector->dirOperator()->view()->setSelected(tmp,false);
00589 }
00590 }
00591
00592
00593 void KateMainWindow::mSlotFixOpenWithMenu()
00594 {
00595
00596 documentOpenWith->popupMenu()->clear();
00597
00598 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00599
00600
00601 KTrader::OfferList offers = KTrader::self()->query(mime->name(), "Type == 'Application'");
00602
00603 for(KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) {
00604 if ((*it)->name() == "Kate") continue;
00605 documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
00606 }
00607
00608 documentOpenWith->popupMenu()->insertItem(i18n("&Other..."));
00609 }
00610
00611 void KateMainWindow::slotOpenWithMenuAction(int idx)
00612 {
00613 KURL::List list;
00614 list.append( m_viewManager->activeView()->getDoc()->url() );
00615 QString* appname = new QString( documentOpenWith->popupMenu()->text(idx) );
00616
00617 *appname = appname->remove('&');
00618 if ( appname->compare(i18n("Other...")) == 0 ) {
00619
00620 KOpenWithDlg* dlg = new KOpenWithDlg(list);
00621 if (dlg->exec())
00622 KRun::run(*dlg->service(), list);
00623 return;
00624 }
00625
00626 QString qry = QString("((Type == 'Application') and (Name == '%1'))").arg( appname->latin1() );
00627 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00628 KTrader::OfferList offers = KTrader::self()->query(mime->name(), qry);
00629
00630 if (!offers.isEmpty()) {
00631 KService::Ptr app = offers.first();
00632 KRun::run(*app, list);
00633 }
00634 else
00635 KMessageBox::error(this, i18n("Application '%1' not found!").arg(appname->latin1()), i18n("Application Not Found!"));
00636
00637
00638 }
00639
00640 void KateMainWindow::pluginHelp()
00641 {
00642 KateApp::self()->invokeHelp (QString::null, "kate-plugins");
00643 }
00644
00645 void KateMainWindow::slotMail()
00646 {
00647 KateMailDialog *d = new KateMailDialog(this, this);
00648 if ( ! d->exec() )
00649 return;
00650 QPtrList<Kate::Document> attDocs = d->selectedDocs();
00651 delete d;
00652
00653 QStringList urls;
00654 Kate::Document *doc;
00655 QPtrListIterator<Kate::Document> it(attDocs);
00656 for ( ; it.current(); ++it ) {
00657 doc = it.current();
00658 if (!doc) continue;
00659 if ( doc->url().isEmpty() ) {
00660
00661 int r = KMessageBox::questionYesNo( this,
00662 i18n("<p>The current document has not been saved, and "
00663 "cannot be attached to an email message."
00664 "<p>Do you want to save it and proceed?"),
00665 i18n("Cannot Send Unsaved File"),KStdGuiItem::saveAs(),KStdGuiItem::cancel() );
00666 if ( r == KMessageBox::Yes ) {
00667 Kate::View *v = (Kate::View*)doc->views().first();
00668 int sr = v->saveAs();
00669 if ( sr == Kate::View::SAVE_OK ) { ;
00670 }
00671 else {
00672 if ( sr != Kate::View::SAVE_CANCEL )
00673 KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
00674 "if you have write permission.") );
00675 continue;
00676 }
00677 }
00678 else
00679 continue;
00680 }
00681 if ( doc->isModified() ) {
00682
00683 int r = KMessageBox::warningYesNoCancel( this,
00684 i18n("<p>The current file:<br><strong>%1</strong><br>has been "
00685 "modified. Modifications will not be available in the attachment."
00686 "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()),
00687 i18n("Save Before Sending?"), KStdGuiItem::save(), i18n("Do Not Save") );
00688 switch ( r ) {
00689 case KMessageBox::Cancel:
00690 continue;
00691 case KMessageBox::Yes:
00692 doc->save();
00693 if ( doc->isModified() ) {
00694 KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
00695 "if you have write permission.") );
00696 continue;
00697 }
00698 break;
00699 default:
00700 break;
00701 }
00702 }
00703
00704 urls << doc->url().url();
00705 }
00706 if ( ! urls.count() )
00707 return;
00708 KateApp::self()->invokeMailer( QString::null,
00709 QString::null,
00710 QString::null,
00711 QString::null,
00712 QString::null,
00713 QString::null,
00714 urls
00715 );
00716 }
00717 void KateMainWindow::tipOfTheDay()
00718 {
00719 KTipDialog::showTip( this, QString::null, true );
00720 }
00721
00722 void KateMainWindow::slotFullScreen(bool t)
00723 {
00724 if (t)
00725 showFullScreen();
00726 else
00727 showNormal();
00728 }
00729
00730 void KateMainWindow::updateGrepDir (bool visible)
00731 {
00732
00733 if (!visible)
00734 return;
00735
00736 if ( m_viewManager->activeView() )
00737 {
00738 if ( m_viewManager->activeView()->getDoc()->url().isLocalFile() )
00739 {
00740 greptool->updateDirName( m_viewManager->activeView()->getDoc()->url().directory() );
00741 }
00742 }
00743 }
00744
00745 bool KateMainWindow::event( QEvent *e )
00746 {
00747 uint type = e->type();
00748 if ( type == QEvent::WindowActivate && modNotification )
00749 {
00750 if ( m_modignore )
00751 {
00752 m_modignore = false;
00753 return KateMDI::MainWindow::event( e );
00754 }
00755 showModOnDiskPrompt();
00756 }
00757
00758
00759 else if ( (type == QEvent::WindowUnblocked || type == QEvent::WindowBlocked) && modNotification)
00760 m_modignore = true;
00761
00762 return KateMDI::MainWindow::event( e );
00763 }
00764
00765 bool KateMainWindow::showModOnDiskPrompt()
00766 {
00767 Kate::Document *doc;
00768
00769 DocVector list( KateDocManager::self()->documents() );
00770 uint cnt = 0;
00771 for( doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() )
00772 {
00773 if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDisc )
00774 {
00775 list.insert( cnt, doc );
00776 cnt++;
00777 }
00778 }
00779
00780 if ( cnt )
00781 {
00782 list.resize( cnt );
00783 KateMwModOnHdDialog mhdlg( list, this );
00784 bool res = mhdlg.exec();
00785
00786 return res;
00787 }
00788 return true;
00789 }
00790
00791 void KateMainWindow::slotDocumentCreated (Kate::Document *doc)
00792 {
00793 connect(doc,SIGNAL(modStateChanged(Kate::Document *)),this,SLOT(updateCaption(Kate::Document *)));
00794 connect(doc,SIGNAL(nameChanged(Kate::Document *)),this,SLOT(updateCaption(Kate::Document *)));
00795 connect(doc,SIGNAL(nameChanged(Kate::Document *)),this,SLOT(slotUpdateOpenWith()));
00796
00797 updateCaption (doc);
00798 }
00799
00800 void KateMainWindow::updateCaption (Kate::Document *doc)
00801 {
00802 if (!m_viewManager->activeView())
00803 {
00804 setCaption ("", false);
00805 return;
00806 }
00807
00808 if (!(m_viewManager->activeView()->getDoc() == doc))
00809 return;
00810
00811 QString c;
00812 if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath()))
00813 {
00814 c = m_viewManager->activeView()->getDoc()->docName();
00815 }
00816 else
00817 {
00818 c = m_viewManager->activeView()->getDoc()->url().prettyURL();
00819 }
00820
00821 QString sessName = KateApp::self()->sessionManager()->activeSession()->sessionName();
00822 if ( !sessName.isEmpty() )
00823 sessName = QString("%1: ").arg( sessName );
00824
00825 setCaption( sessName + KStringHandler::lsqueeze(c,64),
00826 m_viewManager->activeView()->getDoc()->isModified());
00827 }
00828
00829 void KateMainWindow::saveProperties(KConfig *config)
00830 {
00831 QString grp=config->group();
00832
00833 saveSession(config, grp);
00834 m_viewManager->saveViewConfiguration (config, grp);
00835
00836 config->setGroup(grp);
00837 }
00838
00839 void KateMainWindow::readProperties(KConfig *config)
00840 {
00841 QString grp=config->group();
00842
00843 startRestore(config, grp);
00844 finishRestore ();
00845 m_viewManager->restoreViewConfiguration (config, grp);
00846
00847 config->setGroup(grp);
00848 }
00849
00850 void KateMainWindow::saveGlobalProperties( KConfig* sessionConfig )
00851 {
00852 KateDocManager::self()->saveDocumentList (sessionConfig);
00853
00854 sessionConfig->setGroup("General");
00855 sessionConfig->writeEntry ("Last Session", KateApp::self()->sessionManager()->activeSession()->sessionFileRelative());
00856 }
00857
00858