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);
}
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"));
}
}
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);
}
}
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);
}
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);
}
Aggregations