• 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 "katesessionpanel.h"
00035 #include "kategrepdialog.h"
00036 #include "katemailfilesdialog.h"
00037 #include "katemainwindowiface.h"
00038 #include "kateexternaltools.h"
00039 #include "katesavemodifieddialog.h"
00040 #include "katemwmodonhddialog.h"
00041 #include "katesession.h"
00042 #include "katetabwidget.h"
00043 
00044 #include "../interfaces/mainwindow.h"
00045 #include "../interfaces/toolviewmanager.h"
00046 
00047 #include <dcopclient.h>
00048 #include <kinstance.h>
00049 #include <tdeaboutdata.h>
00050 #include <tdeaction.h>
00051 #include <tdecmdlineargs.h>
00052 #include <kdebug.h>
00053 #include <kdialogbase.h>
00054 #include <tdediroperator.h>
00055 #include <kdockwidget.h>
00056 #include <kedittoolbar.h>
00057 #include <tdefiledialog.h>
00058 #include <kglobalaccel.h>
00059 #include <tdeglobal.h>
00060 #include <tdeglobalsettings.h>
00061 #include <kiconloader.h>
00062 #include <kkeydialog.h>
00063 #include <tdelocale.h>
00064 #include <tdemessagebox.h>
00065 #include <kmimetype.h>
00066 #include <kopenwith.h>
00067 #include <tdepopupmenu.h>
00068 #include <ksimpleconfig.h>
00069 #include <kstatusbar.h>
00070 #include <kstdaction.h>
00071 #include <kstandarddirs.h>
00072 #include <ktrader.h>
00073 #include <kuniqueapplication.h>
00074 #include <kurldrag.h>
00075 #include <kdesktopfile.h>
00076 #include <khelpmenu.h>
00077 #include <tdemultitabbar.h>
00078 #include <ktip.h>
00079 #include <tdemenubar.h>
00080 #include <kstringhandler.h>
00081 #include <tqlayout.h>
00082 #include <tqptrvector.h>
00083 
00084 #include <assert.h>
00085 #include <unistd.h>
00086 //END
00087 
00088 uint KateMainWindow::uniqueID = 1;
00089 
00090 KateMainWindow::KateMainWindow (TDEConfig *sconfig, const TQString &sgroup)
00091   : KateMDI::MainWindow (0,(TQString(TQString("__KateMainWindow#%1").arg(uniqueID))).latin1())
00092 {
00093   // first the very important id
00094   myID = uniqueID;
00095   uniqueID++;
00096 
00097   m_modignore = false;
00098 
00099   console = 0;
00100   greptool = 0;
00101 
00102   // here we go, set some usable default sizes
00103   if (!initialGeometrySet())
00104   {
00105     int scnum = TQApplication::desktop()->screenNumber(parentWidget());
00106     TQRect desk = TQApplication::desktop()->screenGeometry(scnum);
00107 
00108     TQSize size;
00109 
00110     // try to load size
00111     if (sconfig)
00112     {
00113       sconfig->setGroup (sgroup);
00114       size.setWidth (sconfig->readNumEntry( TQString::fromLatin1("Width %1").arg(desk.width()), 0 ));
00115       size.setHeight (sconfig->readNumEntry( TQString::fromLatin1("Height %1").arg(desk.height()), 0 ));
00116     }
00117 
00118     // if thats fails, try to reuse size
00119     if (size.isEmpty())
00120     {
00121       // first try to reuse size known from current or last created main window ;=)
00122       if (KateApp::self()->mainWindows () > 0)
00123       {
00124         KateMainWindow *win = KateApp::self()->activeMainWindow ();
00125 
00126         if (!win)
00127           win = KateApp::self()->mainWindow (KateApp::self()->mainWindows ()-1);
00128 
00129         size = win->size();
00130       }
00131       else // now fallback to hard defaults ;)
00132       {
00133         // first try global app config
00134         KateApp::self()->config()->setGroup ("MainWindow");
00135         size.setWidth (KateApp::self()->config()->readNumEntry( TQString::fromLatin1("Width %1").arg(desk.width()), 0 ));
00136         size.setHeight (KateApp::self()->config()->readNumEntry( TQString::fromLatin1("Height %1").arg(desk.height()), 0 ));
00137 
00138         if (size.isEmpty())
00139           size = TQSize (kMin (700, desk.width()), kMin(480, desk.height()));
00140       }
00141 
00142       resize (size);
00143     }
00144   }
00145 
00146   // start session restore if needed
00147   startRestore (sconfig, sgroup);
00148 
00149   m_mainWindow = new Kate::MainWindow (this);
00150   m_toolViewManager = new Kate::ToolViewManager (this);
00151 
00152   m_dcop = new KateMainWindowDCOPIface (this);
00153 
00154   // setup the most important widgets
00155   setupMainWindow();
00156 
00157   // setup the actions
00158   setupActions();
00159 
00160   setStandardToolBarMenuEnabled( true );
00161   setXMLFile( "kateui.rc" );
00162   createShellGUI ( true );
00163 
00164   KatePluginManager::self()->enableAllPluginsGUI (this);
00165 
00166   if ( KateApp::self()->authorize("shell_access") )
00167     Kate::Document::registerCommand(KateExternalToolsCommand::self());
00168 
00169   // connect documents menu aboutToshow
00170   documentMenu = (TQPopupMenu*)factory()->container("documents", this);
00171   connect(documentMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(documentMenuAboutToShow()));
00172 
00173   // caption update
00174   for (uint i = 0; i < KateDocManager::self()->documents(); i++)
00175     slotDocumentCreated (KateDocManager::self()->document(i));
00176 
00177   connect(KateDocManager::self(),TQT_SIGNAL(documentCreated(Kate::Document *)),this,TQT_SLOT(slotDocumentCreated(Kate::Document *)));
00178 
00179   readOptions();
00180 
00181   if (sconfig)
00182     m_viewManager->restoreViewConfiguration (sconfig, sgroup);
00183 
00184   finishRestore ();
00185 
00186   setAcceptDrops(true);
00187 }
00188 
00189 KateMainWindow::~KateMainWindow()
00190 {
00191   // first, save our fallback window size ;)
00192   KateApp::self()->config()->setGroup ("MainWindow");
00193   saveWindowSize (KateApp::self()->config());
00194 
00195   // save other options ;=)
00196   saveOptions();
00197 
00198   KateApp::self()->removeMainWindow (this);
00199 
00200   KatePluginManager::self()->disableAllPluginsGUI (this);
00201 
00202   delete m_dcop;
00203 }
00204 
00205 void KateMainWindow::setupMainWindow ()
00206 {
00207   setToolViewStyle( KMultiTabBar::KDEV3ICON );
00208 
00209   m_tabWidget = new KateTabWidget (centralWidget());
00210 
00211   m_viewManager = new KateViewManager (this);
00212 
00213   KateMDI::ToolView *ft = createToolView("kate_filelist", KMultiTabBar::Left, SmallIcon("application-vnd.tde.tdemultiple"), i18n("Documents"));
00214   filelist = new KateFileList (this, m_viewManager, ft, "filelist");
00215   filelist->readConfig(KateApp::self()->config(), "Filelist");
00216 
00217   KateMDI::ToolView *t = createToolView("kate_fileselector", KMultiTabBar::Left, SmallIcon("document-open"), i18n("Filesystem Browser"));
00218   fileselector = new KateFileSelector( this, m_viewManager, t, "operator");
00219   connect(fileselector->dirOperator(),TQT_SIGNAL(fileSelected(const KFileItem*)),this,TQT_SLOT(fileSelected(const KFileItem*)));
00220 
00221   KateMDI::ToolView *st = createToolView("kate_sessionpanel", KMultiTabBar::Left, SmallIcon("view_choose"), i18n("Sessions"));
00222   m_sessionpanel = new KateSessionPanel( this, m_viewManager, st, "sessionpanel");
00223 
00224   // ONLY ALLOW SHELL ACCESS IF ALLOWED ;)
00225   if (KateApp::self()->authorize("shell_access"))
00226   {
00227     t = createToolView("kate_greptool", KMultiTabBar::Bottom, SmallIcon("filefind"), i18n("Find in Files") );
00228     greptool = new GrepTool( t, "greptool" );
00229     connect(greptool, TQT_SIGNAL(itemSelected(const TQString &,int)), this, TQT_SLOT(slotGrepToolItemSelected(const TQString &,int)));
00230     connect(t,TQT_SIGNAL(visibleChanged(bool)),this, TQT_SLOT(updateGrepDir (bool)));
00231     // WARNING HACK - anders: showing the greptool seems to make the menu accels work
00232     greptool->show();
00233 
00234     t = createToolView("kate_console", KMultiTabBar::Bottom, SmallIcon("konsole"), i18n("Terminal"));
00235     console = new KateConsole (this, t);
00236   }
00237 
00238   // make per default the filelist visible, if we are in session restore, katemdi will skip this ;)
00239   showToolView (ft);
00240 }
00241 
00242 void KateMainWindow::setupActions()
00243 {
00244   TDEAction *a;
00245 
00246   KStdAction::openNew( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentNew() ), actionCollection(), "file_new" )->setWhatsThis(i18n("Create a new document"));
00247   KStdAction::open( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Open an existing document for editing"));
00248 
00249   fileOpenRecent = KStdAction::openRecent (TQT_TQOBJECT(m_viewManager), TQT_SLOT(openURL (const KURL&)), actionCollection());
00250   fileOpenRecent->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
00251 
00252   a=new TDEAction( i18n("Save A&ll"),"save_all", CTRL+Key_L, KateDocManager::self(), TQT_SLOT( saveAll() ), actionCollection(), "file_save_all" );
00253   a->setWhatsThis(i18n("Save all open, modified documents to disk."));
00254 
00255   KStdAction::close( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentClose() ), actionCollection(), "file_close" )->setWhatsThis(i18n("Close the current document."));
00256 
00257   a=new TDEAction( i18n( "Clos&e All" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotDocumentCloseAll() ), actionCollection(), "file_close_all" );
00258   a->setWhatsThis(i18n("Close all open documents."));
00259 
00260   KStdAction::mail( TQT_TQOBJECT(this), TQT_SLOT(slotMail()), actionCollection() )->setWhatsThis(i18n("Send one or more of the open documents as email attachments."));
00261 
00262   KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT( slotFileQuit() ), actionCollection(), "file_quit" )->setWhatsThis(i18n("Close this window"));
00263 
00264   a=new TDEAction(i18n("&New Window"), "window-new", 0, TQT_TQOBJECT(this), TQT_SLOT(newWindow()), actionCollection(), "view_new_view");
00265   a->setWhatsThis(i18n("Create a new Kate view (a new window with the same document list)."));
00266 
00267   if ( KateApp::self()->authorize("shell_access") )
00268   {
00269     externalTools = new KateExternalToolsMenuAction( i18n("External Tools"), actionCollection(), "tools_external", this );
00270     externalTools->setWhatsThis( i18n("Launch external helper applications") );
00271   }
00272 
00273   TDEToggleAction* showFullScreenAction = KStdAction::fullScreen( 0, 0, actionCollection(),this);
00274   connect( showFullScreenAction,TQT_SIGNAL(toggled(bool)), this,TQT_SLOT(slotFullScreen(bool)));
00275 
00276   documentOpenWith = new TDEActionMenu(i18n("Open W&ith"), actionCollection(), "file_open_with");
00277   documentOpenWith->setWhatsThis(i18n("Open the current document using another application registered for its file type, or an application of your choice."));
00278   connect(documentOpenWith->popupMenu(), TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(mSlotFixOpenWithMenu()));
00279   connect(documentOpenWith->popupMenu(), TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotOpenWithMenuAction(int)));
00280 
00281   a=KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(editKeys()), actionCollection());
00282   a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
00283 
00284   a=KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotEditToolbars()), actionCollection());
00285   a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
00286 
00287   TDEAction* settingsConfigure = KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotConfigure()), actionCollection(), "settings_configure");
00288   settingsConfigure->setWhatsThis(i18n("Configure various aspects of this application and the editing component."));
00289 
00290   // pipe to terminal action
00291   if (KateApp::self()->authorize("shell_access"))
00292     new TDEAction(i18n("&Pipe to Console"), "pipe", 0, TQT_TQOBJECT(console), TQT_SLOT(slotPipeToConsole()), actionCollection(), "tools_pipe_to_terminal");
00293 
00294   // tip of the day :-)
00295   KStdAction::tipOfDay( TQT_TQOBJECT(this), TQT_SLOT( tipOfTheDay() ), actionCollection() )->setWhatsThis(i18n("This shows useful tips on the use of this application."));
00296 
00297   if (KatePluginManager::self()->pluginList().count() > 0)
00298   {
00299     a=new TDEAction(i18n("&Plugins Handbook"), 0, TQT_TQOBJECT(this), TQT_SLOT(pluginHelp()), actionCollection(), "help_plugins_contents");
00300     a->setWhatsThis(i18n("This shows help files for various available plugins."));
00301   }
00302 
00303   connect(m_viewManager,TQT_SIGNAL(viewChanged()),TQT_TQOBJECT(this),TQT_SLOT(slotWindowActivated()));
00304   connect(m_viewManager,TQT_SIGNAL(viewChanged()),TQT_TQOBJECT(this),TQT_SLOT(slotUpdateOpenWith()));
00305 
00306   slotWindowActivated ();
00307 
00308   // session actions
00309   new TDEAction(i18n("&New"), "list-add", 0, 
00310       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotNewSession()), actionCollection(), "session_new");
00311   new TDEAction(i18n("&Save"), "document-save", 0, 
00312       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSaveSession()), actionCollection(), "session_save");
00313   new TDEAction(i18n("Save &As..."), "document-save-as", 0, 
00314       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSaveSessionAs()), actionCollection(), "session_save_as");
00315   new TDEAction(i18n("&Rename"), "edit_user", 0,
00316       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotRenameSession()), actionCollection(), "session_rename");
00317   new TDEAction(i18n("&Delete"), "edit-delete", 0,
00318       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotDeleteSession()), actionCollection(), "session_delete");
00319   new TDEAction(i18n("Re&load"), "reload", 0,
00320       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotReloadSession()), actionCollection(), "session_reload");
00321   new TDEAction(i18n("Acti&vate"), "forward", 0,
00322       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotActivateSession()), actionCollection(), "session_activate");
00323   new TDEToggleAction(i18n("Toggle read &only"), "encrypted", 0,
00324       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionToggleReadOnly()), actionCollection(), "session_toggle_read_only");
00325   new TDEAction(i18n("Move &Up"), "go-up", 0,
00326       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionMoveUp()), actionCollection(), "session_move_up");
00327   new TDEAction(i18n("Move Do&wn"), "go-down", 0,
00328       TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionMoveDown()), actionCollection(), "session_move_down");
00329   new KateSessionListActionMenu(this, i18n("Sele&ct session"), actionCollection(), "session_list");
00330 
00331   connect(m_sessionpanel, TQT_SIGNAL(selectionChanged()), TQT_TQOBJECT(this), TQT_SLOT(slotSelectionChanged()));
00332 }
00333 
00334 KateTabWidget *KateMainWindow::tabWidget ()
00335 {
00336   return m_tabWidget;
00337 }
00338 
00339 void KateMainWindow::slotDocumentCloseAll() {
00340   if (queryClose_internal())
00341     KateDocManager::self()->closeAllDocuments(false);
00342 }
00343 
00344 bool KateMainWindow::queryClose_internal() {
00345   uint documentCount=KateDocManager::self()->documents();
00346 
00347   if ( !showModOnDiskPrompt() )
00348     return false;
00349 
00350   TQPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList();
00351   bool shutdown=(modifiedDocuments.count()==0);
00352 
00353   if (!shutdown) {
00354     shutdown=KateSaveModifiedDialog::queryClose(this,modifiedDocuments);
00355   }
00356 
00357   if ( KateDocManager::self()->documents() > documentCount ) {
00358     KMessageBox::information (this,
00359                               i18n ("New file opened while trying to close Kate, closing aborted."),
00360                               i18n ("Closing Aborted"));
00361     shutdown=false;
00362   }
00363 
00364   return shutdown;
00365 }
00366 
00370 bool KateMainWindow::queryClose()
00371 {
00372   // session saving, can we close all views ?
00373   // just test, not close them actually
00374   if (KateApp::self()->sessionSaving())
00375   {
00376     return queryClose_internal();
00377   }
00378 
00379   // normal closing of window
00380   // allow to close all windows until the last without restrictions
00381   if (KateApp::self()->mainWindows() > 1)
00382   {
00383     return true;
00384   }
00385 
00386   // last one: check if we can close all documents and sessions, try run
00387   // and save docs if we really close down !
00388   if (queryClose_internal() && KateApp::self()->query_session_close())
00389   {
00390     // detach the dcopClient
00391     KateApp::self()->dcopClient()->detach();
00392     return true;
00393   }
00394 
00395   return false;
00396 }
00397 
00398 void KateMainWindow::newWindow ()
00399 {
00400   KateApp::self()->newMainWindow ();
00401 }
00402 
00403 void KateMainWindow::slotEditToolbars()
00404 {
00405   saveMainWindowSettings( KateApp::self()->config(), "MainWindow" );
00406   KEditToolbar dlg( factory() );
00407   connect( &dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(slotNewToolbarConfig()) );
00408   dlg.exec();
00409 }
00410 
00411 void KateMainWindow::slotNewToolbarConfig()
00412 {
00413   applyMainWindowSettings( KateApp::self()->config(), "MainWindow" );
00414 }
00415 
00416 void KateMainWindow::slotFileQuit()
00417 {
00418   KateApp::self()->shutdownKate(this);  
00419 }
00420 
00421 void KateMainWindow::readOptions ()
00422 {
00423   TDEConfig *config = KateApp::self()->config ();
00424 
00425   config->setGroup("General");
00426   syncKonsole =  config->readBoolEntry("Sync Konsole", true);
00427   useInstance =  config->readBoolEntry("UseInstance", false);
00428   modNotification = config->readBoolEntry("Modified Notification", false);
00429   KateDocManager::self()->setSaveMetaInfos(config->readBoolEntry("Save Meta Infos", true));
00430   KateDocManager::self()->setDaysMetaInfos(config->readNumEntry("Days Meta Infos", 30));
00431 
00432   m_viewManager->setShowFullPath(config->readBoolEntry("Show Full Path in Title", false));
00433 
00434   fileOpenRecent->setMaxItems( config->readNumEntry("Number of recent files", fileOpenRecent->maxItems() ) );
00435   fileOpenRecent->loadEntries(config, "Recent Files");
00436 
00437   fileselector->readConfig(config, "fileselector");
00438 }
00439 
00440 void KateMainWindow::saveOptions ()
00441 {
00442   TDEConfig *config = KateApp::self()->config ();
00443   config->setGroup("General");
00444 
00445   if (console)
00446     config->writeEntry("Show Console", console->isVisible());
00447   else
00448     config->writeEntry("Show Console", false);
00449 
00450   config->writeEntry("Save Meta Infos", KateDocManager::self()->getSaveMetaInfos());
00451   config->writeEntry("Days Meta Infos", KateDocManager::self()->getDaysMetaInfos());
00452   config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath());
00453   config->writeEntry("Sync Konsole", syncKonsole);
00454   config->writeEntry("UseInstance", useInstance);
00455 
00456   fileOpenRecent->saveEntries(config, "Recent Files");
00457   fileselector->writeConfig(config, "fileselector");
00458   filelist->writeConfig(config, "Filelist");
00459 
00460   config->sync();
00461 }
00462 
00463 void KateMainWindow::slotWindowActivated ()
00464 {
00465   if (m_viewManager->activeView())
00466   {
00467     if (console && syncKonsole)
00468     {
00469       static TQString path;
00470       TQString newPath = m_viewManager->activeView()->getDoc()->url().directory();
00471 
00472       if ( newPath != path )
00473       {
00474         path = newPath;
00475         console->cd (KURL( path ));
00476       }
00477     }
00478 
00479     updateCaption (m_viewManager->activeView()->getDoc());
00480   }
00481 
00482   // update proxy
00483   centralWidget()->setFocusProxy (m_viewManager->activeView());
00484 }
00485 
00486 void KateMainWindow::slotUpdateOpenWith()
00487 {
00488   if (m_viewManager->activeView())
00489     documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty());
00490   else
00491     documentOpenWith->setEnabled(false);
00492 }
00493 
00494 void KateMainWindow::documentMenuAboutToShow()
00495 {
00496   // remove documents
00497   while (documentMenu->count() > 3)
00498     documentMenu->removeItemAt (3);
00499 
00500   TQListViewItem * item = filelist->firstChild();
00501   while( item ) {
00502     // would it be saner to use the screen width as a limit that some random number??
00503     TQString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 );
00504     Kate::Document* doc = ((KateFileListItem *)item)->document();
00505     documentMenu->insertItem (
00506           doc->isModified() ? i18n("'document name [*]', [*] means modified", "%1 [*]").arg(name) : name,
00507           m_viewManager, TQT_SLOT (activateView (int)), 0,
00508           ((KateFileListItem *)item)->documentNumber () );
00509 
00510     item = item->nextSibling();
00511   }
00512   if (m_viewManager->activeView())
00513     documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true);
00514 }
00515 
00516 void KateMainWindow::slotGrepToolItemSelected(const TQString &filename,int linenumber)
00517 {
00518   KURL fileURL;
00519   fileURL.setPath( filename );
00520   m_viewManager->openURL( fileURL );
00521   if ( m_viewManager->activeView() == 0 ) return;
00522   m_viewManager->activeView()->gotoLineNumber( linenumber );
00523   raise();
00524   setActiveWindow();
00525 }
00526 
00527 void KateMainWindow::dragEnterEvent( TQDragEnterEvent *event )
00528 {
00529   event->accept(KURLDrag::canDecode(event));
00530 }
00531 
00532 void KateMainWindow::dropEvent( TQDropEvent *event )
00533 {
00534   slotDropEvent(event);
00535 }
00536 
00537 void KateMainWindow::slotDropEvent( TQDropEvent * event )
00538 {
00539   KURL::List textlist;
00540   if (!KURLDrag::decode(event, textlist)) return;
00541 
00542   for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
00543   {
00544     m_viewManager->openURL (*i);
00545   }
00546 }
00547 
00548 void KateMainWindow::editKeys()
00549 {
00550   KKeyDialog dlg ( false, this );
00551 
00552   TQPtrList<KXMLGUIClient> clients = guiFactory()->clients();
00553 
00554   for( TQPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
00555     dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() );
00556 
00557   dlg.insert( externalTools->actionCollection(), i18n("External Tools") );
00558 
00559   dlg.configure();
00560 
00561   TQPtrList<Kate::Document>  l=KateDocManager::self()->documentList();
00562   for (uint i=0;i<l.count();i++) {
00563 //     kdDebug(13001)<<"reloading Keysettings for document "<<i<<endl;
00564     l.at(i)->reloadXML();
00565     TQPtrList<class KTextEditor::View> l1=l.at(i)->views ();//KTextEditor::Document
00566     for (uint i1=0;i1<l1.count();i1++) {
00567       l1.at(i1)->reloadXML();
00568 //       kdDebug(13001)<<"reloading Keysettings for view "<<i<<"/"<<i1<<endl;
00569     }
00570   }
00571 
00572   externalTools->actionCollection()->writeShortcutSettings( "Shortcuts", new TDEConfig("externaltools", false, false, "appdata") );
00573 }
00574 
00575 void KateMainWindow::openURL (const TQString &name)
00576 {
00577   m_viewManager->openURL (KURL(name));
00578 }
00579 
00580 void KateMainWindow::slotConfigure()
00581 {
00582   if (!m_viewManager->activeView())
00583     return;
00584 
00585   KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView());
00586   dlg->exec();
00587 
00588   delete dlg;
00589   
00590   // Inform Kate that options may have been changed
00591   KateApp::self()->reparse_config();
00592 }
00593 
00594 KURL KateMainWindow::activeDocumentUrl()
00595 {
00596   // anders: i make this one safe, as it may be called during
00597   // startup (by the file selector)
00598   Kate::View *v = m_viewManager->activeView();
00599   if ( v )
00600     return v->getDoc()->url();
00601   return KURL();
00602 }
00603 
00604 void KateMainWindow::fileSelected(const KFileItem * /*file*/)
00605 {
00606   const KFileItemList *list=fileselector->dirOperator()->selectedItems();
00607   KFileItem *tmp;
00608   for (KFileItemListIterator it(*list); (tmp = it.current()); ++it)
00609   {
00610     m_viewManager->openURL(tmp->url());
00611     fileselector->dirOperator()->view()->setSelected(tmp,false);
00612   }
00613 }
00614 
00615 // TODO make this work
00616 void KateMainWindow::mSlotFixOpenWithMenu()
00617 {
00618   //kdDebug(13001)<<"13000"<<"fixing open with menu"<<endl;
00619   documentOpenWith->popupMenu()->clear();
00620   // get a list of appropriate services.
00621   KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00622   //kdDebug(13001)<<"13000"<<"url: "<<m_viewManager->activeView()->getDoc()->url().prettyURL()<<"mime type: "<<mime->name()<<endl;
00623   // some checking goes here...
00624   TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), "Type == 'Application'");
00625   // for each one, insert a menu item...
00626   for(TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) {
00627     if ((*it)->name() == "Kate") continue;
00628     documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
00629   }
00630   // append "Other..." to call the TDE "open with" dialog.
00631   documentOpenWith->popupMenu()->insertItem(i18n("&Other..."));
00632 }
00633 
00634 void KateMainWindow::slotOpenWithMenuAction(int idx)
00635 {
00636   KURL::List list;
00637   list.append( m_viewManager->activeView()->getDoc()->url() );
00638   TQString appname = documentOpenWith->popupMenu()->text(idx);
00639 
00640   appname = appname.remove('&'); //Remove a possible accelerator ... otherwise the application might not get found.
00641   if ( appname.compare(i18n("Other...")) == 0 ) {
00642     // display "open with" dialog
00643     KOpenWithDlg dlg(list);
00644     if (dlg.exec())
00645       KRun::run(*dlg.service(), list);
00646     return;
00647   }
00648 
00649   TQString qry = TQString("((Type == 'Application') and (Name == '%1'))").arg( appname.latin1() );
00650   KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00651   TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), qry);
00652 
00653   if (!offers.isEmpty()) {
00654     KService::Ptr app = offers.first();
00655     KRun::run(*app, list);
00656   }
00657   else
00658     KMessageBox::error(this, i18n("Application '%1' not found!").arg(appname.latin1()), i18n("Application Not Found!"));
00659 }
00660 
00661 void KateMainWindow::pluginHelp()
00662 {
00663   KateApp::self()->invokeHelp (TQString::null, "kate-plugins");
00664 }
00665 
00666 void KateMainWindow::slotMail()
00667 {
00668   KateMailDialog *d = new KateMailDialog(this, this);
00669   if ( ! d->exec() )
00670   {
00671     delete d;
00672     return;
00673   }
00674   TQPtrList<Kate::Document> attDocs = d->selectedDocs();
00675   delete d;
00676   // Check that all selected files are saved (or shouldn't be)
00677   TQStringList urls; // to atthatch
00678   Kate::Document *doc;
00679   TQPtrListIterator<Kate::Document> it(attDocs);
00680   for ( ; it.current(); ++it ) {
00681     doc = it.current();
00682     if (!doc) continue;
00683     if ( doc->url().isEmpty() ) {
00684       // unsaved document. back out unless it gets saved
00685       int r = KMessageBox::questionYesNo( this,
00686               i18n("<p>The current document has not been saved, and "
00687               "cannot be attached to an email message."
00688               "<p>Do you want to save it and proceed?"),
00689               i18n("Cannot Send Unsaved File"),KStdGuiItem::saveAs(),KStdGuiItem::cancel() );
00690       if ( r == KMessageBox::Yes ) {
00691         Kate::View *v = (Kate::View*)doc->views().first();
00692         int sr = v->saveAs();
00693         if ( sr == Kate::View::SAVE_OK ) { ;
00694         }
00695         else {
00696           if ( sr != Kate::View::SAVE_CANCEL ) // ERROR or RETRY(?)
00697             KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
00698                                         "if you have write permission.") );
00699           continue;
00700         }
00701       }
00702       else
00703         continue;
00704     }
00705     if ( doc->isModified() ) {
00706       // warn that document is modified and offer to save it before proceeding.
00707       int r = KMessageBox::warningYesNoCancel( this,
00708                 i18n("<p>The current file:<br><strong>%1</strong><br>has been "
00709                 "modified. Modifications will not be available in the attachment."
00710                 "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()),
00711                 i18n("Save Before Sending?"), KStdGuiItem::save(), i18n("Do Not Save") );
00712       switch ( r ) {
00713         case KMessageBox::Cancel:
00714           continue;
00715         case KMessageBox::Yes:
00716           doc->save();
00717           if ( doc->isModified() ) { // read-only docs ends here, if modified. Hmm.
00718             KMessageBox::sorry( this, i18n("The file could not be saved. Please check "
00719                                       "if you have write permission.") );
00720             continue;
00721           }
00722           break;
00723         default:
00724           break;
00725       }
00726     }
00727     // finally call the mailer
00728     urls << doc->url().url();
00729   } // check selected docs done
00730   if ( ! urls.count() )
00731     return;
00732   KateApp::self()->invokeMailer( TQString::null, // to
00733                       TQString::null, // cc
00734                       TQString::null, // bcc
00735                       TQString::null, // subject
00736                       TQString::null, // body
00737                       TQString::null, // msgfile
00738                       urls           // urls to atthatch
00739                       );
00740 }
00741 void KateMainWindow::tipOfTheDay()
00742 {
00743   KTipDialog::showTip( /*0*/this, TQString::null, true );
00744 }
00745 
00746 void KateMainWindow::slotFullScreen(bool t)
00747 {
00748   if (t)
00749     showFullScreen();
00750   else
00751     showNormal();
00752 }
00753 
00754 void KateMainWindow::updateGrepDir (bool visible)
00755 {
00756   // grepdlg gets hidden
00757   if (!visible)
00758     return;
00759 
00760   if ( m_viewManager->activeView() )
00761   {
00762     if ( m_viewManager->activeView()->getDoc()->url().isLocalFile() )
00763     {
00764       greptool->updateDirName( m_viewManager->activeView()->getDoc()->url().directory() );
00765     }
00766   }
00767 }
00768 
00769 bool KateMainWindow::event( TQEvent *e )
00770 {
00771   uint type = e->type();
00772   if ( type == TQEvent::WindowActivate && modNotification )
00773   {
00774     showModOnDiskPrompt();
00775   }
00776   return KateMDI::MainWindow::event( e );
00777 }
00778 
00779 bool KateMainWindow::showModOnDiskPrompt()
00780 {
00781   Kate::Document *doc;
00782 
00783   DocVector list( KateDocManager::self()->documents() );
00784   uint cnt = 0;
00785   for( doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() )
00786   {
00787     if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDisc )
00788     {
00789       list.insert( cnt, doc );
00790       cnt++;
00791     }
00792   }
00793 
00794   if ( cnt && !m_modignore )
00795   {
00796     list.resize( cnt );
00797     KateMwModOnHdDialog mhdlg( list, this );
00798     m_modignore = true;
00799     bool res = mhdlg.exec();
00800     m_modignore = false;
00801 
00802     return res;
00803   }
00804   return true;
00805 }
00806 
00807 void KateMainWindow::slotDocumentCreated (Kate::Document *doc)
00808 {
00809   connect(doc,TQT_SIGNAL(modStateChanged(Kate::Document *)),this,TQT_SLOT(updateCaption(Kate::Document *)));
00810   connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotNameChanged(Kate::Document *)));
00811   connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotUpdateOpenWith()));
00812 
00813   updateCaption (doc);
00814 }
00815 
00816 void KateMainWindow::slotNameChanged(Kate::Document *doc)
00817 {
00818   updateCaption(doc);
00819   if (!doc->url().isEmpty())
00820     fileOpenRecent->addURL(doc->url());
00821 }
00822 
00823 void KateMainWindow::updateCaption (Kate::Document *doc)
00824 {
00825   if (!m_viewManager->activeView())
00826   {
00827     setCaption ("", false);
00828     return;
00829   }
00830 
00831   if (!(m_viewManager->activeView()->getDoc() == doc))
00832     return;
00833 
00834   TQString c;
00835   if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath()))
00836   {
00837     c = m_viewManager->activeView()->getDoc()->docName();
00838   }
00839   else
00840   {
00841     c = m_viewManager->activeView()->getDoc()->url().prettyURL();
00842   }
00843 
00844   TQString sessName = KateApp::self()->sessionManager()->getActiveSessionName();
00845   if ( !sessName.isEmpty() )
00846     sessName = TQString("%1: ").arg( sessName );
00847 
00848   setCaption( sessName + KStringHandler::lsqueeze(c,64),
00849       m_viewManager->activeView()->getDoc()->isModified());
00850 }
00851 
00852 void KateMainWindow::saveProperties(TDEConfig *config)
00853 {
00854   TQString grp=config->group();
00855 
00856   saveSession(config, grp);
00857   m_viewManager->saveViewConfiguration (config, grp);
00858 
00859   config->setGroup(grp);
00860 }
00861 
00862 void KateMainWindow::readProperties(TDEConfig *config)
00863 {
00864   TQString grp=config->group();
00865 
00866   startRestore(config, grp);
00867   finishRestore ();
00868   m_viewManager->restoreViewConfiguration (config, grp);
00869 
00870   config->setGroup(grp);
00871 }
00872 
00873 //-------------------------------------------
00874 void KateMainWindow::slotSelectionChanged()
00875 {
00876   TDEActionCollection *mwac = actionCollection();  // Main Window Action Collection
00877   TDEActionPtrList actionList = m_sessionpanel->m_actionCollection->actions();
00878   TDEActionPtrList::ConstIterator spa_it;
00879   for (spa_it = actionList.begin(); spa_it != actionList.end(); ++spa_it)
00880   {
00881     TDEAction *a = mwac->action((*spa_it)->name());
00882     TDEToggleAction *ta = dynamic_cast<TDEToggleAction*>(a);
00883     if (ta)
00884     {
00885       ta->setChecked((dynamic_cast<TDEToggleAction*>(*spa_it))->isChecked());
00886     }
00887     if (a)
00888     {
00889       a->setEnabled((*spa_it)->isEnabled());
00890     }  
00891   }              
00892 }
00893 
00894 //-------------------------------------------
00895 void KateMainWindow::activateSession(int sessionId)
00896 {
00897   if (sessionId < 0 || sessionId == KateApp::self()->sessionManager()->getActiveSessionId())
00898   {
00899     return;
00900   }
00901   
00902   // Select the required session in the session panel's listview
00903   TQListViewItem *item = m_sessionpanel->m_listview->firstChild();
00904   int idx = 0;
00905   while (item && idx < sessionId)
00906   {
00907     item = item->nextSibling();
00908     ++idx;
00909   }
00910   if (idx == sessionId && item)
00911   {
00912     // Required session item found, switch session with consistent behavior
00913     m_sessionpanel->m_listview->setSelected(item, true);
00914     m_sessionpanel->slotActivateSession();
00915   }
00916 }
00917 
00918 //-------------------------------------------
00919 KateSessionListActionMenu::KateSessionListActionMenu(KateMainWindow *mw, const TQString &text, TQObject *parent, const char *name)
00920   : TDEActionMenu(text, parent, name), m_mainWindow(mw)
00921 {
00922   connect(popupMenu(), TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(slotAboutToShow()));
00923 }
00924 
00925 //-------------------------------------------
00926 void KateSessionListActionMenu::slotAboutToShow()
00927 {
00928   popupMenu()->clear();
00929 
00930   TQPtrList<KateSession> &sessions = KateApp::self()->sessionManager()->getSessionsList();
00931   for (int idx = 0;  idx < (int)sessions.count();  ++idx)
00932   {
00933     popupMenu()->insertItem(sessions[idx]->getSessionName(), m_mainWindow, TQT_SLOT(activateSession(int)), 0, idx);
00934   }
00935 }
00936 
00937 // 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
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.7.1
This website is maintained by Timothy Pearson.