/* * Copyright 2007-2017 Charles du Jeu - Abstrium SAS * This file is part of Pydio. * * Pydio is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Pydio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Pydio. If not, see . * * The latest code can be found at . */ const React = require('react') const {FontIcon, ListItem, List, FlatButton} = require('material-ui') const Pydio = require('pydio') const PydioDataModel = require('pydio/model/data-model') const LangUtils= require('pydio/util/lang') const {ActionDialogMixin} = Pydio.requireLib('boot') import openInEditor from '../callback/openInEditor' let OtherEditorPickerDialog = React.createClass({ propTypes:{ pydio: React.PropTypes.instanceOf(Pydio), selection: React.PropTypes.instanceOf(PydioDataModel) }, mixins:[ ActionDialogMixin ], getButtons: function(updater){ let actions = []; const mess = this.props.pydio.MessageHash; actions.push(); actions.push(); return actions; }, getDefaultProps: function(){ return { dialogTitleId: 'openother.2', dialogIsModal: false, dialogSize:'sm', dialogPadding: 0, }; }, findActiveEditors : function(mime){ let editors = []; let checkWrite = false; const {pydio} = this.props; if(this.user != null && !this.user.canWrite()){ checkWrite = true; } pydio.Registry.getActiveExtensionByType('editor').forEach(function(el){ if(checkWrite && el.write) return; if(!el.openable) return; editors.push(el); }); return editors; }, clearAssociations: function(){ const mime = this.props.selection.getUniqueNode().getAjxpMime(); let guiPrefs, assoc; try{ guiPrefs = this.props.pydio.user.getPreference("gui_preferences", true); assoc = guiPrefs["other_editor_extensions"]; }catch(e){} if(assoc && assoc[mime]){ const editorClassName = assoc[mime]; let editor; this.props.pydio.Registry.getActiveExtensionByType("editor").forEach(function(ed){ if(ed.editorClass === editorClassName) editor = ed; }); if(editor && editor.mimes.indexOf(mime) !== -1){ editor.mimes = LangUtils.arrayWithout(editor.mimes, editor.mimes.indexOf(mime)); } delete assoc[mime]; guiPrefs["other_editor_extensions"] = assoc; this.props.pydio.user.setPreference("gui_preferences", guiPrefs, true); this.props.pydio.user.savePreference("gui_preferences"); } this.props.onDismiss(); }, selectEditor: function(editor, event){ const {pydio, selection} = this.props; const mime = selection.getUniqueNode().getAjxpMime(); editor.mimes.push(mime); let user = pydio.user; if(!user) return; let guiPrefs = user.getPreference("gui_preferences", true) || {}; let exts = guiPrefs["other_editor_extensions"] || {}; exts[mime] = editor.editorClass; guiPrefs["other_editor_extensions"] = exts; user.setPreference("gui_preferences", guiPrefs, true); user.savePreference("gui_preferences"); openInEditor(pydio)(null, [editor]); this.dismiss(); }, render: function(){ //let items = []; const items = this.findActiveEditors('*').map((e) => { const icon = ; return ; }); return ( {items} ); } }); export {OtherEditorPickerDialog as default}