orderthings.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use babel';
  2. import OrderthingsView from './orderthings-view';
  3. import { CompositeDisposable } from 'atom';
  4. export default {
  5. orderthingsView: null,
  6. modalPanel: null,
  7. subscriptions: null,
  8. activate(state) {
  9. this.orderthingsView = new OrderthingsView(state.orderthingsViewState);
  10. this.modalPanel = atom.workspace.addModalPanel({
  11. item: this.orderthingsView.getElement(),
  12. visible: false
  13. });
  14. // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
  15. this.subscriptions = new CompositeDisposable();
  16. // Register command that toggles this view
  17. this.subscriptions.add(atom.commands.add('atom-workspace', {
  18. 'orderthings:toggle': () => this.toggle()
  19. }));
  20. },
  21. deactivate() {
  22. this.modalPanel.destroy();
  23. this.subscriptions.dispose();
  24. this.orderthingsView.destroy();
  25. },
  26. serialize() {
  27. return {
  28. orderthingsViewState: this.orderthingsView.serialize()
  29. };
  30. },
  31. toggle1() {
  32. console.log('Orderthings was toggled!');
  33. return (
  34. this.modalPanel.isVisible()
  35. ? this.modalPanel.hide()
  36. : this.modalPanel.show()
  37. );
  38. },
  39. toggle() {
  40. let editor;
  41. if (editor = atom.workspace.getActiveTextEditor()) {
  42. let selection = editor.getSelectedText();
  43. let reversed = selection.split('').reverse().join('');
  44. editor.insertText(reversed);
  45. }
  46. }
  47. };