Search in sources :

Example 66 with FileEditor

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

the class EditorFixture method getLayoutEditor.

/**
   * Returns a fixture around the layout editor, <b>if</b> the currently edited file
   * is a layout file and it is currently showing the layout editor tab or the parameter
   * requests that it be opened if necessary
   *
   * @param switchToTabIfNecessary if true, switch to the design tab if it is not already showing
   * @throws IllegalStateException if there is no selected editor or it is not a {@link NlEditor}
   */
@NotNull
public NlEditorFixture getLayoutEditor(boolean switchToTabIfNecessary) {
    if (switchToTabIfNecessary) {
        selectEditorTab(Tab.DESIGN);
    }
    return GuiQuery.getNonNull(() -> {
        FileEditor[] editors = FileEditorManager.getInstance(myFrame.getProject()).getSelectedEditors();
        checkState(editors.length > 0, "no selected editors");
        FileEditor selected = editors[0];
        checkState(selected instanceof NlEditor, "not a %s: %s", NlEditor.class.getSimpleName(), selected);
        return new NlEditorFixture(myFrame.robot(), myFrame, (NlEditor) selected);
    });
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) NlEditor(com.android.tools.idea.uibuilder.editor.NlEditor) NotNull(org.jetbrains.annotations.NotNull)

Example 67 with FileEditor

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

the class EditorFixture method open.

/**
   * Opens up a different file. This will run through the "Open File..." dialog to
   * find and select the given file.
   *
   * @param file the file to open
   * @param tab which tab to open initially, if there are multiple editors
   */
public EditorFixture open(@NotNull final VirtualFile file, @NotNull final Tab tab) {
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            // TODO: Use UI to navigate to the file instead
            Project project = myFrame.getProject();
            FileEditorManager manager = FileEditorManager.getInstance(project);
            if (tab == Tab.EDITOR) {
                manager.openTextEditor(new OpenFileDescriptor(project, file), true);
            } else {
                manager.openFile(file, true);
            }
        }
    });
    selectEditorTab(tab);
    Wait.seconds(5).expecting("file " + quote(file.getPath()) + " to be opened and loaded").until(() -> {
        if (!file.equals(getCurrentFile())) {
            return false;
        }
        FileEditor fileEditor = FileEditorManager.getInstance(myFrame.getProject()).getSelectedEditor(file);
        JComponent editorComponent = fileEditor.getComponent();
        if (editorComponent instanceof JBLoadingPanel) {
            return !((JBLoadingPanel) editorComponent).isLoading();
        }
        return true;
    });
    myFrame.requestFocusIfLost();
    robot.waitForIdle();
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JBLoadingPanel(com.intellij.ui.components.JBLoadingPanel)

Example 68 with FileEditor

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

the class EditorFixture method getTranslationsEditor.

/**
   * Returns a fixture around the {@link com.android.tools.idea.editors.strings.StringResourceEditor} <b>if</b> the currently
   * displayed editor is a translations editor.
   */
@NotNull
public TranslationsEditorFixture getTranslationsEditor() {
    return GuiQuery.getNonNull(() -> {
        FileEditor[] editors = FileEditorManager.getInstance(myFrame.getProject()).getSelectedEditors();
        checkState(editors.length > 0, "no selected editors");
        FileEditor selected = editors[0];
        checkState(selected instanceof StringResourceEditor, "not a %s: %s", StringResourceEditor.class.getSimpleName(), selected);
        return new TranslationsEditorFixture(robot, (StringResourceEditor) selected);
    });
}
Also used : StringResourceEditor(com.android.tools.idea.editors.strings.StringResourceEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with FileEditor

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

the class FloatingToolWindowManager method getActiveWorkBench.

@Nullable
private WorkBench getActiveWorkBench() {
    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focusOwner instanceof WorkBench) {
        return (WorkBench) focusOwner;
    }
    WorkBench current = (WorkBench) SwingUtilities.getAncestorOfClass(WorkBench.class, focusOwner);
    if (current != null) {
        return current;
    }
    FileEditor[] selectedEditors = myEditorManager.getSelectedEditors();
    if (selectedEditors.length == 0) {
        return null;
    }
    if (selectedEditors.length == 1) {
        return myWorkBenchMap.get(selectedEditors[0]);
    }
    if (focusOwner != null) {
        for (FileEditor editor : selectedEditors) {
            if (SwingUtilities.isDescendingFrom(focusOwner, editor.getComponent())) {
                return myWorkBenchMap.get(editor);
            }
        }
    }
    return myWorkBenchMap.get(selectedEditors[0]);
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) ProjectComponent(com.intellij.openapi.components.ProjectComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 70 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project idea-handlebars by dmarcotte.

the class HbStructureViewTest method testStructureView.

public void testStructureView(PsiFile file, Consumer<StructureViewComposite> consumer) {
    final VirtualFile vFile = file.getVirtualFile();
    final FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(vFile);
    final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
    assert builder != null;
    StructureViewComposite composite = null;
    try {
        composite = (StructureViewComposite) builder.createStructureView(fileEditor, file.getProject());
        consumer.consume(composite);
    } finally {
        if (composite != null)
            Disposer.dispose(composite);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureViewComposite(com.intellij.ide.structureView.impl.StructureViewComposite)

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