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