Search in sources :

Example 6 with FileEditorManager

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

the class CCDeleteAllAnswerPlaceholdersAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext context = e.getDataContext();
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
    final Project project = e.getProject();
    if (file == null || project == null) {
        return;
    }
    final TaskFile taskFile = StudyUtils.getTaskFile(project, file);
    if (taskFile == null) {
        return;
    }
    Editor editor = CommonDataKeys.EDITOR.getData(context);
    if (editor == null) {
        FileEditorManager instance = FileEditorManager.getInstance(project);
        if (!instance.isFileOpen(file)) {
            return;
        }
        FileEditor fileEditor = instance.getSelectedEditor(file);
        if (!(fileEditor instanceof TextEditor)) {
            return;
        }
        editor = ((TextEditor) fileEditor).getEditor();
    }
    List<AnswerPlaceholder> placeholders = new ArrayList<>(taskFile.getAnswerPlaceholders());
    final ClearPlaceholders action = new ClearPlaceholders(taskFile, placeholders, editor);
    EduUtils.runUndoableAction(project, ACTION_NAME, action, UndoConfirmationPolicy.REQUEST_CONFIRMATION);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) DataContext(com.intellij.openapi.actionSystem.DataContext) FileEditor(com.intellij.openapi.fileEditor.FileEditor) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 7 with FileEditorManager

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

the class ResourceBundleDeleteProvider method deleteElement.

@Override
public void deleteElement(@NotNull DataContext dataContext) {
    final ResourceBundle[] resourceBundles = ResourceBundle.ARRAY_DATA_KEY.getData(dataContext);
    if (resourceBundles != null && resourceBundles.length != 0) {
        final Project project = CommonDataKeys.PROJECT.getData(dataContext);
        LOG.assertTrue(project != null);
        final PsiElement[] toDelete = Arrays.stream(resourceBundles).flatMap(rb -> rb.getPropertiesFiles().stream()).map(PropertiesFile::getContainingFile).toArray(PsiElement[]::new);
        SafeDeleteHandler.invoke(project, toDelete, true, () -> {
            final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
            for (ResourceBundle bundle : resourceBundles) {
                fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(bundle));
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ResourceBundle(com.intellij.lang.properties.ResourceBundle) ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile) PsiElement(com.intellij.psi.PsiElement)

Example 8 with FileEditorManager

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

the class DaemonCodeAnalyzerImpl method cleanFileLevelHighlights.

@Override
public void cleanFileLevelHighlights(@NotNull Project project, final int group, PsiFile psiFile) {
    if (psiFile == null)
        return;
    FileViewProvider provider = psiFile.getViewProvider();
    VirtualFile vFile = provider.getVirtualFile();
    final FileEditorManager manager = FileEditorManager.getInstance(project);
    for (FileEditor fileEditor : manager.getEditors(vFile)) {
        final List<HighlightInfo> infos = fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS);
        if (infos == null)
            continue;
        List<HighlightInfo> infosToRemove = new ArrayList<>();
        for (HighlightInfo info : infos) {
            if (info.getGroup() == group) {
                manager.removeTopComponent(fileEditor, info.fileLevelComponent);
                infosToRemove.add(info);
            }
        }
        infos.removeAll(infosToRemove);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 9 with FileEditorManager

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

the class EditorNotificationActions method collectDescriptorsForEditor.

public static void collectDescriptorsForEditor(@NotNull Editor editor, @NotNull List<HighlightInfo.IntentionActionDescriptor> descriptors) {
    Project project = editor.getProject();
    if (project == null)
        return;
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    if (!(fileEditorManager instanceof FileEditorManagerImpl))
        return;
    TextEditor fileEditor = TextEditorProvider.getInstance().getTextEditor(editor);
    List<JComponent> components = ((FileEditorManagerImpl) fileEditorManager).getTopComponents(fileEditor);
    for (JComponent component : components) {
        if (component instanceof IntentionActionProvider) {
            IntentionActionWithOptions action = ((IntentionActionProvider) component).getIntentionAction();
            if (action != null) {
                descriptors.add(new HighlightInfo.IntentionActionDescriptor(action, action.getOptions(), null));
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditorManagerImpl(com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl) IntentionActionWithOptions(com.intellij.codeInsight.intention.IntentionActionWithOptions) IntentionActionProvider(com.intellij.codeInsight.intention.IntentionActionProvider)

Example 10 with FileEditorManager

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

the class GeneratedSourceFileChangeTrackerImpl method projectOpened.

@Override
public void projectOpened() {
    final Update check = new Update("check for changes in generated files") {

        @Override
        public void run() {
            checkFiles();
        }
    };
    EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            VirtualFile file = myDocumentManager.getFile(e.getDocument());
            if (file != null) {
                myFilesToCheck.add(file);
                myCheckingQueue.queue(check);
            }
        }
    }, myProject);
    MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {

        @Override
        public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) {
            myFilesToCheck.remove(file);
            if (myEditedGeneratedFiles.remove(file)) {
                myEditorNotifications.updateNotifications(file);
            }
        }
    });
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            myEditedGeneratedFiles.remove(file);
        }
    });
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            myFilesToCheck.addAll(myEditedGeneratedFiles);
            myEditedGeneratedFiles.clear();
            myCheckingQueue.queue(check);
        }
    });
    myCheckingQueue.activate();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Update(com.intellij.util.ui.update.Update) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Aggregations

FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)66 VirtualFile (com.intellij.openapi.vfs.VirtualFile)35 FileEditor (com.intellij.openapi.fileEditor.FileEditor)29 Editor (com.intellij.openapi.editor.Editor)22 Project (com.intellij.openapi.project.Project)21 TextEditor (com.intellij.openapi.fileEditor.TextEditor)12 PsiFile (com.intellij.psi.PsiFile)10 Document (com.intellij.openapi.editor.Document)9 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