@Override public void after(@NotNull List<? extends VFileEvent> events) { if (!myProject.isDisposed()) { Set<VirtualFile> openFiles = ContainerUtil.newHashSet(fileEditorManager.getSelectedFiles()); for (VFileEvent event : events) { VirtualFile file = event.getFile(); if (file != null && openFiles.contains(file)) { notifications.updateNotifications(file); } } } } });
/** * Selects then next or previous editor. */ public void selectNextFile(int count, @NotNull DataContext context) { Project project = PlatformDataKeys.PROJECT.getData(context); if (project == null) return; FileEditorManager fem = FileEditorManager.getInstance(project); // API change - don't merge VirtualFile[] editors = fem.getOpenFiles(); VirtualFile current = fem.getSelectedFiles()[0]; for (int i = 0; i < editors.length; i++) { if (editors[i].equals(current)) { int pos = (i + (count % editors.length) + editors.length) % editors.length; fem.openFile(editors[pos], true); } } }
final VirtualFile[] selectedFiles = FileEditorManager.getInstance(project).getSelectedFiles(); if (selectedFiles.length > 0) { selectedFile = selectedFiles[0];
= FileEditorManager.getInstance(project).getSelectedFiles(); if (selectedFiles.length == 0) { return;
= FileEditorManager.getInstance(project).getSelectedFiles(); if (selectedFiles.length == 0) { setProgressText(toolWindow, "plugin.status.in-progress.no-file");
/** Get the state information associated with the grammar in the current * editor window. If there is no grammar in the editor window, return null. * If there is a grammar, return any existing preview state else * create a new one in store in the map. * * Too dangerous; turning off but might be useful later. public @org.jetbrains.annotations.Nullable PreviewState getPreviewState() { VirtualFile currentGrammarFile = getCurrentGrammarFile(); if ( currentGrammarFile==null ) { return null; } String currentGrammarFileName = currentGrammarFile.getPath(); if ( currentGrammarFileName==null ) { return null; // we are not looking at a grammar file } return getPreviewState(currentGrammarFile); } */ // These "get current editor file" routines should only be used // when you are sure the user is in control and is viewing the // right file (i.e., don't use these during project loading etc...) public static VirtualFile getCurrentEditorFile(Project project) { FileEditorManager fmgr = FileEditorManager.getInstance(project); // "If more than one file is selected (split), the file with most recent focused editor is returned first." from IDE doc on method VirtualFile files[] = fmgr.getSelectedFiles(); if ( files.length == 0 ) { return null; } return files[0]; }
public static boolean isElementInSelectedFile(Project project, PsiElement psiElement) { VirtualFile elementFile = getVirtualFile(project, psiElement); if (elementFile == null) { return false; } VirtualFile[] currentEditedFiles = FileEditorManager.getInstance(project).getSelectedFiles(); for (VirtualFile file : currentEditedFiles) { if (elementFile.equals(file)) { return true; } } return false; }