|
| 1 | +import * as React from 'react'; |
| 2 | +import { |
| 3 | + activityBarService, |
| 4 | + colorThemeService, |
| 5 | + editorService, |
| 6 | + panelService, |
| 7 | +} from 'mo'; |
| 8 | +import { Button } from 'mo/components/button'; |
| 9 | +import { Select, Option } from 'mo/components/select'; |
| 10 | +import { IColorTheme } from 'mo/model/colorTheme'; |
| 11 | +import { IEditorTab } from 'mo/model'; |
| 12 | + |
| 13 | +export default class TestPane extends React.Component { |
| 14 | + constructor(props) { |
| 15 | + super(props); |
| 16 | + } |
| 17 | + |
| 18 | + onClick = (e, item) => { |
| 19 | + console.log('onClick:', e, item); |
| 20 | + }; |
| 21 | + |
| 22 | + onChangeTheme = (e, option) => { |
| 23 | + if (option && option.value) { |
| 24 | + console.log('onChangeTheme:', option.value); |
| 25 | + colorThemeService.applyTheme(option.value); |
| 26 | + } |
| 27 | + }; |
| 28 | + |
| 29 | + renderColorThemes() { |
| 30 | + const colorThemes = colorThemeService.getThemes(); |
| 31 | + const defaultTheme = colorThemeService.colorTheme; |
| 32 | + const options = colorThemes.map((theme: IColorTheme) => { |
| 33 | + return ( |
| 34 | + <Option key={theme.id} value={theme.id}> |
| 35 | + {theme.label} |
| 36 | + </Option> |
| 37 | + ); |
| 38 | + }); |
| 39 | + return ( |
| 40 | + <Select |
| 41 | + defaultValue={defaultTheme.id} |
| 42 | + onSelect={this.onChangeTheme} |
| 43 | + > |
| 44 | + {options} |
| 45 | + </Select> |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + render() { |
| 50 | + const addABar = function () { |
| 51 | + const id = Math.random() * 10 + 1; |
| 52 | + activityBarService.addBar({ |
| 53 | + id: id + '', |
| 54 | + name: 'folder' + id, |
| 55 | + iconName: 'codicon-edit', |
| 56 | + }); |
| 57 | + }; |
| 58 | + |
| 59 | + const addPanel = function () { |
| 60 | + const id = Math.random() * 10 + 1; |
| 61 | + panelService.open({ |
| 62 | + id: 'Pane' + id, |
| 63 | + name: 'Panel' + id, |
| 64 | + label: 'test', |
| 65 | + render: () => <h1>Test Pane</h1>, |
| 66 | + }); |
| 67 | + }; |
| 68 | + |
| 69 | + const newEditor = function () { |
| 70 | + const key = Math.random() * 10 + 1; |
| 71 | + const tabData: IEditorTab = { |
| 72 | + id: `${key}`, |
| 73 | + name: `editor.js`, |
| 74 | + modified: false, |
| 75 | + data: { |
| 76 | + value: `hello javascript ${key}`, |
| 77 | + path: 'desktop/molecule/editor1', |
| 78 | + language: 'javascript', |
| 79 | + }, |
| 80 | + breadcrumb: [{ id: `${key}`, name: 'editor.js' }], |
| 81 | + }; |
| 82 | + console.log('open editor:', tabData); |
| 83 | + editorService.open(tabData); |
| 84 | + }; |
| 85 | + |
| 86 | + const openCommand = function () {}; |
| 87 | + return ( |
| 88 | + <div> |
| 89 | + <div style={{ margin: '50px 20px' }}> |
| 90 | + <Button onClick={addABar}>Add Bar</Button> |
| 91 | + <Button onClick={newEditor}>New Editor</Button> |
| 92 | + <Button onClick={openCommand}>Command Palette</Button> |
| 93 | + </div> |
| 94 | + <div style={{ margin: '50px 20px' }}> |
| 95 | + <h1>Select a ColorTheme:</h1> |
| 96 | + {this.renderColorThemes()} |
| 97 | + </div> |
| 98 | + <div style={{ margin: '50px 20px' }}> |
| 99 | + <h2>Add a new Panel:</h2> |
| 100 | + <Button onClick={addPanel}>Add Panel</Button> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + ); |
| 104 | + } |
| 105 | +} |
0 commit comments