List of usage examples for com.intellij.openapi.editor.actionSystem EditorWriteActionHandler EditorWriteActionHandler
protected EditorWriteActionHandler()
From source file:org.mvnsearch.snippet.plugin.actions.PasteAction.java
License:Apache License
public PasteAction() { super(new EditorWriteActionHandler() { /**//from ww w .j a v a 2s .com * get snippet code and past it into editor * @param editor editor * @param dataContext datacontext */ @SuppressWarnings({ "ConstantConditions" }) public void executeWriteAction(Editor editor, DataContext dataContext) { final Project project = (Project) dataContext.getData(DataConstants.PROJECT); final SnippetProjectComponent projectComponent = project .getComponent(SnippetProjectComponent.class); SearchPanelForm searchPanel = projectComponent.getSearchPanelForm(); String currentSnippet = searchPanel.getCurrentSnippetCode(); if (editor != null && StringUtil.isNotEmpty(currentSnippet)) { CaretModel caretModel = editor.getCaretModel(); com.intellij.openapi.editor.Document document = editor.getDocument(); int offset = caretModel.getOffset(); document.insertString(offset, currentSnippet); } } }); }