Call "elementAppended" on the components only after all of them are added, and minor style fixes.
authorPatrick Walton <pwalton@mozilla.com>
Fri, 24 Sep 2010 16:32:33 +0200
changeset 2045 195674fd2f938d8a5ceac5c0b3f0fbd779257afb
parent 2044 b248b949e9d2b8133dc420a36a00a9297ceb07a0
child 2046 675c99acdf513325fbd200458e51539fe59a660c
push id922
push userpwalton@mozilla.com
push dateFri, 24 Sep 2010 14:33:15 +0000
Call "elementAppended" on the components only after all of them are added, and minor style fixes.
plugins/supported/appconfig/index.js
plugins/supported/text_editor/views/canvas.js
--- a/plugins/supported/appconfig/index.js
+++ b/plugins/supported/appconfig/index.js
@@ -31,16 +31,17 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 var $ = require('jquery').$;
+var _ = require('underscore')._;
 var settings = require('settings').settings;
 var group = require("bespin:promise").group;
 var Promise = require("bespin:promise").Promise;
 var console = require("bespin:console").console;
 var Trace = require("bespin:util/stacktrace").Trace;
 var util = require('bespin:util/util');
 
 var firstBespin = true;
@@ -330,17 +331,19 @@ var generateGUI = function(catalog, conf
     var centerContainer = document.createElement('div');
     centerContainer.setAttribute('class', 'center-container');
     var centerAdded = false;
 
     var element = config.element || document.body;
     // Add the 'bespin' class to the element in case it doesn't have this already.
     util.addClass(element, 'bespin');
     element.appendChild(container);
-    
+
+    var elementAppendedQueue = [];
+
     // this shouldn't be necessary, but it looks like Firefox has an issue
     // with the box-ordinal-group CSS property
     ['north', 'west', 'center', 'east', 'south'].forEach(function(place) {
         var descriptor = config.gui[place];
         if (!descriptor) {
             return;
         }
 
@@ -369,16 +372,18 @@ var generateGUI = function(catalog, conf
                 container.appendChild(centerContainer);
                 centerAdded = true;
             }
             centerContainer.appendChild(element);
         } else {
             container.appendChild(element);
         }
 
-        // Call the elementAppended event if there is one.
-        if (component.elementAppended) {
-            component.elementAppended();
+        // Queue up the "elementAppended" event, if the component has one.
+        if (component.elementAppended != null) {
+            elementAppendedQueue.push(component);
         }
     });
 
+    _(elementAppendedQueue).invoke('elementAppended');
+
     pr.resolve();
 };
--- a/plugins/supported/text_editor/views/canvas.js
+++ b/plugins/supported/text_editor/views/canvas.js
@@ -38,19 +38,17 @@
 var util = require('bespin:util/util');
 var Rect = require('utils/rect');
 var Event = require('events').Event;
 
 /**
  * @class
  *
  * This class provides support for manual scrolling and positioning for canvas-
- * based elements. Getting these elements to play nicely with SproutCore is
- * tricky and error-prone, so all canvas-based views should consider deriving
- * from this class. Derived views should implement drawRect() in order to
+ * based elements. Derived views should implement drawRect() in order to
  * perform the appropriate canvas drawing logic.
  *
  * The actual size of the canvas is always the size of the container the canvas
  * view is placed in.
  *
  * The canvas that is created is available in the domNode attribute and should
  * be added to the document by the caller.
  */
@@ -122,17 +120,19 @@ exports.CanvasView.prototype = {
      * Subclasses can override this method to provide custom behavior whenever
      * the clipping frame changes. The default implementation simply
      * invalidates the entire visible area.
      */
     clippingFrameChanged: function() {
         this.invalidate();
     },
 
-    drawRect: function(rect, context) { },
+    drawRect: function(rect, context) {
+        // abstract
+    },
 
     /**
      * Render the canvas. Rendering is delayed by a few ms to empty the call
      * stack first before rendering. If the canvas was rendered in less then
      * this.minimumRedrawDelay ms, then the next rendering will take in
      * this.minimumRedrawDelay - now + lastRendering ms.
      */
     render: function() {
@@ -309,8 +309,9 @@ Object.defineProperties(exports.CanvasVi
             // The clipping frame might have changed if the size changed.
             this.clippingFrame = {
                 width: frame.width,
                 height: frame.height
             };
         }
     }
 });
+