00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "katemainwindow.h"
00023
#include "katemainwindow.moc"
00024
00025
#include "kateconfigdialog.h"
00026
#include "kateconsole.h"
00027
#include "katedocmanager.h"
00028
#include "katepluginmanager.h"
00029
#include "kateconfigplugindialogpage.h"
00030
#include "kateviewmanager.h"
00031
#include "kateapp.h"
00032
#include "kateprojectlist.h"
00033
#include "kateprojectviews.h"
00034
#include "katefileselector.h"
00035
#include "katefilelist.h"
00036
#include "kategrepdialog.h"
00037
#include "katemailfilesdialog.h"
00038
#include "katemainwindowiface.h"
00039
00040
#include <kmdichildview.h>
00041
#include <dcopclient.h>
00042
#include <kinstance.h>
00043
#include <kaboutdata.h>
00044
#include <kaction.h>
00045
#include <kapplication.h>
00046
#include <kcmdlineargs.h>
00047
#include <kdebug.h>
00048
#include <kdialogbase.h>
00049
#include <kdiroperator.h>
00050
#include <kdockwidget.h>
00051
#include <kedittoolbar.h>
00052
#include <kfiledialog.h>
00053
#include <kglobalaccel.h>
00054
#include <kglobal.h>
00055
#include <kglobalsettings.h>
00056
#include <kiconloader.h>
00057
#include <kkeydialog.h>
00058
#include <klocale.h>
00059
#include <kmessagebox.h>
00060
#include <kmimetype.h>
00061
#include <kopenwith.h>
00062
#include <kpopupmenu.h>
00063
#include <ksimpleconfig.h>
00064
#include <kstatusbar.h>
00065
#include <kstdaction.h>
00066
#include <kstandarddirs.h>
00067
#include <ktrader.h>
00068
#include <kuniqueapplication.h>
00069
#include <kurldrag.h>
00070
#include <kdesktopfile.h>
00071
#include <khelpmenu.h>
00072
#include <ktip.h>
00073
#include <kmenubar.h>
00074
00075
#include <qlayout.h>
00076
00077
#include <assert.h>
00078
#include <unistd.h>
00079
00080
00081 uint KateMainWindow::uniqueID = 1;
00082 KMdi::MdiMode KateMainWindow::defaultMode=KMdi::UndefinedMode;
00083
00084 KateMainWindow::KateMainWindow(KateDocManager *_m_docManager, KatePluginManager *_m_pluginManager,
00085 KateProjectManager *projectMan, KMdi::MdiMode guiMode) :
00086 KMdiMainFrm (0,(QString(
"__KateMainWindow#%1").arg(uniqueID)).latin1(),guiMode)
00087 {
00088
00089 myID = uniqueID;
00090 uniqueID++;
00091
00092
00093 m_docManager = _m_docManager;
00094 m_pluginManager =_m_pluginManager;
00095 m_projectManager = projectMan;
00096
00097 m_project = 0;
00098 m_projectNumber = 0;
00099
00100 activeView = 0;
00101
00102 console = 0;
00103 greptool = 0;
00104
00105
00106 KConfig *config = kapp->config();
00107
00108
00109
if (!initialGeometrySet())
00110 {
00111 config->setGroup (
"Kate Main Window");
00112
int scnum = QApplication::desktop()->screenNumber(parentWidget());
00113 QRect desk = QApplication::desktop()->screenGeometry(scnum);
00114 QSize s ( config->readNumEntry( QString::fromLatin1(
"Width %1").arg(desk.width()), 700 ),
00115 config->readNumEntry( QString::fromLatin1(
"Height %1").arg(desk.height()), 480 ) );
00116
00117 resize (kMin (s.width(), desk.width()), kMin(s.height(), desk.height()));
00118 }
00119
00120 m_mainWindow =
new Kate::MainWindow (
this);
00121 m_toolViewManager =
new Kate::ToolViewManager (
this);
00122 setStandardMDIMenuEnabled(
false);
00123 setManagedDockPositionModeEnabled(
true);
00124
00125 m_dcop =
new KateMainWindowDCOPIface (
this);
00126
00127
00128 setupMainWindow();
00129
00130
00131 setupActions();
00132 projectlist->setupActions();
00133
00134 setStandardToolBarMenuEnabled(
true );
00135 setXMLFile(
"kateui.rc" );
00136 createShellGUI (
true );
00137
00138 m_pluginManager->enableAllPluginsGUI (
this);
00139
00140
00141 documentMenu = (QPopupMenu*)factory()->container(
"documents",
this);
00142 connect(documentMenu, SIGNAL(aboutToShow()),
this, SLOT(documentMenuAboutToShow()));
00143
00144 connect(m_projectManager->projectManager(),SIGNAL(projectDeleted(uint)),
this,SLOT(projectDeleted(uint)));
00145
00146
00147
for (uint i = 0; i < m_docManager->documents(); i++)
00148 slotDocumentCreated (m_docManager->document(i));
00149
00150 connect(m_docManager,SIGNAL(documentCreated(Kate::Document *)),
this,SLOT(slotDocumentCreated(Kate::Document *)));
00151
00152 readOptions(config);
00153
00154
if (console)
00155 console->loadConsoleIfNeeded();
00156
00157 setAcceptDrops(
true);
00158 }
00159
00160 KateMainWindow::~KateMainWindow()
00161 {
00162 saveOptions(kapp->config());
00163
00164 ((KateApp *)kapp)->removeMainWindow (
this);
00165
00166 m_pluginManager->disableAllPluginsGUI (
this);
00167
00168
delete m_dcop;
00169
delete kscript;
00170 }
00171
00172
void KateMainWindow::setupMainWindow ()
00173 {
00174 greptool =
new GrepTool(
this,
"greptool" );
00175 greptool->installEventFilter(
this );
00176 connect(greptool, SIGNAL(itemSelected(
const QString &,
int)),
this, SLOT(slotGrepToolItemSelected(
const QString &,
int)));
00177
00178 greptool->show();
00179 greptool->hide();
00180
00181 KMdiChildView* pMDICover =
new KMdiChildView(
"MainDock");
00182 pMDICover->setName(
"MainDock");
00183
00184
00185 QBoxLayout *ml=
new QHBoxLayout(pMDICover);
00186 ml->setAutoAdd(
true);
00187 m_viewManager =
new KateViewManager (pMDICover, m_docManager,
this);
00188 addWindow(pMDICover);
00189 m_viewManager->show();
00190 pMDICover->show();
00191
00192 filelist =
new KateFileList (m_docManager, m_viewManager,
this,
"filelist");
00193 addToolView(KDockWidget::DockLeft,filelist,SmallIcon(
"kmultiple"), i18n(
"Files"));
00194
00195 QVBox *prBox =
new QVBox (
this,
"projects");
00196 addToolView(KDockWidget::DockLeft,prBox,SmallIcon(
"view_tree"), i18n(
"Projects"));
00197 projectlist =
new KateProjectList (m_projectManager,
this, prBox,
"projectlist");
00198 projectviews =
new KateProjectViews (m_projectManager,
this, prBox,
"projectviews");
00199 prBox->setStretchFactor(projectviews, 2);
00200 prBox->show ();
00201 projectlist->show ();
00202 projectviews->show ();
00203
00204 fileselector =
new KateFileSelector(
this, m_viewManager,
this,
"operator");
00205 addToolView(KDockWidget::DockLeft,fileselector, SmallIcon(
"fileopen"), i18n(
"Selector"));
00206
00207
00208 addToolView( KDockWidget::DockBottom, greptool, SmallIcon(
"filefind"), i18n(
"Find in Files") );
00209
if (kapp->authorize(
"shell_access"))
00210 {
00211 console =
new KateConsole (
this,
"console",viewManager());
00212 console->installEventFilter(
this );
00213 addToolView(KDockWidget::DockBottom,console, SmallIcon(
"konsole"), i18n(
"Terminal"));
00214 }
00215
00216 connect(fileselector->dirOperator(),SIGNAL(fileSelected(
const KFileItem*)),
this,SLOT(fileSelected(
const KFileItem*)));
00217 }
00218
00219
void KateMainWindow::setupActions()
00220 {
00221 KAction *a;
00222
00223 kscript =
new KScriptManager(
this,
"scriptmanager");
00224 scriptMenu =
new KActionMenu( i18n(
"KDE Scri&pts"), actionCollection(),
"scripts");
00225 scriptMenu->setWhatsThis(i18n(
"This shows all available scripts and allows them to be executed."));
00226 setupScripts();
00227 connect( scriptMenu->popupMenu(), SIGNAL(activated(
int)),
this, SLOT(runScript(
int )) );
00228
00229 KStdAction::openNew( m_viewManager, SLOT( slotDocumentNew() ), actionCollection(),
"file_new" )->setWhatsThis(i18n(
"Create a new document"));
00230 KStdAction::open( m_viewManager, SLOT( slotDocumentOpen() ), actionCollection(),
"file_open" )->setWhatsThis(i18n(
"Open an existing document for editing"));
00231
00232 fileOpenRecent = KStdAction::openRecent (m_viewManager, SLOT(openURL (
const KURL&)), actionCollection());
00233 fileOpenRecent->setWhatsThis(i18n(
"This lists files which you have opened recently, and allows you to easily open them again."));
00234
00235 a=
new KAction( i18n(
"Save A&ll"),
"save_all", CTRL+Key_L, m_viewManager, SLOT( slotDocumentSaveAll() ), actionCollection(),
"file_save_all" );
00236 a->setWhatsThis(i18n(
"Save all open, modified documents to disc."));
00237
00238 KStdAction::close( m_viewManager, SLOT( slotDocumentClose() ), actionCollection(),
"file_close" )->setWhatsThis(i18n(
"Close the current document."));
00239
00240 a=
new KAction( i18n(
"Clos&e All" ), 0, m_viewManager, SLOT( slotDocumentCloseAll() ), actionCollection(),
"file_close_all" );
00241 a->setWhatsThis(i18n(
"Close all open documents."));
00242
00243 KStdAction::mail(
this, SLOT(slotMail()), actionCollection() )->setWhatsThis(i18n(
"Send one or more of the open documents as email attachments."));
00244
00245 KStdAction::quit(
this, SLOT( slotFileQuit() ), actionCollection(),
"file_quit" )->setWhatsThis(i18n(
"Close this window"));
00246
00247 a=
new KAction(i18n(
"&New Window"),
"window_new", 0,
this, SLOT(newWindow()), actionCollection(),
"view_new_view");
00248 a->setWhatsThis(i18n(
"Create a new Kate view (a new window with the same document list)."));
00249
00250 a=
new KAction( i18n(
"Split &Vertical"),
"view_left_right", CTRL+SHIFT+Key_L, m_viewManager, SLOT( slotSplitViewSpaceVert() ), actionCollection(),
"view_split_vert");
00251 a->setWhatsThis(i18n(
"Split the currently active view vertically into two views."));
00252
00253 a=
new KAction( i18n(
"Split &Horizontal"),
"view_top_bottom", CTRL+SHIFT+Key_T, m_viewManager, SLOT( slotSplitViewSpaceHoriz() ), actionCollection(),
"view_split_horiz");
00254 a->setWhatsThis(i18n(
"Split the currently active view horizontally into two views."));
00255
00256 a=closeCurrentViewSpace =
new KAction( i18n(
"Close &Current View"),
"view_remove", CTRL+SHIFT+Key_R, m_viewManager, SLOT( slotCloseCurrentViewSpace() ), actionCollection(),
"view_close_current_space");
00257 a->setWhatsThis(i18n(
"Close the currently active splitted view"));
00258
00259 showFullScreenAction = KStdAction::fullScreen( 0, 0, actionCollection(),
this);
00260 connect( showFullScreenAction,SIGNAL(toggled(
bool)),
this,SLOT(slotFullScreen(
bool)));
00261
00262 goNext=
new KAction(i18n(
"Next View"),Key_F8,m_viewManager, SLOT(activateNextView()),actionCollection(),
"go_next");
00263 goNext->setWhatsThis(i18n(
"Make the next split view the active one."));
00264
00265 goPrev=
new KAction(i18n(
"Previous View"),SHIFT+Key_F8,m_viewManager, SLOT(activatePrevView()),actionCollection(),
"go_prev");
00266 goPrev->setWhatsThis(i18n(
"Make the previous split view the active one."));
00267
00268 windowNext = KStdAction::back(filelist, SLOT(slotPrevDocument()), actionCollection());
00269 windowPrev = KStdAction::forward(filelist, SLOT(slotNextDocument()), actionCollection());
00270
00271 documentOpenWith =
new KActionMenu(i18n(
"Open W&ith"), actionCollection(),
"file_open_with");
00272 documentOpenWith->setWhatsThis(i18n(
"Open the current document using another application registered for its file type, or an application of your choice."));
00273 connect(documentOpenWith->popupMenu(), SIGNAL(aboutToShow()),
this, SLOT(mSlotFixOpenWithMenu()));
00274 connect(documentOpenWith->popupMenu(), SIGNAL(activated(
int)),
this, SLOT(slotOpenWithMenuAction(
int)));
00275
00276 a=KStdAction::keyBindings(
this, SLOT(editKeys()), actionCollection());
00277 a->setWhatsThis(i18n(
"Configure the application's keyboard shortcut assignments."));
00278
00279 a=KStdAction::configureToolbars(
this, SLOT(slotEditToolbars()), actionCollection(),
"set_configure_toolbars");
00280 a->setWhatsThis(i18n(
"Configure which items should appear in the toolbar(s)."));
00281
00282
00283
00284 a =
new KAction(i18n(
"&New Project..."),
"filenew", 0,
this, SLOT(slotProjectNew()), actionCollection(),
"project_new");
00285 a =
new KAction(i18n(
"&Open Project..."),
"fileopen", 0,
this, SLOT(slotProjectOpen()), actionCollection(),
"project_open");
00286 saveProject =
new KAction(i18n(
"&Save Project"),
"filesave", 0,
this, SLOT(slotProjectSave()), actionCollection(),
"project_save");
00287 closeProject =
new KAction(i18n(
"&Close Project"),
"fileclose", 0,
this, SLOT(slotProjectClose()), actionCollection(),
"project_close");
00288
00289 recentProjects =
new KRecentFilesAction (i18n(
"Open &Recent"), KShortcut(),
this, SLOT(openConstURLProject (
const KURL&)),actionCollection(),
"project_open_recent");
00290
00291 settingsConfigure = KStdAction::preferences(
this, SLOT(slotConfigure()), actionCollection(),
"settings_configure");
00292 settingsConfigure->setWhatsThis(i18n(
"Configure various aspects of this application and the editing component."));
00293
00294
00295 KStdAction::tipOfDay(
this, SLOT( tipOfTheDay() ), actionCollection() )->setWhatsThis(i18n(
"This shows useful tips on the use of this application."));
00296
00297
if (m_pluginManager->pluginList().count() > 0)
00298 {
00299 a=
new KAction(i18n(
"Contents &Plugins"), 0,
this, SLOT(pluginHelp()), actionCollection(),
"help_plugins_contents");
00300 a->setWhatsThis(i18n(
"This shows help files for various available plugins."));
00301 }
00302
00303 connect(m_viewManager,SIGNAL(viewChanged()),
this,SLOT(slotWindowActivated()));
00304 connect(m_viewManager,SIGNAL(viewChanged()),
this,SLOT(slotUpdateOpenWith()));
00305 connect(m_docManager,SIGNAL(documentChanged()),
this,SLOT(slotDocumentChanged()));
00306
00307 slotWindowActivated ();
00308 slotDocumentChanged();
00309 }
00310
00314
bool KateMainWindow::queryClose()
00315 {
00316 kdDebug(13000)<<
"QUERY CLOSE ********************"<<endl;
00317
00318
00319
00320
if (kapp->sessionSaving())
00321 {
00322
return ( m_projectManager->queryCloseAll () &&
00323 m_docManager->queryCloseDocuments (
this) );
00324 }
00325
00326
00327
00328
if ( ((KateApp *)kapp)->mainWindows () > 1 )
00329
return true;
00330
00331
00332
00333
if ( m_projectManager->queryCloseAll () &&
00334 m_docManager->queryCloseDocuments (
this) )
00335 {
00336 KConfig scfg (
"katesessionrc",
false);
00337
00338 KConfig *config = kapp->config();
00339 config->setGroup(
"General");
00340
00341
if (config->readBoolEntry(
"Restore Projects",
false))
00342 m_projectManager->saveProjectList (&scfg);
00343
00344
if (config->readBoolEntry(
"Restore Documents",
false))
00345 m_docManager->saveDocumentList (&scfg);
00346
00347
if (config->readBoolEntry(
"Restore Window Configuration",
false))
00348 saveProperties (&scfg);
00349
00350
return true;
00351 }
00352
00353
return false;
00354 }
00355
00356
void KateMainWindow::newWindow ()
00357 {
00358 ((KateApp *)kapp)->newMainWindow ();
00359 }
00360
00361
void KateMainWindow::slotEditToolbars()
00362 {
00363 KEditToolbar dlg( factory() );
00364
00365 dlg.exec();
00366 }
00367
00368
void KateMainWindow::slotFileQuit()
00369 {
00370 close ();
00371 }
00372
00373
void KateMainWindow::readOptions(KConfig *config)
00374 {
00375 applyMainWindowSettings(config,
"Kate Main Window");
00376
00377 config->setGroup(
"General");
00378 syncKonsole = config->readBoolEntry(
"Sync Konsole",
true);
00379 modNotification = config->readBoolEntry(
"Modified Notification",
false);
00380
00381 m_viewManager->setShowFullPath(config->readBoolEntry(
"Show Full Path in Title",
false));
00382
00383 fileOpenRecent->setMaxItems( config->readNumEntry(
"Number of recent files", fileOpenRecent->maxItems() ) );
00384 fileOpenRecent->loadEntries(config,
"Recent Files");
00385
00386 fileselector->readConfig(config,
"fileselector");
00387
00388 filelist->setSortType(config->readNumEntry(
"Sort Type of File List", KateFileList::sortByID));
00389
00390 recentProjects->loadEntries (config,
"Recent Projects");
00391 }
00392
00393
void KateMainWindow::saveOptions(KConfig *config)
00394 {
00395 saveMainWindowSettings(config,
"Kate Main Window");
00396
00397 config->setGroup(
"General");
00398
00399
if (console)
00400 config->writeEntry(
"Show Console", console->isVisible());
00401
else
00402 config->writeEntry(
"Show Console",
false);
00403
00404 config->writeEntry(
"Show Full Path in Title", m_viewManager->getShowFullPath());
00405
00406 config->writeEntry(
"Sync Konsole", syncKonsole);
00407
00408 fileOpenRecent->saveEntries(config,
"Recent Files");
00409
00410 fileselector->writeConfig(config,
"fileselector");
00411
00412 config->writeEntry(
"Sort Type of File List", filelist->sortType());
00413
00414 recentProjects->saveEntries (config,
"Recent Projects");
00415 }
00416
00417
void KateMainWindow::slotDocumentChanged()
00418 {
00419
if (m_docManager->documents() > 1)
00420 {
00421 windowNext->setEnabled(
true);
00422 windowPrev->setEnabled(
true);
00423 }
00424
else
00425 {
00426 windowNext->setEnabled(
false);
00427 windowPrev->setEnabled(
false);
00428 }
00429 }
00430
00431
void KateMainWindow::slotWindowActivated ()
00432 {
00433
static QString path;
00434
00435
if (m_viewManager->activeView())
00436 {
00437
if (console && syncKonsole)
00438 {
00439 QString newPath = m_viewManager->activeView()->getDoc()->url().directory();
00440
00441
if ( newPath != path )
00442 {
00443 path = newPath;
00444 console->cd (KURL( path ));
00445 }
00446 }
00447
00448 updateCaption (m_viewManager->activeView()->getDoc());
00449 }
00450
00451
if (m_viewManager->viewSpaceCount() == 1)
00452 closeCurrentViewSpace->setEnabled(
false);
00453
else
00454 closeCurrentViewSpace->setEnabled(
true);
00455 }
00456
00457
void KateMainWindow::slotUpdateOpenWith()
00458 {
00459
if (m_viewManager->activeView())
00460 documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty());
00461
else
00462 documentOpenWith->setEnabled(
false);
00463 }
00464
00465
void KateMainWindow::documentMenuAboutToShow()
00466 {
00467 documentMenu->clear ();
00468 windowNext->plug (documentMenu);
00469 windowPrev->plug (documentMenu);
00470 documentMenu->insertSeparator ();
00471
00472
for (uint z=0; z < filelist->count(); z++)
00473 {
00474 documentMenu->insertItem (filelist->item(z)->text(),
00475 m_viewManager, SLOT (activateView (
int)), 0,
00476 ((KateFileListItem *)filelist->item (z))->documentNumber ());
00477
00478
if (m_viewManager->activeView())
00479 documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(),
true);
00480 }
00481 }
00482
00483
void KateMainWindow::slotGrepToolItemSelected(
const QString &filename,
int linenumber)
00484 {
00485 KURL fileURL;
00486 fileURL.setPath( filename );
00487 m_viewManager->openURL( fileURL );
00488
if ( m_viewManager->activeView() == 0 )
return;
00489 m_viewManager->activeView()->gotoLineNumber( linenumber );
00490 this->raise();
00491 this->setActiveWindow();
00492 }
00493
00494
void KateMainWindow::dragEnterEvent( QDragEnterEvent *event )
00495 {
00496 event->accept(KURLDrag::canDecode(event));
00497 }
00498
00499
void KateMainWindow::dropEvent( QDropEvent *event )
00500 {
00501 slotDropEvent(event);
00502 }
00503
00504
void KateMainWindow::slotDropEvent( QDropEvent * event )
00505 {
00506 KURL::List textlist;
00507
if (!KURLDrag::decode(event, textlist))
return;
00508
00509
for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
00510 {
00511 m_viewManager->openURL (*i);
00512 }
00513 }
00514
00515
void KateMainWindow::editKeys()
00516 {
00517 KKeyDialog dlg (
false,
this );
00518
00519 QPtrList<KXMLGUIClient> clients = guiFactory()->clients();
00520
00521
for( QPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
00522 dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() );
00523
00524 dlg.configure();
00525
00526 QPtrList<Kate::Document> l=m_docManager->documentList();
00527
for (uint i=0;i<l.count();i++) {
00528 kdDebug(13001)<<
"reloading Keysettings for document "<<i<<endl;
00529 l.at(i)->reloadXML();
00530 QPtrList<class KTextEditor::View> l1=l.at(i)->views ();
00531
for (uint i1=0;i1<l1.count();i1++) {
00532 l1.at(i1)->reloadXML();
00533 kdDebug(13001)<<
"reloading Keysettings for view "<<i<<
"/"<<i1<<endl;
00534
00535 }
00536
00537 }
00538 }
00539
00540
void KateMainWindow::openURL (
const QString &name)
00541 {
00542 m_viewManager->openURL (KURL(name));
00543 }
00544
00545
void KateMainWindow::slotConfigure()
00546 {
00547
if (!m_viewManager->activeView())
00548
return;
00549
00550 KateConfigDialog* dlg =
new KateConfigDialog (
this, m_viewManager->activeView());
00551 dlg->exec();
00552
00553
delete dlg;
00554 }
00555
00556
00557
void KateMainWindow::slotGoNext()
00558 {
00559 QFocusEvent::setReason(QFocusEvent::Tab);
00560 focusNextPrevChild(
true);
00561 QFocusEvent::resetReason();
00562 }
00563
00564
00565
void KateMainWindow::slotGoPrev()
00566 {
00567 QFocusEvent::setReason(QFocusEvent::Tab);
00568 focusNextPrevChild(
false);
00569 QFocusEvent::resetReason();
00570 }
00571
00572 KURL KateMainWindow::activeDocumentUrl()
00573 {
00574
00575
00576 Kate::View *v = m_viewManager->activeView();
00577
if ( v )
00578
return v->getDoc()->url();
00579
return KURL();
00580 }
00581
00582
void KateMainWindow::fileSelected(
const KFileItem *file)
00583 {
00584 m_viewManager->openURL( file->url() );
00585 }
00586
00587
void KateMainWindow::mSlotFixOpenWithMenu()
00588 {
00589
00590 documentOpenWith->popupMenu()->clear();
00591
00592 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00593
00594
00595 KTrader::OfferList offers = KTrader::self()->query(mime->name(),
"Type == 'Application'");
00596
00597
for(KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) {
00598
if ((*it)->name() ==
"Kate")
continue;
00599 documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
00600 }
00601
00602 documentOpenWith->popupMenu()->insertItem(i18n(
"&Other..."));
00603 }
00604
00605
void KateMainWindow::slotOpenWithMenuAction(
int idx)
00606 {
00607 KURL::List list;
00608 list.append( m_viewManager->activeView()->getDoc()->url() );
00609 QString* appname =
new QString( documentOpenWith->popupMenu()->text(idx) );
00610
if ( appname->compare(i18n(
"&Other...")) == 0 ) {
00611
00612 KOpenWithDlg* dlg =
new KOpenWithDlg(list);
00613
if (dlg->exec())
00614 KRun::run(*dlg->service(), list);
00615
return;
00616 }
00617 QString qry = QString(
"((Type == 'Application') and (Name == '%1'))").arg( appname->latin1() );
00618 KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() );
00619 KTrader::OfferList offers = KTrader::self()->query(mime->name(), qry);
00620 KService::Ptr app = offers.first();
00621
00622 KRun::run(*app, list);
00623 }
00624
00625
void KateMainWindow::pluginHelp()
00626 {
00627 kapp->invokeHelp (QString::null,
"kate-plugins");
00628 }
00629
00630
void KateMainWindow::setupScripts()
00631 {
00632
00633
00634 QStringList scripts = KGlobal::dirs()->findAllResources(
"data", QString(kapp->name())+
"/scripts/*.desktop",
false,
true );
00635
for (QStringList::Iterator it = scripts.begin(); it != scripts.end(); ++it )
00636 kscript->addScript( *it );
00637 QStringList l ( kscript->scripts() );
00638
for (QStringList::Iterator it=l.begin(); it != l.end(); ++it )
00639 scriptMenu->popupMenu()->insertItem( *it );
00640 }
00641
00642
void KateMainWindow::runScript(
int mIId )
00643 {
00644
00645 kdDebug(13001)<<
"runScript( "<<mIId<<
" ) ["<<scriptMenu->popupMenu()->text( mIId )<<
"]"<<endl;
00646 kscript->runScript( scriptMenu->popupMenu()->text( mIId ) );
00647 }
00648
00649
void KateMainWindow::slotMail()
00650 {
00651
KateMailDialog *d =
new KateMailDialog(
this,
this);
00652
if ( ! d->exec() )
00653
return;
00654 QPtrList<Kate::Document> attDocs = d->
selectedDocs();
00655
delete d;
00656
00657 QStringList urls;
00658 Kate::Document *doc;
00659 QPtrListIterator<Kate::Document> it(attDocs);
00660
for ( ; it.current(); ++it ) {
00661 doc = it.current();
00662
if (!doc)
continue;
00663
if ( doc->url().isEmpty() ) {
00664
00665
int r = KMessageBox::questionYesNo(
this,
00666 i18n(
"<p>The current document has not been saved, and "
00667
"cannot be attached to an email message."
00668
"<p>Do you want to save it and proceed?"),
00669 i18n(
"Cannot Send Unsaved File") );
00670
if ( r == KMessageBox::Yes ) {
00671 Kate::View *v = (Kate::View*)doc->views().first();
00672
int sr = v->saveAs();
00673
if ( sr == Kate::View::SAVE_OK ) { ;
00674 }
00675
else {
00676
if ( sr != Kate::View::SAVE_CANCEL )
00677 KMessageBox::sorry(
this, i18n(
"The file could not be saved. Please check "
00678
"if you have write permission.") );
00679
continue;
00680 }
00681 }
00682
else
00683
continue;
00684 }
00685
if ( doc->isModified() ) {
00686
00687
int r = KMessageBox::warningYesNoCancel(
this,
00688 i18n(
"<p>The current file:<br><strong>%1</strong><br>has been "
00689
"modified. Modifications will not be available in the attachment."
00690
"<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()),
00691 i18n(
"Save Before Sending?") );
00692
switch ( r ) {
00693
case KMessageBox::Cancel:
00694
continue;
00695
case KMessageBox::Yes:
00696 doc->save();
00697
if ( doc->isModified() ) {
00698 KMessageBox::sorry(
this, i18n(
"The file could not be saved. Please check "
00699
"if you have write permission.") );
00700
continue;
00701 }
00702
break;
00703
default:
00704
break;
00705 }
00706 }
00707
00708 urls << doc->url().url();
00709 }
00710
if ( ! urls.count() )
00711
return;
00712 kapp->invokeMailer( QString::null,
00713 QString::null,
00714 QString::null,
00715 QString::null,
00716 QString::null,
00717 QString::null,
00718 urls
00719 );
00720 }
00721
void KateMainWindow::tipOfTheDay()
00722 {
00723 KTipDialog::showTip(
this, QString::null,
true );
00724 }
00725
00726
void KateMainWindow::slotFullScreen(
bool t)
00727 {
00728
if (t)
00729 showFullScreen();
00730
else
00731 showNormal();
00732 }
00733
00734
bool KateMainWindow::eventFilter( QObject *o, QEvent *e )
00735 {
00736
if ( o == greptool && e->type() == QEvent::Show && activeView )
00737 {
00738
if ( activeView->getDoc()->url().isLocalFile() )
00739 {
00740 greptool->updateDirName( activeView->getDoc()->url().directory() );
00741
return true;
00742 }
00743 }
00744
if ( ( o == greptool || o == console ) &&
00745 e->type() == QEvent::Hide && activeView )
00746 {
00747 activeView->setFocus();
00748
return true;
00749 }
00750
return KMdiMainFrm::eventFilter( o, e );
00751 }
00752
00753 KMdiToolViewAccessor *KateMainWindow::addToolView(KDockWidget::DockPosition position, QWidget *widget,
const QPixmap &icon,
const QString &sname,
const QString &tabToolTip,
const QString &tabCaption)
00754 {
00755 widget->setIcon(icon);
00756 widget->setCaption(sname);
00757
00758
return addToolWindow(widget, position, getMainDockWidget(), 25, tabToolTip, tabCaption);
00759 }
00760
00761
bool KateMainWindow::removeToolView(QWidget *w)
00762 {
00763 deleteToolWindow (w);
00764
return true;
00765 }
00766
00767
bool KateMainWindow::removeToolView(KMdiToolViewAccessor *accessor)
00768 {
00769 deleteToolWindow (accessor);
00770
return true;
00771 }
00772
00773
bool KateMainWindow::showToolView(QWidget *){
return false;}
00774
bool KateMainWindow::showToolView(KMdiToolViewAccessor *){
return false;}
00775
00776
bool KateMainWindow::hideToolView(QWidget *){
return false;}
00777
bool KateMainWindow::hideToolView(KMdiToolViewAccessor *){
return false;}
00778
00779
void KateMainWindow::slotProjectNew ()
00780 {
00781 ProjectInfo *info = m_projectManager->newProjectDialog (
this);
00782
00783
if (info)
00784 {
00785 createProject (info->type, info->name, info->fileName);
00786
delete info;
00787 }
00788 }
00789
00790
void KateMainWindow::slotProjectOpen ()
00791 {
00792 QString fileName = KFileDialog::getOpenFileName (QString::null, QString (
"*.kateproject|") + i18n(
"Kate Project Files") + QString (
" (*.kateproject)"),
this, i18n(
"Open Kate Project"));
00793
00794
if (!fileName.isEmpty())
00795 openProject (fileName);
00796 }
00797
00798
void KateMainWindow::slotProjectSave ()
00799 {
00800
if (m_project)
00801 m_project->save ();
00802 }
00803
00804
void KateMainWindow::slotProjectClose ()
00805 {
00806
if (m_project)
00807 {
00808 m_projectManager->close (m_project);
00809 }
00810 }
00811
00812
void KateMainWindow::activateProject (
Kate::Project *project)
00813 {
00814 kdDebug(13001)<<
"activating project "<<project<<endl;
00815
if (m_project)
00816 m_projectManager->disableProjectGUI (m_project,
this);
00817
00818
if (project)
00819 m_projectManager->enableProjectGUI (project,
this);
00820
00821 m_project = project;
00822
00823
if (project)
00824 {
00825 m_projectManager->setCurrentProject (project);
00826 m_projectNumber = project->projectNumber ();
00827 }
00828
else
00829 m_projectNumber = 0;
00830
00831 emit m_mainWindow->projectChanged ();
00832 }
00833
00834
Kate::Project *KateMainWindow::createProject (
const QString &type,
const QString &name,
const QString &filename)
00835 {
00836
Kate::Project *project = m_projectManager->create (type, name, filename);
00837
00838
if (project)
00839 activateProject (project);
00840
00841
return project;
00842 }
00843
00844
Kate::Project *KateMainWindow::openProject (
const QString &filename)
00845 {
00846
Kate::Project *project = m_projectManager->open (filename);
00847
00848
if (project)
00849 {
00850 recentProjects->addURL ( KURL(filename) );
00851 activateProject (project);
00852 }
00853
00854
return project;
00855 }
00856
00857
void KateMainWindow::projectDeleted (uint projectNumber)
00858 {
00859
if (projectNumber == m_projectNumber)
00860 {
00861
if (m_projectManager->projects() > 0)
00862 activateProject (m_projectManager->project(m_projectManager->projects()-1));
00863
else
00864 activateProject (0);
00865 }
00866 }
00867
00868
void KateMainWindow::slotDocumentCreated (Kate::Document *doc)
00869 {
00870 connect(doc,SIGNAL(modStateChanged(Kate::Document *)),
this,SLOT(updateCaption(Kate::Document *)));
00871 connect(doc,SIGNAL(nameChanged(Kate::Document *)),
this,SLOT(updateCaption(Kate::Document *)));
00872 connect(doc,SIGNAL(nameChanged(Kate::Document *)),
this,SLOT(slotUpdateOpenWith()));
00873
00874 updateCaption (doc);
00875 }
00876
00877
void KateMainWindow::updateCaption (Kate::Document *doc)
00878 {
00879
if (!m_viewManager->activeView())
00880 {
00881 setCaption (
"",
false);
00882
return;
00883 }
00884
00885
if (!(m_viewManager->activeView()->getDoc() == doc))
00886
return;
00887
00888
00889 fileselector->kateViewChanged();
00890
00891 QString c;
00892
if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath()))
00893 {
00894 c = m_viewManager->activeView()->getDoc()->docName();
00895
00896
00897
if (c.length() > 64)
00898 c = c.left(64) +
"...";
00899 }
00900
else
00901 {
00902 c = m_viewManager->activeView()->getDoc()->url().prettyURL();
00903
00904
00905
if (c.length() > 64)
00906 c =
"..." + c.right(64);
00907 }
00908
00909 setCaption( c, m_viewManager->activeView()->getDoc()->isModified());
00910 }
00911
00912
void KateMainWindow::openConstURLProject (
const KURL&url)
00913 {
00914 openProject (url.path());
00915 }
00916
00917
void KateMainWindow::saveProperties(KConfig *config) {
00918 kdDebug(13000)<<
"KateMainWindow::saveProperties()********************************************"<<endl
00919 <<config->group()<<endl
00920 <<
"****************************************************************************"<<endl;
00921 assert(config);
00922
00923 kdDebug(13000)<<
"preparing session saving"<<endl;
00924 QString grp=config->group();
00925 QString dockGrp;
00926
00927
if (kapp->sessionSaving()) dockGrp=grp+
"-Docking";
00928
else dockGrp=
"MainWindow0-Docking";
00929
00930
00931
00932
00933
00934 kdDebug(13000)<<
"Before write dock config"<<endl;
00935 writeDockConfig(config,dockGrp);
00936 kdDebug(13000)<<
"After write dock config"<<endl;
00937
00938
00939
if (kapp->sessionSaving()) dockGrp=grp+
"-View Configuration";
00940
else dockGrp=
"MainWindow0-View Configuration";
00941
00942 m_viewManager->saveViewConfiguration (config,dockGrp);
00943 kdDebug(13000)<<
"After saving view configuration"<<endl;
00944 config->setGroup(grp);
00945
00946 }
00947
00948
void KateMainWindow::readProperties(KConfig *config)
00949 {
00950 QString grp=config->group();
00951 QString dockGrp;
00952
00953
if (kapp->isRestored()) dockGrp=grp+
"-Docking";
00954
else dockGrp=
"MainWindow0-Docking";
00955
00956
if (config->hasGroup(dockGrp))
00957 readDockConfig(config,dockGrp);
00958
00959
if (kapp->isRestored()) dockGrp=grp+
"-View Configuration";
00960
else dockGrp=
"MainWindow0-View Configuration";
00961
00962 m_viewManager->restoreViewConfiguration (config,dockGrp);
00963 config->setGroup(grp);
00964 }
00965
00966
void KateMainWindow::saveGlobalProperties( KConfig* sessionConfig )
00967 {
00968 m_projectManager->saveProjectList (sessionConfig);
00969 m_docManager->saveDocumentList (sessionConfig);
00970 }