Search in sources :

Example 11 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class StudyProjectGenerator method openFirstTask.

public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
    LocalFileSystem.getInstance().refresh(false);
    final Lesson firstLesson = StudyUtils.getFirst(course.getLessons());
    if (firstLesson == null)
        return;
    final Task firstTask = StudyUtils.getFirst(firstLesson.getTaskList());
    if (firstTask == null)
        return;
    final VirtualFile taskDir = firstTask.getTaskDir(project);
    if (taskDir == null)
        return;
    final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
    VirtualFile activeVirtualFile = null;
    for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
        final String relativePath = entry.getKey();
        final TaskFile taskFile = entry.getValue();
        taskDir.refresh(false, true);
        final VirtualFile virtualFile = taskDir.findFileByRelativePath(relativePath);
        if (virtualFile != null) {
            if (!taskFile.getActivePlaceholders().isEmpty()) {
                activeVirtualFile = virtualFile;
            }
        }
    }
    if (activeVirtualFile != null) {
        final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
        ProjectView.getInstance(project).select(file, activeVirtualFile, false);
        final FileEditor[] editors = FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
        if (editors.length == 0) {
            return;
        }
        final FileEditor studyEditor = editors[0];
        if (studyEditor instanceof StudyEditor) {
            StudyUtils.selectFirstAnswerPlaceholder((StudyEditor) studyEditor, project);
        }
        FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
    } else {
        String first = StudyUtils.getFirst(taskFiles.keySet());
        if (first != null) {
            NewVirtualFile firstFile = ((VirtualDirectoryImpl) taskDir).refreshAndFindChild(first);
            if (firstFile != null) {
                FileEditorManager.getInstance(project).openFile(firstFile, true);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) PsiFile(com.intellij.psi.PsiFile) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 12 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class BreadcrumbsInitializingActivity method reinitBreadcrumbsComponent.

private static void reinitBreadcrumbsComponent(@NotNull final FileEditorManager fileEditorManager, @NotNull VirtualFile file) {
    if (isSuitable(fileEditorManager.getProject(), file)) {
        FileEditor[] fileEditors = fileEditorManager.getAllEditors(file);
        for (final FileEditor fileEditor : fileEditors) {
            if (fileEditor instanceof TextEditor && fileEditor.isValid()) {
                Editor editor = ((TextEditor) fileEditor).getEditor();
                final BreadcrumbsXmlWrapper existingWrapper = BreadcrumbsXmlWrapper.getBreadcrumbsComponent(editor);
                if (existingWrapper != null) {
                    existingWrapper.queueUpdate();
                    continue;
                }
                final BreadcrumbsXmlWrapper wrapper = new BreadcrumbsXmlWrapper(editor);
                final JComponent c = wrapper.getComponent();
                fileEditorManager.addTopComponent(fileEditor, c);
                Disposer.register(fileEditor, new Disposable() {

                    @Override
                    public void dispose() {
                        disposeWrapper(fileEditorManager, fileEditor, wrapper);
                    }
                });
            }
        }
    } else {
        removeBreadcrumbs(fileEditorManager, file);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 13 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class IpnbSaveAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
    final DataContext context = event.getDataContext();
    final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
    if (editor instanceof IpnbFileEditor) {
        saveAndCheckpoint((IpnbFileEditor) editor);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) FileEditor(com.intellij.openapi.fileEditor.FileEditor) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)

Example 14 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class CreateClassQuickFix method applyFix.

public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement anchor = myAnchor.getElement();
    if (anchor == null || !anchor.isValid()) {
        return;
    }
    if (!(anchor instanceof PyFile)) {
        anchor = PyPsiUtils.getParentRightBefore(anchor, anchor.getContainingFile());
        assert anchor != null;
    }
    PyClass pyClass = PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyClass.class, "class " + myClassName + "(object):\n    pass");
    if (anchor instanceof PyFile) {
        pyClass = (PyClass) anchor.add(pyClass);
    } else {
        pyClass = (PyClass) anchor.getParent().addBefore(pyClass, anchor);
    }
    pyClass = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(pyClass);
    final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(pyClass);
    builder.replaceElement(pyClass.getSuperClassExpressions()[0], "object");
    builder.replaceElement(pyClass.getStatementList(), PyNames.PASS);
    final FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(anchor.getContainingFile().getVirtualFile());
    if (!(editor instanceof TextEditor)) {
        return;
    }
    builder.run(((TextEditor) editor).getEditor(), false);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TemplateBuilder(com.intellij.codeInsight.template.TemplateBuilder) PyFile(com.jetbrains.python.psi.PyFile) PsiElement(com.intellij.psi.PsiElement)

Example 15 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class AddEncodingQuickFix method applyFix.

public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement();
    final PsiFile file = element.getContainingFile();
    if (file == null)
        return;
    PsiElement firstLine = file.getFirstChild();
    if (firstLine instanceof PsiComment && firstLine.getText().startsWith("#!")) {
        firstLine = firstLine.getNextSibling();
    }
    final LanguageLevel languageLevel = LanguageLevel.forElement(file);
    final String commentText = String.format(PyEncodingUtil.ENCODING_FORMAT_PATTERN[myEncodingFormatIndex], myDefaultEncoding);
    final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
    PsiComment encodingComment = elementGenerator.createFromText(languageLevel, PsiComment.class, commentText);
    encodingComment = (PsiComment) file.addBefore(encodingComment, firstLine);
    final FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(element.getContainingFile().getVirtualFile());
    if (fileEditor instanceof TextEditor) {
        if (encodingComment.getNextSibling() == null || !encodingComment.getNextSibling().textContains('\n')) {
            file.addAfter(elementGenerator.createFromText(languageLevel, PsiWhiteSpace.class, "\n"), encodingComment);
        }
        final Editor editor = ((TextEditor) fileEditor).getEditor();
        final Document document = editor.getDocument();
        final int insertedLineNumber = document.getLineNumber(encodingComment.getTextOffset());
        editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(insertedLineNumber + 1, 0));
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Document(com.intellij.openapi.editor.Document) PsiComment(com.intellij.psi.PsiComment) TextEditor(com.intellij.openapi.fileEditor.TextEditor) LanguageLevel(com.jetbrains.python.psi.LanguageLevel) PsiFile(com.intellij.psi.PsiFile) PyElementGenerator(com.jetbrains.python.psi.PyElementGenerator) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

FileEditor (com.intellij.openapi.fileEditor.FileEditor)157 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 TextEditor (com.intellij.openapi.fileEditor.TextEditor)59 Editor (com.intellij.openapi.editor.Editor)43 Project (com.intellij.openapi.project.Project)40 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)37 Nullable (org.jetbrains.annotations.Nullable)21 DataContext (com.intellij.openapi.actionSystem.DataContext)20 PsiFile (com.intellij.psi.PsiFile)19 Document (com.intellij.openapi.editor.Document)15 NotNull (org.jetbrains.annotations.NotNull)14 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)14 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)10 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)8 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)7 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)6 BlobExplorerFileEditor (com.microsoft.intellij.helpers.storage.BlobExplorerFileEditor)6 QueueFileEditor (com.microsoft.intellij.helpers.storage.QueueFileEditor)6 TableFileEditor (com.microsoft.intellij.helpers.storage.TableFileEditor)6