/** * Opens given file in editor. * * @param project current project * @param file file to open */ public static void openFile(@NotNull Project project, @NotNull VirtualFile file) { FileEditorManager.getInstance(project).openFile(file, true); }
@Nullable Editor selectEditor(Project project, @NotNull VirtualFile file) { FileEditorManager fMgr = FileEditorManager.getInstance(project); FileEditor[] feditors = fMgr.openFile(file, true); if (feditors.length > 0) { if (feditors[0] instanceof TextEditor) { return ((TextEditor)feditors[0]).getEditor(); } } return null; }
/** * Selects previous editor tab. */ public void selectPreviousTab(@NotNull DataContext context) { Project project = PlatformDataKeys.PROJECT.getData(context); if (project == null) return; FileEditorManager fem = FileEditorManager.getInstance(project); // API change - don't merge VirtualFile vf = lastSelections.get(fem); if (vf != null) { fem.openFile(vf, true); } else { VimPlugin.indicateError(); } }
/** * 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); } } }
/** * Selects then next or previous editor. */ public boolean selectFile(int count, @NotNull DataContext context) { final Project project = PlatformDataKeys.PROJECT.getData(context); if (project == null) return false; FileEditorManager fem = FileEditorManager.getInstance(project); // API change - don't merge VirtualFile[] editors = fem.getOpenFiles(); if (count == 99) { count = editors.length - 1; } if (count < 0 || count >= editors.length) { return false; } fem.openFile(editors[count], true); return true; }
public boolean openFile(@NotNull String filename, @NotNull DataContext context) { if (logger.isDebugEnabled()) { logger.debug("openFile(" + filename + ")"); } final Project project = PlatformDataKeys.PROJECT.getData(context); // API change - don't merge if (project == null) return false; VirtualFile found = findFile(filename, project); if (found != null) { if (logger.isDebugEnabled()) { logger.debug("found file: " + found); } // Can't open a file unless it has a known file type. The next call will return the known type. // If unknown, IDEA will prompt the user to pick a type. FileType type = FileTypeManager.getInstance().getKnownFileTypeOrAssociate(found, project); if (type != null) { FileEditorManager fem = FileEditorManager.getInstance(project); fem.openFile(found, true); return true; } else { // There was no type and user didn't pick one. Don't open the file // Return true here because we found the file but the user canceled by not picking a type. return true; } } else { VimPlugin.showMessage("Unable to find " + filename); return false; } }
try { PsiFile file = new CreateFileCommandAction(project, directory, fileType).execute(); FileEditorManager.getInstance(project).openFile(file.getVirtualFile(), true); new GeneratorDialog(project, file).show(); } catch (Throwable throwable) {
public void openEditor(final MongoObjectFile mongoObjectFile) { FileEditorManager fileEditorManager = FileEditorManager.getInstance(mongoObjectFile.getProject()); fileEditorManager.openFile(mongoObjectFile, true); }
/** * Scroll to the error specified by the given tree path, or do nothing * if no error is specified. * * @param treePath the tree path to scroll to. */ private void scrollToError(final TreePath treePath) { final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); if (treeNode == null || !(treeNode.getUserObject() instanceof ResultTreeNode)) { return; } final ResultTreeNode nodeInfo = (ResultTreeNode) treeNode.getUserObject(); if (nodeInfo.getFile() == null || nodeInfo.getProblem() == null) { return; // no problem here :-) } final VirtualFile virtualFile = nodeInfo.getFile().getVirtualFile(); if (virtualFile == null || !virtualFile.exists()) { return; } final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); final FileEditor[] editor = fileEditorManager.openFile( virtualFile, true); if (editor.length > 0 && editor[0] instanceof TextEditor) { final LogicalPosition problemPos = new LogicalPosition( Math.max(lineFor(nodeInfo) - 1, 0), Math.max(columnFor(nodeInfo), 0)); final Editor textEditor = ((TextEditor) editor[0]).getEditor(); textEditor.getCaretModel().moveToLogicalPosition(problemPos); textEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER); } }
public static FileEditor[] openFile(Project project, VirtualFile file) { return FileEditorManager.getInstance(project).openFile(file, true); }
private static void associateFileTypeAndNavigate(Project project, VirtualFile virtualFile) { String extension = virtualFile.getExtension(); FileTypeManagerEx fileTypeManagerEx = FileTypeManagerEx.getInstanceEx(); if (extension != null && fileTypeManagerEx.getFileTypeByExtension(extension) == FileTypes.UNKNOWN) { fileTypeManagerEx.associateExtension(StdFileTypes.PLAIN_TEXT, "flex"); } FileEditorManager.getInstance(project).openFile(virtualFile, false, true); //new OpenFileDescriptor(project, virtualFile).navigate(false); }
FileEditorManager.getInstance(project).openFile(virtualFile, true); if (defaultTemplateProperty != null) { PropertiesComponent.getInstance(project).setValue(defaultTemplateProperty, template.getName());
FileEditorManager.getInstance(project).openFile(virtualFile, true); if (defaultTemplateProperty != null) { PropertiesComponent.getInstance(project).setValue(defaultTemplateProperty, template.getName());