export.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { CollapsableControls, CollapsableState, PluginUIComponent } from 'molstar/lib/mol-plugin-ui/base';
  2. import { Button } from 'molstar/lib/mol-plugin-ui/controls/common';
  3. import { GetAppSvg } from 'molstar/lib/mol-plugin-ui/controls/icons';
  4. import { encodeStructureData, downloadAsZipFile } from '../helpers/export';
  5. export class ExportControls extends CollapsableControls {
  6. protected defaultState(): CollapsableState {
  7. return {
  8. header: 'Export',
  9. isCollapsed: true,
  10. brand: { accent: 'gray' as const, svg: ExportOutlinedSvg }
  11. };
  12. }
  13. componentDidMount() {
  14. this.subscribe(this.plugin.managers.structure.hierarchy.behaviors.selection, sel => {
  15. this.setState({ isHidden: sel.structures.length === 0 });
  16. });
  17. }
  18. protected renderControls(): JSX.Element | null {
  19. return <div className={'msp-control-offset'} style={{ paddingTop: '1px' }}>
  20. <CoordinatesExportControls />
  21. </div>;
  22. }
  23. }
  24. class CoordinatesExportControls extends PluginUIComponent {
  25. download = async () => {
  26. const content = encodeStructureData(this.plugin);
  27. await downloadAsZipFile(this.plugin, content);
  28. };
  29. render() {
  30. return <>
  31. <div className='msp-flex-row'>
  32. <Button icon={GetAppSvg} onClick={this.download} title='Save structures as mmCIF files'>
  33. Structures
  34. </Button>
  35. </div>
  36. </>;
  37. }
  38. }
  39. function ExportOutlinedSvg() { return _ExportOutlined; }
  40. const _ExportOutlined = <svg width='24px' height='24px' viewBox='0 0 24 24' strokeWidth='0.1px'><path d="M19 12v7H5v-7H3v9h18v-9h-2zm-6 .67l2.59-2.58L17 11.5l-5 5-5-5 1.41-1.41L11 12.67V3h2v9.67z" /></svg>;