1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/scratchpad/scratchpad-panel.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +"use strict"; 1.10 + 1.11 +const {Cu} = require("chrome"); 1.12 +const EventEmitter = require("devtools/toolkit/event-emitter"); 1.13 +const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); 1.14 + 1.15 + 1.16 +function ScratchpadPanel(iframeWindow, toolbox) { 1.17 + let { Scratchpad } = iframeWindow; 1.18 + this._toolbox = toolbox; 1.19 + this.panelWin = iframeWindow; 1.20 + this.scratchpad = Scratchpad; 1.21 + 1.22 + Scratchpad.target = this.target; 1.23 + Scratchpad.hideMenu(); 1.24 + 1.25 + let deferred = promise.defer(); 1.26 + this._readyObserver = deferred.promise; 1.27 + Scratchpad.addObserver({ 1.28 + onReady: function() { 1.29 + Scratchpad.removeObserver(this); 1.30 + deferred.resolve(); 1.31 + } 1.32 + }); 1.33 + 1.34 + EventEmitter.decorate(this); 1.35 +} 1.36 +exports.ScratchpadPanel = ScratchpadPanel; 1.37 + 1.38 +ScratchpadPanel.prototype = { 1.39 + /** 1.40 + * Open is effectively an asynchronous constructor. For the ScratchpadPanel, 1.41 + * by the time this is called, the Scratchpad will already be ready. 1.42 + */ 1.43 + open: function() { 1.44 + return this._readyObserver.then(() => { 1.45 + this.isReady = true; 1.46 + this.emit("ready"); 1.47 + return this; 1.48 + }); 1.49 + }, 1.50 + 1.51 + get target() { 1.52 + return this._toolbox.target; 1.53 + }, 1.54 + 1.55 + destroy: function() { 1.56 + this.emit("destroyed"); 1.57 + return promise.resolve(); 1.58 + } 1.59 +};