Search in sources :

Example 21 with OpenFileDescriptor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AllIcons(com.intellij.icons.AllIcons) com.intellij.lang.ant.config(com.intellij.lang.ant.config) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Keymap(com.intellij.openapi.keymap.Keymap) AntBuildFilePropertiesAction(com.intellij.lang.ant.config.actions.AntBuildFilePropertiesAction) AntIcons(icons.AntIcons) AntRunConfigurationType(com.intellij.lang.ant.config.execution.AntRunConfigurationType) StringBuilderSpinAllocator(com.intellij.util.StringBuilderSpinAllocator) JBUI(com.intellij.util.ui.JBUI) Disposer(com.intellij.openapi.util.Disposer) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) CommonActionsManager(com.intellij.ide.CommonActionsManager) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RunDialog(com.intellij.execution.impl.RunDialog) TreePath(javax.swing.tree.TreePath) DomEvent(com.intellij.util.xml.events.DomEvent) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeExpander(com.intellij.ide.TreeExpander) Nullable(org.jetbrains.annotations.Nullable) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ContextHelpAction(com.intellij.ide.actions.ContextHelpAction) NotNull(org.jetbrains.annotations.NotNull) IconUtil(com.intellij.util.IconUtil) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) com.intellij.lang.ant.config.impl(com.intellij.lang.ant.config.impl) AntBundle(com.intellij.lang.ant.AntBundle) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) PsiElement(com.intellij.psi.PsiElement) ExecutionHandler(com.intellij.lang.ant.config.execution.ExecutionHandler) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) AntRunConfiguration(com.intellij.lang.ant.config.execution.AntRunConfiguration) DataManager(com.intellij.ide.DataManager) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) BuildFilePropertiesPanel(com.intellij.lang.ant.config.impl.configuration.BuildFilePropertiesPanel) TreeUtil(com.intellij.util.ui.tree.TreeUtil) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) EditKeymapsDialog(com.intellij.openapi.keymap.impl.ui.EditKeymapsDialog) ActionEvent(java.awt.event.ActionEvent) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) com.intellij.execution(com.intellij.execution) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) KeymapManagerListener(com.intellij.openapi.keymap.KeymapManagerListener) FileCopyPasteUtil(com.intellij.ide.dnd.FileCopyPasteUtil) DomEventListener(com.intellij.util.xml.DomEventListener) VfsUtil(com.intellij.openapi.vfs.VfsUtil) DomManager(com.intellij.util.xml.DomManager) RemoveBuildFileAction(com.intellij.lang.ant.config.actions.RemoveBuildFileAction) FileChooser(com.intellij.openapi.fileChooser.FileChooser) javax.swing(javax.swing) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with OpenFileDescriptor

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);
}
Also used : GetFileContentOperation(com.intellij.cvsSupport2.cvsoperations.cvsContent.GetFileContentOperation) DateOrRevisionSettings(com.intellij.cvsSupport2.config.DateOrRevisionSettings) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) CvsRepository(com.intellij.openapi.cvsIntegration.CvsRepository) ComparableVcsRevisionOnOperation(com.intellij.cvsSupport2.history.ComparableVcsRevisionOnOperation) RevisionOrDate(com.intellij.cvsSupport2.cvsoperations.dateOrRevision.RevisionOrDate) File(java.io.File) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile)

Example 23 with OpenFileDescriptor

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();
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 24 with OpenFileDescriptor

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) Navigatable(com.intellij.pom.Navigatable) DomElement(com.intellij.util.xml.DomElement) IProperty(com.intellij.lang.properties.IProperty) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement) FileModificationService(com.intellij.codeInsight.FileModificationService) XmlTag(com.intellij.psi.xml.XmlTag)

Example 25 with OpenFileDescriptor

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);
        }
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor)

Aggregations

OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)155 VirtualFile (com.intellij.openapi.vfs.VirtualFile)97 Project (com.intellij.openapi.project.Project)40 Editor (com.intellij.openapi.editor.Editor)30 PsiElement (com.intellij.psi.PsiElement)27 PsiFile (com.intellij.psi.PsiFile)21 Navigatable (com.intellij.pom.Navigatable)19 Nullable (org.jetbrains.annotations.Nullable)18 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)10 Document (com.intellij.openapi.editor.Document)9 FileEditor (com.intellij.openapi.fileEditor.FileEditor)9 TextRange (com.intellij.openapi.util.TextRange)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9 File (java.io.File)9 Result (com.intellij.openapi.application.Result)8 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)8 NotNull (org.jetbrains.annotations.NotNull)6 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)5 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 XmlTag (com.intellij.psi.xml.XmlTag)5