/** * Saves all files in the project. */ public void saveFiles() { FileDocumentManager.getInstance().saveAllDocuments(); }
@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; }
public void selectionChanged(@NotNull FileEditorManagerEvent event) { // The user has changed the editor they are working with - exit insert/replace mode, and complete any // appropriate repeat if (event.getOldFile() != null) { lastSelections.put(event.getManager(), event.getOldFile()); } } }
@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()); } } }
/** * Gets the virtual file associated with this editor * * @param editor The editor * @return The virtual file for the editor */ @Nullable public static VirtualFile getVirtualFile(@NotNull Editor editor) { return FileDocumentManager.getInstance().getFile(editor.getDocument()); }
private static boolean isLineBreakpointAvailable(@NotNull VirtualFile file, int line, @NotNull Project project) { Document document = FileDocumentManager.getInstance().getDocument(file); if (document == null || document.getLineEndOffset(line) == document.getLineStartOffset(line)) return false; Checker canPutAtChecker = new Checker(); XDebuggerUtil.getInstance().iterateLine(project, document, line, canPutAtChecker); return canPutAtChecker.isLineBreakpointAvailable(); }
/** * Gets the editor for the virtual file within the editor manager. * * @param manager The file editor manager * @param file The virtual file get the editor for * @return The matching editor or null if no match was found */ @Nullable public static Editor getEditor(@NotNull final FileEditorManager manager, @Nullable final VirtualFile file) { if (file == null) { return null; } final Document doc = FileDocumentManager.getInstance().getDocument(file); if (doc == null) { return null; } final Editor[] editors = EditorFactory.getInstance().getEditors(doc, manager.getProject()); if (editors.length > 0) { return editors[0]; } return null; }
/** * 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; }
/** * Saves specific file in the project. */ public void saveFile(@NotNull Editor editor) { FileDocumentManager.getInstance().saveDocument(editor.getDocument()); }
/** * 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); }
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 selectionChanged(@NotNull FileEditorManagerEvent event) { if (ExEntryPanel.getInstance().isActive()) { ExEntryPanel.getInstance().deactivate(false); } final FileEditor fileEditor = event.getOldEditor(); if (fileEditor instanceof TextEditor) { final Editor editor = ((TextEditor) fileEditor).getEditor(); ExOutputModel.getInstance(editor).clear(); if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) { VimPlugin.getMotion().exitVisual(editor); } } } }
private void doFileLineTest(@NotNull String line, int startOffset, int endOffset, String targetPath, int targetLine, int targetColumn) { Filter.Result result = myFilter.applyFilter(line, line.length()); assertNotNull(result); HyperlinkInfo info = assertResultAndGetHyperlink(result, startOffset, endOffset); assertInstanceOf(info, OpenFileHyperlinkInfo.class); OpenFileDescriptor fileDescriptor = ((OpenFileHyperlinkInfo)info).getDescriptor(); assertNotNull(fileDescriptor); assertEquals(targetPath, fileDescriptor.getFile().getPath()); assertEquals("line", targetLine, fileDescriptor.getLine() + 1); assertEquals("column", targetColumn, fileDescriptor.getColumn() + 1); }
/** * Gets the map of marks for the specified file * * @param doc The editor to get the marks for * @return The map of marks. The keys are <code>Character</code>s of the mark names, the values are * <code>Mark</code>s. */ @Nullable private FileMarks<Character, Mark> getFileMarks(@NotNull final Document doc) { VirtualFile vf = FileDocumentManager.getInstance().getFile(doc); if (vf == null) { return null; } return getFileMarks(vf.getPath()); }
@Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = e.getProject(); assert project != null; FileDocumentManager.getInstance().saveAllDocuments(); for (Module module : GoSdkUtil.getGoModules(project)) { for (VirtualFile file : ModuleRootManager.getInstance(module).getContentRoots()) { fmt(project, module, "go fmt " + file.getPath(), file); } } }
private static void resetCursor(@NotNull VirtualFile virtualFile, Project proj, boolean insert) { logger.debug("resetCursor"); Document doc = FileDocumentManager.getInstance().getDocument(virtualFile); if (doc == null) return; // Must be no text editor (such as image) Editor[] editors = EditorFactory.getInstance().getEditors(doc, proj); if (logger.isDebugEnabled()) { logger.debug("There are " + editors.length + " editors for virtual file " + virtualFile.getName()); } for (Editor editor : editors) { editor.getSettings().setBlockCursor(!insert); } }
/** * 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(); } }
@Override public void editorCreated(@NotNull EditorFactoryEvent event) { Document document = event.getEditor().getDocument(); VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (file != null && file.getFileType() == GoFileType.INSTANCE) { checkForUpdates(); } } };
private static void resetCursor(@NotNull Editor editor, boolean insert) { Document doc = editor.getDocument(); VirtualFile vf = FileDocumentManager.getInstance().getFile(doc); if (vf != null) { resetCursor(vf, editor.getProject(), insert); } else { editor.getSettings().setBlockCursor(!insert); } }