com.intellij.openapi.editor.Editor Java Examples

The following examples show how to use com.intellij.openapi.editor.Editor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XBreakpointUtil.java    From consulo with Apache License 2.0 7 votes vote down vote up
@Nonnull
public static Pair<GutterIconRenderer, Object> findSelectedBreakpoint(@Nonnull final Project project, @Nonnull final Editor editor) {
  int offset = editor.getCaretModel().getOffset();
  Document editorDocument = editor.getDocument();

  List<DebuggerSupport> debuggerSupports = DebuggerSupport.getDebuggerSupports();
  for (DebuggerSupport debuggerSupport : debuggerSupports) {
    final BreakpointPanelProvider<?> provider = debuggerSupport.getBreakpointPanelProvider();

    final int textLength = editor.getDocument().getTextLength();
    if (offset > textLength) {
      offset = textLength;
    }

    Object breakpoint = provider.findBreakpoint(project, editorDocument, offset);
    if (breakpoint != null) {
      final GutterIconRenderer iconRenderer = provider.getBreakpointGutterIconRenderer(breakpoint);
      return Pair.create(iconRenderer, breakpoint);
    }
  }
  return Pair.create(null, null);
}
 
Example #2
Source File: ArgumentCompletionContributorTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testExistingKeywordArg() {
  completionTester.runWithAutoPopupEnabled(
      () -> {
        BuildFile file =
            createBuildFile(
                new WorkspacePath("BUILD"),
                "def function(name, deps, srcs):",
                "  # empty function",
                "function(name = \"lib\")");

        Editor editor = editorTest.openFileInEditor(file.getVirtualFile());
        editorTest.setCaretPosition(editor, 2, "function(".length());

        completionTester.joinAutopopup();
        completionTester.joinCompletion();
        String[] completionItems = editorTest.getCompletionItemsAsStrings();
        assertThat(completionItems).asList().containsAllOf("name", "deps", "srcs", "function");
      });
}
 
Example #3
Source File: EnterHandler.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
@Override
public Result postProcessEnter(
    @NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
  if (file.getFileType() != SoyFileType.INSTANCE) {
    return Result.Continue;
  }

  int caretOffset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(caretOffset);
  Document document = editor.getDocument();

  int lineNumber = document.getLineNumber(caretOffset) - 1;
  int lineStartOffset = document.getLineStartOffset(lineNumber);
  String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset));

  if (element instanceof PsiComment && element.getTextOffset() < caretOffset) {
    handleEnterInComment(element, file, editor);
  } else if (lineTextBeforeCaret.startsWith("/*")) {
    insertText(file, editor, " * \n ", 3);
  }

  return Result.Continue;
}
 
Example #4
Source File: CSharpDocHighlightUsagesHandlerFactory.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
public HighlightUsagesHandlerBase createHighlightUsagesHandler(Editor editor, PsiFile file)
{
	int offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
	PsiElement target = file.findElementAt(offset);
	if(target != null && target.getNode().getElementType() == CSharpDocTokenType.XML_NAME)
	{
		CSharpDocTagImpl docTag = PsiTreeUtil.getParentOfType(target, CSharpDocTagImpl.class);
		if(docTag == null)
		{
			return null;
		}
		return new CSharpDocTagHighlightUsagesHandler(editor, file, docTag);
	}
	return null;
}
 
Example #5
Source File: BashPerformanceTest.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
private void doTest(final int iterations) {
    myFixture.configureByFile("functions_issue96.bash");
    enableInspections();

    long start = System.currentTimeMillis();
    PlatformTestUtil.startPerformanceTest(getTestName(true), iterations * 2000, () -> {
        for (int i = 0; i < iterations; i++) {
            long innerStart = System.currentTimeMillis();
            Editor editor = myFixture.getEditor();
            editor.getCaretModel().moveToOffset(editor.getDocument().getTextLength());

            myFixture.type("\n");
            myFixture.type("echo \"hello world\"\n");
            myFixture.type("pri");
            myFixture.complete(CompletionType.BASIC);

            System.out.println("Cycle duration: " + (System.currentTimeMillis() - innerStart));
        }
    }).usesAllCPUCores().attempts(1).assertTiming();

    System.out.println("Complete duration: " + (System.currentTimeMillis() - start));
}
 
Example #6
Source File: MultiCaretCodeInsightAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void iterateOverCarets(@Nonnull final Project project,
                                      @Nonnull final Editor hostEditor,
                                      @Nonnull final MultiCaretCodeInsightActionHandler handler) {
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final PsiFile psiFile = documentManager.getCachedPsiFile(hostEditor.getDocument());
  documentManager.commitAllDocuments();

  hostEditor.getCaretModel().runForEachCaret(new CaretAction() {
    @Override
    public void perform(Caret caret) {
      Editor editor = hostEditor;
      if (psiFile != null) {
        Caret injectedCaret = InjectedLanguageUtil.getCaretForInjectedLanguageNoCommit(caret, psiFile);
        if (injectedCaret != null) {
          caret = injectedCaret;
          editor = caret.getEditor();
        }
      }
      final PsiFile file = PsiUtilBase.getPsiFileInEditor(caret, project);
      if (file != null) {
        handler.invoke(project, editor, caret, file);
      }
    }
  });
}
 
Example #7
Source File: AddXModifierFix.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, Editor editor, @Nonnull PsiElement element) throws IncorrectOperationException
{
	DotNetModifierListOwner owner = CSharpIntentionUtil.findOwner(element);
	if(owner == null || !owner.isWritable())
	{
		return;
	}

	DotNetModifierList modifierList = owner.getModifierList();
	if(modifierList == null)
	{
		return;
	}

	beforeAdd(modifierList);

	for(CSharpModifier modifier : ArrayUtil.reverseArray(myModifiers))
	{
		modifierList.addModifier(modifier);
	}
}
 
Example #8
Source File: ContributionAnnotation.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
void addLocalRepresentation(@NotNull Editor editor) {
  User user = getUser();

  TextAttributes textAttributes = getContributionTextAttributes(editor, user);

  addEditor(editor);

  IFile file = getFile();

  for (AnnotationRange annotationRange : getAnnotationRanges()) {
    int start = annotationRange.getStart();
    int end = annotationRange.getEnd();

    RangeHighlighter rangeHighlighter =
        AbstractEditorAnnotation.addRangeHighlighter(start, end, editor, textAttributes, file);

    if (rangeHighlighter != null) {
      annotationRange.addRangeHighlighter(rangeHighlighter);

    } else {
      log.warn(
          "Could not create range highlighter for range " + annotationRange + " for " + this);
    }
  }
}
 
Example #9
Source File: EclipseCodeStyleManager.java    From EclipseCodeFormatter with Apache License 2.0 6 votes vote down vote up
protected boolean shouldSkipFormatting(PsiFile psiFile, Collection<TextRange> textRanges) {
	VirtualFile virtualFile = psiFile.getVirtualFile();

	if (settings.isFormatSeletedTextInAllFileTypes()) {             
		// when file is being edited, it is important to load text from editor, i think
		final Editor editor = PsiUtilBase.findEditor(psiFile);
		if (editor != null) {
			Document document = editor.getDocument();
			String text = document.getText();
			if (!FileUtils.isWholeFile(textRanges, text)) {
				return false;
			}
		}
	}
	//not else
	if (settings.isFormatOtherFileTypesWithIntelliJ()) {
		return isDisabledFileType(virtualFile);
	}
	return true;
}
 
Example #10
Source File: TargetElementUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
public static PsiReference findReference(Editor editor, int offset) {
  Project project = editor.getProject();
  if (project == null) return null;

  Document document = editor.getDocument();
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (file == null) return null;

  offset = adjustOffset(file, document, offset);

  if (file instanceof PsiCompiledFile) {
    return ((PsiCompiledFile)file).getDecompiledPsiFile().findReferenceAt(offset);
  }

  return file.findReferenceAt(offset);
}
 
Example #11
Source File: CompletionPhase.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean shouldSkipAutoPopup(Editor editor, PsiFile psiFile) {
  int offset = editor.getCaretModel().getOffset();
  int psiOffset = Math.max(0, offset - 1);

  PsiElement elementAt = psiFile.findElementAt(psiOffset);
  if (elementAt == null) return true;

  Language language = PsiUtilCore.findLanguageFromElement(elementAt);

  for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
    final ThreeState result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset);
    if (result != ThreeState.UNSURE) {
      LOG.debug(confidence + " has returned shouldSkipAutopopup=" + result);
      return result == ThreeState.YES;
    }
  }
  return false;
}
 
Example #12
Source File: TemplateLineStartEndHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
  final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
  if (templateState != null && !templateState.isFinished()) {
    final TextRange range = templateState.getCurrentVariableRange();
    final int caretOffset = editor.getCaretModel().getOffset();
    if (range != null && shouldStayInsideVariable(range, caretOffset)) {
      int selectionOffset = editor.getSelectionModel().getLeadSelectionOffset();
      int offsetToMove = myIsHomeHandler ? range.getStartOffset() : range.getEndOffset();
      LogicalPosition logicalPosition = editor.offsetToLogicalPosition(offsetToMove).leanForward(myIsHomeHandler);
      editor.getCaretModel().moveToLogicalPosition(logicalPosition);
      EditorModificationUtil.scrollToCaret(editor);
      if (myWithSelection) {
        editor.getSelectionModel().setSelection(selectionOffset, offsetToMove);
      }
      else {
        editor.getSelectionModel().removeSelection();
      }
      return;
    }
  }
  myOriginalHandler.execute(editor, caret, dataContext);
}
 
Example #13
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  Project project = e.getProject();
  Editor editor = e.getDataContext().getData(CommonDataKeys.EDITOR);
  VirtualFile virtualFile = e.getDataContext().getData(CommonDataKeys.VIRTUAL_FILE);
  if (project == null || editor == null || virtualFile == null) return;
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  String extension = virtualFile.getExtension();
  if (extension != null && (engine == null || !engine.getFileExtensions().contains(extension))) {
    engine = IdeScriptEngineManager.getInstance().getEngineForFileExtension(extension, null);
  }
  if (engine == null) {
    LOG.warn("Script engine not found for: " + virtualFile.getName());
  }
  else {
    executeQuery(project, virtualFile, editor, engine);
  }
}
 
Example #14
Source File: LombokElementRenameHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  PsiElement element = PsiElementRenameHandler.getElement(dataContext);
  if (null == element) {
    element = BaseRefactoringAction.getElementAtCaret(editor, file);
  }

  if (null != element) {
    RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
    element = processor.substituteElementToRename(element, editor);
  }

  if (null != element) {
    editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    PsiElement nameSuggestionContext = file.getViewProvider().findElementAt(editor.getCaretModel().getOffset());
    PsiElementRenameHandler.invoke(element, project, nameSuggestionContext, editor);
  }
}
 
Example #15
Source File: GoogleTranslation.java    From GoogleTranslation with Apache License 2.0 6 votes vote down vote up
private void getTranslation(AnActionEvent event) {
    Editor editor = event.getData(PlatformDataKeys.EDITOR);
    if (editor == null) {
        return;
    }
    SelectionModel model = editor.getSelectionModel();
    String selectedText = model.getSelectedText();
    if (TextUtils.isEmpty(selectedText)) {
        selectedText = getCurrentWords(editor);
        if (TextUtils.isEmpty(selectedText)) {
            return;
        }
    }
    String queryText = strip(addBlanks(selectedText));
    new Thread(new RequestRunnable(mTranslator, editor, queryText)).start();
}
 
Example #16
Source File: DiffDrawUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static LineSeparatorRenderer createDiffLineRenderer(@Nonnull final Editor editor,
                                                            @Nonnull final TextDiffType type,
                                                            @Nonnull SeparatorPlacement placement,
                                                            final boolean doubleLine,
                                                            final boolean resolved) {
  return new LineSeparatorRenderer() {
    @Override
    public void drawLine(Graphics g, int x1, int x2, int y) {
      // TODO: change LineSeparatorRenderer interface ?
      Rectangle clip = g.getClipBounds();
      x2 = clip.x + clip.width;
      if (placement == SeparatorPlacement.TOP) y++;
      drawChunkBorderLine((Graphics2D)g, x1, x2, y, type.getColor(editor), doubleLine, resolved);
    }
  };
}
 
Example #17
Source File: GitLabOpenInBrowserAction.java    From IDEA-GitLab-Integration with MIT License 6 votes vote down vote up
@Nullable
static String makeUrlToOpen(@Nullable Editor editor,
                            @NotNull String relativePath,
                            @NotNull String branch,
                            @NotNull String remoteUrl) {
    final StringBuilder builder = new StringBuilder();
    final String repoUrl = GitlabUrlUtil.makeRepoUrlFromRemoteUrl(remoteUrl);
    if (repoUrl == null) {
        return null;
    }
    builder.append(repoUrl).append("/blob/").append(branch).append(relativePath);

    if (editor != null && editor.getDocument().getLineCount() >= 1) {
        // lines are counted internally from 0, but from 1 on gitlab
        SelectionModel selectionModel = editor.getSelectionModel();
        final int begin = editor.getDocument().getLineNumber(selectionModel.getSelectionStart()) + 1;
        final int selectionEnd = selectionModel.getSelectionEnd();
        int end = editor.getDocument().getLineNumber(selectionEnd) + 1;
        if (editor.getDocument().getLineStartOffset(end - 1) == selectionEnd) {
            end -= 1;
        }
        builder.append("#L").append(begin).append('-').append(end);
    }

    return builder.toString();
}
 
Example #18
Source File: CreateRuleFix.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int findInsertionPoint(Editor editor, PsiFile file) {
	PsiElement atRange = file.findElementAt(textRange.getEndOffset());
	if ( atRange!=null ) {
		RuleSpecNode parentRule = PsiTreeUtil.getParentOfType(atRange, RuleSpecNode.class);

		if ( parentRule!=null ) {
			PsiElement semi = MyPsiUtils.findFirstChildOfType(parentRule, getTokenElementType(SEMI));

			if ( semi!=null ) {
				return semi.getTextOffset() + 1;
			}
			return parentRule.getTextRange().getEndOffset();
		}
	}

	return editor.getDocument().getLineEndOffset(editor.getDocument().getLineCount() - 1);
}
 
Example #19
Source File: HighlightUsagesHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void doHighlightElements(Editor editor, PsiElement[] elements, TextAttributes attributes, boolean clearHighlights) {
  HighlightManager highlightManager = HighlightManager.getInstance(editor.getProject());
  List<TextRange> textRanges = new ArrayList<>(elements.length);
  for (PsiElement element : elements) {
    TextRange range = element.getTextRange();
    // injection occurs
    range = InjectedLanguageManager.getInstance(element.getProject()).injectedToHost(element, range);
    textRanges.add(range);
  }
  highlightRanges(highlightManager, editor, attributes, clearHighlights, textRanges);
}
 
Example #20
Source File: LSPRenameHandler.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
private void performDialogRename(Editor editor) {
    EditorEventManager manager = EditorEventManagerBase.forEditor(editor);
    if (manager != null) {
        String renameTo = Messages.showInputDialog(
                editor.getProject(), "Enter new name: ", "Rename", Messages.getQuestionIcon(), "",
                new NonEmptyInputValidator());
        if (renameTo != null && !renameTo.equals("")) {
            manager.rename(renameTo);
        }
    }
}
 
Example #21
Source File: CoverageLineMarkerRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showHint(final Editor editor, final Point point, final int lineNumber) {
  final JPanel panel = new JPanel(new BorderLayout());
  panel.add(createActionsToolbar(editor, lineNumber), BorderLayout.NORTH);

  final LineData lineData = getLineData(lineNumber);
  final Editor uEditor;
  if (lineData != null && lineData.getStatus() != LineCoverage.NONE && !mySubCoverageActive) {
    final EditorFactory factory = EditorFactory.getInstance();
    final Document doc = factory.createDocument(getReport(editor, lineNumber));
    doc.setReadOnly(true);
    uEditor = factory.createEditor(doc, editor.getProject());
    panel.add(EditorFragmentComponent.createEditorFragmentComponent(uEditor, 0, doc.getLineCount(), false, false), BorderLayout.CENTER);
  } else {
    uEditor = null;
  }


  final LightweightHint hint = new LightweightHint(panel){
    @Override
    public void hide() {
      if (uEditor != null) EditorFactory.getInstance().releaseEditor(uEditor);
      super.hide();

    }
  };
  HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point,
                                                   HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, -1, false, new HintHint(editor, point));
}
 
Example #22
Source File: RestoreFoldArrangementCallback.java    From consulo with Apache License 2.0 5 votes vote down vote up
public RestoreFoldArrangementCallback(@Nonnull Editor editor) {
  myEditor = editor;

  Project project = editor.getProject();
  if (project == null) {
    myCodeFoldingState = null;
  }
  else {
    final CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(editor.getProject());
    myCodeFoldingState = foldingManager.saveFoldingState(editor);
  }
}
 
Example #23
Source File: ExtractIncludeFileBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void highlightInEditor(final Project project, final IncludeDuplicate pair, final Editor editor) {
  final HighlightManager highlightManager = HighlightManager.getInstance(project);
  EditorColorsManager colorsManager = EditorColorsManager.getInstance();
  TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
  final int startOffset = pair.getStart().getTextRange().getStartOffset();
  final int endOffset = pair.getEnd().getTextRange().getEndOffset();
  highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, null);
  final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
  editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}
 
Example #24
Source File: DotEnvKeyGotoHandler.java    From idea-php-dotenv-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
    if(psiElement == null || psiElement.getParent() == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    psiElement = psiElement.getParent();

    if(!(psiElement instanceof DotEnvKey)) {
        return PsiElement.EMPTY_ARRAY;
    }

    return EnvironmentVariablesApi.getKeyUsages(psiElement.getProject(), psiElement.getText());
}
 
Example #25
Source File: CSharpChangeSignatureHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
public PsiElement findTargetMember(PsiFile file, Editor editor)
{
	return findTargetMember(file.findElementAt(editor.getCaretModel().getOffset()));
}
 
Example #26
Source File: DoctrineClassGeneratorAction.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    if (!(file instanceof PhpFile) || !DoctrineUtil.isDoctrineOrmInVendor(project)) {
        return false;
    }

    int offset = editor.getCaretModel().getOffset();
    if (offset <= 0) {
        return false;
    }

    PsiElement psiElement = file.findElementAt(offset);
    if (psiElement == null) {
        return false;
    }

    if (!PlatformPatterns.psiElement().inside(PhpClass.class).accepts(psiElement)) {
        return false;
    }

    PhpClass phpClass = PsiTreeUtil.getParentOfType(psiElement, PhpClass.class);
    if (phpClass == null) {
        return false;
    }

    PhpDocComment docComment = phpClass.getDocComment();
    if (docComment == null) {
        return true;
    }

    PhpDocCommentAnnotation container = AnnotationUtil.getPhpDocCommentAnnotationContainer(docComment);

    return container == null || container.getPhpDocBlock(supportedClass()) == null;
}
 
Example #27
Source File: MyActionUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void moveCursor(Editor editor, int cursorOffset) {
	CaretModel caretModel = editor.getCaretModel();
	caretModel.moveToOffset(cursorOffset);
	ScrollingModel scrollingModel = editor.getScrollingModel();
	scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
	editor.getContentComponent().requestFocus();
}
 
Example #28
Source File: HintManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void showQuestionHint(@Nonnull final Editor editor,
                             final int offset1,
                             final int offset2,
                             @Nonnull final LightweightHint hint,
                             @Nonnull final QuestionAction action,
                             @PositionFlags short constraint) {
  final VisualPosition pos1 = editor.offsetToVisualPosition(offset1);
  final VisualPosition pos2 = editor.offsetToVisualPosition(offset2);
  final Point p = getHintPosition(hint, editor, pos1, pos2, constraint);
  showQuestionHint(editor, p, offset1, offset2, hint, action, constraint);
}
 
Example #29
Source File: TailType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static PsiFile getFile(Editor editor) {
  Project project = editor.getProject();
  assert project != null;
  PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  assert psiFile != null;
  return psiFile;
}
 
Example #30
Source File: PrintAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent event){
  Presentation presentation = event.getPresentation();
  DataContext dataContext = event.getDataContext();
  VirtualFile file = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE);
  if(file != null && file.isDirectory()) {
    presentation.setEnabled(true);
    return;
  }
  Editor editor = dataContext.getData(PlatformDataKeys.EDITOR);
  PsiFile psiFile = dataContext.getData(LangDataKeys.PSI_FILE);
  presentation.setEnabled(psiFile != null || editor != null);
}