feat(tooltip): 添加环境变量展开预览悬停提示

- 新增 expand_env_vars 函数,调用 ExpandEnvironmentStringsA 展开 %VAR%
- sync_string_list_to_ui 中对含 % 的路径设置 ITEMTIP 属性
- 鼠标悬停时显示展开后的完整路径

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 23:45:58 +08:00
parent e5d24389b4
commit 485d16a180
3 changed files with 42 additions and 1 deletions
+4
View File
@@ -30,4 +30,8 @@ char *stristr(const char *haystack, const char *needle);
// 检查字符串列表中是否存在指定路径(不区分大小写)
int string_list_contains(const StringList *list, const char *str);
// 展开环境变量(如 %JAVA_HOME%\bin → C:\Java\bin
// 返回 malloc 分配的字符串,调用者负责释放;无变量返回 NULL
char *expand_env_vars(const char *path);
#endif // STRING_EXT_H
+15 -1
View File
@@ -1,7 +1,9 @@
#include "ui/ui_utils.h"
#include "utils/os_env.h"
#include "utils/string_ext.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// 刷新列表样式(斑马纹 + 有效性检查)
void refresh_single_list_style(Ihandle *list)
@@ -61,7 +63,19 @@ void sync_string_list_to_ui(Ihandle *list_ui, const StringList *str_list)
for (int i = 0; i < str_list->count; i++)
{
IupSetAttributeId(list_ui, "", i + 1, string_list_get(str_list, i));
const char *item = string_list_get(str_list, i);
IupSetAttributeId(list_ui, "", i + 1, item);
// 对含环境变量的路径设置悬停提示
if (item && strchr(item, '%'))
{
char *expanded = expand_env_vars(item);
if (expanded)
{
IupSetAttributeId(list_ui, "ITEMTIP", i + 1, expanded);
free(expanded);
}
}
}
IupSetInt(list_ui, "COUNT", str_list->count);
+23
View File
@@ -140,3 +140,26 @@ int string_list_contains(const StringList *list, const char *str)
}
return 0;
}
// 展开环境变量(如 %JAVA_HOME%\bin → C:\Java\bin
char *expand_env_vars(const char *path)
{
if (!path || !strchr(path, '%'))
return NULL;
DWORD size = ExpandEnvironmentStringsA(path, NULL, 0);
if (size == 0)
return NULL;
char *expanded = (char *)malloc(size);
if (!expanded)
return NULL;
if (ExpandEnvironmentStringsA(path, expanded, size) == 0)
{
free(expanded);
return NULL;
}
return expanded;
}