commandBarComponent.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import * as React from "react";
  2. import { GlobalState } from '../globalState';
  3. import { CommandButtonComponent } from './commandButtonComponent';
  4. import { CommandDropdownComponent } from './commandDropdownComponent';
  5. import { Utilities } from '../tools/utilities';
  6. require("../scss/commandBar.scss");
  7. declare var Versions: any;
  8. interface ICommandBarComponentProps {
  9. globalState: GlobalState;
  10. }
  11. export class CommandBarComponent extends React.Component<ICommandBarComponentProps> {
  12. public constructor(props: ICommandBarComponentProps) {
  13. super(props);
  14. }
  15. onPlay() {
  16. this.props.globalState.onRunRequiredObservable.notifyObservers();
  17. }
  18. onNew() {
  19. this.props.globalState.onNewRequiredObservable.notifyObservers();
  20. }
  21. onClear() {
  22. this.props.globalState.onClearRequiredObservable.notifyObservers();
  23. }
  24. onSave() {
  25. this.props.globalState.onSaveRequiredObservable.notifyObservers();
  26. }
  27. onDownload() {
  28. this.props.globalState.onDownloadRequiredObservable.notifyObservers();
  29. }
  30. onInspector() {
  31. this.props.globalState.onInspectorRequiredObservable.notifyObservers(!this.props.globalState.inspectorIsOpened);
  32. }
  33. onExamples() {
  34. this.props.globalState.onExamplesDisplayChangedObservable.notifyObservers();
  35. }
  36. public render() {
  37. let activeVersion = Utilities.ReadStringFromStore("version", "Latest");
  38. var versionOptions = Object.keys(Versions).map(key => {
  39. return {
  40. label: key,
  41. storeKey: "version",
  42. defaultValue: "Latest",
  43. isActive: activeVersion === key,
  44. onClick: () => {
  45. Utilities.StoreStringToStore("version", key);
  46. window.location.reload();
  47. }
  48. }
  49. });
  50. return (
  51. <div className={"commands " + (this.props.globalState.language === "JS" ? "background-js" : "background-ts")}>
  52. <div className="commands-left">
  53. <CommandButtonComponent globalState={this.props.globalState} tooltip="Run" icon="play" shortcut="Alt+Enter" isActive={true} onClick={()=> this.onPlay()}/>
  54. <CommandButtonComponent globalState={this.props.globalState} tooltip="Save" icon="save" shortcut="Ctrl+S" isActive={false} onClick={()=> this.onSave()}/>
  55. <CommandButtonComponent globalState={this.props.globalState} tooltip="Inspector" icon="inspector" isActive={false} onClick={()=> this.onInspector()}/>
  56. <CommandButtonComponent globalState={this.props.globalState} tooltip="Download" icon="download" shortcut="Shift+Ctrl+S"isActive={false} onClick={()=> this.onDownload()}/>
  57. <CommandButtonComponent globalState={this.props.globalState} tooltip="Create new" icon="new" isActive={false} onClick={()=> this.onNew()}/>
  58. <CommandButtonComponent globalState={this.props.globalState} tooltip="Clear code" icon="clear" isActive={false} onClick={()=> this.onClear()}/>
  59. <CommandDropdownComponent globalState={this.props.globalState} icon="options" tooltip="Options" items={[
  60. {
  61. label: "Theme",
  62. storeKey: "theme",
  63. defaultValue: "Light",
  64. subItems: [
  65. "Light",
  66. "Dark"
  67. ],
  68. onClick: () => {
  69. this.props.globalState.onThemeChangedObservable.notifyObservers();
  70. }
  71. },
  72. {
  73. label: "Font size",
  74. storeKey: "font-size",
  75. defaultValue: "14",
  76. subItems: [
  77. "12",
  78. "14",
  79. "16",
  80. "18",
  81. "20",
  82. "22",
  83. "24",
  84. "26",
  85. "28",
  86. "30",
  87. ],
  88. onClick: () => {
  89. this.props.globalState.onFontSizeChangedObservable.notifyObservers();
  90. }
  91. },
  92. {
  93. label: "Safe mode",
  94. storeKey: "safe-mode",
  95. defaultValue: false,
  96. onCheck: () => {}
  97. },
  98. {
  99. label: "CTRL+S to save",
  100. storeKey: "ctrl-s-to-save",
  101. defaultValue: true,
  102. onCheck: () => {}
  103. },
  104. {
  105. label: "editor",
  106. storeKey: "editor",
  107. defaultValue: true,
  108. onCheck: (value) => {this.props.globalState.onEditorDisplayChangedObservable.notifyObservers(value)}
  109. }, {
  110. label: "minimap",
  111. storeKey: "minimap",
  112. defaultValue: true,
  113. onCheck: (value) => {this.props.globalState.onMinimapChangedObservable.notifyObservers(value)}
  114. }, {
  115. label: "fullscreen",
  116. onClick: () => {this.props.globalState.onFullcreenRequiredObservable.notifyObservers()}
  117. }, {
  118. label: "fullscreen editor",
  119. onClick: () => {this.props.globalState.onEditorFullcreenRequiredObservable.notifyObservers()}
  120. }, {
  121. label: "format code",
  122. onClick: () => {this.props.globalState.onFormatCodeRequiredObservable.notifyObservers()}
  123. },
  124. {
  125. label: "metadata",
  126. onClick: () => {this.props.globalState.onDisplayMetadataObservable.notifyObservers(true)}
  127. },
  128. {
  129. label: "QR code",
  130. onClick: () => {this.props.globalState.onQRCodeRequiredObservable.notifyObservers(true)}
  131. }
  132. ]}/>
  133. </div>
  134. <div className="commands-right">
  135. <CommandDropdownComponent globalState={this.props.globalState} icon="version" tooltip="Versions" toRight={true} items={versionOptions} />
  136. <CommandButtonComponent globalState={this.props.globalState} tooltip="Examples" icon="examples" onClick={()=> this.onExamples()} isActive={false}/>
  137. </div>
  138. </div>
  139. );
  140. }
  141. }