package com.pastebin.jetbrains;

import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.project.Project;
import com.pastebin.jetbrains.ui.PastebinLoginDialog;
import com.pastebin.jetbrains.ui.PastebinSubmitDialog;

/**
 * @author Yuri Denison
 * @date 12.07.12
 */
public class CreatePasteAction extends EditorAction {
  public CreatePasteAction() {
    super(new PastebinHandler());
    getTemplatePresentation().setIcon(PastebinUtil.ICON);
  }

  @Override
  public void update(AnActionEvent e) {
    super.update(e);
    if (ActionPlaces.isPopupPlace(e.getPlace())) {
      e.getPresentation().setVisible(e.getPresentation().isEnabled());
    }
  }

  private static class PastebinHandler extends EditorActionHandler {
    @Override
    public void execute(Editor editor, DataContext dataContext) {
      final Project project = LangDataKeys.PROJECT.getData(dataContext);
      if (editor == null) {
        return;
      }
      final Document document = editor.getDocument();
      final SelectionModel selectionModel = editor.getSelectionModel();

      final String text = selectionModel.hasSelection() ? selectionModel.getSelectedText() : document.getText();
      PastebinUtil.submitPaste(project, text);
    }
  }
}

@@ -67,17 +67,193 @@
 nSystem.
-*
+ActionPlaces;%0Aimport com.intellij.openapi.actionSystem.AnActionEvent;%0Aimport com.intellij.openapi.actionSystem.DataContext;%0Aimport com.intellij.openapi.actionSystem.LangDataKeys
 ;%0Aimport
@@ -564,117 +564,8 @@
 ect;
-%0Aimport com.pastebin.jetbrains.ui.PastebinLoginDialog;%0Aimport com.pastebin.jetbrains.ui.PastebinSubmitDialog;
 %0A%0A/*
@@ -1226,60 +1226,8 @@
 t);%0A
-      if (editor == null) %7B%0A        return;%0A      %7D%0A
     

fix editor