// Path: src/com/karateca/jstoolbox/MyAction.java
// 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);
// 
//     // Need the following objects.
//     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();
//   }
// 
//   protected String getCurrentFilePath(AnActionEvent event) {
//     VirtualFile virtualFile = event.getData(LangDataKeys.VIRTUAL_FILE);
//     return virtualFile == null ? "" : virtualFile.getCanonicalPath();
//   }
// 
//   protected boolean isJsFile(AnActionEvent e) {
//     PsiFile file = e.getData(LangDataKeys.PSI_FILE);
// 
//     return file != null && file.getName().endsWith(".js");
//   }
// 
//   /**
//    * Run a write operation within a command.
//    *
//    * @param project The current project.
//    * @param description The command description.
//    * @param action The action to run.
//    */
//   protected void runWriteActionInsideCommand(Project project,
//       String description, final Runnable action) {
//     CommandProcessor.getInstance().executeCommand(project, new Runnable() {
//       @Override
//       public void run() {
//         ApplicationManager.getApplication().runWriteAction(action);
//       }
//     }, description, null);
//   }
// 
//   protected Editor getEditor(AnActionEvent actionEvent) {
//     return actionEvent.getData(PlatformDataKeys.EDITOR);
//   }
// }


import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.Project;
import com.karateca.jstoolbox.MyAction;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
      return false;
    }

    return editor.getSelectionModel().hasSelection();
  }

  public void actionPerformed(@NotNull AnActionEvent actionEvent) {
    getEditor(actionEvent);
    if (editor == null) {
      return;
    }

    project = actionEvent.getProject();
    SortDialog dialog = new SortDialog(project);
    dialog.show();
    if (dialog.isOK()) {
      doSort(dialog.getSortToken(), SortDialog.ignoreCase);
    }
  }

  private void doSort(String separator, final boolean ignoreCase) {
    final SelectionModel selectionModel = editor.getSelectionModel();
    String selectedText = selectionModel.getSelectedText();
    if (selectedText == null) {
      return;
    }

    List<String> strings = Arrays.asList(selectedText.split(separator));
    strings.sort((s, s2) -> {
      if (ignoreCase) {
// Path: src/com/karateca/jstoolbox/MyAction.java
// 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);
// 
//     // Need the following objects.
//     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();
//   }
// 
//   protected String getCurrentFilePath(AnActionEvent event) {
//     VirtualFile virtualFile = event.getData(LangDataKeys.VIRTUAL_FILE);
//     return virtualFile == null ? "" : virtualFile.getCanonicalPath();
//   }
// 
//   protected boolean isJsFile(AnActionEvent e) {
//     PsiFile file = e.getData(LangDataKeys.PSI_FILE);
// 
//     return file != null && file.getName().endsWith(".js");
//   }
// 
//   /**
//    * Run a write operation within a command.
//    *
//    * @param project The current project.
//    * @param description The command description.
//    * @param action The action to run.
//    */
//   protected void runWriteActionInsideCommand(Project project,
//       String description, final Runnable action) {
//     CommandProcessor.getInstance().executeCommand(project, new Runnable() {
//       @Override
//       public void run() {
//         ApplicationManager.getApplication().runWriteAction(action);
//       }
//     }, description, null);
//   }
// 
//   protected Editor getEditor(AnActionEvent actionEvent) {
//     return actionEvent.getData(PlatformDataKeys.EDITOR);
//   }
// }


// Path: src/com/karateca/jstoolbox/sort/SortSelection.java
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.Project;
import com.karateca.jstoolbox.MyAction;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;

      return false;
    }

    return editor.getSelectionModel().hasSelection();
  }

  public void actionPerformed(@NotNull AnActionEvent actionEvent) {
    getEditor(actionEvent);
    if (editor == null) {
      return;
    }

    project = actionEvent.getProject();
    SortDialog dialog = new SortDialog(project);
    dialog.show();
    if (dialog.isOK()) {
      doSort(dialog.getSortToken(), SortDialog.ignoreCase);
    }
  }

  private void doSort(String separator, final boolean ignoreCase) {
    final SelectionModel selectionModel = editor.getSelectionModel();
    String selectedText = selectionModel.getSelectedText();
    if (selectedText == null) {
      return;
    }

    List<String> strings = Arrays.asList(selectedText.split(separator));
    strings.sort((s, s2) -> {
      if (ignoreCase) {
        s = s.toLowerCase();