import React from 'react'; import ReactCSSTransitionGroup from 'react-addons-css-transition-group'; import { withRouter } from 'react-router'; import { Prompt } from "react-router-dom"; import { Subject } from 'rxjs/Subject'; import { NgIf, Fab, Icon, Dropdown, DropdownButton, DropdownList, DropdownItem } from '../../components/'; import { confirm, currentShare } from '../../helpers/'; import { Editor } from './editor'; import { MenuBar } from './menubar'; import { OrgTodosViewer, OrgEventsViewer } from './org_viewer'; import './ide.scss'; @withRouter export class IDE extends React.Component { constructor(props){ super(props); this.state = { event: new Subject(), contentToSave: props.content, appear_agenda: false, appear_todo: false, mode: null, folding: null }; } componentDidMount(){ this.unblock = this.props.history.block((nextLocation)=>{ if(this.props.needSaving === false) return true; confirm.now(
Do you want to save the changes ?
, () =>{ return this.save() .then(() => this.props.history.push(nextLocation)); }, () => { this.props.needSavingUpdate(false) .then(() => this.props.history.push(nextLocation)); } ); return false; }); } componentWillUnmount(){ this.unblock(); window.clearInterval(this.state.id); } save(){ if(this.props.needSaving === false) return; // the ipad is the new IE, they don't support the file object so we got to fallback :( let blob = new window.Blob([this.state.contentToSave], {type : 'text/plain'}); return this.props.onSave(blob).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(force = null){ this.setState({appear_agenda: force === null ? !this.state.appear_agenda : !!force}); } toggleTodo(force = null){ this.setState({appear_todo: force === null ? !this.state.appear_todo : !!force}); } onModeChange(){ this.state.event.next(["fold"]); } goTo(lineNumber){ this.state.event.next(["goTo", lineNumber]); } download(){ document.cookie = "download=yes; path=/; max-age=120;"; this.setState({random: Math.random()}); this.state.id = window.setInterval(() => { if(/download=yes/.test(document.cookie) === false){ window.clearInterval(this.state.id); this.setState({random: Math.random()}); } }, 100); } render(){ const changeExt = function(filename, ext){ return filename.replace(/\.org$/, "."+ext); }; return (
this.download()} enable={/download=yes/.test(document.cookie) ? false : true}> Save current file Export as HTML Export as PDF Export as Text Export as Latex Export as Calendar Export as Beamer Export as Open office Export as Markdown
); } }