michael@0: /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: const {Cu} = require("chrome"); michael@0: const EventEmitter = require("devtools/toolkit/event-emitter"); michael@0: const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); michael@0: michael@0: michael@0: function ScratchpadPanel(iframeWindow, toolbox) { michael@0: let { Scratchpad } = iframeWindow; michael@0: this._toolbox = toolbox; michael@0: this.panelWin = iframeWindow; michael@0: this.scratchpad = Scratchpad; michael@0: michael@0: Scratchpad.target = this.target; michael@0: Scratchpad.hideMenu(); michael@0: michael@0: let deferred = promise.defer(); michael@0: this._readyObserver = deferred.promise; michael@0: Scratchpad.addObserver({ michael@0: onReady: function() { michael@0: Scratchpad.removeObserver(this); michael@0: deferred.resolve(); michael@0: } michael@0: }); michael@0: michael@0: EventEmitter.decorate(this); michael@0: } michael@0: exports.ScratchpadPanel = ScratchpadPanel; michael@0: michael@0: ScratchpadPanel.prototype = { michael@0: /** michael@0: * Open is effectively an asynchronous constructor. For the ScratchpadPanel, michael@0: * by the time this is called, the Scratchpad will already be ready. michael@0: */ michael@0: open: function() { michael@0: return this._readyObserver.then(() => { michael@0: this.isReady = true; michael@0: this.emit("ready"); michael@0: return this; michael@0: }); michael@0: }, michael@0: michael@0: get target() { michael@0: return this._toolbox.target; michael@0: }, michael@0: michael@0: destroy: function() { michael@0: this.emit("destroyed"); michael@0: return promise.resolve(); michael@0: } michael@0: };