use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class AntExplorer method getData.
@Nullable
public Object getData(@NonNls String dataId) {
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
final AntBuildFile buildFile = getCurrentBuildFile();
if (buildFile == null) {
return null;
}
final VirtualFile file = buildFile.getVirtualFile();
if (file == null) {
return null;
}
final TreePath treePath = myTree.getLeadSelectionPath();
if (treePath == null) {
return null;
}
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
if (node == null) {
return null;
}
if (node.getUserObject() instanceof AntTargetNodeDescriptor) {
final AntTargetNodeDescriptor targetNodeDescriptor = (AntTargetNodeDescriptor) node.getUserObject();
final AntBuildTargetBase buildTarget = targetNodeDescriptor.getTarget();
final OpenFileDescriptor descriptor = buildTarget.getOpenFileDescriptor();
if (descriptor != null) {
final VirtualFile descriptorFile = descriptor.getFile();
if (descriptorFile.isValid()) {
return descriptor;
}
}
}
if (file.isValid()) {
return new OpenFileDescriptor(myProject, file);
}
} else if (PlatformDataKeys.HELP_ID.is(dataId)) {
return HelpID.ANT;
} else if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
return myProject != null ? myTreeExpander : null;
} else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
final List<VirtualFile> virtualFiles = collectAntFiles(buildFile -> {
final VirtualFile virtualFile = buildFile.getVirtualFile();
if (virtualFile != null && virtualFile.isValid()) {
return virtualFile;
}
return null;
});
return virtualFiles == null ? null : virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
} else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
final List<PsiElement> elements = collectAntFiles(AntBuildFile::getAntFile);
return elements == null ? null : elements.toArray(new PsiElement[elements.size()]);
}
return super.getData(dataId);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class CvsServicesImpl method openInEditor.
public void openInEditor(Project project, CvsModule cvsFile) {
CvsRepository repository = cvsFile.getRepository();
RevisionOrDate revisionOrDate = RevisionOrDateImpl.createOn(new DateOrRevisionSettings().updateFrom(repository.getDateOrRevision()));
GetFileContentOperation operation = new GetFileContentOperation(new File(cvsFile.getPathInCvs()), CvsRootConfiguration.createOn(repository), revisionOrDate);
ComparableVcsRevisionOnOperation revision = new ComparableVcsRevisionOnOperation(operation, project);
VcsVirtualFile vcsVirtualFile = new VcsVirtualFile(cvsFile.getPathInCvs(), revision, VcsFileSystem.getInstance());
OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, vcsVirtualFile);
FileEditorManager.getInstance(project).openTextEditor(openFileDescriptor, false);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class ExecutionPointHighlighter method doShow.
private void doShow(boolean navigate) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (ApplicationManager.getApplication().isUnitTestMode())
return;
removeHighlighter();
OpenFileDescriptor fileDescriptor = myOpenFileDescriptor;
if (!navigate && myOpenFileDescriptor != null) {
fileDescriptor = new OpenFileDescriptor(myProject, myOpenFileDescriptor.getFile());
}
myEditor = null;
if (fileDescriptor != null) {
if (!navigate) {
FileEditor editor = FileEditorManager.getInstance(fileDescriptor.getProject()).getSelectedEditor(fileDescriptor.getFile());
if (editor instanceof TextEditor) {
myEditor = ((TextEditor) editor).getEditor();
}
}
if (myEditor == null) {
myEditor = XDebuggerUtilImpl.createEditor(fileDescriptor);
}
}
if (myEditor != null) {
addHighlighter();
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class AntCreatePropertyFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
final PsiFile containingFile = psiElement.getContainingFile();
final FileModificationService modificationService = FileModificationService.getInstance();
Navigatable result = null;
if (myPropFile != null) {
final VirtualFile vFile = myPropFile.getVirtualFile();
boolean canModify = true;
if (myPropFile instanceof PsiFile) {
canModify = modificationService.prepareFileForWrite((PsiFile) myPropFile);
} else if (vFile != null) {
canModify = modificationService.prepareVirtualFilesForWrite(project, Collections.singleton(vFile));
}
if (canModify) {
final IProperty generatedProperty = myPropFile.addProperty(myCanonicalText, "");
result = vFile != null ? new OpenFileDescriptor(project, vFile, generatedProperty.getPsiElement().getTextRange().getEndOffset()) : generatedProperty;
}
} else {
if (containingFile instanceof XmlFile) {
final XmlFile xmlFile = (XmlFile) containingFile;
final XmlTag rootTag = xmlFile.getRootTag();
if (rootTag != null && modificationService.prepareFileForWrite(xmlFile)) {
final XmlTag propTag = rootTag.createChildTag(PROPERTY, rootTag.getNamespace(), null, false);
propTag.setAttribute(NAME_ATTR, myCanonicalText);
propTag.setAttribute(VALUE_ATTR, "");
final DomElement contextElement = DomUtil.getDomElement(descriptor.getPsiElement());
PsiElement generated;
if (contextElement == null) {
generated = rootTag.addSubTag(propTag, true);
} else {
final AntDomTarget containingTarget = contextElement.getParentOfType(AntDomTarget.class, false);
final DomElement anchor = containingTarget != null ? containingTarget : contextElement;
final XmlTag tag = anchor.getXmlTag();
if (!rootTag.equals(tag)) {
generated = tag.getParent().addBefore(propTag, tag);
} else {
generated = rootTag.addSubTag(propTag, true);
}
}
if (generated instanceof XmlTag) {
final XmlAttribute valueAttrib = ((XmlTag) generated).getAttribute(VALUE_ATTR);
if (valueAttrib != null) {
final XmlAttributeValue valueElement = valueAttrib.getValueElement();
if (valueElement instanceof Navigatable) {
result = (Navigatable) valueElement;
}
}
}
if (result == null && generated instanceof Navigatable) {
result = (Navigatable) generated;
}
}
}
}
if (result != null) {
result.navigate(true);
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class OverrideImplementUtil method overrideOrImplement.
public static List<PsiGenerationInfo<PsiMethod>> overrideOrImplement(PsiClass psiClass, @NotNull PsiMethod baseMethod) throws IncorrectOperationException {
FileEditorManager fileEditorManager = FileEditorManager.getInstance(baseMethod.getProject());
List<PsiGenerationInfo<PsiMethod>> results = new ArrayList<>();
try {
List<PsiGenerationInfo<PsiMethod>> prototypes = convert2GenerationInfos(overrideOrImplementMethod(psiClass, baseMethod, false));
if (prototypes.isEmpty())
return null;
PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(baseMethod.getContainingClass(), psiClass, PsiSubstitutor.EMPTY);
PsiElement anchor = getDefaultAnchorToOverrideOrImplement(psiClass, baseMethod, substitutor);
results = GenerateMembersUtil.insertMembersBeforeAnchor(psiClass, anchor, prototypes);
return results;
} finally {
PsiFile psiFile = psiClass.getContainingFile();
Editor editor = fileEditorManager.openTextEditor(new OpenFileDescriptor(psiFile.getProject(), psiFile.getVirtualFile()), true);
if (editor != null && !results.isEmpty()) {
results.get(0).positionCaret(editor, true);
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
}
}
}
Aggregations