TextToolbar.mjs (1882B)
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 { Component } from "resource://devtools/client/shared/vendor/react.mjs"; 6 import PropTypes from "resource://devtools/client/shared/vendor/react-prop-types.mjs"; 7 import { createFactories } from "resource://devtools/client/shared/react-utils.mjs"; 8 9 import ToolbarClass from "resource://devtools/client/jsonview/components/reps/Toolbar.mjs"; 10 11 const { Toolbar, ToolbarButton } = createFactories(ToolbarClass); 12 13 /** 14 * This object represents a toolbar displayed within the 15 * 'Raw Data' panel. 16 */ 17 class TextToolbar extends Component { 18 static get propTypes() { 19 return { 20 actions: PropTypes.object, 21 isValidJson: PropTypes.bool, 22 }; 23 } 24 25 constructor(props) { 26 super(props); 27 this.onPrettify = this.onPrettify.bind(this); 28 this.onSave = this.onSave.bind(this); 29 this.onCopy = this.onCopy.bind(this); 30 } 31 32 // Commands 33 34 onPrettify() { 35 this.props.actions.onPrettify(); 36 } 37 38 onSave() { 39 this.props.actions.onSaveJson(); 40 } 41 42 onCopy() { 43 this.props.actions.onCopyJson(); 44 } 45 46 render() { 47 return Toolbar( 48 {}, 49 ToolbarButton( 50 { 51 className: "btn save", 52 onClick: this.onSave, 53 }, 54 JSONView.Locale["jsonViewer.Save"] 55 ), 56 ToolbarButton( 57 { 58 className: "btn copy", 59 onClick: this.onCopy, 60 }, 61 JSONView.Locale["jsonViewer.Copy"] 62 ), 63 this.props.isValidJson 64 ? ToolbarButton( 65 { 66 className: "btn prettyprint", 67 onClick: this.onPrettify, 68 }, 69 JSONView.Locale["jsonViewer.PrettyPrint"] 70 ) 71 : null 72 ); 73 } 74 } 75 76 export default { TextToolbar };