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 { 00349 return false; 00350 } 00351 00352 TQPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList(); 00353 bool shutdown = (modifiedDocuments.count() == 0); 00354 00355 if (!shutdown) 00356 { 00357 shutdown = KateSaveModifiedDialog::queryClose(this,modifiedDocuments); 00358 } 00359 00360 if ( KateDocManager::self()->documents() > documentCount ) { 00361 KMessageBox::information (this, 00362 i18n ("New file opened while trying to close Kate, closing aborted."), 00363 i18n ("Closing Aborted")); 00364 return false; 00365 } 00366 00367 if (!shutdown) 00368 { 00369 return false; 00370 } 00371 00372 return KateApp::self()->query_session_close(); 00373 } 00374 00378 bool KateMainWindow::queryClose() 00379 { 00380 // session saving, can we close all views ? 00381 // just test, not close them actually 00382 if (KateApp::self()->sessionSaving()) 00383 { 00384 return queryClose_internal(); 00385 } 00386 00387 // normal closing of window 00388 // allow to close all windows until the last without restrictions 00389 if (KateApp::self()->mainWindows() > 1) 00390 { 00391 return true; 00392 } 00393 00394 // last one: check if we can close all documents and sessions, try run 00395 // and save docs if we really close down ! 00396 if (queryClose_internal()) 00397 { 00398 // detach the dcopClient 00399 KateApp::self()->dcopClient()->detach(); 00400 return true; 00401 } 00402 00403 return false; 00404 } 00405 00406 void KateMainWindow::newWindow () 00407 { 00408 KateApp::self()->newMainWindow (); 00409 } 00410 00411 void KateMainWindow::slotEditToolbars() 00412 { 00413 saveMainWindowSettings( KateApp::self()->config(), "MainWindow" ); 00414 KEditToolbar dlg( factory() ); 00415 connect( &dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(slotNewToolbarConfig()) ); 00416 dlg.exec(); 00417 } 00418 00419 void KateMainWindow::slotNewToolbarConfig() 00420 { 00421 applyMainWindowSettings( KateApp::self()->config(), "MainWindow" ); 00422 } 00423 00424 void KateMainWindow::slotFileQuit() 00425 { 00426 KateApp::self()->shutdownKate(this); 00427 } 00428 00429 void KateMainWindow::readOptions () 00430 { 00431 TDEConfig *config = KateApp::self()->config (); 00432 00433 config->setGroup("General"); 00434 showSessionName = config->readBoolEntry("Show session name", false); 00435 syncKonsole = config->readBoolEntry("Sync Konsole", true); 00436 useInstance = config->readBoolEntry("UseInstance", false); 00437 modNotification = config->readBoolEntry("Modified Notification", false); 00438 KateDocManager::self()->setSaveMetaInfos(config->readBoolEntry("Save Meta Infos", true)); 00439 KateDocManager::self()->setDaysMetaInfos(config->readNumEntry("Days Meta Infos", 30)); 00440 00441 m_viewManager->setShowFullPath(config->readBoolEntry("Show Full Path in Title", false)); 00442 00443 fileOpenRecent->setMaxItems( config->readNumEntry("Number of recent files", fileOpenRecent->maxItems() ) ); 00444 fileOpenRecent->loadEntries(config, "Recent Files"); 00445 00446 fileselector->readConfig(config, "fileselector"); 00447 } 00448 00449 void KateMainWindow::saveOptions () 00450 { 00451 TDEConfig *config = KateApp::self()->config (); 00452 config->setGroup("General"); 00453 00454 if (console) 00455 config->writeEntry("Show Console", console->isVisible()); 00456 else 00457 config->writeEntry("Show Console", false); 00458 00459 config->writeEntry("Show session name", showSessionName); 00460 config->writeEntry("Save Meta Infos", KateDocManager::self()->getSaveMetaInfos()); 00461 config->writeEntry("Days Meta Infos", KateDocManager::self()->getDaysMetaInfos()); 00462 config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath()); 00463 config->writeEntry("Sync Konsole", syncKonsole); 00464 config->writeEntry("UseInstance", useInstance); 00465 00466 fileOpenRecent->saveEntries(config, "Recent Files"); 00467 fileselector->writeConfig(config, "fileselector"); 00468 filelist->writeConfig(config, "Filelist"); 00469 00470 config->sync(); 00471 } 00472 00473 void KateMainWindow::slotWindowActivated () 00474 { 00475 if (m_viewManager->activeView()) 00476 { 00477 if (console && syncKonsole) 00478 { 00479 static TQString path; 00480 TQString newPath = m_viewManager->activeView()->getDoc()->url().directory(); 00481 00482 if ( newPath != path ) 00483 { 00484 path = newPath; 00485 console->cd (KURL( path )); 00486 } 00487 } 00488 00489 updateCaption (m_viewManager->activeView()->getDoc()); 00490 } 00491 00492 // update proxy 00493 centralWidget()->setFocusProxy (m_viewManager->activeView()); 00494 } 00495 00496 void KateMainWindow::slotUpdateOpenWith() 00497 { 00498 if (m_viewManager->activeView()) 00499 documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty()); 00500 else 00501 documentOpenWith->setEnabled(false); 00502 } 00503 00504 void KateMainWindow::documentMenuAboutToShow() 00505 { 00506 // remove documents 00507 while (documentMenu->count() > 3) 00508 documentMenu->removeItemAt (3); 00509 00510 TQListViewItem * item = filelist->firstChild(); 00511 while( item ) { 00512 // would it be saner to use the screen width as a limit that some random number?? 00513 TQString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 ); 00514 Kate::Document* doc = ((KateFileListItem *)item)->document(); 00515 documentMenu->insertItem ( 00516 doc->isModified() ? i18n("'document name [*]', [*] means modified", "%1 [*]").arg(name) : name, 00517 m_viewManager, TQT_SLOT (activateView (int)), 0, 00518 ((KateFileListItem *)item)->documentNumber () ); 00519 00520 item = item->nextSibling(); 00521 } 00522 if (m_viewManager->activeView()) 00523 documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true); 00524 } 00525 00526 void KateMainWindow::slotGrepToolItemSelected(const TQString &filename,int linenumber) 00527 { 00528 KURL fileURL; 00529 fileURL.setPath( filename ); 00530 m_viewManager->openURL( fileURL ); 00531 if ( m_viewManager->activeView() == 0 ) return; 00532 m_viewManager->activeView()->gotoLineNumber( linenumber ); 00533 raise(); 00534 setActiveWindow(); 00535 } 00536 00537 void KateMainWindow::dragEnterEvent( TQDragEnterEvent *event ) 00538 { 00539 event->accept(KURLDrag::canDecode(event)); 00540 } 00541 00542 void KateMainWindow::dropEvent( TQDropEvent *event ) 00543 { 00544 slotDropEvent(event); 00545 } 00546 00547 void KateMainWindow::slotDropEvent( TQDropEvent * event ) 00548 { 00549 KURL::List textlist; 00550 if (!KURLDrag::decode(event, textlist)) return; 00551 00552 for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i) 00553 { 00554 m_viewManager->openURL (*i); 00555 } 00556 } 00557 00558 void KateMainWindow::editKeys() 00559 { 00560 KKeyDialog dlg ( false, this ); 00561 00562 TQPtrList<KXMLGUIClient> clients = guiFactory()->clients(); 00563 00564 for( TQPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it ) 00565 dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() ); 00566 00567 dlg.insert( externalTools->actionCollection(), i18n("External Tools") ); 00568 00569 dlg.configure(); 00570 00571 TQPtrList<Kate::Document> l=KateDocManager::self()->documentList(); 00572 for (uint i=0;i<l.count();i++) { 00573 // kdDebug(13001)<<"reloading Keysettings for document "<<i<<endl; 00574 l.at(i)->reloadXML(); 00575 TQPtrList<class KTextEditor::View> l1=l.at(i)->views ();//KTextEditor::Document 00576 for (uint i1=0;i1<l1.count();i1++) { 00577 l1.at(i1)->reloadXML(); 00578 // kdDebug(13001)<<"reloading Keysettings for view "<<i<<"/"<<i1<<endl; 00579 } 00580 } 00581 00582 externalTools->actionCollection()->writeShortcutSettings( "Shortcuts", new TDEConfig("externaltools", false, false, "appdata") ); 00583 } 00584 00585 void KateMainWindow::openURL (const TQString &name) 00586 { 00587 m_viewManager->openURL (KURL(name)); 00588 } 00589 00590 void KateMainWindow::slotConfigure() 00591 { 00592 if (!m_viewManager->activeView()) 00593 return; 00594 00595 KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView()); 00596 dlg->exec(); 00597 00598 delete dlg; 00599 00600 // Inform Kate that options may have been changed 00601 KateApp::self()->reparse_config(); 00602 } 00603 00604 KURL KateMainWindow::activeDocumentUrl() 00605 { 00606 // anders: i make this one safe, as it may be called during 00607 // startup (by the file selector) 00608 Kate::View *v = m_viewManager->activeView(); 00609 if ( v ) 00610 return v->getDoc()->url(); 00611 return KURL(); 00612 } 00613 00614 void KateMainWindow::fileSelected(const KFileItem * /*file*/) 00615 { 00616 const KFileItemList *list=fileselector->dirOperator()->selectedItems(); 00617 KFileItem *tmp; 00618 for (KFileItemListIterator it(*list); (tmp = it.current()); ++it) 00619 { 00620 m_viewManager->openURL(tmp->url()); 00621 fileselector->dirOperator()->view()->setSelected(tmp,false); 00622 } 00623 } 00624 00625 // TODO make this work 00626 void KateMainWindow::mSlotFixOpenWithMenu() 00627 { 00628 //kdDebug(13001)<<"13000"<<"fixing open with menu"<<endl; 00629 documentOpenWith->popupMenu()->clear(); 00630 // get a list of appropriate services. 00631 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() ); 00632 //kdDebug(13001)<<"13000"<<"url: "<<m_viewManager->activeView()->getDoc()->url().prettyURL()<<"mime type: "<<mime->name()<<endl; 00633 // some checking goes here... 00634 TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), "Type == 'Application'"); 00635 // for each one, insert a menu item... 00636 for(TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) { 00637 if ((*it)->name() == "Kate") continue; 00638 documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() ); 00639 } 00640 // append "Other..." to call the TDE "open with" dialog. 00641 documentOpenWith->popupMenu()->insertItem(i18n("&Other...")); 00642 } 00643 00644 void KateMainWindow::slotOpenWithMenuAction(int idx) 00645 { 00646 KURL::List list; 00647 list.append( m_viewManager->activeView()->getDoc()->url() ); 00648 TQString appname = documentOpenWith->popupMenu()->text(idx); 00649 00650 appname = appname.remove('&'); //Remove a possible accelerator ... otherwise the application might not get found. 00651 if ( appname.compare(i18n("Other...")) == 0 ) { 00652 // display "open with" dialog 00653 KOpenWithDlg dlg(list); 00654 if (dlg.exec()) 00655 KRun::run(*dlg.service(), list); 00656 return; 00657 } 00658 00659 TQString qry = TQString("((Type == 'Application') and (Name == '%1'))").arg( appname.latin1() ); 00660 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() ); 00661 TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), qry); 00662 00663 if (!offers.isEmpty()) { 00664 KService::Ptr app = offers.first(); 00665 KRun::run(*app, list); 00666 } 00667 else 00668 KMessageBox::error(this, i18n("Application '%1' not found!").arg(appname.latin1()), i18n("Application Not Found!")); 00669 } 00670 00671 void KateMainWindow::pluginHelp() 00672 { 00673 KateApp::self()->invokeHelp (TQString::null, "kate-plugins"); 00674 } 00675 00676 void KateMainWindow::slotMail() 00677 { 00678 KateMailDialog *d = new KateMailDialog(this, this); 00679 if ( ! d->exec() ) 00680 { 00681 delete d; 00682 return; 00683 } 00684 TQPtrList<Kate::Document> attDocs = d->selectedDocs(); 00685 delete d; 00686 // Check that all selected files are saved (or shouldn't be) 00687 TQStringList urls; // to atthatch 00688 Kate::Document *doc; 00689 TQPtrListIterator<Kate::Document> it(attDocs); 00690 for ( ; it.current(); ++it ) { 00691 doc = it.current(); 00692 if (!doc) continue; 00693 if ( doc->url().isEmpty() ) { 00694 // unsaved document. back out unless it gets saved 00695 int r = KMessageBox::questionYesNo( this, 00696 i18n("<p>The current document has not been saved, and " 00697 "cannot be attached to an email message." 00698 "<p>Do you want to save it and proceed?"), 00699 i18n("Cannot Send Unsaved File"),KStdGuiItem::saveAs(),KStdGuiItem::cancel() ); 00700 if ( r == KMessageBox::Yes ) { 00701 Kate::View *v = (Kate::View*)doc->views().first(); 00702 int sr = v->saveAs(); 00703 if ( sr == Kate::View::SAVE_OK ) { ; 00704 } 00705 else { 00706 if ( sr != Kate::View::SAVE_CANCEL ) // ERROR or RETRY(?) 00707 KMessageBox::sorry( this, i18n("The file could not be saved. Please check " 00708 "if you have write permission.") ); 00709 continue; 00710 } 00711 } 00712 else 00713 continue; 00714 } 00715 if ( doc->isModified() ) { 00716 // warn that document is modified and offer to save it before proceeding. 00717 int r = KMessageBox::warningYesNoCancel( this, 00718 i18n("<p>The current file:<br><strong>%1</strong><br>has been " 00719 "modified. Modifications will not be available in the attachment." 00720 "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()), 00721 i18n("Save Before Sending?"), KStdGuiItem::save(), i18n("Do Not Save") ); 00722 switch ( r ) { 00723 case KMessageBox::Cancel: 00724 continue; 00725 case KMessageBox::Yes: 00726 doc->save(); 00727 if ( doc->isModified() ) { // read-only docs ends here, if modified. Hmm. 00728 KMessageBox::sorry( this, i18n("The file could not be saved. Please check " 00729 "if you have write permission.") ); 00730 continue; 00731 } 00732 break; 00733 default: 00734 break; 00735 } 00736 } 00737 // finally call the mailer 00738 urls << doc->url().url(); 00739 } // check selected docs done 00740 if ( ! urls.count() ) 00741 return; 00742 KateApp::self()->invokeMailer( TQString::null, // to 00743 TQString::null, // cc 00744 TQString::null, // bcc 00745 TQString::null, // subject 00746 TQString::null, // body 00747 TQString::null, // msgfile 00748 urls // urls to atthatch 00749 ); 00750 } 00751 void KateMainWindow::tipOfTheDay() 00752 { 00753 KTipDialog::showTip( /*0*/this, TQString::null, true ); 00754 } 00755 00756 void KateMainWindow::slotFullScreen(bool t) 00757 { 00758 if (t) 00759 showFullScreen(); 00760 else 00761 showNormal(); 00762 } 00763 00764 void KateMainWindow::updateGrepDir (bool visible) 00765 { 00766 // grepdlg gets hidden 00767 if (!visible) 00768 return; 00769 00770 if ( m_viewManager->activeView() ) 00771 { 00772 if ( m_viewManager->activeView()->getDoc()->url().isLocalFile() ) 00773 { 00774 greptool->updateDirName( m_viewManager->activeView()->getDoc()->url().directory() ); 00775 } 00776 } 00777 } 00778 00779 bool KateMainWindow::event( TQEvent *e ) 00780 { 00781 uint type = e->type(); 00782 if ( type == TQEvent::WindowActivate && modNotification ) 00783 { 00784 showModOnDiskPrompt(); 00785 } 00786 return KateMDI::MainWindow::event( e ); 00787 } 00788 00789 bool KateMainWindow::showModOnDiskPrompt() 00790 { 00791 Kate::Document *doc; 00792 00793 DocVector list( KateDocManager::self()->documents() ); 00794 uint cnt = 0; 00795 for( doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() ) 00796 { 00797 if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDisc ) 00798 { 00799 list.insert( cnt, doc ); 00800 cnt++; 00801 } 00802 } 00803 00804 if ( cnt && !m_modignore ) 00805 { 00806 list.resize( cnt ); 00807 KateMwModOnHdDialog mhdlg( list, this ); 00808 m_modignore = true; 00809 bool res = mhdlg.exec(); 00810 m_modignore = false; 00811 00812 return res; 00813 } 00814 return true; 00815 } 00816 00817 void KateMainWindow::slotDocumentCreated (Kate::Document *doc) 00818 { 00819 connect(doc,TQT_SIGNAL(modStateChanged(Kate::Document *)),this,TQT_SLOT(updateCaption(Kate::Document *))); 00820 connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotNameChanged(Kate::Document *))); 00821 connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotUpdateOpenWith())); 00822 00823 updateCaption (doc); 00824 } 00825 00826 void KateMainWindow::slotNameChanged(Kate::Document *doc) 00827 { 00828 updateCaption(doc); 00829 if (!doc->url().isEmpty()) 00830 fileOpenRecent->addURL(doc->url()); 00831 } 00832 00833 void KateMainWindow::updateCaption(Kate::Document *doc) 00834 { 00835 if (!m_viewManager->activeView()) 00836 { 00837 setCaption ("", false); 00838 return; 00839 } 00840 00841 if (!(m_viewManager->activeView()->getDoc() == doc)) 00842 return; 00843 00844 TQString c; 00845 if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath())) 00846 { 00847 c = m_viewManager->activeView()->getDoc()->docName(); 00848 } 00849 else 00850 { 00851 c = m_viewManager->activeView()->getDoc()->url().prettyURL(); 00852 } 00853 00854 if (showSessionName) 00855 { 00856 TQString sessName = KateApp::self()->sessionManager()->getActiveSessionName(); 00857 if (!sessName.isEmpty()) 00858 { 00859 sessName = TQString("%1: ").arg(sessName); 00860 } 00861 setCaption(KStringHandler::lsqueeze(sessName,32) + KStringHandler::lsqueeze(c,64), 00862 m_viewManager->activeView()->getDoc()->isModified()); 00863 } 00864 else 00865 { 00866 setCaption(KStringHandler::lsqueeze(c,64), m_viewManager->activeView()->getDoc()->isModified()); 00867 } 00868 } 00869 00870 void KateMainWindow::saveProperties(TDEConfig *config) 00871 { 00872 TQString grp=config->group(); 00873 00874 saveSession(config, grp); 00875 m_viewManager->saveViewConfiguration (config, grp); 00876 00877 config->setGroup(grp); 00878 } 00879 00880 void KateMainWindow::readProperties(TDEConfig *config) 00881 { 00882 TQString grp=config->group(); 00883 00884 startRestore(config, grp); 00885 finishRestore (); 00886 m_viewManager->restoreViewConfiguration (config, grp); 00887 00888 config->setGroup(grp); 00889 } 00890 00891 //------------------------------------------- 00892 void KateMainWindow::slotSelectionChanged() 00893 { 00894 TDEActionCollection *mwac = actionCollection(); // Main Window Action Collection 00895 TDEActionPtrList actionList = m_sessionpanel->m_actionCollection->actions(); 00896 TDEActionPtrList::ConstIterator spa_it; 00897 for (spa_it = actionList.begin(); spa_it != actionList.end(); ++spa_it) 00898 { 00899 TDEAction *a = mwac->action((*spa_it)->name()); 00900 TDEToggleAction *ta = dynamic_cast<TDEToggleAction*>(a); 00901 if (ta) 00902 { 00903 ta->setChecked((dynamic_cast<TDEToggleAction*>(*spa_it))->isChecked()); 00904 } 00905 if (a) 00906 { 00907 a->setEnabled((*spa_it)->isEnabled()); 00908 } 00909 } 00910 } 00911 00912 //------------------------------------------- 00913 void KateMainWindow::activateSession(int sessionId) 00914 { 00915 if (sessionId < 0 || sessionId == KateApp::self()->sessionManager()->getActiveSessionId()) 00916 { 00917 return; 00918 } 00919 00920 // Select the required session in the session panel's listview 00921 TQListViewItem *item = m_sessionpanel->m_listview->firstChild(); 00922 int idx = 0; 00923 while (item && idx < sessionId) 00924 { 00925 item = item->nextSibling(); 00926 ++idx; 00927 } 00928 if (idx == sessionId && item) 00929 { 00930 // Required session item found, switch session with consistent behavior 00931 m_sessionpanel->m_listview->setSelected(item, true); 00932 m_sessionpanel->slotActivateSession(); 00933 } 00934 } 00935 00936 //------------------------------------------- 00937 KateSessionListActionMenu::KateSessionListActionMenu(KateMainWindow *mw, const TQString &text, TQObject *parent, const char *name) 00938 : TDEActionMenu(text, parent, name), m_mainWindow(mw) 00939 { 00940 connect(popupMenu(), TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(slotAboutToShow())); 00941 } 00942 00943 //------------------------------------------- 00944 void KateSessionListActionMenu::slotAboutToShow() 00945 { 00946 popupMenu()->clear(); 00947 00948 TQPtrList<KateSession> &sessions = KateApp::self()->sessionManager()->getSessionsList(); 00949 for (int idx = 0; idx < (int)sessions.count(); ++idx) 00950 { 00951 popupMenu()->insertItem(sessions[idx]->getSessionName(), m_mainWindow, TQT_SLOT(activateSession(int)), 0, idx); 00952 } 00953 } 00954 00955 // kate: space-indent on; indent-width 2; replace-tabs on;
Trinity API Reference