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