Search in sources :

Example 96 with FileEditor

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

the class FileFixture method isOpenAndSelected.

private boolean isOpenAndSelected() {
    FileEditorManager editorManager = FileEditorManager.getInstance(myProject);
    FileEditor selectedEditor = editorManager.getSelectedEditor(myVirtualFile);
    if (selectedEditor != null) {
        JComponent component = selectedEditor.getComponent();
        if (component.isVisible() && component.isShowing()) {
            Document document = FileDocumentManager.getInstance().getDocument(myVirtualFile);
            if (document != null) {
                PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
                if (psiFile != null) {
                    DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject);
                    //noinspection ConstantConditions
                    boolean isRunning = method("isRunning").withReturnType(boolean.class).in(codeAnalyzer).invoke();
                    return !isRunning;
                }
            }
        }
    }
    return false;
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) PsiFile(com.intellij.psi.PsiFile) DaemonCodeAnalyzerEx(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerEx) Document(com.intellij.openapi.editor.Document)

Example 97 with FileEditor

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

the class EditorFixture method getCurrentFile.

/**
   * Returns the current file being shown in the editor, if there is a current
   * editor open and it's a file editor
   *
   * @return the currently edited file or null
   */
@Nullable
public VirtualFile getCurrentFile() {
    FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
    VirtualFile[] selectedFiles = manager.getSelectedFiles();
    if (selectedFiles.length > 0) {
        // we should be sure that EditorComponent is already showing
        VirtualFile selectedFile = selectedFiles[0];
        if (manager.getEditors(selectedFile).length == 0)
            return null;
        else {
            FileEditor editor = manager.getEditors(selectedFile)[0];
            return editor.getComponent().isShowing() ? selectedFile : null;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable)

Example 98 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community 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);
            }
        }
    });
    pause(new Condition("File " + quote(file.getPath()) + " to be opened") {

        @Override
        public boolean test() {
            //noinspection ConstantConditions
            return execute(new GuiQuery<Boolean>() {

                @Override
                protected Boolean executeInEDT() throws Throwable {
                    FileEditor[] editors = FileEditorManager.getInstance(myFrame.getProject()).getEditors(file);
                    if (editors.length == 0)
                        return false;
                    return editors[0].getComponent().isShowing();
                }
            });
        }
    }, SHORT_TIMEOUT);
    // TODO: Maybe find a better way to keep Documents in sync with their VirtualFiles.
    invokeActionViaKeystroke("Synchronize");
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Condition(org.fest.swing.timing.Condition) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) GuiQuery(org.fest.swing.edt.GuiQuery) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 99 with FileEditor

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

the class DetectableIndentOptionsProvider method getNotificationInfo.

@Nullable
@Override
public EditorNotificationInfo getNotificationInfo(@NotNull final Project project, @NotNull final VirtualFile file, @NotNull final FileEditor fileEditor, @NotNull IndentOptions userOptions, @NotNull IndentOptions detectedOptions) {
    final NotificationLabels labels = getNotificationLabels(userOptions, detectedOptions);
    final Editor editor = fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null;
    if (labels == null || editor == null)
        return null;
    ActionLabelData okAction = new ActionLabelData(ApplicationBundle.message("code.style.indents.detector.accept"), () -> setAccepted(file));
    ActionLabelData disableForSingleFile = new ActionLabelData(labels.revertToOldSettingsLabel, () -> {
        disableForFile(file);
        if (editor instanceof EditorEx) {
            ((EditorEx) editor).reinitSettings();
        }
    });
    ActionLabelData showSettings = new ActionLabelData(ApplicationBundle.message("code.style.indents.detector.show.settings"), () -> ShowSettingsUtilImpl.showSettingsDialog(project, "preferences.sourceCode", "detect indent"));
    final List<ActionLabelData> actions = ContainerUtil.newArrayList(okAction, disableForSingleFile, showSettings);
    return new EditorNotificationInfo() {

        @NotNull
        @Override
        public List<ActionLabelData> getLabelAndActions() {
            return actions;
        }

        @NotNull
        @Override
        public String getTitle() {
            return labels.title;
        }
    };
}
Also used : TextEditor(com.intellij.openapi.fileEditor.TextEditor) EditorEx(com.intellij.openapi.editor.ex.EditorEx) ActionLabelData(com.intellij.psi.codeStyle.EditorNotificationInfo.ActionLabelData) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable)

Example 100 with FileEditor

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

the class EditorMultiCaretStateRestoreTest method testRestoreState.

public void testRestoreState() throws Exception {
    String text = "some<caret> text<caret>\n" + "some <selection><caret>other</selection> <selection>text<caret></selection>\n" + "<selection>ano<caret>ther</selection> line";
    PsiFile psiFile = myFixture.configureByText(PlainTextFileType.INSTANCE, text);
    VirtualFile virtualFile = psiFile.getVirtualFile();
    assertNotNull(virtualFile);
    myManager.openFile(virtualFile, false);
    myManager.closeAllFiles();
    FileEditor[] fileEditors = myManager.openFile(virtualFile, false);
    assertNotNull(fileEditors);
    assertEquals(1, fileEditors.length);
    Editor editor = ((TextEditor) fileEditors[0]).getEditor();
    verifyEditorState(editor, text);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) PsiFile(com.intellij.psi.PsiFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

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