kate Library API Documentation

katemainwindow.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
00004    Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 //BEGIN Includes
00022 #include "katemainwindow.h"
00023 #include "katemainwindow.moc"
00024 
00025 #include "kateconfigdialog.h"
00026 
00027 #include "kateconsole.h"
00028 #include "katedocmanager.h"
00029 #include "katepluginmanager.h"
00030 #include "kateconfigplugindialogpage.h"
00031 #include "kateviewmanager.h"
00032 #include "kateapp.h"
00033 #include "kateprojectlist.h"
00034 #include "kateprojectviews.h"
00035 #include "katefileselector.h"
00036 #include "katefilelist.h"
00037 #include "katemailfilesdialog.h"
00038 #include "katemainwindowiface.h"
00039 
00040 #include <kmdichildview.h>
00041 #include <dcopclient.h>
00042 #include <kinstance.h>
00043 #include <kaboutdata.h>
00044 #include <kaction.h>
00045 #include <kapplication.h>
00046 #include <kcmdlineargs.h>
00047 #include <kdebug.h>
00048 #include <kdialogbase.h>
00049 #include <kdiroperator.h>
00050 #include <kdockwidget.h>
00051 #include <kedittoolbar.h>
00052 #include <kfiledialog.h>
00053 #include <kglobalaccel.h>
00054 #include <kglobal.h>
00055 #include <kglobalsettings.h>
00056 #include <kiconloader.h>
00057 #include <kkeydialog.h>
00058 #include <klocale.h>
00059 #include <kmessagebox.h>
00060 #include <kmimetype.h>
00061 #include <kopenwith.h>
00062 #include <kpopupmenu.h>
00063 #include <ksimpleconfig.h>
00064 #include <kstatusbar.h>
00065 #include <kstdaction.h>
00066 #include <kstandarddirs.h>
00067 #include <ktrader.h>
00068 #include <kuniqueapplication.h>
00069 #include <kurldrag.h>
00070 #include <kdesktopfile.h>
00071 #include <khelpmenu.h>
00072 
00073 #include <qlayout.h>
00074 
00075 #include <ktip.h>
00076 
00077 #include <kmenubar.h>
00078 
00079 #include "kategrepdialog.h"
00080 
00081 #include <assert.h>
00082 #include <unistd.h>
00083 //END
00084 
00085 uint KateMainWindow::uniqueID = 1;
00086 KMdi::MdiMode KateMainWindow::defaultMode=KMdi::UndefinedMode;
00087 
00088 KateMainWindow::KateMainWindow(KateDocManager *_m_docManager, KatePluginManager *_m_pluginManager,
00089     KateProjectManager *projectMan, KMdi::MdiMode guiMode) :
00090     KMdiMainFrm (0,(QString("__KateMainWindow#%1").arg(uniqueID)).latin1(),guiMode)
00091 {
00092   // first the very important id
00093   myID = uniqueID;
00094   uniqueID++;
00095 
00096   // init some vars
00097   m_docManager =  _m_docManager;
00098   m_pluginManager =_m_pluginManager;
00099   m_projectManager = projectMan;
00100 
00101   m_project = 0;
00102   m_projectNumber = 0;
00103 
00104   activeView = 0;
00105 
00106   console = 0;
00107   greptool = 0;
00108 
00109   // now the config
00110   KConfig *config = kapp->config();
00111 
00112   // first init size while we are still invisible, avoid flicker
00113   if (!initialGeometrySet())
00114   {
00115     config->setGroup ("Kate Main Window");
00116     int scnum = QApplication::desktop()->screenNumber(parentWidget());
00117     QRect desk = QApplication::desktop()->screenGeometry(scnum);
00118     QSize s ( config->readNumEntry( QString::fromLatin1("Width %1").arg(desk.width()), 700 ),
00119               config->readNumEntry( QString::fromLatin1("Height %1").arg(desk.height()), 480 ) );
00120 
00121     resize (kMin (s.width(), desk.width()), kMin(s.height(), desk.height()));
00122   }
00123 
00124   m_mainWindow = new Kate::MainWindow (this);
00125   m_toolViewManager = new Kate::ToolViewManager (this);
00126   setStandardMDIMenuEnabled(false);
00127   setManagedDockPositionModeEnabled(true);
00128 
00129   m_dcop = new KateMainWindowDCOPIface (this);
00130 
00131   // setup the most important widgets
00132   setupMainWindow();
00133   
00134   // setup the actions
00135   setupActions();
00136   projectlist->setupActions();
00137 
00138   setStandardToolBarMenuEnabled( true );
00139   setXMLFile( "kateui.rc" );
00140   createShellGUI ( true );
00141 
00142   m_pluginManager->enableAllPluginsGUI (this);
00143 
00144   // connect settings menu aboutToshow
00145   documentMenu = (QPopupMenu*)factory()->container("documents", this);
00146   connect(documentMenu, SIGNAL(aboutToShow()), this, SLOT(documentMenuAboutToShow()));
00147 
00148   connect(m_projectManager->projectManager(),SIGNAL(projectDeleted(uint)),this,SLOT(projectDeleted(uint)));
00149 
00150   // caption update
00151   for (uint i = 0; i < m_docManager->documents(); i++)
00152     slotDocumentCreated (m_docManager->document(i));
00153 
00154   connect(m_docManager,SIGNAL(documentCreated(Kate::Document *)),this,SLOT(slotDocumentCreated(Kate::Document *)));
00155 
00156   readOptions(config);
00157 
00158   if (console)
00159     console->loadConsoleIfNeeded();
00160 
00161   setAcceptDrops(true);
00162 }
00163 
00164 KateMainWindow::~KateMainWindow()
00165 {
00166   saveOptions(kapp->config());
00167 
00168   ((KateApp *)kapp)->removeMainWindow (this);
00169 
00170   m_pluginManager->disableAllPluginsGUI (this);
00171 
00172   delete m_dcop;
00173   delete kscript;
00174 }
00175 
00176 void KateMainWindow::setupMainWindow ()
00177 {
00178   greptool = new GrepTool( this, "greptool" );
00179   greptool->installEventFilter( this );
00180   connect(greptool, SIGNAL(itemSelected(const QString &,int)), this, SLOT(slotGrepToolItemSelected(const QString &,int)));
00181   // WARNING HACK - anders: showing the greptool seems to make the menu accels work
00182   greptool->show();
00183   greptool->hide();
00184 
00185   KMdiChildView* pMDICover = new KMdiChildView("MainDock");
00186   pMDICover->setName("MainDock");
00187 
00188   //mainDock->setGeometry(100, 100, 100, 100);
00189   QBoxLayout *ml=new QHBoxLayout(pMDICover);
00190   ml->setAutoAdd(true);
00191   m_viewManager = new KateViewManager (pMDICover, m_docManager,this);
00192   addWindow(pMDICover);
00193   m_viewManager->show();
00194   pMDICover->show();
00195 
00196   filelist = new KateFileList (m_docManager, m_viewManager, this/*filelistDock*/, "filelist");
00197   addToolView(KDockWidget::DockLeft,filelist,SmallIcon("kmultiple"), i18n("Files"));
00198 
00199   QVBox *prBox = new QVBox (this,"projects");
00200   addToolView(KDockWidget::DockLeft,prBox,SmallIcon("view_tree"), i18n("Projects"));
00201   projectlist = new KateProjectList (m_projectManager, this, prBox/*filelistDock*/, "projectlist");
00202   projectviews = new KateProjectViews (m_projectManager, this, prBox/*filelistDock*/, "projectviews");
00203   prBox->setStretchFactor(projectviews, 2);
00204   prBox->show ();
00205   projectlist->show ();
00206   projectviews->show ();
00207 
00208   fileselector = new KateFileSelector( this, m_viewManager, /*fileselectorDock*/ this, "operator");
00209   addToolView(KDockWidget::DockLeft,fileselector, SmallIcon("fileopen"), i18n("Selector"));
00210 
00211   // TEST
00212   addToolView( KDockWidget::DockBottom, greptool, SmallIcon("filefind"), i18n("Find in Files") );
00213   if (kapp->authorize("shell_access"))
00214   {
00215      console = new KateConsole (this, "console",viewManager());
00216      console->installEventFilter( this );
00217      addToolView(KDockWidget::DockBottom,console, SmallIcon("konsole"), i18n("Terminal"));
00218   }
00219 
00220   connect(fileselector->dirOperator(),SIGNAL(fileSelected(const KFileItem*)),this,SLOT(fileSelected(const KFileItem*)));
00221 }
00222 
00223 void KateMainWindow::setupActions()
00224 {
00225   KAction *a;
00226 
00227   kscript = new KScriptManager(this, "scriptmanager");
00228   scriptMenu = new KActionMenu( i18n("KDE Scri&pts"), actionCollection(), "scripts");
00229   scriptMenu->setWhatsThis(i18n("This shows all available scripts and allows them to be executed."));
00230   setupScripts();
00231   connect( scriptMenu->popupMenu(), SIGNAL(activated( int)), this, SLOT(runScript( int )) );
00232 
00233   KStdAction::openNew( m_viewManager, SLOT( slotDocumentNew() ), actionCollection(), "file_new" )->setWhatsThis(i18n("Create a new document"));
00234   KStdAction::open( m_viewManager, SLOT( slotDocumentOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Open an existing document for editing"));
00235 
00236   fileOpenRecent = KStdAction::openRecent (m_viewManager, SLOT(openURL (const KURL&)), actionCollection());
00237   fileOpenRecent->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
00238 
00239   a=new KAction( i18n("Save A&ll"),"save_all", CTRL+Key_L, m_viewManager, SLOT( slotDocumentSaveAll() ), actionCollection(), "file_save_all" );
00240   a->setWhatsThis(i18n("Save all open, modified documents to disc."));
00241 
00242   KStdAction::close( m_viewManager, SLOT( slotDocumentClose() ), actionCollection(), "file_close" )->setWhatsThis(i18n("Close the current document."));
00243 
00244   a=new KAction( i18n( "Clos&e All" ), 0, m_viewManager, SLOT( slotDocumentCloseAll() ), actionCollection(), "file_close_all" );
00245   a->setWhatsThis(i18n("Close all open documents."));
00246 
00247   KStdAction::mail( this, SLOT(slotMail()), actionCollection() )->setWhatsThis(i18n("Send one or more of the open documents as email attachments."));
00248 
00249   KStdAction::quit( this, SLOT( slotFileQuit() ), actionCollection(), "file_quit" )->setWhatsThis(i18n("Close this window"));
00250 
00251   a=new KAction(i18n("&New Window"), "window_new", 0, this, SLOT(newWindow()), actionCollection(), "view_new_view");
00252   a->setWhatsThis(i18n("Create a new Kate view (a new window with the same document list)."));
00253 
00254   a=new KAction( i18n("Split &Vertical"), "view_left_right", CTRL+SHIFT+Key_L, m_viewManager, SLOT( slotSplitViewSpaceVert() ), actionCollection(), "view_split_vert");
00255   a->setWhatsThis(i18n("Split the currently active view vertically into two views."));
00256 
00257   a=new KAction( i18n("Split &Horizontal"), "view_top_bottom", CTRL+SHIFT+Key_T, m_viewManager, SLOT( slotSplitViewSpaceHoriz() ), actionCollection(), "view_split_horiz");
00258   a->setWhatsThis(i18n("Split the currently active view horizontally into two views."));
00259 
00260   a=closeCurrentViewSpace = new KAction( i18n("Close &Current View"), "view_remove", CTRL+SHIFT+Key_R, m_viewManager, SLOT( slotCloseCurrentViewSpace() ), actionCollection(), "view_close_current_space");
00261   a->setWhatsThis(i18n("Close the currently active splitted view"));
00262 
00263   showFullScreenAction = KStdAction::fullScreen( 0, 0, actionCollection(),this);
00264   connect( showFullScreenAction,SIGNAL(toggled(bool)), this,SLOT(slotFullScreen(bool)));
00265 
00266   goNext=new KAction(i18n("Next View"),Key_F8,m_viewManager, SLOT(activateNextView()),actionCollection(),"go_next");
00267   goNext->setWhatsThis(i18n("Make the next split view the active one."));
00268 
00269   goPrev=new KAction(i18n("Previous View"),SHIFT+Key_F8,m_viewManager, SLOT(activatePrevView()),actionCollection(),"go_prev");
00270   goPrev->setWhatsThis(i18n("Make the previous split view the active one."));
00271 
00272   windowNext = KStdAction::back(filelist, SLOT(slotPrevDocument()), actionCollection());
00273   windowPrev = KStdAction::forward(filelist, SLOT(slotNextDocument()), actionCollection());
00274 
00275   documentOpenWith = new KActionMenu(i18n("Open W&ith"), actionCollection(), "file_open_with");
00276   documentOpenWith->setWhatsThis(i18n("Open the current document using another application registered for its file type, or an application of your choice."));
00277   connect(documentOpenWith->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(mSlotFixOpenWithMenu()));
00278   connect(documentOpenWith->popupMenu(), SIGNAL(activated(int)), this, SLOT(slotOpenWithMenuAction(int)));
00279 
00280   a=KStdAction::keyBindings(this, SLOT(editKeys()), actionCollection());
00281   a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
00282 
00283   a=KStdAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection(), "set_configure_toolbars");
00284   a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
00285 
00286 
00287   // project menu
00288   a = new KAction(i18n("&New Project..."), "filenew", 0, this, SLOT(slotProjectNew()), actionCollection(), "project_new");
00289   a = new KAction(i18n("&Open Project..."), "fileopen", 0, this, SLOT(slotProjectOpen()), actionCollection(), "project_open");
00290   saveProject = new KAction(i18n("&Save Project"), "filesave", 0, this, SLOT(slotProjectSave()), actionCollection(), "project_save");
00291   closeProject = new KAction(i18n("&Close Project"), "fileclose", 0, this, SLOT(slotProjectClose()), actionCollection(), "project_close");
00292 
00293   recentProjects = new KRecentFilesAction (i18n("Open &Recent"), KShortcut(), this, SLOT(openConstURLProject (const KURL&)),actionCollection(), "project_open_recent");
00294 
00295   settingsConfigure = KStdAction::preferences(this, SLOT(slotConfigure()), actionCollection(), "settings_configure");
00296   settingsConfigure->setWhatsThis(i18n("Configure various aspects of this application and the editing component."));
00297 
00298   // tip of the day :-)
00299   KStdAction::tipOfDay( this, SLOT( tipOfTheDay() ), actionCollection() )->setWhatsThis(i18n("This shows useful tips on the use of this application."));
00300 
00301   if (m_pluginManager->pluginList().count() > 0)
00302   {
00303     a=new KAction(i18n("Contents &Plugins"), 0, this, SLOT(pluginHelp()), actionCollection(), "help_plugins_contents");
00304     a->setWhatsThis(i18n("This shows help files for various available plugins."));
00305   }
00306 
00307   connect(m_viewManager,SIGNAL(viewChanged()),this,SLOT(slotWindowActivated()));
00308   connect(m_docManager,SIGNAL(documentChanged()),this,SLOT(slotDocumentChanged()));
00309 
00310   slotWindowActivated ();
00311   slotDocumentChanged();
00312 }
00313 
00317 bool KateMainWindow::queryClose()
00318 {
00319   kdDebug(13000)<<"QUERY CLOSE ********************"<<endl;
00320   
00321   // session saving, can we close all projects & views ?
00322   // just test, not close them actually
00323   if (kapp->sessionSaving())
00324   {    
00325     return ( m_projectManager->queryCloseAll () &&
00326              m_docManager->queryCloseDocuments (this) );
00327   }
00328   
00329   // normal closing of window
00330   // allow to close all windows until the last without restrictions
00331   if ( ((KateApp *)kapp)->mainWindows () > 1 )
00332     return true;
00333     
00334   // last one: check if we can close all projects/document, try run
00335   // and save projects/docs if we really close down !
00336   if ( m_projectManager->queryCloseAll () &&
00337        m_docManager->queryCloseDocuments (this) )
00338   {
00339     KSimpleConfig scfg ("katesessionrc", false);
00340     
00341     KConfig *config = kapp->config();
00342     config->setGroup("General");
00343   
00344     if (config->readBoolEntry("Restore Projects", false))
00345       m_projectManager->saveProjectList (&scfg);
00346   
00347     if (config->readBoolEntry("Restore Documents", false))
00348       m_docManager->saveDocumentList (&scfg);
00349     
00350     if (config->readBoolEntry("Restore Window Configuration", false))
00351       saveProperties (&scfg);
00352   
00353     return true;
00354   }
00355 
00356   return false;
00357 }
00358 
00359 void KateMainWindow::newWindow ()
00360 {
00361   ((KateApp *)kapp)->newMainWindow ();
00362 }
00363 
00364 void KateMainWindow::slotEditToolbars()
00365 {
00366   KEditToolbar dlg( factory() );
00367 
00368   dlg.exec();
00369 }
00370 
00371 void KateMainWindow::slotFileQuit()
00372 {
00373   close ();
00374 }
00375 
00376 void KateMainWindow::readOptions(KConfig *config)
00377 {
00378   applyMainWindowSettings(config, "Kate Main Window");
00379 
00380   config->setGroup("General");
00381   syncKonsole =  config->readBoolEntry("Sync Konsole", true);
00382   modNotification = config->readBoolEntry("Modified Notification", false);
00383 
00384   m_viewManager->setShowFullPath(config->readBoolEntry("Show Full Path in Title", false));
00385 
00386   fileOpenRecent->setMaxItems( config->readNumEntry("Number of recent files", fileOpenRecent->maxItems() ) );
00387   fileOpenRecent->loadEntries(config, "Recent Files");
00388 
00389   fileselector->readConfig(config, "fileselector");
00390 
00391   filelist->setSortType(config->readNumEntry("Sort Type of File List", KateFileList::sortByID));
00392 
00393   recentProjects->loadEntries (config, "Recent Projects");
00394 }
00395 
00396 void KateMainWindow::saveOptions(KConfig *config)
00397 {
00398   saveMainWindowSettings(config, "Kate Main Window");
00399 
00400   config->setGroup("General");
00401 
00402   if (console)
00403     config->writeEntry("Show Console", console->isVisible());
00404   else
00405     config->writeEntry("Show Console", false);
00406 
00407   config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath());
00408 
00409   config->writeEntry("Sync Konsole", syncKonsole);
00410 
00411   fileOpenRecent->saveEntries(config, "Recent Files");
00412 
00413   fileselector->writeConfig(config, "fileselector");
00414 
00415   config->writeEntry("Sort Type of File List", filelist->sortType());
00416 
00417   recentProjects->saveEntries (config, "Recent Projects");
00418 }
00419 
00420 void KateMainWindow::slotDocumentChanged()
00421 {
00422   if (m_docManager->documents()  > 1)
00423   {
00424     windowNext->setEnabled(true);
00425     windowPrev->setEnabled(true);
00426   }
00427   else
00428   {
00429     windowNext->setEnabled(false);
00430     windowPrev->setEnabled(false);
00431   }
00432 }
00433 
00434 void KateMainWindow::slotWindowActivated ()
00435 {
00436   static QString path;
00437 
00438   if (m_viewManager->activeView())
00439   {
00440     documentOpenWith->setEnabled (!m_viewManager->activeView()->document()->url().isEmpty());
00441 
00442     if (console && syncKonsole)
00443     {
00444       QString newPath = m_viewManager->activeView()->getDoc()->url().directory();
00445 
00446       if ( newPath != path )
00447       {
00448         path = newPath;
00449         console->cd (path);
00450       }
00451     }
00452 
00453     updateCaption (m_viewManager->activeView()->getDoc());
00454   }
00455   else
00456   {
00457     documentOpenWith->setEnabled (false);
00458   }
00459 
00460   if (m_viewManager->viewSpaceCount() == 1)
00461     closeCurrentViewSpace->setEnabled(false);
00462   else
00463     closeCurrentViewSpace->setEnabled(true);
00464 }
00465 
00466 void KateMainWindow::documentMenuAboutToShow()
00467 {
00468   documentMenu->clear ();
00469   windowNext->plug (documentMenu);
00470   windowPrev->plug (documentMenu);
00471   documentMenu->insertSeparator ();
00472 
00473   for (uint z=0; z < filelist->count(); z++)
00474   {
00475     documentMenu->insertItem (filelist->item(z)->text(),
00476                               m_viewManager, SLOT (activateView (int)), 0,
00477                               ((KateFileListItem *)filelist->item (z))->documentNumber ());
00478 
00479     if (m_viewManager->activeView())
00480       documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true);
00481   }
00482 }
00483 
00484 void KateMainWindow::slotGrepToolItemSelected(const QString &filename,int linenumber)
00485 {
00486   KURL fileURL;
00487   fileURL.setPath( filename );
00488   m_viewManager->openURL( fileURL );
00489   if ( m_viewManager->activeView() == 0 ) return;
00490   m_viewManager->activeView()->gotoLineNumber( linenumber );
00491   this->raise();
00492   this->setActiveWindow();
00493 }
00494 
00495 void KateMainWindow::dragEnterEvent( QDragEnterEvent *event )
00496 {
00497   event->accept(KURLDrag::canDecode(event));
00498 }
00499 
00500 void KateMainWindow::dropEvent( QDropEvent *event )
00501 {
00502   slotDropEvent(event);
00503 }
00504 
00505 void KateMainWindow::slotDropEvent( QDropEvent * event )
00506 {
00507   KURL::List textlist;
00508   if (!KURLDrag::decode(event, textlist)) return;
00509 
00510   for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
00511   {
00512     m_viewManager->openURL (*i);
00513   }
00514 }
00515 
00516 void KateMainWindow::editKeys()
00517 {
00518   KKeyDialog dlg ( false, this );
00519 
00520   QPtrList<KXMLGUIClient> clients = guiFactory()->clients();
00521 
00522   for( QPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
00523     dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() );
00524 
00525   dlg.configure();
00526 
00527   QPtrList<Kate::Document>  l=m_docManager->documentList();
00528   for (uint i=0;i<l.count();i++) {
00529     kdDebug(13001)<<"reloading Keysettings for document "<<i<<endl;
00530     l.at(i)->reloadXML();
00531     QPtrList<class KTextEditor::View> l1=l.at(i)->views ();//KTextEditor::Document
00532     for (uint i1=0;i1<l1.count();i1++) {
00533         l1.at(i1)->reloadXML();
00534         kdDebug(13001)<<"reloading Keysettings for view "<<i<<"/"<<i1<<endl;
00535 
00536     }
00537 
00538   }
00539 }
00540 
00541 void KateMainWindow::openURL (const QString &name)
00542 {
00543   m_viewManager->openURL (KURL(name));
00544 }
00545 
00546 void KateMainWindow::slotConfigure()
00547 {
00548   if (!m_viewManager->activeView())
00549     return;
00550     
00551   KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView());
00552   dlg->exec();
00553   
00554   delete dlg;
00555 }
00556 
00557 //Set focus to next input element
00558 void KateMainWindow::slotGoNext()
00559 {
00560   QFocusEvent::setReason(QFocusEvent::Tab);
00561   /*res= */focusNextPrevChild(true); //TRUE == NEXT , FALSE = PREV
00562   QFocusEvent::resetReason();
00563 }
00564 
00565 //Set focus to previous input element
00566 void KateMainWindow::slotGoPrev()
00567 {
00568   QFocusEvent::setReason(QFocusEvent::Tab);
00569   /*res= */focusNextPrevChild(false); //TRUE == NEXT , FALSE = PREV
00570   QFocusEvent::resetReason();
00571 }
00572 
00573 KURL KateMainWindow::activeDocumentUrl()
00574 {
00575   // anders: i make this one safe, as it may be called during
00576   // startup (by the file selector)
00577   Kate::View *v = m_viewManager->activeView();
00578   if ( v )
00579     return v->getDoc()->url();
00580   return KURL();
00581 }
00582 
00583 void KateMainWindow::fileSelected(const KFileItem *file)
00584 {
00585   m_viewManager->openURL( file->url() );
00586 }
00587 
00588 void KateMainWindow::mSlotFixOpenWithMenu()
00589 {
00590   //kdDebug(13001)<<"13000"<<"fixing open with menu"<<endl;
00591   documentOpenWith->popupMenu()->clear();
00592   // get a list of appropriate services.
00593   KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00594   //kdDebug(13001)<<"13000"<<"url: "<<m_viewManager->activeView()->getDoc()->url().prettyURL()<<"mime type: "<<mime->name()<<endl;
00595   // some checking goes here...
00596   KTrader::OfferList offers = KTrader::self()->query(mime->name(), "Type == 'Application'");
00597   // for each one, insert a menu item...
00598   for(KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) {
00599     if ((*it)->name() == "Kate") continue;
00600     documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
00601   }
00602   // append "Other..." to call the KDE "open with" dialog.
00603   documentOpenWith->popupMenu()->insertItem(i18n("&Other..."));
00604 }
00605 
00606 void KateMainWindow::slotOpenWithMenuAction(int idx)
00607 {
00608   KURL::List list;
00609   list.append( m_viewManager->activeView()->getDoc()->url() );
00610   QString* appname = new QString( documentOpenWith->popupMenu()->text(idx) );
00611   if ( appname->compare(i18n("&Other...")) == 0 ) {
00612     // display "open with" dialog
00613     KOpenWithDlg* dlg = new KOpenWithDlg(list);
00614     if (dlg->exec())
00615       KRun::run(*dlg->service(), list);
00616     return;
00617   }
00618   QString qry = QString("((Type == 'Application') and (Name == '%1'))").arg( appname->latin1() );
00619   KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00620   KTrader::OfferList offers = KTrader::self()->query(mime->name(), qry);
00621   KService::Ptr app = offers.first();
00622   // some checking here: pop a wacko message it the app wasn't found.
00623   KRun::run(*app, list);
00624 }
00625 
00626 void KateMainWindow::pluginHelp()
00627 {
00628   kapp->invokeHelp (QString::null, "kate-plugins");
00629 }
00630 
00631 void KateMainWindow::setupScripts()
00632 {
00633   // locate all scripts, local as well as global.
00634   // The script manager will do the nessecary sanity checking
00635   QStringList scripts = KGlobal::dirs()->findAllResources("data", QString(kapp->name())+"/scripts/*.desktop", false, true );
00636   for (QStringList::Iterator it = scripts.begin(); it != scripts.end(); ++it )
00637     kscript->addScript( *it );
00638   QStringList l ( kscript->scripts() );
00639   for (QStringList::Iterator it=l.begin(); it != l.end(); ++it )
00640     scriptMenu->popupMenu()->insertItem( *it );
00641 }
00642 
00643 void KateMainWindow::runScript( int mIId )
00644 {
00645     //kdDebug(13000) << "Starting script engine..." << endl;
00646         kdDebug(13001)<<"runScript( "<<mIId<<" ) ["<<scriptMenu->popupMenu()->text( mIId )<<"]"<<endl;
00647     kscript->runScript( scriptMenu->popupMenu()->text( mIId ) );
00648 }
00649 
00650 void KateMainWindow::slotMail()
00651 {
00652   KateMailDialog *d = new KateMailDialog(this, this);
00653   if ( ! d->exec() )
00654     return;
00655   QPtrList<Kate::Document> attDocs = d->selectedDocs();
00656   delete d;
00657   // Check that all selected files are saved (or shouldn't be)
00658   QStringList urls; // to atthatch
00659   Kate::Document *doc;
00660   QPtrListIterator<Kate::Document> it(attDocs);
00661   for ( ; it.current(); ++it ) {
00662     doc = it.current();
00663     if (!doc) continue;
00664     if ( doc->url().isEmpty() ) {
00665       // unsaved document. back out unless it gets saved
00666       int r = KMessageBox::questionYesNo( this,
00667               i18n("<p>The current document has not been saved, and "
00668               "cannot be attached to an email message."
00669               "<p>Do you want to save it and proceed?"),
00670               i18n("Cannot Send Unsaved File") );
00671       if ( r == KMessageBox::Yes ) {
00672         Kate::View *v = (Kate::View*)doc->views().first();
00673         int sr = v->saveAs();
00674         if ( sr == Kate::View::SAVE_OK ) { ;
00675         }
00676         else {
00677           if ( sr != Kate::View::SAVE_CANCEL ) // ERROR or RETRY(?)
00678             KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
00679                                         "if you have write permission.") );
00680           continue;
00681         }
00682       }
00683       else
00684         continue;
00685     }
00686     if ( doc->isModified() ) {
00687       // warn that document is modified and offer to save it before proceeding.
00688       int r = KMessageBox::warningYesNoCancel( this,
00689                 i18n("<p>The current file:<br><strong>%1</strong><br>has been "
00690                 "modified. Modifications will not be available in the attachment."
00691                 "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()),
00692                 i18n("Save Before Sending?") );
00693       switch ( r ) {
00694         case KMessageBox::Cancel:
00695           continue;
00696         case KMessageBox::Yes:
00697           doc->save();
00698           if ( doc->isModified() ) { // read-only docs ends here, if modified. Hmm.
00699             KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
00700                                       "if you have write permission.") );
00701             continue;
00702           }
00703           break;
00704         default:
00705           break;
00706       }
00707     }
00708     // finally call the mailer
00709     urls << doc->url().url();
00710   } // check selected docs done
00711   if ( ! urls.count() )
00712     return;
00713   kapp->invokeMailer( QString::null, // to
00714                       QString::null, // cc
00715                       QString::null, // bcc
00716                       QString::null, // subject
00717                       QString::null, // body
00718                       QString::null, // msgfile
00719                       urls           // urls to atthatch
00720                       );
00721 }
00722 void KateMainWindow::tipOfTheDay()
00723 {
00724   KTipDialog::showTip( /*0*/this, QString::null, true );
00725 }
00726 
00727 void KateMainWindow::slotFullScreen(bool t)
00728 {
00729   if (t)
00730     showFullScreen();
00731   else
00732     showNormal();
00733 }
00734 
00735 bool KateMainWindow::eventFilter( QObject *o, QEvent *e )
00736 {
00737   if ( o == greptool && e->type() == QEvent::Show && activeView )
00738   {
00739     if ( activeView->getDoc()->url().isLocalFile() )
00740     {
00741       greptool->updateDirName( activeView->getDoc()->url().directory() );
00742       return true;
00743     }
00744   }
00745   if ( ( o == greptool || o == console ) &&
00746       e->type() == QEvent::Hide && activeView )
00747   {
00748      activeView->setFocus();
00749      return true;
00750   }
00751   return KMdiMainFrm::eventFilter( o, e );
00752 }
00753 
00754 KMdiToolViewAccessor *KateMainWindow::addToolView(KDockWidget::DockPosition position, QWidget *widget, const QPixmap &icon, const QString &sname, const QString &tabToolTip, const QString &tabCaption)
00755 {
00756   widget->setIcon(icon);
00757   widget->setCaption(sname);
00758   
00759   return addToolWindow(widget, position, getMainDockWidget(), 25, tabToolTip, tabCaption);
00760 }
00761 
00762 bool KateMainWindow::removeToolView(QWidget *w)
00763 {
00764   deleteToolWindow (w);
00765   return true;
00766 }
00767 
00768 bool KateMainWindow::removeToolView(KMdiToolViewAccessor *accessor)
00769 {
00770   deleteToolWindow (accessor);
00771   return true;
00772 }
00773 
00774 bool KateMainWindow::showToolView(QWidget *){return false;}
00775 bool KateMainWindow::showToolView(KMdiToolViewAccessor *){return false;}
00776 
00777 bool KateMainWindow::hideToolView(QWidget *){return false;}
00778 bool KateMainWindow::hideToolView(KMdiToolViewAccessor *){return false;}
00779 
00780 void KateMainWindow::slotProjectNew ()
00781 {
00782   ProjectInfo *info = m_projectManager->newProjectDialog (this);
00783 
00784   if (info)
00785   {
00786     createProject (info->type, info->name, info->fileName);
00787     delete info;
00788   }
00789 }
00790 
00791 void KateMainWindow::slotProjectOpen ()
00792 {
00793   QString fileName = KFileDialog::getOpenFileName (QString::null, QString ("*.kateproject|") + i18n("Kate Project Files") + QString (" (*.kateproject)"), this, i18n("Open Kate Project"));
00794 
00795   if (!fileName.isEmpty())
00796     openProject (fileName);
00797 }
00798 
00799 void KateMainWindow::slotProjectSave ()
00800 {
00801   if (m_project)
00802     m_project->save ();
00803 }
00804 
00805 void KateMainWindow::slotProjectClose ()
00806 {
00807   if (m_project)
00808   {
00809     m_projectManager->close (m_project);
00810   }
00811 }
00812 
00813 void KateMainWindow::activateProject (Kate::Project *project)
00814 {
00815   kdDebug(13001)<<"activating project "<<project<<endl;
00816   if (m_project)
00817     m_projectManager->disableProjectGUI (m_project, this);
00818 
00819   if (project)
00820     m_projectManager->enableProjectGUI (project, this);
00821 
00822   m_project = project;
00823 
00824   if (project)
00825   {
00826     m_projectManager->setCurrentProject (project);
00827     m_projectNumber = project->projectNumber ();
00828   }
00829   else
00830     m_projectNumber = 0;
00831 
00832   emit m_mainWindow->projectChanged ();
00833 }
00834 
00835 Kate::Project *KateMainWindow::createProject (const QString &type, const QString &name, const QString &filename)
00836 {
00837   Kate::Project *project = m_projectManager->create (type, name, filename);
00838 
00839   if (project)
00840     activateProject (project);
00841 
00842   return project;
00843 }
00844 
00845 Kate::Project *KateMainWindow::openProject (const QString &filename)
00846 {
00847   Kate::Project *project = m_projectManager->open (filename);
00848 
00849   if (project)
00850   {
00851     recentProjects->addURL ( KURL(filename) );
00852     activateProject (project);
00853   }
00854 
00855   return project;
00856 }
00857 
00858 void KateMainWindow::projectDeleted (uint projectNumber)
00859 {
00860   if (projectNumber == m_projectNumber)
00861   {
00862     if (m_projectManager->projects() > 0)
00863       activateProject (m_projectManager->project(m_projectManager->projects()-1));
00864     else
00865       activateProject (0);
00866   }
00867 }
00868 
00869 void KateMainWindow::slotDocumentCreated (Kate::Document *doc)
00870 {
00871   connect(doc,SIGNAL(modStateChanged(Kate::Document *)),this,SLOT(updateCaption(Kate::Document *)));
00872   connect(doc,SIGNAL(nameChanged(Kate::Document *)),this,SLOT(updateCaption(Kate::Document *)));
00873 
00874   updateCaption (doc);
00875 }
00876 
00877 void KateMainWindow::updateCaption (Kate::Document *doc)
00878 {
00879   if (!m_viewManager->activeView())
00880   {
00881     setCaption ("", false);
00882     return;
00883   }
00884 
00885   if (!(m_viewManager->activeView()->getDoc() == doc))
00886     return;
00887 
00888   // update the sync action
00889   fileselector->kateViewChanged();
00890 
00891   QString c;
00892   if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath()))
00893   {
00894     c = m_viewManager->activeView()->getDoc()->docName();
00895 
00896     //File name shouldn't be too long - Maciek
00897     if (c.length() > 64)
00898       c = c.left(64) + "...";
00899   }
00900   else
00901   {
00902     c = m_viewManager->activeView()->getDoc()->url().prettyURL();
00903 
00904     //File name shouldn't be too long - Maciek
00905     if (c.length() > 64)
00906       c = "..." + c.right(64);
00907   }
00908 
00909   setCaption( c, m_viewManager->activeView()->getDoc()->isModified());
00910 }
00911 
00912 void KateMainWindow::openConstURLProject (const KURL&url)
00913 {
00914   openProject (url.path());
00915 }
00916 
00917 void KateMainWindow::saveProperties(KConfig *config) {
00918     kdDebug(13000)<<"KateMainWindow::saveProperties()********************************************"<<endl
00919               <<config->group()<<endl
00920               <<"****************************************************************************"<<endl;
00921   assert(config);
00922 
00923   kdDebug(13000)<<"preparing session saving"<<endl;
00924   QString grp=config->group();
00925   QString dockGrp;
00926 
00927   if (kapp->sessionSaving()) dockGrp=grp+"-Docking";
00928     else dockGrp="MainWindow0-Docking";
00929 /*  if (config->readNumEntry("GUIMode",KMdi::UndefinedMode)!=mdiMode()) {
00930         config->writeEntry("GUIMode",mdiMode());
00931         config->deleteGroup("MainWindow0-Docking");
00932   }*/
00933 
00934   kdDebug(13000)<<"Before write dock config"<<endl;
00935   writeDockConfig(config,dockGrp);
00936   kdDebug(13000)<<"After write dock config"<<endl;
00937 
00938 
00939   if (kapp->sessionSaving()) dockGrp=grp+"-View Configuration";
00940     else dockGrp="MainWindow0-View Configuration";
00941 
00942   m_viewManager->saveViewConfiguration (config,dockGrp);
00943   kdDebug(13000)<<"After saving view configuration"<<endl;
00944   config->setGroup(grp);
00945 
00946 }
00947 
00948 void KateMainWindow::readProperties(KConfig *config)
00949 {
00950   QString grp=config->group();
00951   QString dockGrp;
00952 
00953   if (kapp->isRestored()) dockGrp=grp+"-Docking";
00954     else dockGrp="MainWindow0-Docking";
00955 
00956   if (config->hasGroup(dockGrp))
00957         readDockConfig(config,dockGrp);
00958 
00959   if (kapp->isRestored()) dockGrp=grp+"-View Configuration";
00960     else dockGrp="MainWindow0-View Configuration";
00961 
00962   m_viewManager->restoreViewConfiguration (config,dockGrp);
00963   config->setGroup(grp);
00964 }
00965 
00966 void KateMainWindow::saveGlobalProperties( KConfig* sessionConfig )
00967 {
00968   m_projectManager->saveProjectList (sessionConfig);
00969   m_docManager->saveDocumentList (sessionConfig);
00970 }
KDE Logo
This file is part of the documentation for kate Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 5 04:41:10 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003