Search in sources :

Example 61 with FileEditor

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

the class DvcsUtil method getSelectedFile.

/**
   * Returns the currently selected file, based on which VcsBranch or StatusBar components will identify the current repository root.
   */
@Nullable
@CalledInAwt
public static VirtualFile getSelectedFile(@NotNull Project project) {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
    final FileEditor fileEditor = StatusBarUtil.getCurrentFileEditor(project, statusBar);
    VirtualFile result = null;
    if (fileEditor != null) {
        if (fileEditor instanceof TextEditor) {
            Document document = ((TextEditor) fileEditor).getEditor().getDocument();
            result = FileDocumentManager.getInstance().getFile(document);
        } else if (fileEditor instanceof ImageFileEditor) {
            result = ((ImageFileEditor) fileEditor).getImageEditor().getFile();
        }
    }
    if (result == null) {
        final FileEditorManager manager = FileEditorManager.getInstance(project);
        if (manager != null) {
            Editor editor = manager.getSelectedTextEditor();
            if (editor != null) {
                result = FileDocumentManager.getInstance().getFile(editor.getDocument());
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Document(com.intellij.openapi.editor.Document) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) StatusBar(com.intellij.openapi.wm.StatusBar) CalledInAwt(org.jetbrains.annotations.CalledInAwt) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with FileEditor

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

the class AutoScrollFromSourceHandler method install.

public void install() {
    final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            final FileEditor editor = event.getNewEditor();
            if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) {
                myAlarm.cancelAllRequests();
                myAlarm.addRequest(() -> selectElementFromEditor(editor), getAlarmDelay(), getModalityState());
            }
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileEditor(com.intellij.openapi.fileEditor.FileEditor) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener)

Example 63 with FileEditor

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

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)

Example 64 with FileEditor

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

the class ConnectionDetailsView method update.

/**
   * Updates the view to show given data. If given {@code httpData} is not null, show the details and set the view to be visible;
   * otherwise, clears the view and set view to be invisible.
   */
public void update(@Nullable HttpData httpData) {
    setBackground(JBColor.background());
    myEditorPanel.removeAll();
    myFieldsPanel.removeAll();
    myCallstackView.setText("");
    if (httpData != null) {
        VirtualFile payloadVirtualFile = httpData.getResponsePayloadFile() != null ? LocalFileSystem.getInstance().findFileByIoFile(httpData.getResponsePayloadFile()) : null;
        if (payloadVirtualFile != null) {
            // TODO: Find proper project to refactor this.
            Project project = ProjectManager.getInstance().getDefaultProject();
            // TODO: Investigate when the editor provider is null.
            FileEditorProvider[] editorProviders = FileEditorProviderManager.getInstance().getProviders(project, payloadVirtualFile);
            FileEditor editor = editorProviders.length > 0 ? editorProviders[0].createEditor(project, payloadVirtualFile) : null;
            if (editor != null) {
                myEditorPanel.add(editor.getComponent(), BorderLayout.CENTER);
            }
        }
        int row = 0;
        myFieldsPanel.add(new NoWrapBoldLabel("Request"), new TabularLayout.Constraint(row, 0));
        myFieldsPanel.add(new JLabel(HttpData.getUrlName(httpData.getUrl())), new TabularLayout.Constraint(row, 2));
        String contentType = httpData.getResponseField(HttpData.FIELD_CONTENT_TYPE);
        if (contentType != null) {
            row++;
            myFieldsPanel.add(new NoWrapBoldLabel("Content type"), new TabularLayout.Constraint(row, 0));
            // Content type looks like "type/subtype;" or "type/subtype; parameters".
            // Always convert to "type"
            contentType = contentType.split(";")[0];
            myFieldsPanel.add(new JLabel(contentType), new TabularLayout.Constraint(row, 2));
        }
        HyperlinkLabel urlLabel = new HyperlinkLabel(httpData.getUrl());
        urlLabel.setHyperlinkTarget(httpData.getUrl());
        row++;
        myFieldsPanel.add(new NoWrapBoldLabel("URL"), new TabularLayout.Constraint(row, 0));
        myFieldsPanel.add(urlLabel, new TabularLayout.Constraint(row, 2));
        String contentLength = httpData.getResponseField(HttpData.FIELD_CONTENT_LENGTH);
        if (contentLength != null) {
            contentLength = contentLength.split(";")[0];
            row++;
            myFieldsPanel.add(new NoWrapBoldLabel("Content length"), new TabularLayout.Constraint(row, 0));
            myFieldsPanel.add(new JLabel(contentLength), new TabularLayout.Constraint(row, 2));
        }
        // TODO: We are showing the callstack but we can't currently click on any of the links to
        // navigate to the code.
        myCallstackView.setText(httpData.getTrace());
        repaint();
    }
    setVisible(httpData != null);
    revalidate();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) TabularLayout(com.android.tools.adtui.TabularLayout) HyperlinkLabel(com.intellij.ui.HyperlinkLabel)

Example 65 with FileEditor

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

the class EditorFixture method selectEditorTab.

/**
   * Selects the given tab in the current editor. Used to switch between
   * design mode and editor mode for example.
   *
   * @param tab the tab to switch to
   */
public EditorFixture selectEditorTab(@NotNull final Tab tab) {
    String tabName = tab.myTabName;
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            VirtualFile currentFile = getCurrentFile();
            assertNotNull("Can't switch to tab " + tabName + " when no file is open in the editor", currentFile);
            FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
            FileEditor[] editors = manager.getAllEditors(currentFile);
            FileEditor target = null;
            for (FileEditor editor : editors) {
                if (tabName == null || tabName.equals(editor.getName())) {
                    target = editor;
                    break;
                }
            }
            if (target != null) {
                // Have to use reflection
                //FileEditorManagerImpl#setSelectedEditor(final FileEditor editor)
                method("setSelectedEditor").withParameterTypes(FileEditor.class).in(manager).invoke(target);
                return;
            }
            List<String> tabNames = Lists.newArrayList();
            for (FileEditor editor : editors) {
                tabNames.add(editor.getName());
            }
            fail("Could not find editor tab \"" + (tabName != null ? tabName : "<default>") + "\": Available tabs = " + tabNames);
        }
    });
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) List(java.util.List) JBList(com.intellij.ui.components.JBList)

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