Search in sources :

Example 1 with InplaceRefactoring

use of com.intellij.refactoring.rename.inplace.InplaceRefactoring in project intellij-community by JetBrains.

the class ReassignVariableUtil method finishTemplate.

private static void finishTemplate(Editor editor) {
    final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
    final InplaceRefactoring renamer = editor.getUserData(InplaceRefactoring.INPLACE_RENAMER);
    if (templateState != null && renamer != null) {
        templateState.gotoEnd(true);
        editor.putUserData(InplaceRefactoring.INPLACE_RENAMER, null);
    }
}
Also used : TemplateState(com.intellij.codeInsight.template.impl.TemplateState) InplaceRefactoring(com.intellij.refactoring.rename.inplace.InplaceRefactoring)

Example 2 with InplaceRefactoring

use of com.intellij.refactoring.rename.inplace.InplaceRefactoring 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

InplaceRefactoring (com.intellij.refactoring.rename.inplace.InplaceRefactoring)2 LookupEx (com.intellij.codeInsight.lookup.LookupEx)1 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)1 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)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