/** * 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 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; }
/** * 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); } } }
@Nullable private XSourcePosition findPosition() { XDebugSession debugSession = getSession(); if (debugSession == null) return null; XStackFrame stackFrame = debugSession.getCurrentStackFrame(); if (stackFrame == null) return null; Project project = debugSession.getProject(); XSourcePosition position = debugSession.getCurrentPosition(); Editor editor = ((FileEditorManagerImpl)FileEditorManager.getInstance(project)).getSelectedTextEditor(true); if (editor == null || position == null) return null; String name = myName.startsWith("&") ? myName.replaceFirst("\\&", "") : myName; PsiElement resolved = findTargetElement(project, position, editor, name); if (resolved == null) return null; VirtualFile virtualFile = resolved.getContainingFile().getVirtualFile(); return XDebuggerUtil.getInstance().createPositionByOffset(virtualFile, resolved.getTextOffset()); } });
FileEditorManager manager = FileEditorManager.getInstance(project); manager.openFile(psiClass.getContainingFile().getVirtualFile(), true, true); FileEditorManager manager = FileEditorManager.getInstance(project); manager.openFile(psiClass.getContainingFile().getVirtualFile(), true, true);
@Nullable private XSourcePosition findPosition() { XDebugSession debugSession = myProcess.getSession(); if (debugSession == null) { return null; } XStackFrame stackFrame = debugSession.getCurrentStackFrame(); if (stackFrame == null) { return null; } Project project = debugSession.getProject(); XSourcePosition position = debugSession.getCurrentPosition(); Editor editor = ((FileEditorManagerImpl) FileEditorManager.getInstance(project)) .getSelectedTextEditor(true); if (editor == null || position == null) { return null; } String name = myName.startsWith("&") ? myName.replaceFirst("\\&", "") : myName; PsiElement resolved = findTargetElement(project, position, editor, name); if (resolved == null) { return null; } VirtualFile virtualFile = resolved.getContainingFile().getVirtualFile(); return XDebuggerUtil.getInstance().createPositionByOffset(virtualFile, resolved.getTextOffset()); } });
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; } }
private void highlightSearch(final boolean noSmartCase) { Project[] projects = ProjectManager.getInstance().getOpenProjects(); for (Project project : projects) { Editor current = FileEditorManager.getInstance(project).getSelectedTextEditor(); Editor[] editors = current == null ? null : EditorFactory.getInstance().getEditors(current.getDocument(), project); if (editors == null) { continue; } for (final Editor editor : editors) { String els = EditorData.getLastSearch(editor); if (!showSearchHighlight) { removeSearchHighlight(editor); continue; } else if (lastSearch != null && lastSearch.equals(els)) { continue; } else if (lastSearch == null) { continue; } removeSearchHighlight(editor); highlightSearchLines(editor, lastSearch, 0, -1, shouldIgnoreCase(lastSearch, noSmartCase)); EditorData.setLastSearch(editor, lastSearch); } } }
@Override protected void postProcess(PsiFile createdElement, String templateName, Map<String, String> customProperties) { if (createdElement instanceof GoFile) { GoPackageClause packageClause = ((GoFile)createdElement).getPackage(); if (packageClause == null) { return; } Project project = createdElement.getProject(); Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (editor == null) { return; } VirtualFile virtualFile = createdElement.getContainingFile().getVirtualFile(); if (virtualFile == null) { return; } if (FileDocumentManager.getInstance().getDocument(virtualFile) == editor.getDocument()) { editor.getCaretModel().moveToOffset(packageClause.getTextRange().getEndOffset()); } } }
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 testUndo() { DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); updateSettings(true); myFixture.configureByText("a.go", "package main\n\nfunc main() { <caret> }"); myFixture.type("fmt."); myFixture.doHighlighting(); myFixture.doHighlighting(); myFixture.checkResult("package main\n\nimport \"fmt\"\n\nfunc main() { fmt. }"); FileEditor editor = FileEditorManager.getInstance(myFixture.getProject()).getSelectedEditor(myFixture.getFile().getVirtualFile()); UndoManager.getInstance(myFixture.getProject()).undo(editor); myFixture.checkResult("package main\n\nfunc main() { <caret> }"); }
public void openEditor(final MongoObjectFile mongoObjectFile) { FileEditorManager fileEditorManager = FileEditorManager.getInstance(mongoObjectFile.getProject()); fileEditorManager.openFile(mongoObjectFile, true); }
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if(selectedTextEditor != null) { popup.showInBestPositionFor(selectedTextEditor);
/** * 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); } }
@Override public void run() { VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath); if (file != null && file.isValid()) { FileEditorProvider[] providers = FileEditorProviderManager.getInstance() .getProviders(project, file); if (providers.length != 0) { OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file); FileEditorManager.getInstance(project).openTextEditor(descriptor, true); } } } });
final Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (selectedTextEditor != null) { selectedFile = FileDocumentManager.getInstance().getFile(selectedTextEditor.getDocument()); final VirtualFile[] selectedFiles = FileEditorManager.getInstance(project).getSelectedFiles(); if (selectedFiles.length > 0) { selectedFile = selectedFiles[0];
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, phpClass.getContainingFile().getVirtualFile()), true); if(editor == null) { return;
= FileEditorManager.getInstance(project).getSelectedFiles(); if (selectedFiles.length == 0) { return;