Search in sources :

Example 1 with EncodingProjectManager

use of com.intellij.openapi.vfs.encoding.EncodingProjectManager in project intellij-community by JetBrains.

the class EncodingManager method applySettings.

private void applySettings(VirtualFile file) {
    if (file == null)
        return;
    if (!Utils.isEnabled(CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings()))
        return;
    // Prevent "setEncoding" calling "saveAll" from causing an endless loop
    isApplyingSettings = true;
    try {
        final String filePath = Utils.getFilePath(myProject, file);
        final List<OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(myProject, filePath);
        final EncodingProjectManager encodingProjectManager = EncodingProjectManager.getInstance(myProject);
        final String charset = Utils.configValueForKey(outPairs, charsetKey);
        if (!charset.isEmpty()) {
            final Charset newCharset = encodingMap.get(charset);
            if (newCharset != null) {
                if (Comparing.equal(newCharset, file.getCharset()))
                    return;
                encodingProjectManager.setEncoding(file, newCharset);
            } else {
                Utils.invalidConfigMessage(myProject, charset, charsetKey, filePath);
            }
        }
    } finally {
        isApplyingSettings = false;
    }
}
Also used : OutPair(org.editorconfig.core.EditorConfig.OutPair) EncodingProjectManager(com.intellij.openapi.vfs.encoding.EncodingProjectManager) Charset(java.nio.charset.Charset)

Aggregations

EncodingProjectManager (com.intellij.openapi.vfs.encoding.EncodingProjectManager)1 Charset (java.nio.charset.Charset)1 OutPair (org.editorconfig.core.EditorConfig.OutPair)1