MCPcopy Create free account
hub / github.com/XUANXUQAQ/File-Engine / getHtml

Method getHtml

src/main/java/file/engine/frames/SearchBar.java:4294–4331  ·  view source on GitHub ↗

根据path或command生成显示html @param path path @param command command @param isResultStringContracted 结果是否压缩,在显示path的情况下可能由于文件路径太长而不显示 @return html

(String path, String command, boolean[] isResultStringContracted)

Source from the content-addressed store, hash-verified

4292 * @return html
4293 */
4294 private String getHtml(String path, String command, boolean[] isResultStringContracted) {
4295 String colorHex = "#" + ColorUtil.parseColorHex(labelFontColor);
4296 String template = "<html><body style=\"color: " + colorHex + ";\">%s</body></html>";
4297 isResultStringContracted[0] = false;
4298 if (path == null) {
4299 // 命令模式
4300 String[] info = RegexUtil.semicolon.split(command);
4301 String commandPath = info[1];
4302 String commandName = info[0];
4303 var keywordToHighlight = new String[]{getSearchBarText().substring(1)};
4304 return String.format(template, "<div>" +
4305 highLight(commandName, keywordToHighlight) + "<br>" +
4306 "<div style=\"overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: smaller;\">" +
4307 "&gt;&gt;" + commandPath +
4308 "</div>" +
4309 "</div>");
4310 }
4311 if (command == null) {
4312 // 普通模式
4313 String parentPath = FileUtil.getParentPath(path);
4314 String fileName = FileUtil.getFileName(path);
4315 parentPath = getContractPath(parentPath);
4316 int needWidth = label1.getFontMetrics(label1.getFont()).stringWidth(parentPath);
4317 if (label1.getWidth() >= needWidth) {
4318 return String.format(template, "<div>" +
4319 highLight(fileName, keywords) + "<br>" +
4320 "<div style=\"overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: smaller;\">" + parentPath +
4321 "</div>" +
4322 "</div>");
4323 } else {
4324 isResultStringContracted[0] = true;
4325 return String.format(template, "<div>" +
4326 highLight(fileName, keywords) +
4327 "</div>");
4328 }
4329 }
4330 return template.replace("%s", "");
4331 }
4332
4333 /**
4334 * 在label上显示当前文件路径对应文件的信息

Callers 2

showResultOnLabelMethod · 0.95
showCommandOnLabelMethod · 0.95

Calls 6

parseColorHexMethod · 0.95
getSearchBarTextMethod · 0.95
highLightMethod · 0.95
getParentPathMethod · 0.95
getFileNameMethod · 0.95
getContractPathMethod · 0.95

Tested by

no test coverage detected