Search in sources :

Example 46 with DataContext

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

the class ExtractSuperclassHandler method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
    if (elements.length != 1)
        return;
    myProject = project;
    mySubclass = (PsiClass) elements[0];
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, mySubclass))
        return;
    Editor editor = dataContext != null ? CommonDataKeys.EDITOR.getData(dataContext) : null;
    if (mySubclass.isInterface()) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("superclass.cannot.be.extracted.from.an.interface"));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.EXTRACT_SUPERCLASS);
        return;
    }
    if (mySubclass.isEnum()) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("superclass.cannot.be.extracted.from.an.enum"));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.EXTRACT_SUPERCLASS);
        return;
    }
    List<MemberInfo> memberInfos = MemberInfo.extractClassMembers(mySubclass, new MemberInfo.Filter<PsiMember>() {

        @Override
        public boolean includeMember(PsiMember element) {
            return true;
        }
    }, false);
    if (mySubclass instanceof PsiAnonymousClass) {
        memberInfos = ContainerUtil.filter(memberInfos, memberInfo -> !(memberInfo.getMember() instanceof PsiClass && memberInfo.getOverrides() != null));
    }
    final ExtractSuperclassDialog dialog = new ExtractSuperclassDialog(project, mySubclass, memberInfos, this);
    if (!dialog.showAndGet() || !dialog.isExtractSuperclass()) {
        return;
    }
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
        final Runnable action = () -> doRefactoring(project, mySubclass, dialog);
        ApplicationManager.getApplication().runWriteAction(action);
    }, REFACTORING_NAME, null);
}
Also used : DescriptiveNameUtil(com.intellij.lang.findUsages.DescriptiveNameUtil) ArrayUtil(com.intellij.util.ArrayUtil) DataContext(com.intellij.openapi.actionSystem.DataContext) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) LocalHistoryAction(com.intellij.history.LocalHistoryAction) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) ContainerUtil(com.intellij.util.containers.ContainerUtil) ScrollType(com.intellij.openapi.editor.ScrollType) Project(com.intellij.openapi.project.Project) PsiUtil(com.intellij.psi.util.PsiUtil) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) HelpID(com.intellij.refactoring.HelpID) PullUpConflictsUtil(com.intellij.refactoring.memberPullUp.PullUpConflictsUtil) ProgressManager(com.intellij.openapi.progress.ProgressManager) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ContextAwareActionHandler(com.intellij.lang.ContextAwareActionHandler) Editor(com.intellij.openapi.editor.Editor) ExtractClassUtil(com.intellij.refactoring.extractInterface.ExtractClassUtil) CommandProcessor(com.intellij.openapi.command.CommandProcessor) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) List(java.util.List) ElementsHandler(com.intellij.refactoring.lang.ElementsHandler) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) LocalHistory(com.intellij.history.LocalHistory) NotNull(org.jetbrains.annotations.NotNull) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) Editor(com.intellij.openapi.editor.Editor)

Example 47 with DataContext

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

the class MergeFilesAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    DataContext context = e.getDataContext();
    VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
    if (files == null || files.length != 3) {
        return;
    }
    DiffRequestFactory diffRequestFactory = DiffRequestFactory.getInstance();
    try {
        Project project = CommonDataKeys.PROJECT.getData(context);
        String title = DiffBundle.message("merge.files.dialog.title");
        List<String> titles = ContainerUtil.list(files[0].getPresentableUrl(), files[1].getPresentableUrl(), files[2].getPresentableUrl());
        VirtualFile outputFile = files[1];
        List<VirtualFile> contents = ContainerUtil.list(files[0], files[1], files[2]);
        MergeRequest request = diffRequestFactory.createMergeRequestFromFiles(project, outputFile, contents, title, titles, null);
        request.putUserData(DiffUserDataKeys.HELP_ID, "cvs.merge");
        DiffManager.getInstance().showMerge(project, request);
    } catch (InvalidDiffRequestException err) {
        Messages.showErrorDialog(err.getLocalizedMessage(), DiffBundle.message("merge.files.dialog.title"));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) MergeRequest(com.intellij.diff.merge.MergeRequest) DiffRequestFactory(com.intellij.diff.DiffRequestFactory) InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException)

Example 48 with DataContext

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

the class MergeFilesAction method update.

public void update(AnActionEvent e) {
    DataContext context = e.getDataContext();
    Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null) {
        e.getPresentation().setEnabled(false);
        return;
    }
    VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
    if (files == null || files.length != 3) {
        e.getPresentation().setEnabled(false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext)

Example 49 with DataContext

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

the class ImmediatePainterTest method assertRenderedCorrectly.

private void assertRenderedCorrectly(int offset, char c) throws IOException {
    myEditor.getCaretModel().getPrimaryCaret().moveToOffset(offset);
    JComponent editorComponent = myEditor.getContentComponent();
    Dimension size = editorComponent.getPreferredSize();
    editorComponent.setSize(size);
    KeyboardFocusManager.setCurrentKeyboardFocusManager(new MockFocusManager(editorComponent));
    BufferedImage image = UIUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    BufferedImage immediateImage;
    DataContext dataContext = ((EditorImpl) myEditor).getDataContext();
    try {
        editorComponent.paint(graphics);
        ((EditorImpl) myEditor).processKeyTypedImmediately(c, graphics, dataContext);
        immediateImage = copy(image);
        ((EditorImpl) myEditor).processKeyTypedNormally(c, dataContext);
        editorComponent.paint(graphics);
    } finally {
        graphics.dispose();
    }
    assertEqual(immediateImage, image);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) BufferedImage(java.awt.image.BufferedImage)

Example 50 with DataContext

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

the class UnshelveSilentlyAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = ObjectUtils.assertNotNull(getEventProject(e));
    FileDocumentManager.getInstance().saveAllDocuments();
    DataContext dataContext = e.getDataContext();
    ShelveChangesManager.getInstance(project).unshelveSilentlyAsynchronously(project, getShelvedLists(dataContext), getShelveChanges(dataContext), getBinaryShelveChanges(dataContext), null);
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext)

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)204 Project (com.intellij.openapi.project.Project)73 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 NotNull (org.jetbrains.annotations.NotNull)23 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)23 Editor (com.intellij.openapi.editor.Editor)22 Nullable (org.jetbrains.annotations.Nullable)21 FileEditor (com.intellij.openapi.fileEditor.FileEditor)20 PsiFile (com.intellij.psi.PsiFile)17 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)16 Module (com.intellij.openapi.module.Module)13 PsiElement (com.intellij.psi.PsiElement)13 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 DataManager (com.intellij.ide.DataManager)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)9 List (java.util.List)9 Consumer (com.intellij.util.Consumer)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 Transferable (java.awt.datatransfer.Transferable)6