import React from 'react'; import ReactCSSTransitionGroup from 'react-addons-css-transition-group'; import { Subject } from 'rxjs/Subject'; import { NgIf, Fab, Icon } from '../../components/'; import { Editor } from './editor'; import { MenuBar } from './menubar'; import { OrgTodosViewer, OrgEventsViewer } from './org_viewer'; import './ide.scss'; export class IDE extends React.Component { constructor(props){ super(props); this.state = { event: new Subject(), contentToSave: props.content, needSaving: false, appear_agenda: false, appear_todo: false, mode: null, folding: null }; } save(){ if(this.props.needSaving === false) return; let file, blob = new window.Blob([this.state.contentToSave], {type : 'text/plain'}); try{ file = new window.File([blob], 'test.txt'); }catch(err){ // for crappy browser: // https://stackoverflow.com/questions/33821631/alternative-for-file-constructor-for-safari file = blob; } this.props.onSave(file) .then(() => this.props.needSavingUpdate(false)); } onUpdate(property, refresh, value){ this.setState({ [property]: value }, () => { if(refresh){ this.state.event.next(["refresh"]); } if(this.props.content === this.state.contentToSave){ this.props.needSavingUpdate(false); }else{ this.props.needSavingUpdate(true); } }); } /* Org Viewer specific stuff */ toggleAgenda(){ this.setState({appear_agenda: !this.state.appear_agenda}); } toggleTodo(){ this.setState({appear_todo: !this.state.appear_todo}); } onModeChange(){ this.state.event.next(["fold"]); } goTo(lineNumber){ this.state.event.next(["goTo", lineNumber]); } render(){ return (
); } }