Search in sources :

Example 76 with FileEditor

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

the class EditorFixture method getMergedManifestEditor.

@NotNull
public MergedManifestFixture getMergedManifestEditor() {
    return GuiQuery.getNonNull(() -> {
        FileEditor[] editors = FileEditorManager.getInstance(myFrame.getProject()).getSelectedEditors();
        checkState(editors.length > 0, "no selected editors");
        Component manifestPanel = editors[0].getComponent().getComponent(0);
        checkState(manifestPanel instanceof ManifestPanel, "not a %s: %s", ManifestPanel.class.getSimpleName(), manifestPanel);
        return new MergedManifestFixture(robot, (ManifestPanel) manifestPanel);
    });
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) ThemeEditorComponent(com.android.tools.idea.editors.theme.ThemeEditorComponent) ManifestPanel(com.android.tools.idea.editors.manifest.ManifestPanel) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with FileEditor

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

the class GenerateLayoutTestSkeletonAction method getSurface.

@Nullable
private static DesignSurface getSurface(@NotNull Project project) {
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    FileEditor[] editors = fileEditorManager.getSelectedEditors();
    for (FileEditor fileEditor : editors) {
        if (fileEditor instanceof NlEditor) {
            return ((NlEditor) fileEditor).getComponent().getSurface();
        }
    }
    Editor editor = fileEditorManager.getSelectedTextEditor();
    if (editor == null) {
        return null;
    }
    NlPreviewManager previewManager = NlPreviewManager.getInstance(project);
    if (previewManager.isWindowVisible()) {
        return previewManager.getPreviewForm().getSurface();
    }
    PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (file == null) {
        return null;
    }
    for (FileEditor fileEditor : fileEditorManager.getEditors(file.getVirtualFile())) {
        if (fileEditor instanceof NlEditor) {
            return ((NlEditor) fileEditor).getComponent().getSurface();
        }
    }
    return null;
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NlPreviewManager(com.android.tools.idea.uibuilder.editor.NlPreviewManager) NlEditor(com.android.tools.idea.uibuilder.editor.NlEditor) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NlEditor(com.android.tools.idea.uibuilder.editor.NlEditor) Nullable(org.jetbrains.annotations.Nullable)

Example 78 with FileEditor

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

the class HprofEditorFixture method findByFileName.

@NotNull
public static HprofEditorFixture findByFileName(@NotNull Robot robot, @NotNull final IdeFrameFixture frame, @NotNull final String hprofFileName) {
    HprofEditor hprofEditor = GuiQuery.getNonNull(() -> {
        FileEditor[] openEditors = null;
        FileEditorManagerImpl fileEditorManager = (FileEditorManagerImpl) FileEditorManager.getInstance(frame.getProject());
        for (EditorsSplitters splitters : fileEditorManager.getAllSplitters()) {
            for (EditorWindow window : splitters.getWindows()) {
                for (EditorWithProviderComposite editorWithProviderComposite : window.getEditors()) {
                    if (editorWithProviderComposite.getFile().getName().endsWith(hprofFileName)) {
                        if (openEditors != null) {
                            throw new ComponentLookupException(String.format("More than one Hprof editor for file '%s' found", hprofFileName));
                        }
                        openEditors = editorWithProviderComposite.getEditors();
                    }
                }
            }
        }
        if (openEditors == null) {
            throw new ComponentLookupException(String.format("Cannot find any open Hprof editors for file '%s'", hprofFileName));
        }
        HprofEditor targetEditor = null;
        for (FileEditor editor : openEditors) {
            if (editor instanceof HprofEditor) {
                if (targetEditor != null) {
                    throw new ComponentLookupException(String.format("More than one Hprof editor pane for file '%s' found", hprofFileName));
                } else {
                    targetEditor = (HprofEditor) editor;
                }
            }
        }
        return targetEditor;
    });
    return new HprofEditorFixture(robot, frame, hprofEditor);
}
Also used : EditorWithProviderComposite(com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite) HprofEditor(com.android.tools.idea.editors.hprof.HprofEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) EditorsSplitters(com.intellij.openapi.fileEditor.impl.EditorsSplitters) FileEditorManagerImpl(com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with FileEditor

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

the class AnnotateLocalFileAction method perform.

private static void perform(AnActionEvent e, boolean selected) {
    final VcsContext context = VcsContextFactory.SERVICE.getInstance().createContextOn(e);
    if (!selected) {
        for (Editor editor : getEditors(context)) {
            editor.getGutter().closeAllAnnotations();
        }
    } else {
        Project project = assertNotNull(context.getProject());
        VirtualFile selectedFile = assertNotNull(context.getSelectedFile());
        Editor editor = context.getEditor();
        if (editor == null) {
            FileEditor[] fileEditors = FileEditorManager.getInstance(project).openFile(selectedFile, false);
            for (FileEditor fileEditor : fileEditors) {
                if (fileEditor instanceof TextEditor) {
                    editor = ((TextEditor) fileEditor).getEditor();
                }
            }
        }
        LOG.assertTrue(editor != null);
        doAnnotate(editor, project);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 80 with FileEditor

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

the class EditorNotificationsImpl method createTask.

@Nullable
private ReadTask createTask(@NotNull final ProgressIndicator indicator, @NotNull final VirtualFile file) {
    List<FileEditor> editors = ContainerUtil.filter(FileEditorManager.getInstance(myProject).getAllEditors(file), editor -> !(editor instanceof TextEditor) || AsyncEditorLoader.isEditorLoaded(((TextEditor) editor).getEditor()));
    if (editors.isEmpty())
        return null;
    return new ReadTask() {

        private boolean isOutdated() {
            if (myProject.isDisposed() || !file.isValid() || indicator != getCurrentProgress(file)) {
                return true;
            }
            for (FileEditor editor : editors) {
                if (!editor.isValid()) {
                    return true;
                }
            }
            return false;
        }

        @Nullable
        @Override
        public Continuation performInReadAction(@NotNull ProgressIndicator indicator) throws ProcessCanceledException {
            if (isOutdated())
                return null;
            final List<Provider> providers = DumbService.getInstance(myProject).filterByDumbAwareness(EXTENSION_POINT_NAME.getExtensions(myProject));
            final List<Runnable> updates = ContainerUtil.newArrayList();
            for (final FileEditor editor : editors) {
                for (final Provider<?> provider : providers) {
                    final JComponent component = provider.createNotificationPanel(file, editor);
                    updates.add(() -> updateNotification(editor, provider.getKey(), component));
                }
            }
            return new Continuation(() -> {
                if (!isOutdated()) {
                    file.putUserData(CURRENT_UPDATES, null);
                    for (Runnable update : updates) {
                        update.run();
                    }
                }
            }, ModalityState.any());
        }

        @Override
        public void onCanceled(@NotNull ProgressIndicator ignored) {
            if (getCurrentProgress(file) == indicator) {
                updateNotifications(file);
            }
        }
    };
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotNull(org.jetbrains.annotations.NotNull) RefactoringElementListenerProvider(com.intellij.refactoring.listeners.RefactoringElementListenerProvider) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadTask(com.intellij.openapi.progress.util.ReadTask) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileEditor (com.intellij.openapi.fileEditor.FileEditor)140 TextEditor (com.intellij.openapi.fileEditor.TextEditor)54 VirtualFile (com.intellij.openapi.vfs.VirtualFile)53 Editor (com.intellij.openapi.editor.Editor)41 Project (com.intellij.openapi.project.Project)34 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)27 DataContext (com.intellij.openapi.actionSystem.DataContext)20 Nullable (org.jetbrains.annotations.Nullable)19 PsiFile (com.intellij.psi.PsiFile)16 Document (com.intellij.openapi.editor.Document)14 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)14 NotNull (org.jetbrains.annotations.NotNull)13 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)8 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)6 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)6 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)5 FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)5 PsiElement (com.intellij.psi.PsiElement)5 List (java.util.List)5