Java Code Examples for com.intellij.openapi.vfs.encoding.EncodingProjectManager#getInstance()
The following examples show how to use
com.intellij.openapi.vfs.encoding.EncodingProjectManager#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncodingManager.java From editorconfig-jetbrains with MIT License | 6 votes |
private void applySettings(VirtualFile file) { if (file == null || !file.isInLocalFileSystem()) return; // Prevent "setEncoding" calling "saveAll" from causing an endless loop isApplyingSettings = true; final String filePath = file.getCanonicalPath(); final List<OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(filePath); final EncodingProjectManager encodingProjectManager = EncodingProjectManager.getInstance(project); final String charset = Utils.configValueForKey(outPairs, charsetKey); if (!charset.isEmpty()) { if (encodingMap.containsKey(charset)) { encodingProjectManager.setEncoding(file, encodingMap.get(charset)); LOG.debug(Utils.appliedConfigMessage(charset, charsetKey, filePath)); } else { LOG.warn(Utils.invalidConfigMessage(charset, charsetKey, filePath)); } } isApplyingSettings = false; }
Example 2
Source File: PersistentFSImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public VirtualFile createChildFile(Object requestor, @Nonnull VirtualFile parent, @Nonnull String file) throws IOException { getDelegate(parent).createChildFile(requestor, parent, file); processEvent(new VFileCreateEvent(requestor, parent, file, false, null, null, false, null)); final VirtualFile child = parent.findChild(file); if (child == null) { throw new IOException("Cannot create child file '" + file + "' at " + parent.getPath()); } if (child.getCharset().equals(StandardCharsets.UTF_8)) { Project project = ProjectLocator.getInstance().guessProjectForFile(child); EncodingManager encodingManager = project == null ? EncodingManager.getInstance() : EncodingProjectManager.getInstance(project); if (encodingManager.shouldAddBOMForNewUtf8File()) { child.setBOM(CharsetToolkit.UTF8_BOM); } } return child; }
Example 3
Source File: FilePathImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public Charset getCharset(Project project) { // try to find existing virtual file VirtualFile existing = myVirtualFile != null && myVirtualFile.isValid() ? myVirtualFile : null; if (existing == null) { LocalFileSystem lfs = LocalFileSystem.getInstance(); for (File f = myFile; f != null; f = f.getParentFile()) { existing = lfs.findFileByIoFile(f); if (existing != null && existing.isValid()) { break; } } } if (existing != null) { Charset rc = existing.getCharset(); if (rc != null) { return rc; } } EncodingManager e = project != null ? EncodingProjectManager.getInstance(project) : null; if (e == null) { e = EncodingManager.getInstance(); } return e.getDefaultCharset(); }
Example 4
Source File: LocalFilePath.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public Charset getCharset(@Nullable Project project) { VirtualFile file = getVirtualFile(); String path = myPath; while ((file == null || !file.isValid()) && !path.isEmpty()) { path = PathUtil.getParentPath(path); file = LocalFileSystem.getInstance().findFileByPath(path); } if (file != null) { return file.getCharset(); } EncodingManager e = project == null ? EncodingManager.getInstance() : EncodingProjectManager.getInstance(project); return e.getDefaultCharset(); }
Example 5
Source File: VcsHistoryUtil.java From consulo with Apache License 2.0 | 5 votes |
public static String loadRevisionContentGuessEncoding(@Nonnull final VcsFileRevision revision, @Nullable final VirtualFile file, @javax.annotation.Nullable final Project project) throws VcsException, IOException { final byte[] bytes = loadRevisionContent(revision); if (file != null) { return new String(bytes, file.getCharset()); } EncodingManager e = project != null ? EncodingProjectManager.getInstance(project) : null; if (e == null) { e = EncodingManager.getInstance(); } return CharsetToolkit.bytesToString(bytes, e.getDefaultCharset()); }
Example 6
Source File: RemoteFilePath.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public Charset getCharset(@Nullable Project project) { EncodingManager em = project == null ? EncodingManager.getInstance() : EncodingProjectManager.getInstance(project); return em.getDefaultCharset(); }