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);
}
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));
}
});
}
}
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);
}
}
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));
}
}
}
}
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();
}
Aggregations