KDevelop API Documentation

newmainwindow.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  newmainwindow.cpp
00003                              -------------------
00004     begin                : october 2003
00005     copyright            : (C) 2003, 2004 by the KDevelop team
00006     email                : team@kdevelop.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include <qlayout.h>
00018 #include <qmultilineedit.h>
00019 #include <qvbox.h>
00020 #include <qcheckbox.h>
00021 #include <qvaluelist.h>
00022 #include <qobjectlist.h>
00023 #include <qtabbar.h>
00024 #include <qtoolbutton.h>
00025 
00026 #include <kaboutdata.h>
00027 #include <kdeversion.h>
00028 #include <kapplication.h>
00029 #include <kstdaction.h>
00030 #include <kdebug.h>
00031 #include <kaction.h>
00032 #include <klocale.h>
00033 #include <kmenubar.h>
00034 #include <kconfig.h>
00035 #include <kstatusbar.h>
00036 #include <kdialogbase.h>
00037 #include <kkeydialog.h>
00038 #include <kmessagebox.h>
00039 #include <kiconloader.h>
00040 #include <kdevproject.h>
00041 #include <ktexteditor/view.h>
00042 #include <kmultitabbar.h>
00043 #include <ktabwidget.h>
00044 #include <kparts/part.h>
00045 #include <kdockwidget.h>
00046 #include <knotifydialog.h>
00047 #include <kedittoolbar.h>
00048 #include <designer.h>
00049 
00050 #include "kdevplugin.h"
00051 #include "projectmanager.h"
00052 #include "plugincontroller.h"
00053 #include "partcontroller.h"
00054 #include "kdevcore.h"
00055 #include "kdevpartcontroller.h"
00056 #include "partselectwidget.h"
00057 #include "api.h"
00058 #include "core.h"
00059 #include "settingswidget.h"
00060 #include "statusbar.h"
00061 
00062 #include "kpopupmenu.h"
00063 #include "documentationpart.h"
00064 #include "editorproxy.h"
00065 
00066 #include "toplevel.h"
00067 #include "mainwindowshare.h"
00068 #include "newmainwindow.h"
00069 
00070 /***************************
00071 WHAT'S NOT WORKING:
00072 
00073 Toolview widgets without a name doesn't show in the side toolbars. (Port safety method from old mainwindow)
00074 Culprits are: debugger views, problem reporter, more???
00075 
00076 UI mode can now only be changed via a restart. This is intentional!
00077 
00078 
00079 ****************************/
00080 
00081 NewMainWindow::NewMainWindow(QWidget *parent, const char *name, KMdi::MdiMode mdimode)
00082  : KMdiMainFrm(parent, name, mdimode )
00083 // ,m_pWindowMenu(0L)
00084 // ,m_bSwitching(false)
00085 {
00086     resize( 800, 600 ); // starts kdevelop at 800x600 the first time
00087   
00088     // isn't it fun with stuff you have no idea what it does?
00089     this->setManagedDockPositionModeEnabled(true);
00090     
00091     // does this work at all?
00092     this->setStandardMDIMenuEnabled( false );
00093 
00094     KConfig *config = kapp->config();
00095     config->setGroup("UI");
00096     int mdiStyle = config->readNumEntry("MDIStyle", 1);
00097 
00098     this->setToolviewStyle( mdiStyle ); // KDEV3 style of KMultiTabBar
00099     
00100     m_pMainWindowShare = new MainWindowShare(this);
00101     
00102     m_raiseEditor = new KAction( i18n("Raise &Editor"), ALT+Key_C,
00103                                  this, SLOT(raiseEditor()),
00104                                  actionCollection(), "raise_editor");
00105     m_raiseEditor->setToolTip(i18n("Raise editor"));
00106     m_raiseEditor->setWhatsThis(i18n("<b>Raise editor</b><p>Focuses the editor."));
00107         
00108    
00109     //@fixme why is this part of KDevMainWindow?
00110 //    previous_output_view = NULL;
00111 }
00112 
00113 
00114 void NewMainWindow::init() {
00115 
00116     actionCollection()->setHighlightingEnabled( true );
00117 //    m_windowDynamicMenus.setAutoDelete(true);
00118 
00119     setStandardToolBarMenuEnabled( true );
00120 
00121     if (TopLevel::mode == TopLevel::AssistantMode)
00122         setXMLFile("kdevassistantui.rc");
00123     else
00124         setXMLFile("kdevelopui.rc");
00125 
00126     createFramework();
00127     createActions();
00128     createStatusBar();
00129 
00130     createGUI(0);
00131 
00132     //adymo: commented by me - this is a hell, we don't want to enter it, do we?
00133 /*    QString appstr = "kdev";
00134     if (KGlobal::instance()->aboutData())
00135         appstr = KGlobal::instance()->aboutData()->appName();
00136     QString uimode = QString( "%1uimode%2rc" ).arg(appstr).arg( m_mdiMode );
00137     KConfig uiConfig( uimode, true );
00138     readDockConfig( &uiConfig );*/
00139 
00140     m_pMainWindowShare->init();
00141     
00142     // remove the kmdi-created menu
00143     delete m_pWindowMenu;
00144     
00145     // get the xmlgui created one instead
00146     m_pWindowMenu = static_cast<QPopupMenu*>(main()->child( "window", "KPopupMenu" ));
00147 
00148     if( !m_pWindowMenu )
00149     {
00150         kdDebug(9000) << "Couldn't find the XMLGUI window menu. Creating new." << endl;
00151         
00152         m_pWindowMenu = new QPopupMenu( main(), "window");
00153         menuBar()->insertItem(i18n("&Window"),m_pWindowMenu);
00154     }
00155     
00156     actionCollection()->action( "file_close" )->plug( m_pWindowMenu );
00157     actionCollection()->action( "file_close_all" )->plug( m_pWindowMenu );
00158     actionCollection()->action( "file_closeother" )->plug( m_pWindowMenu );
00159 
00160     QObject::connect( m_pWindowMenu, SIGNAL(activated(int)), this, SLOT(openURL(int )) );
00161     QObject::connect( m_pWindowMenu, SIGNAL(aboutToShow()), this, SLOT(fillWindowMenu()) );
00162                    
00163     menuBar()->setEnabled( false );
00164     
00165     if ( PluginController::pluginServices().isEmpty() ) {
00166         KMessageBox::sorry( this, i18n("Unable to find plugins, KDevelop will not work properly!\nPlease make sure "
00167                                        "that KDevelop is installed in your KDE directory, otherwise you have to add KDevelop's installation "
00168                                        "path to the environment variable KDEDIRS and run kbuildsycoca. Restart KDevelop afterwards.\n"
00169                                        "Example for BASH users:\nexport KDEDIRS=/path/to/kdevelop:$KDEDIRS && kbuildsycoca"),
00170                             i18n("Could Not Find Plugins") );
00171     }
00172     
00173     connect( Core::getInstance(), SIGNAL(coreInitialized()), this, SLOT(slotCoreInitialized()) );
00174     
00175     connect( PartController::getInstance(), SIGNAL(partURLChanged(KParts::ReadOnlyPart * )),
00176         this, SLOT(slotPartURLChanged(KParts::ReadOnlyPart * )) );
00177     
00178     connect( PartController::getInstance(), SIGNAL(documentChangedState(const KURL &, DocumentState)), 
00179         this, SLOT(documentChangedState(const KURL&, DocumentState )) );
00180 
00181 
00182     Core::getInstance()->loadLicenses();
00183 
00184     if ( tabWidget() )
00185     {
00186         KConfig *config = kapp->config();
00187         config->setGroup("UI");
00188         
00189         int tabvisibility = config->readNumEntry( "TabWidgetVisibility", KMdi::AlwaysShowTabs );
00190         setTabWidgetVisibility( (KMdi::TabWidgetVisibility)tabvisibility );
00191         
00192         bool CloseOnHover = config->readBoolEntry( "CloseOnHover", false );
00193         tabWidget()->setHoverCloseButton( CloseOnHover );
00194         
00195         bool CloseOnHoverDelay = config->readBoolEntry( "CloseOnHoverDelay", false );
00196         tabWidget()->setHoverCloseButtonDelayed( CloseOnHoverDelay );
00197         
00198         openNewTabAfterCurrent = config->readBoolEntry( "OpenNewTabAfterCurrent", false );
00199         showTabIcons = config->readBoolEntry( "ShowTabIcons", true );
00200   
00201         if (config->readBoolEntry( "ShowCloseTabsButton", true ))
00202         {
00203             QToolButton *but = new QToolButton(tabWidget());
00204             but->setIconSet(SmallIcon("tab_remove"));
00205             but->adjustSize();
00206             but->hide();
00207             connect(but, SIGNAL(clicked()), actionCollection()->action( "file_close" ), SIGNAL(activated()));
00208             tabWidget()->setCornerWidget(but, TopRight);
00209         }
00210         tabWidget()->setTabReorderingEnabled(true);
00211         connect(tabWidget(), SIGNAL(movedTab(int, int)), this, SLOT(tabMoved(int, int)));
00212         connect(tabWidget(), SIGNAL(contextMenu(QWidget*,const QPoint &)), this, SLOT(tabContext(QWidget*,const QPoint &)));        
00213     }
00214 }
00215 
00216 void NewMainWindow::tabContext(QWidget* widget,const QPoint & pos)
00217 {
00218 
00219     KPopupMenu tabMenu;
00220 
00221     tabMenu.insertTitle( dynamic_cast<KMdiChildView*>(widget)->tabCaption() );
00222 
00223     //Find the document on whose tab the user clicked
00224     m_currentTabURL = QString::null;
00225     QPtrListIterator<KParts::Part> it( *PartController::getInstance()->parts() );
00226     while ( KParts::Part* part = it.current()
00227           )
00228     {
00229         QWidget * top_widget = EditorProxy::getInstance()->topWidgetForPart( part );
00230         if ( top_widget && top_widget->parentWidget() == widget)
00231         {
00232             if( KParts::ReadOnlyPart * ro_part = dynamic_cast<KParts::ReadOnlyPart*>(part))
00233             {
00234                 m_currentTabURL = ro_part->url();
00235 
00236                 tabMenu.insertItem( i18n("Close"),0);
00237 
00238                 if(PartController::getInstance()->parts()->count() > 1)
00239                     tabMenu.insertItem( i18n("Close All Others"), 4 );
00240 
00241                 if(!dynamic_cast<DocumentationPart*>(ro_part))
00242                 {
00243                     if(KParts::ReadWritePart * rw_part = dynamic_cast<KParts::ReadWritePart*>( ro_part ))
00244                         if(!dynamic_cast<KInterfaceDesigner::Designer*>(ro_part))
00245                         {
00246                             //FIXME: we do workaround the inability of the KDevDesigner part
00247                             // to deal with these global actions here.
00248                             if(rw_part->isModified())
00249                                 tabMenu.insertItem( i18n("Save"),1);
00250 
00251                             tabMenu.insertItem( i18n("Reload"),2);
00252                         }
00253                 }
00254                 else
00255                 {
00256                     tabMenu.insertItem( i18n("Duplicate"), 3 );
00257                     break;
00258                 }
00259 
00260                 //Create the file context
00261                 KURL::List list;
00262                 list << m_currentTabURL;
00263                 FileContext context( list );
00264                 Core::getInstance()->fillContextMenu(&tabMenu, &context);
00265 
00266             }
00267             break;
00268         }
00269         ++it;
00270     }
00271 
00272     connect( &tabMenu, SIGNAL( activated(int) ), this, SLOT(tabContextActivated(int)) );
00273 
00274     tabMenu.exec(pos);
00275 
00276 }
00277 
00278 void NewMainWindow::tabContextActivated(int id)
00279 {
00280     if(m_currentTabURL.isEmpty())
00281         return;
00282 
00283     switch(id)
00284     {
00285     case 0:
00286         PartController::getInstance()->closeFile(m_currentTabURL);
00287         break;
00288     case 1:
00289         PartController::getInstance()->saveFile(m_currentTabURL);
00290         break;
00291     case 2:
00292         PartController::getInstance()->reloadFile(m_currentTabURL);
00293         break;
00294     case 3:
00295         PartController::getInstance()->showDocument(m_currentTabURL, true);
00296         break;
00297     case 4:
00298         PartController::getInstance()->closeAllOthers(m_currentTabURL);
00299         break;
00300     default:
00301         break;
00302     }
00303 
00304 }
00305 
00306 NewMainWindow::~NewMainWindow() 
00307 {
00308     TopLevel::invalidateInstance( this );
00309 }
00310 
00311 void NewMainWindow::slotCoreInitialized( )
00312 {
00313     menuBar()->setEnabled( true );
00314 }
00315 
00316 void NewMainWindow::openURL( int id )
00317 {
00318     QValueList< QPair< int, KURL > >::ConstIterator it = m_windowList.begin();
00319     while ( it != m_windowList.end() )
00320     {
00321         if ( (*it).first == id )
00322         {
00323             KURL url( (*it).second );
00324             if ( !url.isEmpty() )
00325             {
00326                 PartController::getInstance()->activatePart( PartController::getInstance()->partForURL( url ) );
00327                 return;
00328             }
00329         }
00330         ++it;
00331     }
00332 }
00333 
00334 void NewMainWindow::fillWindowMenu()
00335 {
00336     bool hasWidget = ( PartController::getInstance()->activeWidget() != 0 );    // hmmm... works??
00337     
00338     // clear menu
00339     QValueList< QPair< int, KURL > >::ConstIterator it = m_windowList.begin();
00340     while ( it != m_windowList.end() )
00341     {
00342         m_pWindowMenu->removeItem( (*it).first );
00343         ++it;
00344     }
00345     
00346     int temp = 0;
00347         
00348     if  ( m_mdiMode == KMdi::ChildframeMode )
00349     {
00350         temp = m_pWindowMenu->insertItem(i18n("&Minimize All"), this, SLOT(iconifyAllViews()));
00351         m_pWindowMenu->setItemEnabled( temp, hasWidget );
00352         m_windowList << qMakePair( temp, KURL() );
00353         
00354         m_windowList << qMakePair( m_pWindowMenu->insertSeparator(), KURL() );
00355         
00356         temp = m_pWindowMenu->insertItem(i18n("&Tile..."), m_pPlacingMenu);
00357         m_windowList << qMakePair( temp, KURL() );
00358         m_pWindowMenu->setItemEnabled( temp, hasWidget );
00359     
00360         m_pPlacingMenu->clear();
00361         m_pPlacingMenu->insertItem(i18n("Ca&scade Windows"), m_pMdi,SLOT(cascadeWindows()));
00362         m_pPlacingMenu->insertItem(i18n("Cascade &Maximized"), m_pMdi,SLOT(cascadeMaximized()));
00363         m_pPlacingMenu->insertItem(i18n("Expand &Vertically"), m_pMdi,SLOT(expandVertical()));
00364         m_pPlacingMenu->insertItem(i18n("Expand &Horizontally"), m_pMdi,SLOT(expandHorizontal()));
00365         m_pPlacingMenu->insertItem(i18n("Tile &Non-overlapped"), m_pMdi,SLOT(tileAnodine()));
00366         m_pPlacingMenu->insertItem(i18n("Tile Overla&pped"), m_pMdi,SLOT(tilePragma()));
00367         m_pPlacingMenu->insertItem(i18n("Tile V&ertically"), m_pMdi,SLOT(tileVertically()));
00368     }
00369 
00370     m_windowList << qMakePair( m_pWindowMenu->insertSeparator(), KURL() );
00371     
00372     QMap<QString, KURL> map;    
00373     QStringList string_list;
00374     KURL::List list = PartController::getInstance()->openURLs();    
00375     KURL::List::Iterator itt = list.begin();
00376     while ( itt != list.end() )
00377     {
00378         map[(*itt).fileName()] = *itt;
00379         string_list.append((*itt).fileName());
00380         ++itt;
00381     }
00382     string_list.sort();
00383     
00384     list.clear();
00385     for(uint i = 0; i != string_list.size(); ++i)
00386         list.append(map[string_list[i]]);
00387     
00388     itt = list.begin();
00389     while ( itt != list.end() )
00390     {
00391         temp = m_pWindowMenu->insertItem( (*itt).fileName() );
00392         m_windowList << qMakePair( temp, *itt );
00393         
00394         ++itt;
00395     }
00396 }
00397 
00398 bool NewMainWindow::queryClose()
00399 {
00400     saveSettings(); //moved from queryClose so tab settings can be saved while
00401                     //the components still exist.
00402     return Core::getInstance()->queryClose();
00403 }
00404 
00405 bool NewMainWindow::queryExit()
00406 {
00407   return true;
00408 }
00409 
00410 KMainWindow *NewMainWindow::main() {
00411     return this;
00412 }
00413 
00414 void NewMainWindow::createStatusBar() {
00415     (void) new KDevStatusBar(this);
00416 //    QMainWindow::statusBar();
00417 }
00418 
00419 
00420 void NewMainWindow::createFramework() {
00421 
00422     PartController::createInstance( this );
00423 
00424     connect(this, SIGNAL(viewActivated(KMdiChildView*)), this, SLOT(slotViewActivated(KMdiChildView*)) );
00425 //     connect(this, SIGNAL(currentChanged(QWidget*)), PartController::getInstance(), SLOT(slotCurrentChanged(QWidget*)));
00426 //    connect(this, SIGNAL(sigCloseWindow(const QWidget *)), PartController::getInstance(),SLOT(slotClosePartForWidget(const QWidget *)));
00427     connect(PartController::getInstance(), SIGNAL(activePartChanged(KParts::Part*)), this, SLOT(createGUI(KParts::Part*)));
00428 }
00429 
00430 void NewMainWindow::slotViewActivated(KMdiChildView* child)
00431 {
00432     kdDebug(9000) << "======> view activated: " << child << endl;
00433     if( !child || !child->focusedChildWidget() )
00434         return;
00435     
00436     emit currentChanged( child->focusedChildWidget() );
00437 }
00438 
00439 void NewMainWindow::createActions() 
00440 {
00441     m_pMainWindowShare->createActions();
00442 
00443     connect(m_pMainWindowShare, SIGNAL(gotoNextWindow()), this, SLOT(activateNextWin()) );
00444     connect(m_pMainWindowShare, SIGNAL(gotoPreviousWindow()), this, SLOT(activatePrevWin()) );
00445     connect(m_pMainWindowShare, SIGNAL(gotoFirstWindow()), this, SLOT(activateFirstWin()) );
00446     connect(m_pMainWindowShare, SIGNAL(gotoLastWindow()), this, SLOT(activateLastWin()) );
00447 }
00448 
00449 void NewMainWindow::embedPartView(QWidget *view, const QString &name, const QString& ) 
00450 {
00451     if( !view ) return;
00452 
00453     QString shortName = name;
00454     shortName = shortName.right( shortName.length() - (shortName.findRev('/') +1));
00455 
00456     KMdiChildView * child = createWrapper(view, name, shortName);
00457     
00458     if (showTabIcons)
00459     {
00460         const QPixmap* wndIcon = view->icon();
00461         if (!wndIcon || (wndIcon && (wndIcon->size().height() > 16)))
00462             child->setIcon(SmallIcon("kdevelop")); // was empty or too big, take something useful
00463     }
00464     else
00465         child->setIcon(QPixmap());
00466 
00467     unsigned int mdiFlags = KMdi::StandardAdd | KMdi::UseKMdiSizeHint;
00468     int tabIndex = -1;
00469     if ( tabWidget() && openNewTabAfterCurrent)
00470         if (tabWidget()->count() > 0)
00471             tabIndex = tabWidget()->currentPageIndex() + 1;
00472     addWindow(child, mdiFlags, tabIndex);
00473 }
00474 
00475 void NewMainWindow::embedSelectView(QWidget *view, const QString &name, const QString &toolTip) 
00476 {
00477     embedView( KDockWidget::DockLeft, view, name, toolTip );
00478 }
00479 
00480 void NewMainWindow::embedSelectViewRight ( QWidget* view, const QString& name, const QString &toolTip) 
00481 {
00482     embedView( KDockWidget::DockRight, view, name, toolTip );
00483     if (TopLevel::mode == TopLevel::AssistantMode)
00484         raiseView(view);
00485 }
00486 
00487 void NewMainWindow::embedOutputView(QWidget *view, const QString &name, const QString &toolTip) 
00488 {
00489     embedView( KDockWidget::DockBottom, view, name, toolTip );
00490 }
00491 
00492 KDockWidget::DockPosition NewMainWindow::recallToolViewPosition( const QString & widgetName, KDockWidget::DockPosition defaultPos )
00493 {
00494     KConfig * config = kapp->config();
00495     config->setGroup( "ToolDockPosition" );
00496 
00497     QString position = config->readEntry( widgetName, "DockNone" );
00498 
00499     if ( position == "DockLeft" ) return KDockWidget::DockLeft;
00500     if ( position == "DockRight" ) return KDockWidget::DockRight;
00501     if ( position == "DockBottom" ) return KDockWidget::DockBottom;
00502     if ( position == "DockTop" ) return KDockWidget::DockTop;
00503 
00504     return defaultPos;
00505 }
00506 
00507 void NewMainWindow::rememberToolViewPosition( const QString & widgetName, KDockWidget::DockPosition pos )
00508 {
00509     KConfig * config = kapp->config();
00510     config->setGroup( "ToolDockPosition" );
00511 
00512     QString position = "DockNone";
00513 
00514     switch( pos )
00515     {
00516         case KDockWidget::DockLeft:
00517             position = "DockLeft";
00518             break;
00519         case KDockWidget::DockRight:
00520             position = "DockRight";
00521             break;
00522         case KDockWidget::DockBottom:
00523             position = "DockBottom";
00524             break;
00525         case KDockWidget::DockTop:
00526             position = "DockTop";
00527             break;
00528         default: ;
00529     }
00530 
00531     config->writeEntry( widgetName, position );
00532 }
00533 
00534 void NewMainWindow::embedView( KDockWidget::DockPosition pos, QWidget *view, const QString &name, const QString &toolTip)
00535 {
00536     if( !view ) return;
00537 
00538     if ( !m_availableToolViews.contains( view ) && !m_unAvailableToolViews.contains( view ) )
00539     {
00540         pos = recallToolViewPosition( view->name(), pos );  // we have a new view. where should it go?
00541     }
00542     
00543     KMdiMainFrm::addToolWindow( view, pos, getMainDockWidget(), 20, toolTip, name );
00544     m_availableToolViews.insert( view, ToolViewData( pos, name, toolTip ) );
00545 }
00546 
00547 void NewMainWindow::childWindowCloseRequest( KMdiChildView * childView )
00548 {
00549     const QPtrList<KParts::Part> * partlist = PartController::getInstance()->parts();
00550     QPtrListIterator<KParts::Part> it( *partlist );
00551     while ( KParts::Part* part = it.current() )
00552     {
00553         QWidget * widget = EditorProxy::getInstance()->topWidgetForPart( part );
00554         if ( widget && widget->parentWidget() == childView )
00555         {
00556             PartController::getInstance()->closePart( part );
00557             return;
00558         }
00559         ++it;
00560     }
00561 }
00562 
00563 static KDockWidget::DockPosition getDockWidgetDockingBorder( QWidget * w )
00564 {
00565     int depth = 0;
00566     while( w && depth < 10 )
00567     {
00568         if ( KDockWidget * dockWidget = dynamic_cast<KDockWidget*>( w ) )
00569         {
00570             KDockWidget::DockPosition pos = dockWidget->currentDockPosition();
00571             if ( pos == KDockWidget::DockLeft || pos == KDockWidget::DockRight || pos == KDockWidget::DockBottom || pos == KDockWidget::DockTop )
00572             {
00573                 return pos;
00574             }
00575         }
00576         depth++;
00577         w = w->parentWidget();
00578     }
00579     return KDockWidget::DockNone;
00580 }
00581 
00582 void NewMainWindow::removeView( QWidget * view )
00583 {
00584     kdDebug(9000) << k_funcinfo << " - view: " << view << endl;
00585     
00586     if( !view || !view->parentWidget() )
00587         return;
00588     
00589     kdDebug(9000) << "parentWidget: " << view->parentWidget() << endl;
00590 
00591     if( KMdiChildView * childView = static_cast<KMdiChildView*>(view->parentWidget()->qt_cast("KMdiChildView")) ) 
00592     {
00593         (void) view->reparent(0, QPoint(0,0), false );
00594         closeWindow( childView );
00595     } 
00596     else if( view->parentWidget()->qt_cast("KDockWidget") ) 
00597     {
00598         rememberToolViewPosition( view->name(), getDockWidgetDockingBorder( view ) );
00599         (void) view->reparent(0, QPoint(0,0), false );
00600         deleteToolWindow( view );
00601     }
00602 }
00603 
00604 void NewMainWindow::setViewAvailable(QWidget * view, bool bEnabled) 
00605 {
00606     if ( !view ) return;
00607 
00608     if ( bEnabled )
00609     {
00610         if ( m_availableToolViews.contains( view ) ) return; // already visible
00611 
00612         if ( m_unAvailableToolViews.contains( view ) )
00613         {
00614             ToolViewData t = m_unAvailableToolViews[ view ];
00615             m_unAvailableToolViews.remove( view );
00616 
00617             KMdiMainFrm::addToolWindow( view, t.position, getMainDockWidget(), 20, t.toolTip, t.name );
00618             m_availableToolViews.insert( view, t );
00619         }
00620     }
00621     else
00622     {
00623         if ( m_unAvailableToolViews.contains( view ) ) return; // already hidden
00624 
00625         if ( m_availableToolViews.contains( view ) )
00626         {
00627             ToolViewData t = m_availableToolViews[ view ];
00628             m_availableToolViews.remove( view );
00629 
00630             KDockWidget::DockPosition pos = getDockWidgetDockingBorder( view );
00631             t.position = ( pos != KDockWidget::DockNone ? pos : t.position );   // the view might have changed position
00632 
00633             removeView( view );
00634             m_unAvailableToolViews.insert( view, t );
00635         }
00636     }
00637 }
00638 
00639 void NewMainWindow::raiseView(QWidget *view) 
00640 {
00641     kdDebug(9000) << k_funcinfo << endl;
00642     
00643     if( !view || !view->parentWidget() )
00644         return;
00645 
00646     view->parentWidget()->setFocus();
00647 
00648     if( QGuardedPtr<KDockWidget> dockWidget = static_cast<KDockWidget*>(view->parentWidget()->qt_cast("KDockWidget")) ) {
00649         if( !dockWidget->isVisible() )
00650             makeDockVisible( dockWidget );
00651     }
00652 }
00653 
00654 
00655 void NewMainWindow::lowerView(QWidget *)
00656 {
00657   // seems there's nothing to do here
00658 }
00659 
00660 
00661 void NewMainWindow::createGUI(KParts::Part *part) {
00662     if ( !part )
00663         setCaption( QString::null );
00664     KMdiMainFrm::createGUI(part);
00665 
00666     m_pMainWindowShare->slotGUICreated( part );
00667 }
00668 
00669 
00670 void NewMainWindow::loadSettings() {
00671     KConfig *config = kapp->config();
00672 
00673     ProjectManager::getInstance()->loadSettings();
00674     applyMainWindowSettings(config, "Mainwindow");
00675 }
00676 
00677 void NewMainWindow::setUserInterfaceMode( const QString & )
00678 {
00679 /*  
00680     // immediately switch the mode likely set in the uimode part
00681     if (uiMode == "Childframe") {
00682     switchToChildframeMode();
00683     }
00684     else if (uiMode == "TabPage") {
00685     switchToTabPageMode();
00686     }
00687     else if (uiMode == "Toplevel") {
00688     switchToToplevelMode();
00689     }
00690     else if (uiMode == "KMDI-IDEAl") {
00691         switchToIDEAlMode();
00692     }
00693 */  
00694 }
00695 
00696 void NewMainWindow::saveSettings() 
00697 {
00698     KConfig *config = kapp->config();
00699 
00700     ProjectManager::getInstance()->saveSettings();
00701     saveMainWindowSettings(config, "Mainwindow");
00702 
00703     QString appstr = "kdev";
00704     if (KGlobal::instance()->aboutData())
00705         appstr = KGlobal::instance()->aboutData()->appName();
00706     QString uimode = QString( "%1uimode%2rc" ).arg(appstr).arg( m_mdiMode );
00707     KConfig uiConfig( uimode );
00708     writeDockConfig( &uiConfig );
00709 
00710     QValueList<QWidget*> widgetList = m_pToolViews->keys();
00711     QValueList<QWidget*>::Iterator it = widgetList.begin();
00712     while( it != widgetList.end() )
00713     {
00714         rememberToolViewPosition( (*it)->name(), getDockWidgetDockingBorder( *it ) );   
00715         ++it;
00716     }
00717 }
00718 
00719 void NewMainWindow::raiseEditor( )
00720 {
00721     kdDebug() << k_funcinfo << endl;
00722     
00723     KDevPartController * partcontroller = API::getInstance()->partController();
00724     if ( partcontroller->activePart() && partcontroller->activePart()->widget() )
00725     {
00726         partcontroller->activePart()->widget()->setFocus();
00727     }
00728 }
00729 
00730 void NewMainWindow::setCaption( const QString & caption )
00731 {
00732     KDevProject * project = API::getInstance()->project();
00733     if ( project /*&& !caption.isEmpty()*/ )
00734     {
00735         QString projectname = project->projectName();
00736 
00737         QString suffix(".kdevelop");
00738         if ( projectname.endsWith( suffix ) )
00739         {
00740             projectname.truncate( projectname.length() - suffix.length() );
00741         }
00742 
00743         KMdiMainFrm::setCaption( projectname + " - " + caption );
00744     }
00745     else
00746     {
00747         KMdiMainFrm::setCaption( caption );
00748     }
00749 }
00750 
00751 //@fixme - not currently connected - should it be?
00752 void NewMainWindow::projectOpened() 
00753 {
00754     // why would we reload mainwindow settings on project load?
00755     loadSettings();
00756 }
00757 
00758 void NewMainWindow::prepareToCloseViews()
00759 {
00760   // seems there's nothing to do here
00761 }
00762 
00763 void NewMainWindow::guiRestoringFinished()
00764 {
00765   // seems there's nothing to do here
00766 }
00767 
00768 void NewMainWindow::storeOutputViewTab( )
00769 {
00770   // seems there's nothing to do here
00771 }
00772 
00773 void NewMainWindow::restoreOutputViewTab( )
00774 {
00775   // seems there's nothing to do here
00776 }
00777 
00778 void NewMainWindow::lowerAllViews( )
00779 {
00780   // seems there's nothing to do here
00781 }
00782 
00783 void NewMainWindow::slotPartURLChanged( KParts::ReadOnlyPart * ro_part )
00784 {
00785     kdDebug() << k_funcinfo << endl;
00786     
00787     if ( QWidget * widget = EditorProxy::getInstance()->topWidgetForPart( ro_part ) )
00788     {
00789         KMdiChildView * childView = dynamic_cast<KMdiChildView*>( widget->parentWidget() );
00790         if ( childView )
00791         {
00792             childView->setMDICaption( ro_part->url().fileName() );
00793             
00794         }
00795     }
00796 }
00797 
00798 void NewMainWindow::documentChangedState( const KURL & url, DocumentState state )
00799 {
00800     QWidget * widget = EditorProxy::getInstance()->topWidgetForPart( PartController::getInstance()->partForURL( url ) );
00801     if ( widget )
00802     {
00803         //calculate the icon size if showTabIcons is false
00804         //this is necessary to avoid tab resizing by setIcon() call
00805         int isize = 16;
00806         if (tabWidget() && !showTabIcons)
00807         {
00808             isize = tabWidget()->fontMetrics().height() - 1;
00809 //          kdDebug() << "size: " << isize << endl;
00810             isize = isize > 16 ? 16 : isize;
00811         }
00812         switch( state )
00813         {
00814             // we should probably restore the original icon instead of just using "kdevelop",
00815             // but I have never seen any other icon in use so this should do for now
00816             case Clean:
00817                 if (showTabIcons)
00818                     widget->setIcon( SmallIcon("kdevelop", isize));
00819                 else    
00820                     widget->setIcon(QPixmap());
00821                 break;
00822             case Modified:
00823                 widget->setIcon( SmallIcon("filesave", isize));
00824                 break;
00825             case Dirty:
00826                 widget->setIcon( SmallIcon("revert", isize));
00827                 break;
00828             case DirtyAndModified:
00829                 widget->setIcon( SmallIcon("stop", isize));
00830                 break;
00831         }
00832     }
00833 }
00834 
00835 void NewMainWindow::tabMoved( int from, int to )
00836 {
00837     KMdiChildView *view = m_pDocumentViews->at(from);
00838     m_pDocumentViews->remove(from);
00839     m_pDocumentViews->insert(to, view);
00840 }
00841 
00842 #include "newmainwindow.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:42 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003