package com.karateca.jstoolbox.generatemethod;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.karateca.jstoolbox.MyAction;

/**
 * @author Andres Dominguez
 */
public class GenerateMethodAction extends MyAction {

  public void actionPerformed(AnActionEvent e) {
    if (!canEnableAction(e)) {
      return;
    }


  }
}

@@ -112,126 +112,594 @@
 com.
-karateca.jstoolbox.MyAction;%0A%0A/**%0A * @author Andres Dominguez%0A */%0Apublic class GenerateMethodAction extends MyAction %7B
+intellij.openapi.actionSystem.PlatformDataKeys;%0Aimport com.intellij.openapi.editor.impl.DocumentImpl;%0Aimport com.intellij.openapi.editor.impl.EditorImpl;%0Aimport com.intellij.openapi.project.Project;%0Aimport com.intellij.openapi.vfs.VirtualFile;%0Aimport com.karateca.jstoolbox.MyAction;%0A%0Aimport javax.swing.event.ChangeEvent;%0Aimport javax.swing.event.ChangeListener;%0A%0A/**%0A * @author Andres Dominguez%0A */%0Apublic class GenerateMethodAction extends MyAction %7B%0A%0A  private Project project;%0A  private EditorImpl editor;%0A  private DocumentImpl document;%0A  private NamespaceFinder namespaceFinder;
 %0A%0A  
@@ -740,17 +740,27 @@
 onEvent 
-e
+actionEvent
 ) %7B%0A    
@@ -780,17 +780,27 @@
 eAction(
-e
+actionEvent
 )) %7B%0A   
@@ -817,15 +817,1478 @@
 %0A    %7D%0A%0A
+    project = actionEvent.getData(PlatformDataKeys.PROJECT);%0A    editor = (EditorImpl) actionEvent.getData(PlatformDataKeys.EDITOR);%0A    VirtualFile virtualFile = actionEvent%0A        .getData(PlatformDataKeys.VIRTUAL_FILE);%0A    document = (DocumentImpl) editor.getDocument();%0A%0A    namespaceFinder = new NamespaceFinder(project, document, virtualFile);%0A%0A    // Async callback to get the search results for it( and describe(%0A    namespaceFinder.addResultsReadyListener(new ChangeListener() %7B%0A      @Override%0A      public void stateChanged(ChangeEvent changeEvent) %7B%0A        if (changeEvent.getSource().equals(%22NamespaceFound%22)) %7B%0A          String namespace = namespaceFinder.getNamespaceFound();%0A%0A          // TODO: show error: %22not found%22%0A          if (namespace != null) %7B%0A            addMethod(namespace);%0A          %7D%0A        %7D%0A      %7D%0A    %7D);%0A%0A    namespaceFinder.findText(%22goog.provide%22, false);%0A  %7D%0A%0A  private void addMethod(final String namespace) %7B%0A    runWriteActionInsideCommand(project, %22Added method%22, new Runnable() %7B%0A      @Override%0A      public void run() %7B%0A        int offset = editor.getCaretModel().getOffset();%0A%0A        String methodTemplate = String.format(%22%25s.prototype. = function() %7B%5Cn%22 +%0A            %22  %5Cn%22 +%0A            %22%7D;%22, namespace);%0A        document.replaceString(offset, offset, methodTemplate);%0A%0A        // Put the caret after %22protoype.%22%0A        editor.getCaretModel().moveToOffset(offset + namespace.length() + 11);%0A      %7D%0A    %7D);
 %0A  %7D%0A%7D%0A

add implementation