Browse Source

Triggering commands from main menu, context menu, keyboard shortcut.

Frederic G. MARAND 6 years ago
parent
commit
b7493523ed
4 changed files with 20 additions and 47 deletions
  1. 1 1
      keymaps/orderthings.json
  2. 5 31
      lib/orderthings.js
  3. 4 4
      menus/orderthings.json
  4. 10 11
      package.json

+ 1 - 1
keymaps/orderthings.json

@@ -1,5 +1,5 @@
 {
   "atom-workspace": {
-    "ctrl-alt-o": "orderthings:toggle"
+    "ctrl-alt-s": "orderthings:fetch"
   }
 }

+ 5 - 31
lib/orderthings.js

@@ -1,57 +1,31 @@
 '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
-    });
-
+  activate() {
     // 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()
+      'orderthings:fetch': () => this.fetch()
     }));
   },
 
   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() {
+  fetch() {
     let editor;
     if (editor = atom.workspace.getActiveTextEditor()) {
       let selection = editor.getSelectedText();
-      let reversed = selection.split('').reverse().join('');
-      editor.insertText(reversed);
+      selection = selection.split('').reverse().join('');
+      editor.insertText(selection);
     }
   }
 };

+ 4 - 4
menus/orderthings.json

@@ -2,8 +2,8 @@
   "context-menu": {
     "atom-text-editor": [
       {
-        "label": "Toggle orderthings",
-        "command": "orderthings:toggle"
+        "label": "Fetch orderthings",
+        "command": "orderthings:fetch"
       }
     ]
   },
@@ -15,8 +15,8 @@
           "label": "Order all the things!",
           "submenu": [
             {
-              "label": "Toggle",
-              "command": "orderthings:toggle"
+              "label": "Fetch",
+              "command": "orderthings:fetch"
             }
           ]
         }

+ 10 - 11
package.json

@@ -1,18 +1,17 @@
 {
-  "name": "orderthings",
-  "main": "./lib/orderthings",
-  "version": "0.0.0",
-  "description": "A short description of your package",
-  "keywords": [
-  ],
+  "//": "activationCommands are lazy-loaded. Do not use for packages needing immediate activation, like those modifyin Atom's appearance",
   "activationCommands": {
-    "atom-workspace": "orderthings:toggle"
+    "atom-workspace": "orderthings:fetch"
   },
-  "repository": "https://github.com/atom/orderthings",
-  "license": "MIT",
+  "dependencies": {},
+  "description": "A short description of your package",
   "engines": {
     "atom": ">=1.0.0 <2.0.0"
   },
-  "dependencies": {
-  }
+  "keywords": [],
+  "license": "MIT",
+  "main": "./lib/orderthings",
+  "name": "orderthings",
+  "repository": "http://code.osinet.fr/fgm/js__atom__plugin_tutorial",
+  "version": "0.0.0"
 }