package com.karateca.jstoolbox;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiFile;

/**
 * @author Andres Dominguez.
 */
public abstract class MyAction extends AnAction {
  @Override
  public void update(AnActionEvent e) {
    e.getPresentation().setEnabled(canEnableAction(e));
  }

  protected boolean canEnableAction(AnActionEvent e) {
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    PsiFile file = e.getData(LangDataKeys.PSI_FILE);
    return !(editor == null || file == null || e.getProject() == null);
  }

  protected String getCurrentFileName(AnActionEvent e) {
    PsiFile file = e.getData(LangDataKeys.PSI_FILE);
    return file == null ? "" : file.getName();
  }
}

@@ -279,21 +279,180 @@
 api.
-editor.Editor
+application.ApplicationManager;%0Aimport com.intellij.openapi.command.CommandProcessor;%0Aimport com.intellij.openapi.editor.Editor;%0Aimport com.intellij.openapi.project.Project
 ;%0Aim
@@ -1026,32 +1026,32 @@
 Keys.PSI_FILE);%0A
-
     return file 
@@ -1084,11 +1084,540 @@
 e();%0A  %7D
+%0A%0A  /**%0A   * Run a write operation within a command.%0A   *%0A   * @param project The current project.%0A   * @param description The command description.%0A   * @param action The action to run.%0A   */%0A  protected void runWriteActionInsideCommand(Project project,%0A      String description, final Runnable action) %7B%0A    CommandProcessor.getInstance().executeCommand(project, new Runnable() %7B%0A      @Override%0A      public void run() %7B%0A        ApplicationManager.getApplication().runWriteAction(action);%0A      %7D%0A    %7D, description, null);%0A  %7D
 %0A%7D%0A

introduce runWriteActionInsideCommand