commandBarComponent.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: "Theme",
  43. storeKey: "theme",
  44. defaultValue: "Light",
  45. subItems: [
  46. "Light",
  47. "Dark"
  48. ],
  49. onClick: () => {
  50. this.props.globalState.onThemeChangedObservable.notifyObservers();
  51. }
  52. },
  53. {
  54. label: "Font size",
  55. storeKey: "font-size",
  56. defaultValue: "14",
  57. subItems: [
  58. "12",
  59. "14",
  60. "16",
  61. "18",
  62. "20",
  63. "22",
  64. "24",
  65. "26",
  66. "28",
  67. "30",
  68. ],
  69. onClick: () => {
  70. this.props.globalState.onFontSizeChangedObservable.notifyObservers();
  71. }
  72. },
  73. {
  74. label: "Safe mode",
  75. storeKey: "safe-mode",
  76. defaultValue: false,
  77. onCheck: () => {}
  78. },
  79. {
  80. label: "CTRL+S to save",
  81. storeKey: "ctrl-s-to-save",
  82. defaultValue: true,
  83. onCheck: () => {}
  84. },
  85. {
  86. label: "editor",
  87. storeKey: "editor",
  88. defaultValue: true,
  89. onCheck: (value) => {this.props.globalState.onEditorDisplayChangedObservable.notifyObservers(value)}
  90. }, {
  91. label: "minimap",
  92. storeKey: "minimap",
  93. defaultValue: true,
  94. onCheck: (value) => {this.props.globalState.onMinimapChangedObservable.notifyObservers(value)}
  95. }, {
  96. label: "fullscreen",
  97. onClick: () => {this.props.globalState.onFullcreenRequiredObservable.notifyObservers()}
  98. }, {
  99. label: "fullscreen editor",
  100. onClick: () => {this.props.globalState.onEditorFullcreenRequiredObservable.notifyObservers()}
  101. }, {
  102. label: "format code",
  103. onClick: () => {this.props.globalState.onFormatCodeRequiredObservable.notifyObservers()}
  104. },
  105. {
  106. label: "metadata",
  107. onClick: () => {this.props.globalState.onDisplayMetadataObservable.notifyObservers(true)}
  108. }
  109. ]}/>
  110. </div>
  111. );
  112. }
  113. }