/* eslint-disable react/jsx-no-target-blank */ import React from "react"; import ReactCSSTransitionGroup from "react-addons-css-transition-group"; import { withRouter } from "react-router"; 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 { t } from "../../locales/"; import "./ide.scss"; class IDEComponent 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(
{ t("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 :( return this.props.onSave( new window.Blob( [this.state.contentToSave], { type: "text/plain" }, ), ); } 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({ refresh: Date.now(), id: window.setInterval(() => { if (/download=yes/.test(document.cookie) === false) { window.clearInterval(this.state.id); this.setState({ refresh: Date.now() }); } }, 100), }); } render() { const changeExt = function(filename, ext) { return filename.replace(/\.org$/, "."+ext); }; return (
this.download()} enable={/download=yes/.test(document.cookie) ? false : true}> { t("Save current file") } { t("Export as {{VALUE}}", "HTML") } { t("Export as {{VALUE}}", "PDF") } { t("Export as {{VALUE}}", "Markdown") } { t("Export as {{VALUE}}", "TXT") } { t("Export as {{VALUE}}", "Latex") } { t("Export as {{VALUE}}", "ical") } { t("Export as {{VALUE}}", "Open office") } { t("Export as {{VALUE}}", "Beamer") }
); } } export const IDE = withRouter(IDEComponent);