index.js (4918B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 import React, { Component } from "devtools/client/shared/vendor/react"; 6 import PropTypes from "devtools/client/shared/vendor/react-prop-types"; 7 8 import actions from "../../actions/index"; 9 import { getSelectedPrimaryPaneTab } from "../../selectors/index"; 10 import { prefs, features } from "../../utils/prefs"; 11 import { connect } from "devtools/client/shared/vendor/react-redux"; 12 import { primaryPaneTabs } from "../../constants"; 13 14 import Outline from "./Outline"; 15 import SourcesTree from "./SourcesTree"; 16 import ProjectSearch from "./ProjectSearch"; 17 import Tracer from "./Tracer"; 18 const AppErrorBoundary = require("resource://devtools/client/shared/components/AppErrorBoundary.js"); 19 20 const { TabPanel, Tabs } = ChromeUtils.importESModule( 21 "resource://devtools/client/shared/components/tabs/Tabs.mjs", 22 { global: "current" } 23 ); 24 25 // Note that the following list should follow the same order as displayed 26 const tabs = [ 27 primaryPaneTabs.SOURCES, 28 primaryPaneTabs.OUTLINE, 29 primaryPaneTabs.PROJECT_SEARCH, 30 ]; 31 if (features.javascriptTracing) { 32 tabs.push(primaryPaneTabs.TRACER); 33 } 34 35 class PrimaryPanes extends Component { 36 constructor(props) { 37 super(props); 38 39 this.state = { 40 alphabetizeOutline: prefs.alphabetizeOutline, 41 }; 42 } 43 44 static get propTypes() { 45 return { 46 selectedTab: PropTypes.oneOf(tabs).isRequired, 47 setPrimaryPaneTab: PropTypes.func.isRequired, 48 setActiveSearch: PropTypes.func.isRequired, 49 closeActiveSearch: PropTypes.func.isRequired, 50 }; 51 } 52 53 onAlphabetizeClick = () => { 54 const alphabetizeOutline = !prefs.alphabetizeOutline; 55 prefs.alphabetizeOutline = alphabetizeOutline; 56 this.setState({ alphabetizeOutline }); 57 }; 58 59 onActivateTab = index => { 60 const tab = tabs.at(index); 61 this.props.setPrimaryPaneTab(tab); 62 if (tab == primaryPaneTabs.PROJECT_SEARCH) { 63 this.props.setActiveSearch(tab); 64 } else { 65 this.props.closeActiveSearch(); 66 } 67 }; 68 69 render() { 70 const { selectedTab } = this.props; 71 return React.createElement( 72 "aside", 73 { 74 className: "tab-panel sources-panel", 75 }, 76 React.createElement( 77 Tabs, 78 { 79 activeTab: tabs.indexOf(selectedTab), 80 onAfterChange: this.onActivateTab, 81 }, 82 React.createElement( 83 TabPanel, 84 { 85 id: "sources-tab", 86 key: `sources-tab${ 87 selectedTab === primaryPaneTabs.SOURCES ? "-selected" : "" 88 }`, 89 className: "tab sources-tab", 90 title: L10N.getStr("sources.header"), 91 }, 92 React.createElement(SourcesTree, null) 93 ), 94 React.createElement( 95 TabPanel, 96 { 97 id: "outline-tab", 98 key: `outline-tab${ 99 selectedTab === primaryPaneTabs.OUTLINE ? "-selected" : "" 100 }`, 101 className: "tab outline-tab", 102 title: L10N.getStr("outline.header"), 103 }, 104 React.createElement(Outline, { 105 alphabetizeOutline: this.state.alphabetizeOutline, 106 onAlphabetizeClick: this.onAlphabetizeClick, 107 }) 108 ), 109 React.createElement( 110 TabPanel, 111 { 112 id: "search-tab", 113 key: `search-tab${ 114 selectedTab === primaryPaneTabs.PROJECT_SEARCH ? "-selected" : "" 115 }`, 116 className: "tab search-tab", 117 title: L10N.getStr("search.header"), 118 }, 119 React.createElement(ProjectSearch, null) 120 ), 121 features.javascriptTracing 122 ? React.createElement( 123 TabPanel, 124 { 125 id: "tracer-tab", 126 key: `tracer-tab${ 127 selectedTab === primaryPaneTabs.TRACER ? "-selected" : "" 128 }`, 129 className: "tab tracer-tab", 130 title: L10N.getStr("tracer.header"), 131 }, 132 // As the tracer is an application on its own (and is prototypish) 133 // let's encapsulate it to track its own exceptions. 134 React.createElement( 135 AppErrorBoundary, 136 { 137 componentName: "Debugger", 138 panel: "JavaScript Tracer", 139 }, 140 React.createElement(Tracer) 141 ) 142 ) 143 : null 144 ) 145 ); 146 } 147 } 148 149 const mapStateToProps = state => { 150 return { 151 selectedTab: getSelectedPrimaryPaneTab(state), 152 }; 153 }; 154 155 const connector = connect(mapStateToProps, { 156 setPrimaryPaneTab: actions.setPrimaryPaneTab, 157 setActiveSearch: actions.setActiveSearch, 158 closeActiveSearch: actions.closeActiveSearch, 159 }); 160 161 export default connector(PrimaryPanes);