Search in sources :

Example 51 with FileEditor

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

the class RunIdeConsoleAction method configureConsole.

public static void configureConsole(@NotNull VirtualFile file, @NotNull FileEditorManager source) {
    MyRunAction runAction = new MyRunAction();
    for (FileEditor fileEditor : source.getEditors(file)) {
        if (!(fileEditor instanceof TextEditor))
            continue;
        Editor editor = ((TextEditor) fileEditor).getEditor();
        runAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, editor.getComponent());
    }
}
Also used : 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 52 with FileEditor

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

the class FindManagerImpl method findNextUsageInFile.

private boolean findNextUsageInFile(@NotNull FileEditor fileEditor, @NotNull SearchResults.Direction direction) {
    if (fileEditor instanceof TextEditor) {
        TextEditor textEditor = (TextEditor) fileEditor;
        Editor editor = textEditor.getEditor();
        editor.getCaretModel().removeSecondaryCarets();
        if (tryToFindNextUsageViaEditorSearchComponent(editor, direction)) {
            return true;
        }
        RangeHighlighter[] highlighters = ((HighlightManagerImpl) HighlightManager.getInstance(myProject)).getHighlighters(editor);
        if (highlighters.length > 0) {
            return highlightNextHighlighter(highlighters, editor, editor.getCaretModel().getOffset(), direction == SearchResults.Direction.DOWN, false);
        }
    }
    if (direction == SearchResults.Direction.DOWN) {
        return myFindUsagesManager.findNextUsageInFile(fileEditor);
    }
    return myFindUsagesManager.findPreviousUsageInFile(fileEditor);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) HighlightManagerImpl(com.intellij.codeInsight.highlighting.HighlightManagerImpl)

Example 53 with FileEditor

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

the class FindManagerImpl method findUsagesInEditor.

@Override
public void findUsagesInEditor(@NotNull PsiElement element, @NotNull FileEditor fileEditor) {
    if (fileEditor instanceof TextEditor) {
        TextEditor textEditor = (TextEditor) fileEditor;
        Editor editor = textEditor.getEditor();
        Document document = editor.getDocument();
        PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
        myFindUsagesManager.findUsages(element, psiFile, fileEditor, false, null);
    }
}
Also used : TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 54 with FileEditor

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

the class StructureViewWrapperImpl method rebuild.

public void rebuild() {
    if (myProject.isDisposed())
        return;
    Dimension referenceSize = null;
    if (myStructureView != null) {
        if (myStructureView instanceof StructureView.Scrollable) {
            referenceSize = ((StructureView.Scrollable) myStructureView).getCurrentSize();
        }
        myStructureView.storeState();
        Disposer.dispose(myStructureView);
        myStructureView = null;
        myFileEditor = null;
    }
    if (myModuleStructureComponent != null) {
        Disposer.dispose(myModuleStructureComponent);
        myModuleStructureComponent = null;
    }
    final ContentManager contentManager = myToolWindow.getContentManager();
    contentManager.removeAllContents(true);
    if (!isStructureViewShowing()) {
        return;
    }
    VirtualFile file = myFile;
    if (file == null) {
        final VirtualFile[] selectedFiles = FileEditorManager.getInstance(myProject).getSelectedFiles();
        if (selectedFiles.length > 0) {
            file = selectedFiles[0];
        }
    }
    String[] names = { "" };
    if (file != null && file.isValid()) {
        if (file.isDirectory()) {
            if (ProjectRootsUtil.isModuleContentRoot(file, myProject)) {
                Module module = ModuleUtilCore.findModuleForFile(file, myProject);
                if (module != null && !(ModuleUtil.getModuleType(module) instanceof InternalModuleType)) {
                    myModuleStructureComponent = new ModuleStructureComponent(module);
                    createSinglePanel(myModuleStructureComponent.getComponent());
                    Disposer.register(this, myModuleStructureComponent);
                }
            }
        } else {
            FileEditor editor = FileEditorManager.getInstance(myProject).getSelectedEditor(file);
            boolean needDisposeEditor = false;
            if (editor == null) {
                editor = createTempFileEditor(file);
                needDisposeEditor = true;
            }
            if (editor != null && editor.isValid()) {
                final StructureViewBuilder structureViewBuilder = editor.getStructureViewBuilder();
                if (structureViewBuilder != null) {
                    myStructureView = structureViewBuilder.createStructureView(editor, myProject);
                    myFileEditor = editor;
                    Disposer.register(this, myStructureView);
                    updateHeaderActions(myStructureView);
                    if (myStructureView instanceof StructureView.Scrollable) {
                        ((StructureView.Scrollable) myStructureView).setReferenceSizeWhileInitializing(referenceSize);
                    }
                    if (myStructureView instanceof StructureViewComposite) {
                        final StructureViewComposite composite = (StructureViewComposite) myStructureView;
                        final StructureViewComposite.StructureViewDescriptor[] views = composite.getStructureViews();
                        myPanels = new JPanel[views.length];
                        names = new String[views.length];
                        for (int i = 0; i < myPanels.length; i++) {
                            myPanels[i] = createContentPanel(views[i].structureView.getComponent());
                            names[i] = views[i].title;
                        }
                    } else {
                        createSinglePanel(myStructureView.getComponent());
                    }
                    myStructureView.restoreState();
                    myStructureView.centerSelectedRow();
                }
            }
            if (needDisposeEditor && editor != null) {
                Disposer.dispose(editor);
            }
        }
    }
    if (myModuleStructureComponent == null && myStructureView == null) {
        createSinglePanel(new JLabel(IdeBundle.message("message.nothing.to.show.in.structure.view"), SwingConstants.CENTER));
    }
    for (int i = 0; i < myPanels.length; i++) {
        final Content content = ContentFactory.SERVICE.getInstance().createContent(myPanels[i], names[i], false);
        contentManager.addContent(content);
        if (i == 0 && myStructureView != null) {
            Disposer.register(content, myStructureView);
        }
    }
    if (myPendingSelection != null) {
        Runnable selection = myPendingSelection;
        myPendingSelection = null;
        selection.run();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureViewComposite(com.intellij.ide.structureView.impl.StructureViewComposite) InternalModuleType(com.intellij.openapi.module.InternalModuleType) Module(com.intellij.openapi.module.Module)

Example 55 with FileEditor

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

the class MacroManager method getCorrectContext.

private static DataContext getCorrectContext(DataContext dataContext) {
    if (PlatformDataKeys.FILE_EDITOR.getData(dataContext) != null) {
        return dataContext;
    }
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return dataContext;
    }
    FileEditorManager editorManager = FileEditorManager.getInstance(project);
    VirtualFile[] files = editorManager.getSelectedFiles();
    if (files.length == 0) {
        return dataContext;
    }
    FileEditor fileEditor = editorManager.getSelectedEditor(files[0]);
    return fileEditor == null ? dataContext : DataManager.getInstance().getDataContext(fileEditor.getComponent());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

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