Search in sources :

Example 46 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager 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 47 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager 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 48 with FileEditorManager

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

the class DaemonCodeAnalyzerImpl method getFileLevelHighlights.

@Override
@NotNull
@TestOnly
public List<HighlightInfo> getFileLevelHighlights(@NotNull Project project, @NotNull PsiFile file) {
    VirtualFile vFile = file.getViewProvider().getVirtualFile();
    final FileEditorManager manager = FileEditorManager.getInstance(project);
    return Arrays.stream(manager.getEditors(vFile)).map(fileEditor -> fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS)).filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Storage(com.intellij.openapi.components.Storage) EdtExecutorService(com.intellij.util.concurrency.EdtExecutorService) PowerSaveMode(com.intellij.ide.PowerSaveMode) UIUtil(com.intellij.util.ui.UIUtil) HighlightingPass(com.intellij.codeHighlighting.HighlightingPass) NamedScopeManager(com.intellij.psi.search.scope.packageSet.NamedScopeManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) ModalityState(com.intellij.openapi.application.ModalityState) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) AutoPopupController(com.intellij.codeInsight.AutoPopupController) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) ApplicationInfoImpl(com.intellij.openapi.application.impl.ApplicationInfoImpl) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) State(com.intellij.openapi.components.State) Disposer(com.intellij.openapi.util.Disposer) BackgroundEditorHighlighter(com.intellij.codeHighlighting.BackgroundEditorHighlighter) Logger(com.intellij.openapi.diagnostic.Logger) TextEditor(com.intellij.openapi.fileEditor.TextEditor) RangeMarker(com.intellij.openapi.editor.RangeMarker) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) java.util.concurrent(java.util.concurrent) IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent) TextEditorImpl(com.intellij.openapi.fileEditor.impl.text.TextEditorImpl) TextRange(com.intellij.openapi.util.TextRange) com.intellij.codeInsight.daemon(com.intellij.codeInsight.daemon) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Collectors(java.util.stream.Collectors) Pass(com.intellij.codeHighlighting.Pass) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) PsiDocumentManagerBase(com.intellij.psi.impl.PsiDocumentManagerBase) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl) FileLevelIntentionComponent(com.intellij.codeInsight.intention.impl.FileLevelIntentionComponent) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) java.util(java.util) NonNls(org.jetbrains.annotations.NonNls) ThreadDumper(com.intellij.diagnostic.ThreadDumper) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Project(com.intellij.openapi.project.Project) TextEditorProvider(com.intellij.openapi.fileEditor.impl.text.TextEditorProvider) Key(com.intellij.openapi.util.Key) AsyncEditorLoader(com.intellij.openapi.fileEditor.impl.text.AsyncEditorLoader) FileType(com.intellij.openapi.fileTypes.FileType) Editor(com.intellij.openapi.editor.Editor) Disposable(com.intellij.openapi.Disposable) RefreshQueueImpl(com.intellij.openapi.vfs.newvfs.RefreshQueueImpl) TestOnly(org.jetbrains.annotations.TestOnly) StoragePathMacros(com.intellij.openapi.components.StoragePathMacros) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) HintManager(com.intellij.codeInsight.hint.HintManager) Element(org.jdom.Element) HeavyProcessLatch(com.intellij.util.io.storage.HeavyProcessLatch) DependencyValidationManager(com.intellij.packageDependencies.DependencyValidationManager) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TestOnly(org.jetbrains.annotations.TestOnly) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with FileEditorManager

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

the class DaemonCodeAnalyzerImpl method addFileLevelHighlight.

@Override
public void addFileLevelHighlight(@NotNull final Project project, final int group, @NotNull final HighlightInfo info, @NotNull final PsiFile psiFile) {
    VirtualFile vFile = psiFile.getViewProvider().getVirtualFile();
    final FileEditorManager manager = FileEditorManager.getInstance(project);
    for (FileEditor fileEditor : manager.getEditors(vFile)) {
        if (fileEditor instanceof TextEditor) {
            FileLevelIntentionComponent component = new FileLevelIntentionComponent(info.getDescription(), info.getSeverity(), info.getGutterIconRenderer(), info.quickFixActionRanges, project, psiFile, ((TextEditor) fileEditor).getEditor(), info.getToolTip());
            manager.addTopComponent(fileEditor, component);
            List<HighlightInfo> fileLevelInfos = fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS);
            if (fileLevelInfos == null) {
                fileLevelInfos = new ArrayList<>();
                fileEditor.putUserData(FILE_LEVEL_HIGHLIGHTS, fileLevelInfos);
            }
            info.fileLevelComponent = component;
            info.setGroup(group);
            fileLevelInfos.add(info);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileLevelIntentionComponent(com.intellij.codeInsight.intention.impl.FileLevelIntentionComponent)

Example 50 with FileEditorManager

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

the class StructureViewUpdatingTest method testJavaClassStructure.

public void testJavaClassStructure() throws Exception {
    final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
    final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
    final FileEditor fileEditor = fileEditors[0];
    try {
        final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
        final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile());
        structureViewComponent.setActionActive(InheritedMembersNodeProvider.ID, true);
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + "  getValue(): int\n" + "  getClass(): Class<? extends Object>\n" + "  hashCode(): int\n" + "  equals(Object): boolean\n" + "  clone(): Object\n" + "  toString(): String\n" + "  notify(): void\n" + "  notifyAll(): void\n" + "  wait(long): void\n" + "  wait(long, int): void\n" + "  wait(): void\n" + "  finalize(): void\n" + "  myField1: boolean\n" + "  myField2: boolean\n");
        new WriteCommandAction.Simple(getProject()) {

            @Override
            protected void run() throws Throwable {
                final int offset = document.getLineStartOffset(5);
                document.insertString(offset, "    boolean myNewField = false;\n");
            }
        }.execute().throwException();
        PsiDocumentManager.getInstance(myProject).commitDocument(document);
        PlatformTestUtil.waitForAlarm(600);
        //TreeUtil.expand(structureViewComponent.getTree(), 3);
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + "  getValue(): int\n" + "  getClass(): Class<? extends Object>\n" + "  hashCode(): int\n" + "  equals(Object): boolean\n" + "  clone(): Object\n" + "  toString(): String\n" + "  notify(): void\n" + "  notifyAll(): void\n" + "  wait(long): void\n" + "  wait(long, int): void\n" + "  wait(): void\n" + "  finalize(): void\n" + "  myField1: boolean\n" + "  myField2: boolean\n" + "  myNewField: boolean = false\n");
        Disposer.dispose(structureViewComponent);
    } finally {
        fileEditorManager.closeFile(virtualFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) PsiClass(com.intellij.psi.PsiClass) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent) Document(com.intellij.openapi.editor.Document)

Aggregations

FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)67 VirtualFile (com.intellij.openapi.vfs.VirtualFile)36 FileEditor (com.intellij.openapi.fileEditor.FileEditor)29 Editor (com.intellij.openapi.editor.Editor)22 Project (com.intellij.openapi.project.Project)22 TextEditor (com.intellij.openapi.fileEditor.TextEditor)12 Document (com.intellij.openapi.editor.Document)10 PsiFile (com.intellij.psi.PsiFile)10 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 Nullable (org.jetbrains.annotations.Nullable)8 TextRange (com.intellij.openapi.util.TextRange)6 NotNull (org.jetbrains.annotations.NotNull)6 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)5 PsiElement (com.intellij.psi.PsiElement)5 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 GuiTask (org.fest.swing.edt.GuiTask)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3