From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- devtools/client/inspector/toolsidebar.js | 325 +++++++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 devtools/client/inspector/toolsidebar.js (limited to 'devtools/client/inspector/toolsidebar.js') diff --git a/devtools/client/inspector/toolsidebar.js b/devtools/client/inspector/toolsidebar.js new file mode 100644 index 000000000..d013b7b84 --- /dev/null +++ b/devtools/client/inspector/toolsidebar.js @@ -0,0 +1,325 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var EventEmitter = require("devtools/shared/event-emitter"); +var Telemetry = require("devtools/client/shared/telemetry"); +var { Task } = require("devtools/shared/task"); + +/** + * This object represents replacement for ToolSidebar + * implemented in devtools/client/framework/sidebar.js module + * + * This new component is part of devtools.html aimed at + * removing XUL and use HTML for entire DevTools UI. + * There are currently two implementation of the side bar since + * the `sidebar.js` module (mentioned above) is still used by + * other panels. + * As soon as all panels are using this HTML based + * implementation it can be removed. + */ +function ToolSidebar(tabbox, panel, uid, options = {}) { + EventEmitter.decorate(this); + + this._tabbox = tabbox; + this._uid = uid; + this._panelDoc = this._tabbox.ownerDocument; + this._toolPanel = panel; + this._options = options; + + if (!options.disableTelemetry) { + this._telemetry = new Telemetry(); + } + + this._tabs = []; + + if (this._options.hideTabstripe) { + this._tabbox.setAttribute("hidetabs", "true"); + } + + this.render(); + + this._toolPanel.emit("sidebar-created", this); +} + +exports.ToolSidebar = ToolSidebar; + +ToolSidebar.prototype = { + TABPANEL_ID_PREFIX: "sidebar-panel-", + + // React + + get React() { + return this._toolPanel.React; + }, + + get ReactDOM() { + return this._toolPanel.ReactDOM; + }, + + get browserRequire() { + return this._toolPanel.browserRequire; + }, + + get InspectorTabPanel() { + return this._toolPanel.InspectorTabPanel; + }, + + // Rendering + + render: function () { + let Tabbar = this.React.createFactory(this.browserRequire( + "devtools/client/shared/components/tabs/tabbar")); + + let sidebar = Tabbar({ + toolbox: this._toolPanel._toolbox, + showAllTabsMenu: true, + onSelect: this.handleSelectionChange.bind(this), + }); + + this._tabbar = this.ReactDOM.render(sidebar, this._tabbox); + }, + + /** + * Register a side-panel tab. + * + * @param {string} tab uniq id + * @param {string} title tab title + * @param {React.Component} panel component. See `InspectorPanelTab` as an example. + * @param {boolean} selected true if the panel should be selected + */ + addTab: function (id, title, panel, selected) { + this._tabbar.addTab(id, title, selected, panel); + this.emit("new-tab-registered", id); + }, + + /** + * Helper API for adding side-panels that use existing DOM nodes + * (defined within inspector.xhtml) as the content. + * + * @param {string} tab uniq id + * @param {string} title tab title + * @param {boolean} selected true if the panel should be selected + */ + addExistingTab: function (id, title, selected) { + let panel = this.InspectorTabPanel({ + id: id, + idPrefix: this.TABPANEL_ID_PREFIX, + key: id, + title: title, + }); + + this.addTab(id, title, panel, selected); + }, + + /** + * Helper API for adding side-panels that use existing