List of usage examples for com.intellij.openapi.fileEditor FileEditorManager getSelectedFiles
public abstract VirtualFile @NotNull [] getSelectedFiles();
From source file:com.atlassian.theplugin.idea.ui.linkhiglighter.FileEditorListenerImpl.java
License:Apache License
public void scanOpenEditors() { final FileEditorManager editorManager = FileEditorManager.getInstance(project); if (editorManager == null) { return;/*from w w w. ja v a2 s .c om*/ } for (VirtualFile openFile : editorManager.getSelectedFiles()) { if (!linkHighlighters.containsKey(openFile)) { PsiFile psiFile = safeFindFile(openFile); if (psiFile != null) { Editor editor = editorManager.getSelectedTextEditor(); if (editor != null) { addHighlighter(openFile, psiFile, editor); } } } else { linkHighlighters.get(openFile).reparseAll(); linkHighlighters.get(openFile).checkComments(); } } }
From source file:com.echologic.xfiles.RefreshAction.java
License:Open Source License
public void actionPerformed(AnActionEvent event) { log.debug("actionPerformed"); if (filter == null) { log.debug("no filter selected"); return;/*from ww w .ja v a 2s. com*/ } long start = System.currentTimeMillis(); final Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT); CountingFilterListener listener = new CountingFilterListener(); filter.setListener(listener); XFilesContentIterator content = new XFilesContentIterator(project); content.setFilter(filter); content.iterate(); listener.log(); List included = content.getIncluded(); model.clear(); for (Iterator iterator = included.iterator(); iterator.hasNext();) { VirtualFile file = (VirtualFile) iterator.next(); model.addElement(file); } long finish = System.currentTimeMillis(); long delta = finish - start; WindowManager windowManager = WindowManager.getInstance(); StatusBar statusBar = windowManager.getStatusBar(project); statusBar.setInfo(filter.getName() + " filter refreshed in " + delta + "ms; " + content + listener); FileEditorManager editorManager = FileEditorManager.getInstance(project); VirtualFile[] files = editorManager.getSelectedFiles(); if (files != null && files.length > 0) model.setSelectedItem(files[0]); }
From source file:com.facebook.buck.intellij.ideabuck.fixup.MoveResourceFiles.java
License:Apache License
@Override public void onFileCreate(VFileCreateEvent event, Facet facet) { Project project = facet.getModule().getProject(); FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); VirtualFile[] selectedFiles = fileEditorManager.getSelectedFiles(); if (selectedFiles.length != 1) { log("Oh, dear. We have a new file in a Project View resource directory, but we have %d selected files", selectedFiles.length);//w ww . ja va 2s.co m ErrorDialog.showErrorDialog(project, "Error moving new file", "We have a new file in a Project View resource directory, but we have %d selected files and so don't know which BUCK file to examine", selectedFiles.length); return; // we are expecting a SINGLE file, here } VirtualFile selection = selectedFiles[0]; Editor editor = fileEditorManager.getSelectedTextEditor(); moveResourceFile(event.getPath(), project, selection, editor); }
From source file:com.goide.inspections.GoFileIgnoredByBuildToolNotificationProvider.java
License:Apache License
public GoFileIgnoredByBuildToolNotificationProvider(@Nonnull Project project, @Nonnull EditorNotifications notifications, @Nonnull FileEditorManager fileEditorManager) { myProject = project;//from ww w.j a v a2s .com MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@Nonnull 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); } } } } }); }
From source file:com.goide.inspections.MismatchedBuildTargetNotificationProvider.java
License:Apache License
public MismatchedBuildTargetNotificationProvider(@NotNull Project project, @NotNull final EditorNotifications notifications, @NotNull final FileEditorManager fileEditorManager) { myProject = project;/*from w ww. ja v a2 s .c o m*/ MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(GoModuleSettings.TOPIC, new GoModuleSettings.BuildTargetListener() { @Override public void changed(@NotNull Module module) { notifications.updateAllNotifications(); } }); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @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); } } } } }); }
From source file:com.intellij.ide.macro.MacroManager.java
License:Apache License
private static DataContext getCorrectContext(DataContext dataContext) { if (PlatformDataKeys.FILE_EDITOR.getData(dataContext) != null) { return dataContext; }/*from w ww . j a v a2s. co m*/ Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return dataContext; } FileEditorManager editorManager = FileEditorManager.getInstance(project); VirtualFile[] files = editorManager.getSelectedFiles(); if (files.length == 0) { return dataContext; } FileEditor fileEditor = editorManager.getSelectedEditor(files[0]); return fileEditor == null ? dataContext : DataManager.getInstance().getDataContext(fileEditor.getComponent()); }
From source file:com.intellij.ide.todo.CurrentFileTodosPanel.java
License:Apache License
CurrentFileTodosPanel(Project project, TodoPanelSettings settings, Content content) { super(project, settings, true, content); FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); VirtualFile[] files = fileEditorManager.getSelectedFiles(); PsiFile psiFile = files.length == 0 ? null : PsiManager.getInstance(myProject).findFile(files[0]); setFile(psiFile);//from w ww . jav a2 s. c om MyFileEditorManagerListener fileEditorManagerListener = new MyFileEditorManagerListener(); // It's important to remove this listener. It prevents invocation of setFile method after the tree builder // is disposed. fileEditorManager.addFileEditorManagerListener(fileEditorManagerListener, this); }
From source file:com.maddyhome.idea.vim.group.FileGroup.java
License:Open Source License
/** * Selects then next or previous editor/*from ww w. ja va2 s. co m*/ * * @param count * @param context */ public void selectNextFile(int count, @NotNull DataContext context) { Project proj = PlatformDataKeys.PROJECT.getData(context); FileEditorManager fem = FileEditorManager.getInstance(proj); // 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); } } }
From source file:com.sixrr.metrics.utils.PluginPsiUtil.java
License:Apache License
public static boolean isElementInSelectedFile(Project project, PsiElement psiElement) { final VirtualFile elementFile = getVirtualFile(psiElement); if (elementFile == null) { return false; }//from ww w. j a va2 s . c om final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); final VirtualFile[] currentEditedFiles = fileEditorManager.getSelectedFiles(); for (final VirtualFile file : currentEditedFiles) { if (elementFile.equals(file)) { return true; } } return false; }
From source file:com.thoughtworks.gauge.formatter.SpecFormatter.java
License:Open Source License
@Override public void actionPerformed(AnActionEvent anActionEvent) { final Project project = anActionEvent.getData(LangDataKeys.PROJECT); if (project == null) { return;/*from w w w . j a va2 s .com*/ } String projectDir = project.getBasePath(); if (projectDir == null) { return; } FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); VirtualFile selectedFile = fileEditorManager.getSelectedFiles()[0]; String fileName = selectedFile.getCanonicalPath(); Document doc = FileDocumentManager.getInstance().getDocument(selectedFile); if (doc != null) { FileDocumentManager.getInstance().saveDocument(doc); } try { GaugeSettingsModel settings = getGaugeSettings(); ProcessBuilder processBuilder = new ProcessBuilder(settings.getGaugePath(), Constants.FORMAT, fileName); GaugeUtil.setGaugeEnvironmentsTo(processBuilder, settings); processBuilder.directory(new File(projectDir)); Process process = processBuilder.start(); int exitCode = process.waitFor(); if (exitCode != 0) { String output = String.format("<pre>%s</pre>", GaugeUtil.getOutput(process.getInputStream(), "\n") .replace("<", "<").replace(">", ">")); Notifications.Bus.notify(new Notification("Spec Formatting", "Error: Spec Formatting", output, NotificationType.ERROR)); return; } VirtualFileManager.getInstance().syncRefresh(); selectedFile.refresh(false, false); } catch (Exception e) { e.printStackTrace(); Messages.showErrorDialog("Error on formatting spec", "Format Error"); } }