[gnome-shell] Use _onDestroy() handlers for cleanup in delegates



commit 9f43ed3f95bb70f2c15c4cebd27f1205fb8849e8
Author: Florian Müllner <fmuellner src gnome org>
Date:   Thu Feb 18 16:43:58 2010 +0100

    Use _onDestroy() handlers for cleanup in delegates
    
    Unify the style of <delegate>.destroy() methods to only contain a
    call to <delegate>.actor.destroy() and handle additional cleanup
    in a _onDestroy() signal handler.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=609454

 js/ui/lightbox.js       |   18 ++++++++++++------
 js/ui/workspace.js      |   10 +++++++---
 js/ui/workspacesView.js |    9 ++++++---
 3 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/js/ui/lightbox.js b/js/ui/lightbox.js
index ffb583b..9434c79 100644
--- a/js/ui/lightbox.js
+++ b/js/ui/lightbox.js
@@ -47,7 +47,7 @@ Lightbox.prototype = {
         container.add_actor(this.actor);
         this.actor.raise_top();
 
-        this._destroySignalId = this.actor.connect('destroy', Lang.bind(this, this.destroy));
+        this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
 
         if (width && height) {
             this.actor.width = width;
@@ -135,18 +135,24 @@ Lightbox.prototype = {
     /**
      * destroy:
      *
-     * Destroys the lightbox. This is called automatically if the
-     * lightbox's container is destroyed.
+     * Destroys the lightbox.
      */
     destroy : function() {
+        this.actor.destroy();
+    },
+
+    /**
+     * _onDestroy:
+     *
+     * This is called when the lightbox' actor is destroyed, either
+     * by destroying its container or by explicitly calling this.destroy().
+     */
+    _onDestroy: function() {
         if (this._allocationChangedSignalId != 0)
             this._container.disconnect(this._allocationChangedSignalId);
         this._container.disconnect(this._actorAddedSignalId);
         this._container.disconnect(this._actorRemovedSignalId);
 
-        this.actor.disconnect(this._destroySignalId);
-
         this.highlight(null);
-        this.actor.destroy();
     }
 };
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index 3af8c71..8ca507c 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -581,6 +581,9 @@ Workspace.prototype = {
 
         this.actor = new Clutter.Group();
         this.actor._delegate = this;
+
+        this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
+
         // Auto-sizing is unreliable in the presence of ClutterClone, so rather than
         // implicitly counting on the workspace actor to be sized to the size of the
         // included desktop actor clone, set the size explicitly to the screen size.
@@ -1330,10 +1333,11 @@ Workspace.prototype = {
     },
 
     destroy : function() {
-        Tweener.removeTweens(this.actor);
         this.actor.destroy();
-        this.actor = null;
-        this._windowOverlaysGroup.destroy();
+    },
+
+    _onDestroy: function(actor) {
+        Tweener.removeTweens(actor);
 
         this._metaWorkspace.disconnect(this._windowAddedId);
         this._metaWorkspace.disconnect(this._windowRemovedId);
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 0cdca95..73144eb 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -39,6 +39,8 @@ GenericWorkspacesView.prototype = {
         this.actor = new St.Bin({ style_class: "workspaces" });
         this._actor = new Clutter.Group();
 
+        this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
+
         this.actor.add_actor(this._actor);
         this.actor.connect('style-changed', Lang.bind(this,
             function() {
@@ -181,13 +183,14 @@ GenericWorkspacesView.prototype = {
     },
 
     destroy: function() {
+        this.actor.destroy();
+    },
+
+    _onDestroy: function() {
         for (let w = 0; w < this._workspaces.length; w++)
             this._workspaces[w].destroy();
         this._workspaces = [];
 
-        this.actor.destroy();
-        this.actor = null;
-
         Main.overview.disconnect(this._overviewShowingId);
         global.screen.disconnect(this._nWorkspacesNotifyId);
         global.window_manager.disconnect(this._switchWorkspaceNotifyId);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]