KDE/kdevelop/lib

Adam Treat treat at kde.org
Thu Aug 3 16:13:08 UTC 2006


SVN commit 569357 by treat:

KDevCore provides a set of fundamental objects for the KDevPlatform.

These objects sometimes depend upon each other, but we can not know
how an application will order the creation of the various objects.

Because of this, all initialization of resources that depend upon one
or more KDevCore objects should go in an 'initialize' method that is
called by KDevCore::initialize();  Similarly, all cleanup of resources
that depend upon one or more KDevCore objects should go in a 'cleanUp'
method that is called by KDevMainWindow::queryClose();  Once this
cleanUp is performed the objects can be safely deleted from KDevCore.

CCMAIL: kdevelop-devel at kdevelop.org



 M  +5 -0      kdevcore.cpp  
 M  +12 -11    kdevdocumentcontroller.cpp  
 M  +8 -7      kdevdocumentcontroller.h  
 M  +6 -14     kdevmainwindow.cpp  
 M  +5 -0      kdevplugincontroller.cpp  
 M  +3 -0      kdevplugincontroller.h  
 M  +5 -0      kdevprojectcontroller.cpp  
 M  +3 -0      kdevprojectcontroller.h  


--- trunk/KDE/kdevelop/lib/kdevcore.cpp #569356:569357
@@ -202,6 +202,11 @@
 
 void KDevCore::initialize()
 {
+    //All KDevCore API objects can utilize all resources which
+    //depend upon one another.  Can not do this in the constructor
+    //as they might depend upon one another.
+
+    //FIXME standardize on 'initialize' method name.
     Q_ASSERT( d->documentController );
     Q_ASSERT( d->mainWindow );
     d->documentController->init();
--- trunk/KDE/kdevelop/lib/kdevdocumentcontroller.cpp #569356:569357
@@ -92,6 +92,17 @@
     m_openNextAsText = false;
 }
 
+KDevDocumentController::~KDevDocumentController()
+{
+}
+
+void KDevDocumentController::cleanUp()
+{
+    querySaveDocuments();
+    blockSignals( true ); //No more signals as we're ready to close
+    closeAllDocuments();
+}
+
 void KDevDocumentController::setEncoding( const QString &encoding )
 {
     m_presetEncoding = encoding;
@@ -438,16 +449,6 @@
     return state;
 }
 
-bool KDevDocumentController::readyToClose()
-{
-    blockSignals( true );
-
-    // this should never return false, as the files are already saved
-    closeAllDocuments();
-
-    return true;
-}
-
 bool KDevDocumentController::querySaveDocuments()
 {
     return saveDocumentsDialog();
@@ -704,7 +705,7 @@
 void KDevDocumentController::updateMenuItems()
 {
     //FIXME by moving all of this out of documentcontroller preferably
-    return;
+
     bool hasWriteParts = false;
     bool hasReadOnlyParts = false;
 
--- trunk/KDE/kdevelop/lib/kdevdocumentcontroller.h #569356:569357
@@ -79,7 +79,11 @@
     /**Constructor.
     @param parent The parent object.*/
     KDevDocumentController( QObject *parent = 0 );
+    virtual ~KDevDocumentController();
 
+    /** Release all resources that depend on other KDevCore objects */
+    void cleanUp();
+
     /**Call this before a call to @ref editDocument to set the encoding of the
     document to be opened.
     @param encoding The encoding to open as.*/
@@ -145,19 +149,13 @@
     @return The DocumentState enum corresponding to the document state.*/
     KDevDocument::DocumentState documentState( KDevDocument* document ) const;
 
-    bool readyToClose();
-    bool querySaveDocuments();
-    void openEmptyTextDocument();
-    void integrateTextEditorPart( KTextEditor::Document* doc );
-
 public Q_SLOTS:
     /**Opens a new or existing document.
     @param url The full Url of the document to open.
     @param range The location information, if applicable.
     @param activate Indicates whether to fully activate the document.*/
     Q_SCRIPTABLE KDevDocument* editDocument( const KUrl &url,
-            const KTextEditor::Cursor& range =
-                KTextEditor::Cursor::invalid(),
+            const KTextEditor::Cursor& range = KTextEditor::Cursor::invalid(),
             bool activate = true );
 
     /**Saves all open documents.
@@ -231,6 +229,9 @@
     void slotNewDesignerStatus( const QString &formName, int status );
 
 private:
+    bool querySaveDocuments();
+    void openEmptyTextDocument();
+    void integrateTextEditorPart( KTextEditor::Document* doc );
     void setCursorPosition( KParts::Part *part,
                             const KTextEditor::Cursor& cursor );
     bool openAsDialog( const KUrl &url, KMimeType::Ptr mimeType );
--- trunk/KDE/kdevelop/lib/kdevmainwindow.cpp #569356:569357
@@ -414,22 +414,14 @@
 
 bool KDevMainWindow::queryClose()
 {
-    bool success = true;
-    //FIXME change all of these method calls to cleanUp()
-    if ( !KDevCore::projectController() ->closeProject() )
-        success = false;
+    //All KDevCore API objects must release all resources which
+    //depend upon one another.
+    KDevCore::projectController() ->cleanUp();
+    KDevCore::documentController() ->cleanUp();
+    KDevCore::pluginController() ->cleanUp();
 
-    if ( !KDevCore::documentController() ->querySaveDocuments() )
-        success = false;
-
-    if ( !KDevCore::documentController() ->readyToClose() )
-        success = false;
-
-    if ( !KDevCore::pluginController() ->unloadPlugins() )
-        success = false;
-
     saveSettings();
-    return success;
+    return true;
 }
 
 void KDevMainWindow::setupWindowMenu()
--- trunk/KDE/kdevelop/lib/kdevplugincontroller.cpp #569356:569357
@@ -78,6 +78,11 @@
     unloadPlugins();
 }
 
+void KDevPluginController::cleanUp()
+{
+    unloadPlugins();
+}
+
 KService::List KDevPluginController::query( const QString &serviceType,
         const QString &constraint )
 {
--- trunk/KDE/kdevelop/lib/kdevplugincontroller.h #569356:569357
@@ -53,6 +53,9 @@
     KDevPluginController();
     virtual ~KDevPluginController();
 
+    /** Release all resources that depend on other KDevCore objects */
+    void cleanUp();
+
     /**
      * Returns a uniquely specified plugin. If it isn't already loaded, it will be.
      * Use with caution! See extension for parameter details.
--- trunk/KDE/kdevelop/lib/kdevprojectcontroller.cpp #569356:569357
@@ -47,6 +47,11 @@
 KDevProjectController::~KDevProjectController()
 {}
 
+void KDevProjectController::cleanUp()
+{
+    closeProject();
+}
+
 void KDevProjectController::init()
 {
     KConfig * config = KDevConfig::standard();
--- trunk/KDE/kdevelop/lib/kdevprojectcontroller.h #569356:569357
@@ -36,6 +36,9 @@
     KDevProjectController( QObject *parent = 0 );
     virtual ~KDevProjectController();
 
+    /** Release all resources that depend on other KDevCore objects */
+    void cleanUp();
+
     QString name() const;
     void setName( const QString &name );
 




More information about the KDevelop-devel mailing list