private static boolean checkFileLoadedInWrongEncoding(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly, @NotNull VirtualFile virtualFile, @NotNull Charset charset, @NotNull List<ProblemDescriptor> descriptors) { if (FileDocumentManager.getInstance().isFileModified(virtualFile) // when file is modified, it's too late to reload it || EncodingUtil.checkCanReload(virtualFile).second != null // can't reload in another encoding, no point trying ) { return true; } if (!isGoodCharset(virtualFile, charset)) { descriptors.add(manager.createProblemDescriptor(file, "File was loaded in the wrong encoding: '"+charset+"'", RELOAD_ENCODING_FIX, ProblemHighlightType.GENERIC_ERROR, isOnTheFly)); return false; } return true; }
private static boolean checkFileLoadedInWrongEncoding(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly, @NotNull String text, @NotNull VirtualFile virtualFile, @NotNull Charset charset, @NotNull List<ProblemDescriptor> descriptors) { if (FileDocumentManager.getInstance().isFileModified(virtualFile) // when file is modified, it's too late to reload it || EncodingUtil.checkCanReload(virtualFile).second != null // can't reload in another encoding, no point trying ) { return true; } if (!isGoodCharset(virtualFile, text, charset, file.getProject())) { descriptors.add(manager.createProblemDescriptor(file, "File was loaded in the wrong encoding: '"+charset+"'", RELOAD_ENCODING_FIX, ProblemHighlightType.GENERIC_ERROR, isOnTheFly)); return false; } return true; }
private static boolean checkFileLoadedInWrongEncoding(@Nonnull PsiFile file, @Nonnull InspectionManager manager, boolean isOnTheFly, @Nonnull VirtualFile virtualFile, @Nonnull Charset charset, @Nonnull List<ProblemDescriptor> descriptors) { if (FileDocumentManager.getInstance().isFileModified(virtualFile) // when file is modified, it's too late to reload it || EncodingUtil.checkCanReload(virtualFile).second != null // can't reload in another encoding, no point trying ) { return true; } if (!isGoodCharset(virtualFile, charset)) { descriptors.add(manager.createProblemDescriptor(file, "File was loaded in the wrong encoding: '" + charset + "'", RELOAD_ENCODING_FIX, ProblemHighlightType.GENERIC_ERROR, isOnTheFly)); return false; } return true; }
private void update() { if (update.isDisposed()) return; update.cancelAllRequests(); update.addRequest(new Runnable() { @Override public void run() { if (isDisposed()) return; VirtualFile file = getSelectedFile(); actionEnabled = false; String charsetName = null; Pair<Charset, String> check = null; if (file != null) { check = EncodingUtil.checkSomeActionEnabled(file); Charset charset = null; if (LoadTextUtil.wasCharsetDetectedFromBytes(file) != null) { charset = cachedCharsetFromContent(file); } if (charset == null) { charset = file.getCharset(); } actionEnabled = check == null || check.second == null; if (!actionEnabled) { charset = check.first; } if (charset != null) { charsetName = charset.displayName(); } } if (charsetName == null) { charsetName = "n/a"; } String toolTipText; if (actionEnabled) { toolTipText = String.format( "File Encoding%n%s", charsetName); myComponent.setForeground(UIUtil.getActiveTextColor()); myComponent.setTextAlignment(Component.LEFT_ALIGNMENT); } else { String failReason = check == null ? "" : check.second; toolTipText = String.format("File encoding is disabled%n%s", failReason); myComponent.setForeground(UIUtil.getInactiveTextColor()); myComponent.setTextAlignment(Component.CENTER_ALIGNMENT); } myComponent.setToolTipText(toolTipText); myComponent.setText(charsetName); if (myStatusBar != null) { myStatusBar.updateWidget(ID()); } } }, 200, ModalityState.any()); }
private void update() { if (update.isDisposed()) return; update.cancelAllRequests(); update.addRequest(() -> { if (isDisposed()) return; VirtualFile file = getSelectedFile(); actionEnabled = false; String charsetName = null; Pair<Charset, String> check = null; if (file != null) { check = EncodingUtil.checkSomeActionEnabled(file); Charset charset = null; if (LoadTextUtil.wasCharsetDetectedFromBytes(file) != null) { charset = cachedCharsetFromContent(file); } if (charset == null) { charset = file.getCharset(); } actionEnabled = check == null || check.second == null; if (!actionEnabled) { charset = check.first; } if (charset != null) { charsetName = charset.displayName(); } } if (charsetName == null) { charsetName = file != null ? "n/a" : ""; } String toolTipText; if (actionEnabled) { toolTipText = String.format( "File Encoding%n%s", charsetName); myComponent.setForeground(UIUtil.getActiveTextColor()); myComponent.setTextAlignment(Component.LEFT_ALIGNMENT); } else { String failReason = check == null ? "" : check.second; toolTipText = String.format("File encoding is disabled%n%s", failReason); myComponent.setForeground(UIUtil.getInactiveTextColor()); myComponent.setTextAlignment(Component.CENTER_ALIGNMENT); } myComponent.setToolTipText(toolTipText); myComponent.setText(charsetName); if (myStatusBar != null) { myStatusBar.updateWidget(ID()); } }, 200, ModalityState.any()); }