'use babel'; import OrderthingsView from './orderthings-view'; import { CompositeDisposable } from 'atom'; export default { orderthingsView: null, modalPanel: null, subscriptions: null, activate(state) { this.orderthingsView = new OrderthingsView(state.orderthingsViewState); this.modalPanel = atom.workspace.addModalPanel({ item: this.orderthingsView.getElement(), visible: false }); // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable this.subscriptions = new CompositeDisposable(); // Register command that toggles this view this.subscriptions.add(atom.commands.add('atom-workspace', { 'orderthings:toggle': () => this.toggle() })); }, deactivate() { this.modalPanel.destroy(); this.subscriptions.dispose(); this.orderthingsView.destroy(); }, serialize() { return { orderthingsViewState: this.orderthingsView.serialize() }; }, toggle1() { console.log('Orderthings was toggled!'); return ( this.modalPanel.isVisible() ? this.modalPanel.hide() : this.modalPanel.show() ); }, toggle() { let editor; if (editor = atom.workspace.getActiveTextEditor()) { let selection = editor.getSelectedText(); let reversed = selection.split('').reverse().join(''); editor.insertText(reversed); } } };