Search in sources :

Example 1 with DocCommandGroupId

use of com.intellij.openapi.editor.actionSystem.DocCommandGroupId in project intellij-community by JetBrains.

the class BaseRefactoringAction method actionPerformed.

@Override
public final void actionPerformed(@NotNull AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    if (project == null)
        return;
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    final Editor editor = e.getData(CommonDataKeys.EDITOR);
    final PsiElement[] elements = getPsiElementArray(dataContext);
    int eventCount = IdeEventQueue.getInstance().getEventCount();
    RefactoringActionHandler handler;
    try {
        handler = getHandler(dataContext);
    } catch (ProcessCanceledException ignored) {
        return;
    }
    if (handler == null) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.symbol.to.refactor"));
        CommonRefactoringUtil.showErrorHint(project, editor, message, RefactoringBundle.getCannotRefactorMessage(null), null);
        return;
    }
    InplaceRefactoring activeInplaceRenamer = InplaceRefactoring.getActiveInplaceRenamer(editor);
    if (!InplaceRefactoring.canStartAnotherRefactoring(editor, project, handler, elements) && activeInplaceRenamer != null) {
        InplaceRefactoring.unableToStartWarning(project, editor);
        return;
    }
    if (activeInplaceRenamer == null) {
        final LookupEx lookup = LookupManager.getActiveLookup(editor);
        if (lookup instanceof LookupImpl) {
            Runnable command = () -> ((LookupImpl) lookup).finishLookup(Lookup.NORMAL_SELECT_CHAR);
            Document doc = editor.getDocument();
            DocCommandGroupId group = DocCommandGroupId.noneGroupId(doc);
            CommandProcessor.getInstance().executeCommand(editor.getProject(), command, "Completion", group, UndoConfirmationPolicy.DEFAULT, doc);
        }
    }
    IdeEventQueue.getInstance().setEventCount(eventCount);
    if (editor != null) {
        final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (file == null)
            return;
        DaemonCodeAnalyzer.getInstance(project).autoImportReferenceAtCursor(editor, file);
        handler.invoke(project, editor, file, dataContext);
    } else {
        handler.invoke(project, elements, dataContext);
    }
}
Also used : RefactoringActionHandler(com.intellij.refactoring.RefactoringActionHandler) Document(com.intellij.openapi.editor.Document) Project(com.intellij.openapi.project.Project) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) DocCommandGroupId(com.intellij.openapi.editor.actionSystem.DocCommandGroupId) Editor(com.intellij.openapi.editor.Editor) LookupEx(com.intellij.codeInsight.lookup.LookupEx) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) InplaceRefactoring(com.intellij.refactoring.rename.inplace.InplaceRefactoring)

Aggregations

LookupEx (com.intellij.codeInsight.lookup.LookupEx)1 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 DocCommandGroupId (com.intellij.openapi.editor.actionSystem.DocCommandGroupId)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 RefactoringActionHandler (com.intellij.refactoring.RefactoringActionHandler)1 InplaceRefactoring (com.intellij.refactoring.rename.inplace.InplaceRefactoring)1