commandBarComponent.tsx 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import * as React from "react";
  2. import { GlobalState } from '../globalState';
  3. import { CommandButtonComponent } from './commandButtonComponent';
  4. import { CommandDropdownComponent } from './commandDropdownComponent';
  5. require("../scss/commandBar.scss");
  6. interface ICommandBarComponentProps {
  7. globalState: GlobalState;
  8. }
  9. export class CommandBarComponent extends React.Component<ICommandBarComponentProps> {
  10. public constructor(props: ICommandBarComponentProps) {
  11. super(props);
  12. }
  13. onPlay() {
  14. this.props.globalState.onRunRequiredObservable.notifyObservers();
  15. }
  16. onNew() {
  17. this.props.globalState.onNewRequiredObservable.notifyObservers();
  18. }
  19. onClear() {
  20. this.props.globalState.onClearRequiredObservable.notifyObservers();
  21. }
  22. onSave() {
  23. this.props.globalState.onSaveRequiredObservable.notifyObservers();
  24. }
  25. onDownload() {
  26. this.props.globalState.onDownloadRequiredObservable.notifyObservers();
  27. }
  28. onInspector() {
  29. this.props.globalState.onInspectorRequiredObservable.notifyObservers();
  30. }
  31. public render() {
  32. return (
  33. <div className={"commands " + (this.props.globalState.language === "JS" ? "background-js" : "background-ts")}>
  34. <CommandButtonComponent globalState={this.props.globalState} tooltip="Run" icon="play" shortcut="Alt+Enter" isActive={true} onClick={()=> this.onPlay()}/>
  35. <CommandButtonComponent globalState={this.props.globalState} tooltip="Save" icon="save" shortcut="Ctrl+S" isActive={false} onClick={()=> this.onSave()}/>
  36. <CommandButtonComponent globalState={this.props.globalState} tooltip="Inspector" icon="inspector" isActive={false} onClick={()=> this.onInspector()}/>
  37. <CommandButtonComponent globalState={this.props.globalState} tooltip="Download" icon="download" shortcut="Shift+Ctrl+S"isActive={false} onClick={()=> this.onDownload()}/>
  38. <CommandButtonComponent globalState={this.props.globalState} tooltip="Create new" icon="new" isActive={false} onClick={()=> this.onNew()}/>
  39. <CommandButtonComponent globalState={this.props.globalState} tooltip="Clear code" icon="clear" isActive={false} onClick={()=> this.onClear()}/>
  40. <CommandDropdownComponent globalState={this.props.globalState} icon="options" tooltip="Options" items={[
  41. {
  42. label: "Safe mode",
  43. storeKey: "safe-mode",
  44. defaultValue: false,
  45. onCheck: () => {}
  46. },
  47. {
  48. label: "CTRL+S to save",
  49. storeKey: "ctrl-s-to-save",
  50. defaultValue: true,
  51. onCheck: () => {}
  52. },
  53. {
  54. label: "editor",
  55. storeKey: "editor",
  56. defaultValue: true,
  57. onCheck: (value) => {this.props.globalState.onEditorDisplayChangedObservable.notifyObservers(value)}
  58. }, {
  59. label: "minimap",
  60. storeKey: "minimap",
  61. defaultValue: true,
  62. onCheck: (value) => {this.props.globalState.onMinimapChangedObservable.notifyObservers(value)}
  63. }, {
  64. label: "fullscreen",
  65. onClick: () => {this.props.globalState.onFullcreenRequiredObservable.notifyObservers()}
  66. }, {
  67. label: "fullscreen editor",
  68. onClick: () => {this.props.globalState.onEditorFullcreenRequiredObservable.notifyObservers()}
  69. }, {
  70. label: "format code",
  71. onClick: () => {this.props.globalState.onFormatCodeRequiredObservable.notifyObservers()}
  72. },
  73. {
  74. label: "metadata",
  75. onClick: () => {this.props.globalState.onDisplayMetadataObservable.notifyObservers(true)}
  76. }
  77. ]}/>
  78. </div>
  79. );
  80. }
  81. }