Example usage for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor

List of usage examples for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor

Introduction

In this page you can find the example usage for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor.

Prototype

public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int offset) 

Source Link

Usage

From source file:org.exbin.deltahex.intellij.FileOpenAsHexAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
        return;/*from  w  ww  .j  a v  a 2  s .  c om*/
    }

    FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(true, false, true, false, false, false);
    VirtualFile virtualFile = FileChooser.chooseFile(chooserDescriptor, project, null);
    if (virtualFile != null && virtualFile.isValid() && !virtualFile.isDirectory()) {
        DeltaHexVirtualFile deltaHexVirtualFile = new DeltaHexVirtualFile(virtualFile);
        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, deltaHexVirtualFile, 0);
        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        List<FileEditor> editors = fileEditorManager.openEditor(descriptor, true);
        fileEditorManager.setSelectedEditor(virtualFile, DeltaHexWindowProvider.DELTAHEX_EDITOR_TYPE_ID);
        for (FileEditor fileEditor : editors) {
            if (fileEditor instanceof DeltaHexFileEditor) {
                ((DeltaHexFileEditor) fileEditor).openFile(deltaHexVirtualFile);
            }
        }
    }
}

From source file:org.exbin.deltahex.intellij.OpenAsHexAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
        return;/*from  ww w  . ja  v  a  2s. c o m*/
    }
    VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
    if (virtualFile != null && virtualFile.isValid() && !virtualFile.isDirectory()) {
        DeltaHexVirtualFile deltaHexVirtualFile = new DeltaHexVirtualFile(virtualFile);
        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, deltaHexVirtualFile, 0);
        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        List<FileEditor> editors = fileEditorManager.openEditor(descriptor, true);
        fileEditorManager.setSelectedEditor(virtualFile, DeltaHexWindowProvider.DELTAHEX_EDITOR_TYPE_ID);
        for (FileEditor fileEditor : editors) {
            if (fileEditor instanceof DeltaHexFileEditor) {
                ((DeltaHexFileEditor) fileEditor).openFile(deltaHexVirtualFile);
            }
        }
    }
}

From source file:org.intellij.lang.xpath.xslt.quickfix.CreateTemplateFix.java

License:Apache License

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final XmlTag tag = XsltCodeInsightUtil.getTemplateTag(myTag, false);
    if (tag == null) {
        return;//from   w  ww.  j ava2 s. c  om
    }

    final XmlTag parentTag = tag.getParentTag();
    assert parentTag != null;

    XmlTag templateTag = parentTag.createChildTag("template", XsltSupport.XSLT_NS, DUMMY_TAG, false);
    templateTag.setAttribute("name", myName);

    final XmlTag[] arguments = myTag.findSubTags("with-param", XsltSupport.XSLT_NS);
    if (arguments.length > 0) {
        final XmlTag dummy = templateTag.findFirstSubTag("dummy");
        for (XmlTag arg : arguments) {
            final String argName = arg.getAttributeValue("name");
            if (argName != null) {
                final XmlTag paramTag = parentTag.createChildTag("param", XsltSupport.XSLT_NS, null, false);
                paramTag.setAttribute("name", argName);
                templateTag.addBefore(paramTag, dummy);
            }
        }
    }

    // TODO ensure we have line breaks before the new <xsl:template> and between its opening and closing tags

    XmlTag newTemplateTag = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(templateTag);

    OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project,
            myTag.getContainingFile().getVirtualFile(), newTemplateTag.getTextRange().getStartOffset());
    FileEditorManager.getInstance(project).openTextEditor(openFileDescriptor, true);
}

From source file:org.intellij.xquery.debugger.XQuerySourcePosition.java

License:Apache License

@NotNull
@Override//from  ww  w  .j a v a2  s .  c om
public Navigatable createNavigatable(@NotNull Project project) {
    return this.getOffset() != -1 ? new OpenFileDescriptor(project, this.getFile(), this.getOffset())
            : new OpenFileDescriptor(project, this.getFile(), this.getLine(), 0);
}

From source file:org.jetbrains.jet.plugin.codeInsight.ktSignature.EditSignatureAction.java

License:Apache License

static void invokeEditSignature(@NotNull PsiElement elementInEditor, @NotNull Editor editor,
        @Nullable Point point) {//from www  .j a  v  a2 s.  c  o  m
    PsiAnnotation annotation = findKotlinSignatureAnnotation(elementInEditor);
    assert annotation != null;
    if (annotation.getContainingFile() == elementInEditor.getContainingFile()) {
        // not external, go to
        for (PsiNameValuePair pair : annotation.getParameterList().getAttributes()) {
            if (pair.getName() == null || "value".equals(pair.getName())) {
                PsiAnnotationMemberValue value = pair.getValue();
                if (value != null) {
                    VirtualFile virtualFile = value.getContainingFile().getVirtualFile();
                    assert virtualFile != null;

                    PsiElement firstChild = value.getFirstChild();
                    if (firstChild != null
                            && firstChild.getNode().getElementType() == JavaTokenType.STRING_LITERAL) {
                        new OpenFileDescriptor(value.getProject(), virtualFile, value.getTextOffset() + 1)
                                .navigate(true);
                    } else {
                        NavigationUtil.activateFileWithPsiElement(value);
                    }
                }
            }
        }
    } else {
        PsiModifierListOwner annotationOwner = getAnnotationOwner(elementInEditor);
        boolean editable = isAnnotationEditable(elementInEditor);
        EditSignatureBalloon balloon = new EditSignatureBalloon(annotationOwner, getKotlinSignature(annotation),
                editable);
        balloon.show(point, editor, elementInEditor);
    }
}

From source file:org.jetbrains.jet.plugin.ktSignature.EditSignatureAction.java

License:Apache License

static void invokeEditSignature(@NotNull PsiElement elementInEditor, @NotNull Editor editor,
        @Nullable Point point) {// w  ww  .ja  v a 2  s . com
    PsiAnnotation annotation = KotlinSignatureUtil.findKotlinSignatureAnnotation(elementInEditor);
    assert annotation != null;
    if (annotation.getContainingFile() == elementInEditor.getContainingFile()) {
        // not external, go to
        for (PsiNameValuePair pair : annotation.getParameterList().getAttributes()) {
            if (pair.getName() == null || "value".equals(pair.getName())) {
                PsiAnnotationMemberValue value = pair.getValue();
                if (value != null) {
                    VirtualFile virtualFile = value.getContainingFile().getVirtualFile();
                    assert virtualFile != null;

                    PsiElement firstChild = value.getFirstChild();
                    if (firstChild != null
                            && firstChild.getNode().getElementType() == JavaTokenType.STRING_LITERAL) {
                        new OpenFileDescriptor(value.getProject(), virtualFile, value.getTextOffset() + 1)
                                .navigate(true);
                    } else {
                        NavigationUtil.activateFileWithPsiElement(value);
                    }
                }
            }
        }
    } else {
        PsiModifierListOwner annotationOwner = KotlinSignatureUtil.getAnnotationOwner(elementInEditor);
        boolean editable = KotlinSignatureUtil.isAnnotationEditable(elementInEditor);
        //noinspection ConstantConditions
        EditSignatureBalloon balloon = new EditSignatureBalloon(annotationOwner,
                KotlinSignatureUtil.getKotlinSignature(annotation), editable, annotation.getQualifiedName());
        balloon.show(point, editor, elementInEditor);
    }
}

From source file:org.jetbrains.kotlin.idea.ktSignature.EditSignatureAction.java

License:Apache License

static void invokeEditSignature(@NotNull PsiElement elementInEditor, @NotNull Editor editor,
        @Nullable Point point) {/*from  ww w .ja v  a2  s .  c  o m*/
    PsiAnnotation annotation = KotlinSignatureUtil.findKotlinSignatureAnnotation(elementInEditor);
    assert annotation != null;
    if (annotation.getContainingFile() == elementInEditor.getContainingFile()) {
        // not external, go to
        for (PsiNameValuePair pair : annotation.getParameterList().getAttributes()) {
            if (pair.getName() == null || "value".equals(pair.getName())) {
                PsiAnnotationMemberValue value = pair.getValue();
                if (value != null) {
                    VirtualFile virtualFile = value.getContainingFile().getVirtualFile();
                    assert virtualFile != null;

                    PsiElement firstChild = value.getFirstChild();
                    if (firstChild != null
                            && firstChild.getNode().getElementType() == JavaTokenType.STRING_LITERAL) {
                        new OpenFileDescriptor(value.getProject(), virtualFile, value.getTextOffset() + 1)
                                .navigate(true);
                    } else {
                        NavigationUtil.activateFileWithPsiElement(value);
                    }
                }
            }
        }
    } else {
        PsiModifierListOwner annotationOwner = KotlinSignatureUtil
                .getAnalyzableAnnotationOwner(elementInEditor);
        boolean editable = KotlinSignatureUtil.isAnnotationEditable(elementInEditor);
        //noinspection ConstantConditions
        EditSignatureBalloon balloon = new EditSignatureBalloon(annotationOwner,
                KotlinSignatureUtil.getKotlinSignature(annotation), editable, annotation.getQualifiedName());
        balloon.show(point, editor, elementInEditor);
    }
}

From source file:org.jetbrains.plugins.clojure.repl.LanguageConsoleImpl.java

License:Apache License

public void setLanguage(Language language) {
    PsiFile prevFile = myFile;/*w  ww  . j ava  2 s  . c  om*/
    if (prevFile != null) {
        VirtualFile file = prevFile.getVirtualFile();
        assert file instanceof LightVirtualFile;
        ((LightVirtualFile) file).setValid(false);
        ((PsiManagerEx) prevFile.getManager()).getFileManager().setViewProvider(file, null);
    }

    @NonNls
    String name = getTitle();
    LightVirtualFile newVFile = new LightVirtualFile(name, language, myEditorDocument.getText());
    FileDocumentManagerImpl.registerDocument(myEditorDocument, newVFile);
    myFile = ((PsiFileFactoryImpl) PsiFileFactory.getInstance(myProject)).trySetupPsiForFile(newVFile, language,
            true, false);
    if (myFile == null) {
        throw new AssertionError("file=null, name=" + name + ", language=" + language.getDisplayName());
    }
    PsiDocumentManagerImpl.cachePsi(myEditorDocument, myFile);
    FileContentUtil.reparseFiles(myProject, Collections.<VirtualFile>singletonList(newVFile), false);

    if (prevFile != null) {
        FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(getProject());
        VirtualFile file = prevFile.getVirtualFile();
        if (file != null && myFullEditor != null) {
            myFullEditor = null;
            FileEditor prevEditor = editorManager.getSelectedEditor(file);
            boolean focusEditor;
            int offset;
            if (prevEditor != null) {
                offset = prevEditor instanceof TextEditor
                        ? ((TextEditor) prevEditor).getEditor().getCaretModel().getOffset()
                        : 0;
                Component owner = FocusManager.getCurrentManager().getFocusOwner();
                focusEditor = owner != null
                        && SwingUtilities.isDescendingFrom(owner, prevEditor.getComponent());
            } else {
                focusEditor = false;
                offset = 0;
            }
            editorManager.closeFile(file);
            myFullEditor = editorManager.openTextEditor(new OpenFileDescriptor(getProject(), newVFile, offset),
                    focusEditor);
            setConsoleFilePinned(editorManager);
        }
    }
}

From source file:org.jetbrains.plugins.github.GithubCreateGistContentTest.java

License:Apache License

public void testCreateFromEditor() throws Throwable {
    VirtualFile file = myProjectRoot.findFileByRelativePath("file.txt");
    assertNotNull(file);/*from  w w  w .ja  v a 2  s  .  c om*/
    Editor editor = FileEditorManager.getInstance(myProject)
            .openTextEditor(new OpenFileDescriptor(myProject, file, 0), false);
    assertNotNull(editor);
    ((EditorImpl) editor).setCaretActive();

    List<FileContent> expected = new ArrayList<FileContent>();
    expected.add(new FileContent("file.txt", "file.txt content"));

    List<FileContent> actual = GithubCreateGistAction.collectContents(myProject, editor, file, null);

    checkEquals(expected, actual);
}

From source file:org.jetbrains.plugins.github.GithubCreateGistContentTest.java

License:Apache License

public void testCreateFromEditorWithoutFile() throws Throwable {
    VirtualFile file = myProjectRoot.findFileByRelativePath("file.txt");
    assertNotNull(file);//from  www .j  a  va  2s  .c  o m
    Editor editor = FileEditorManager.getInstance(myProject)
            .openTextEditor(new OpenFileDescriptor(myProject, file, 0), false);
    assertNotNull(editor);
    ((EditorImpl) editor).setCaretActive();

    List<FileContent> expected = new ArrayList<FileContent>();
    expected.add(new FileContent("", "file.txt content"));

    List<FileContent> actual = GithubCreateGistAction.collectContents(myProject, editor, null, null);

    checkEquals(expected, actual);
}