• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

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

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kate

Skip menu "kate"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for kate by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |