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 <tdeaboutdata.h> 00049 #include <tdeaction.h> 00050 #include <tdecmdlineargs.h> 00051 #include <kdebug.h> 00052 #include <kdialogbase.h> 00053 #include <tdediroperator.h> 00054 #include <kdockwidget.h> 00055 #include <kedittoolbar.h> 00056 #include <tdefiledialog.h> 00057 #include <kglobalaccel.h> 00058 #include <tdeglobal.h> 00059 #include <tdeglobalsettings.h> 00060 #include <kiconloader.h> 00061 #include <kkeydialog.h> 00062 #include <tdelocale.h> 00063 #include <tdemessagebox.h> 00064 #include <kmimetype.h> 00065 #include <kopenwith.h> 00066 #include <tdepopupmenu.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 <tdemultitabbar.h> 00077 #include <ktip.h> 00078 #include <tdemenubar.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 (TDEConfig *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("application-vnd.tde.tdemultiple"), 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("document-open"), 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 TDEAction *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 TDEAction( 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 TDEAction( 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 TDEAction(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 TDEToggleAction* showFullScreenAction = KStdAction::fullScreen( 0, 0, actionCollection(),this); 00270 connect( showFullScreenAction,TQT_SIGNAL(toggled(bool)), this,TQT_SLOT(slotFullScreen(bool))); 00271 00272 documentOpenWith = new TDEActionMenu(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 TDEAction* 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 TDEAction(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 TDEAction(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 TDEAction(i18n("Menu entry Session->New", "&New"), "document-new", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); 00306 new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); 00307 new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); 00308 new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); 00309 new TDEAction(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 TDEConfig *config = KateApp::self()->config (); 00406 00407 config->setGroup("General"); 00408 syncKonsole = config->readBoolEntry("Sync Konsole", true); 00409 useInstance = config->readBoolEntry("UseInstance", false); 00410 modNotification = config->readBoolEntry("Modified Notification", false); 00411 KateDocManager::self()->setSaveMetaInfos(config->readBoolEntry("Save Meta Infos", true)); 00412 KateDocManager::self()->setDaysMetaInfos(config->readNumEntry("Days Meta Infos", 30)); 00413 00414 m_viewManager->setShowFullPath(config->readBoolEntry("Show Full Path in Title", false)); 00415 00416 fileOpenRecent->setMaxItems( config->readNumEntry("Number of recent files", fileOpenRecent->maxItems() ) ); 00417 fileOpenRecent->loadEntries(config, "Recent Files"); 00418 00419 fileselector->readConfig(config, "fileselector"); 00420 } 00421 00422 void KateMainWindow::saveOptions () 00423 { 00424 TDEConfig *config = KateApp::self()->config (); 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 config->writeEntry("Days Meta Infos", KateDocManager::self()->getDaysMetaInfos()); 00434 config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath()); 00435 config->writeEntry("Sync Konsole", syncKonsole); 00436 config->writeEntry("UseInstance", useInstance); 00437 00438 fileOpenRecent->saveEntries(config, "Recent Files"); 00439 fileselector->writeConfig(config, "fileselector"); 00440 filelist->writeConfig(config, "Filelist"); 00441 00442 config->sync(); 00443 } 00444 00445 void KateMainWindow::slotWindowActivated () 00446 { 00447 if (m_viewManager->activeView()) 00448 { 00449 if (console && syncKonsole) 00450 { 00451 static TQString path; 00452 TQString newPath = m_viewManager->activeView()->getDoc()->url().directory(); 00453 00454 if ( newPath != path ) 00455 { 00456 path = newPath; 00457 console->cd (KURL( path )); 00458 } 00459 } 00460 00461 updateCaption (m_viewManager->activeView()->getDoc()); 00462 } 00463 00464 // update proxy 00465 centralWidget()->setFocusProxy (m_viewManager->activeView()); 00466 } 00467 00468 void KateMainWindow::slotUpdateOpenWith() 00469 { 00470 if (m_viewManager->activeView()) 00471 documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty()); 00472 else 00473 documentOpenWith->setEnabled(false); 00474 } 00475 00476 void KateMainWindow::documentMenuAboutToShow() 00477 { 00478 // remove documents 00479 while (documentMenu->count() > 3) 00480 documentMenu->removeItemAt (3); 00481 00482 TQListViewItem * item = filelist->firstChild(); 00483 while( item ) { 00484 // would it be saner to use the screen width as a limit that some random number?? 00485 TQString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 ); 00486 Kate::Document* doc = ((KateFileListItem *)item)->document(); 00487 documentMenu->insertItem ( 00488 doc->isModified() ? i18n("'document name [*]', [*] means modified", "%1 [*]").arg(name) : name, 00489 m_viewManager, TQT_SLOT (activateView (int)), 0, 00490 ((KateFileListItem *)item)->documentNumber () ); 00491 00492 item = item->nextSibling(); 00493 } 00494 if (m_viewManager->activeView()) 00495 documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true); 00496 } 00497 00498 void KateMainWindow::slotGrepToolItemSelected(const TQString &filename,int linenumber) 00499 { 00500 KURL fileURL; 00501 fileURL.setPath( filename ); 00502 m_viewManager->openURL( fileURL ); 00503 if ( m_viewManager->activeView() == 0 ) return; 00504 m_viewManager->activeView()->gotoLineNumber( linenumber ); 00505 raise(); 00506 setActiveWindow(); 00507 } 00508 00509 void KateMainWindow::dragEnterEvent( TQDragEnterEvent *event ) 00510 { 00511 event->accept(KURLDrag::canDecode(event)); 00512 } 00513 00514 void KateMainWindow::dropEvent( TQDropEvent *event ) 00515 { 00516 slotDropEvent(event); 00517 } 00518 00519 void KateMainWindow::slotDropEvent( TQDropEvent * event ) 00520 { 00521 KURL::List textlist; 00522 if (!KURLDrag::decode(event, textlist)) return; 00523 00524 for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i) 00525 { 00526 m_viewManager->openURL (*i); 00527 } 00528 } 00529 00530 void KateMainWindow::editKeys() 00531 { 00532 KKeyDialog dlg ( false, this ); 00533 00534 TQPtrList<KXMLGUIClient> clients = guiFactory()->clients(); 00535 00536 for( TQPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it ) 00537 dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() ); 00538 00539 dlg.insert( externalTools->actionCollection(), i18n("External Tools") ); 00540 00541 dlg.configure(); 00542 00543 TQPtrList<Kate::Document> l=KateDocManager::self()->documentList(); 00544 for (uint i=0;i<l.count();i++) { 00545 // kdDebug(13001)<<"reloading Keysettings for document "<<i<<endl; 00546 l.at(i)->reloadXML(); 00547 TQPtrList<class KTextEditor::View> l1=l.at(i)->views ();//KTextEditor::Document 00548 for (uint i1=0;i1<l1.count();i1++) { 00549 l1.at(i1)->reloadXML(); 00550 // kdDebug(13001)<<"reloading Keysettings for view "<<i<<"/"<<i1<<endl; 00551 } 00552 } 00553 00554 externalTools->actionCollection()->writeShortcutSettings( "Shortcuts", new TDEConfig("externaltools", false, false, "appdata") ); 00555 } 00556 00557 void KateMainWindow::openURL (const TQString &name) 00558 { 00559 m_viewManager->openURL (KURL(name)); 00560 } 00561 00562 void KateMainWindow::slotConfigure() 00563 { 00564 if (!m_viewManager->activeView()) 00565 return; 00566 00567 KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView()); 00568 dlg->exec(); 00569 00570 delete dlg; 00571 } 00572 00573 KURL KateMainWindow::activeDocumentUrl() 00574 { 00575 // anders: i make this one safe, as it may be called during 00576 // startup (by the file selector) 00577 Kate::View *v = m_viewManager->activeView(); 00578 if ( v ) 00579 return v->getDoc()->url(); 00580 return KURL(); 00581 } 00582 00583 void KateMainWindow::fileSelected(const KFileItem * /*file*/) 00584 { 00585 const KFileItemList *list=fileselector->dirOperator()->selectedItems(); 00586 KFileItem *tmp; 00587 for (KFileItemListIterator it(*list); (tmp = it.current()); ++it) 00588 { 00589 m_viewManager->openURL(tmp->url()); 00590 fileselector->dirOperator()->view()->setSelected(tmp,false); 00591 } 00592 } 00593 00594 // TODO make this work 00595 void KateMainWindow::mSlotFixOpenWithMenu() 00596 { 00597 //kdDebug(13001)<<"13000"<<"fixing open with menu"<<endl; 00598 documentOpenWith->popupMenu()->clear(); 00599 // get a list of appropriate services. 00600 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() ); 00601 //kdDebug(13001)<<"13000"<<"url: "<<m_viewManager->activeView()->getDoc()->url().prettyURL()<<"mime type: "<<mime->name()<<endl; 00602 // some checking goes here... 00603 TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), "Type == 'Application'"); 00604 // for each one, insert a menu item... 00605 for(TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) { 00606 if ((*it)->name() == "Kate") continue; 00607 documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() ); 00608 } 00609 // append "Other..." to call the TDE "open with" dialog. 00610 documentOpenWith->popupMenu()->insertItem(i18n("&Other...")); 00611 } 00612 00613 void KateMainWindow::slotOpenWithMenuAction(int idx) 00614 { 00615 KURL::List list; 00616 list.append( m_viewManager->activeView()->getDoc()->url() ); 00617 TQString appname = documentOpenWith->popupMenu()->text(idx); 00618 00619 appname = appname.remove('&'); //Remove a possible accelerator ... otherwise the application might not get found. 00620 if ( appname.compare(i18n("Other...")) == 0 ) { 00621 // display "open with" dialog 00622 KOpenWithDlg dlg(list); 00623 if (dlg.exec()) 00624 KRun::run(*dlg.service(), list); 00625 return; 00626 } 00627 00628 TQString qry = TQString("((Type == 'Application') and (Name == '%1'))").arg( appname.latin1() ); 00629 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() ); 00630 TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), qry); 00631 00632 if (!offers.isEmpty()) { 00633 KService::Ptr app = offers.first(); 00634 KRun::run(*app, list); 00635 } 00636 else 00637 KMessageBox::error(this, i18n("Application '%1' not found!").arg(appname.latin1()), i18n("Application Not Found!")); 00638 } 00639 00640 void KateMainWindow::pluginHelp() 00641 { 00642 KateApp::self()->invokeHelp (TQString::null, "kate-plugins"); 00643 } 00644 00645 void KateMainWindow::slotMail() 00646 { 00647 KateMailDialog *d = new KateMailDialog(this, this); 00648 if ( ! d->exec() ) 00649 { 00650 delete d; 00651 return; 00652 } 00653 TQPtrList<Kate::Document> attDocs = d->selectedDocs(); 00654 delete d; 00655 // Check that all selected files are saved (or shouldn't be) 00656 TQStringList urls; // to atthatch 00657 Kate::Document *doc; 00658 TQPtrListIterator<Kate::Document> it(attDocs); 00659 for ( ; it.current(); ++it ) { 00660 doc = it.current(); 00661 if (!doc) continue; 00662 if ( doc->url().isEmpty() ) { 00663 // unsaved document. back out unless it gets saved 00664 int r = KMessageBox::questionYesNo( this, 00665 i18n("<p>The current document has not been saved, and " 00666 "cannot be attached to an email message." 00667 "<p>Do you want to save it and proceed?"), 00668 i18n("Cannot Send Unsaved File"),KStdGuiItem::saveAs(),KStdGuiItem::cancel() ); 00669 if ( r == KMessageBox::Yes ) { 00670 Kate::View *v = (Kate::View*)doc->views().first(); 00671 int sr = v->saveAs(); 00672 if ( sr == Kate::View::SAVE_OK ) { ; 00673 } 00674 else { 00675 if ( sr != Kate::View::SAVE_CANCEL ) // ERROR or RETRY(?) 00676 KMessageBox::sorry( this, i18n("The file could not be saved. Please check " 00677 "if you have write permission.") ); 00678 continue; 00679 } 00680 } 00681 else 00682 continue; 00683 } 00684 if ( doc->isModified() ) { 00685 // warn that document is modified and offer to save it before proceeding. 00686 int r = KMessageBox::warningYesNoCancel( this, 00687 i18n("<p>The current file:<br><strong>%1</strong><br>has been " 00688 "modified. Modifications will not be available in the attachment." 00689 "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()), 00690 i18n("Save Before Sending?"), KStdGuiItem::save(), i18n("Do Not Save") ); 00691 switch ( r ) { 00692 case KMessageBox::Cancel: 00693 continue; 00694 case KMessageBox::Yes: 00695 doc->save(); 00696 if ( doc->isModified() ) { // read-only docs ends here, if modified. Hmm. 00697 KMessageBox::sorry( this, i18n("The file could not be saved. Please check " 00698 "if you have write permission.") ); 00699 continue; 00700 } 00701 break; 00702 default: 00703 break; 00704 } 00705 } 00706 // finally call the mailer 00707 urls << doc->url().url(); 00708 } // check selected docs done 00709 if ( ! urls.count() ) 00710 return; 00711 KateApp::self()->invokeMailer( TQString::null, // to 00712 TQString::null, // cc 00713 TQString::null, // bcc 00714 TQString::null, // subject 00715 TQString::null, // body 00716 TQString::null, // msgfile 00717 urls // urls to atthatch 00718 ); 00719 } 00720 void KateMainWindow::tipOfTheDay() 00721 { 00722 KTipDialog::showTip( /*0*/this, TQString::null, true ); 00723 } 00724 00725 void KateMainWindow::slotFullScreen(bool t) 00726 { 00727 if (t) 00728 showFullScreen(); 00729 else 00730 showNormal(); 00731 } 00732 00733 void KateMainWindow::updateGrepDir (bool visible) 00734 { 00735 // grepdlg gets hidden 00736 if (!visible) 00737 return; 00738 00739 if ( m_viewManager->activeView() ) 00740 { 00741 if ( m_viewManager->activeView()->getDoc()->url().isLocalFile() ) 00742 { 00743 greptool->updateDirName( m_viewManager->activeView()->getDoc()->url().directory() ); 00744 } 00745 } 00746 } 00747 00748 bool KateMainWindow::event( TQEvent *e ) 00749 { 00750 uint type = e->type(); 00751 if ( type == TQEvent::WindowActivate && modNotification ) 00752 { 00753 showModOnDiskPrompt(); 00754 } 00755 return KateMDI::MainWindow::event( e ); 00756 } 00757 00758 bool KateMainWindow::showModOnDiskPrompt() 00759 { 00760 Kate::Document *doc; 00761 00762 DocVector list( KateDocManager::self()->documents() ); 00763 uint cnt = 0; 00764 for( doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() ) 00765 { 00766 if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDisc ) 00767 { 00768 list.insert( cnt, doc ); 00769 cnt++; 00770 } 00771 } 00772 00773 if ( cnt && !m_modignore ) 00774 { 00775 list.resize( cnt ); 00776 KateMwModOnHdDialog mhdlg( list, this ); 00777 m_modignore = true; 00778 bool res = mhdlg.exec(); 00779 m_modignore = false; 00780 00781 return res; 00782 } 00783 return true; 00784 } 00785 00786 void KateMainWindow::slotDocumentCreated (Kate::Document *doc) 00787 { 00788 connect(doc,TQT_SIGNAL(modStateChanged(Kate::Document *)),this,TQT_SLOT(updateCaption(Kate::Document *))); 00789 connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotNameChanged(Kate::Document *))); 00790 connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotUpdateOpenWith())); 00791 00792 updateCaption (doc); 00793 } 00794 00795 void KateMainWindow::slotNameChanged(Kate::Document *doc) 00796 { 00797 updateCaption(doc); 00798 if (!doc->url().isEmpty()) 00799 fileOpenRecent->addURL(doc->url()); 00800 } 00801 00802 void KateMainWindow::updateCaption (Kate::Document *doc) 00803 { 00804 if (!m_viewManager->activeView()) 00805 { 00806 setCaption ("", false); 00807 return; 00808 } 00809 00810 if (!(m_viewManager->activeView()->getDoc() == doc)) 00811 return; 00812 00813 TQString c; 00814 if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath())) 00815 { 00816 c = m_viewManager->activeView()->getDoc()->docName(); 00817 } 00818 else 00819 { 00820 c = m_viewManager->activeView()->getDoc()->url().prettyURL(); 00821 } 00822 00823 TQString sessName = KateApp::self()->sessionManager()->activeSession()->sessionName(); 00824 if ( !sessName.isEmpty() ) 00825 sessName = TQString("%1: ").arg( sessName ); 00826 00827 setCaption( sessName + KStringHandler::lsqueeze(c,64), 00828 m_viewManager->activeView()->getDoc()->isModified()); 00829 } 00830 00831 void KateMainWindow::saveProperties(TDEConfig *config) 00832 { 00833 TQString grp=config->group(); 00834 00835 saveSession(config, grp); 00836 m_viewManager->saveViewConfiguration (config, grp); 00837 00838 config->setGroup(grp); 00839 } 00840 00841 void KateMainWindow::readProperties(TDEConfig *config) 00842 { 00843 TQString grp=config->group(); 00844 00845 startRestore(config, grp); 00846 finishRestore (); 00847 m_viewManager->restoreViewConfiguration (config, grp); 00848 00849 config->setGroup(grp); 00850 } 00851 00852 void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) 00853 { 00854 KateDocManager::self()->saveDocumentList (sessionConfig); 00855 00856 sessionConfig->setGroup("General"); 00857 sessionConfig->writeEntry ("Last Session", KateApp::self()->sessionManager()->activeSession()->sessionFileRelative()); 00858 } 00859 00860 // kate: space-indent on; indent-width 2; replace-tabs on;