From 2746b5674ea805c7f47d097dd8d70fbd06dd4b79 Mon Sep 17 00:00:00 2001 From: LHY0125 <3364451258@qq.com> Date: Mon, 16 Mar 2026 17:53:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=8F=8C=E5=87=BB?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD=E5=B9=B6=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E5=B0=BA=E5=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为列表添加双击回调,双击项目可触发编辑对话框 - 实现自定义输入对话框以支持更宽的编辑区域 - 统一增大所有按钮尺寸至100x32像素 - 移除临时备份文件 --- include/callbacks.h | 4 + path_backup_20260315_224109.txt | 59 ------------ src/callbacks.c | 158 +++++++++++++++++++++++++++++++- src/main.c | 23 +++-- 4 files changed, 171 insertions(+), 73 deletions(-) delete mode 100644 path_backup_20260315_224109.txt diff --git a/include/callbacks.h b/include/callbacks.h index 89a80ac..ea7dcc3 100644 --- a/include/callbacks.h +++ b/include/callbacks.h @@ -3,6 +3,7 @@ #include +// 按钮回调 int btn_new_cb(Ihandle* self); int btn_edit_cb(Ihandle* self); int btn_browse_cb(Ihandle* self); @@ -13,4 +14,7 @@ int btn_ok_cb(Ihandle* self); int btn_cancel_cb(Ihandle* self); int btn_help_cb(Ihandle* self); +// 双击回调 +int list_dblclick_cb(Ihandle* self, int item, char* text); + #endif // CALLBACKS_H \ No newline at end of file diff --git a/path_backup_20260315_224109.txt b/path_backup_20260315_224109.txt deleted file mode 100644 index eb0a7e9..0000000 --- a/path_backup_20260315_224109.txt +++ /dev/null @@ -1,59 +0,0 @@ -C:\Program Files\Common Files\Oracle\Java\javapath -C:\Program Files\dotnet -C:\Program Files\Microsoft SQL Server\150\Tools\Binn -C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn -C:\Program Files\nodejs -C:\Program Files\NVIDIA Corporation\Nsight Compute 2022.1.0 -C:\Program Files\NVIDIA Corporation\NVIDIA app\NvDLISR -C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin -C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include -C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib -C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\libnvvp -C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common -C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit -C:\WINDOWS -C:\WINDOWS\system32 -C:\WINDOWS\System32\OpenSSH -C:\WINDOWS\System32\Wbem -C:\WINDOWS\System32\WindowsPowerShell\v1.0 -C:\Users\33644\.dotnet\tools -C:\Users\33644\AppData\Local\Microsoft\WindowsApps -C:\Users\33644\AppData\Local\Programs\Python\Python38 -C:\Users\33644\AppData\Local\Programs\Python\Python38\Scripts -C:\Users\33644\AppData\Roaming\npm -D:\Microsoft VS Code\bin -D:\PowerShell\PowerShell-7.5.4 -D:\Program Files (x86)\Graphviz\bin -D:\Program Files (x86)\Inno Setup 6 -D:\Program Files (x86)\NSIS\Bin -D:\Program Files (x86)\VMware\VMware Workstation\bin -D:\Program Files\cmake\bin -D:\Program Files\JetBrains\PyCharm 2024.1.6\bin -D:\ProgramData\anaconda3 -D:\ProgramData\anaconda3\bin -D:\ProgramData\anaconda3\condabin -D:\ProgramData\anaconda3\Library\bin -D:\ProgramData\anaconda3\Library\usr\bin -D:\ProgramData\anaconda3\Scripts -D:\Python\Python3.8 -D:\Python\Python3.8\Scripts -D:\settings\Git\cmd -D:\settings\Java\jdk-25.0.1\bin -D:\settings\Java\jdk-25.0.1\jre\bin -D:\settings\MATLAB\R2024a\bin -D:\settings\MATLAB\R2024a\runtime\win64 -D:\settings\mingw64\bin -D:\settings\MySQL\MySQL Server 8.0\bin -D:\settings\MySQL\MySQL Shell 8.0\bin -D:\settings\settings\apache-maven-3.9.6\bin -D:\settings\settings\libs\ffmpeg-8.0.1-essentials_build\bin -D:\settings\settings\libs\GitHub CLI -D:\settings\settings\libs\SDL\SDL3-3.2.22\x86_64-w64-mingw32\bin -D:\settings\settings\libs\SDL\SDL3_image-3.2.4\x86_64-w64-mingw32\bin -D:\settings\settings\libs\uv-x86_64-pc-windows-msvc -D:\settings\settings\PuTTY -D:\settings\settings\Scoop\apps\iperf\iperf3.exe -D:\settings\settings\Scoop\shims -D:\settings\TortoiseGit\bin -D:\texlive\2025\bin\windows -D:\texlive\2025\bin\windows\xelatex.exe diff --git a/src/callbacks.c b/src/callbacks.c index 770e22f..1bbe8d9 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -5,11 +5,139 @@ #include #include +// 简单的自定义输入对话框,支持更宽的输入框 +// 返回 1 表示确定,0 表示取消 +int show_custom_input_dialog(const char *title, const char *label_text, char *buffer, int buffer_size) +{ + Ihandle *text = IupText(NULL); + IupSetAttribute(text, "VALUE", buffer); + IupSetAttribute(text, "EXPAND", "HORIZONTAL"); + IupSetAttribute(text, "RASTERSIZE", "600x"); // 设置宽度为600像素 + IupSetAttribute(text, "VISIBLECOLUMNS", "80"); // 设置可见列数 + + // 如果是编辑模式,全选文本 + if (strlen(buffer) > 0) + { + IupSetAttribute(text, "SELECTION", "ALL"); + } + + Ihandle *dlg = IupDialog( + IupVbox( + IupLabel(label_text), + text, + IupHbox( + IupFill(), + IupButton("确定", "1"), // "1" will be returned by IupPopup + IupButton("取消", "0"), // "0" will be returned by IupPopup + NULL), + NULL)); + + // 布局设置 + IupSetAttribute(dlg, "TITLE", title); + IupSetAttribute(dlg, "MINBOX", "NO"); + IupSetAttribute(dlg, "MAXBOX", "NO"); + IupSetAttribute(dlg, "RESIZE", "NO"); + IupSetAttribute(dlg, "MARGIN", "10x10"); + IupSetAttribute(dlg, "GAP", "10"); + + // 按钮响应 + // 这是一个简单的 hack:IupPopup 的参数 x, y 如果是 IUP_CENTER 等,它是一个模态循环。 + // 但是标准的 IupPopup 不返回按钮值。 + // 我们使用 IupAlarm 类似的逻辑,或者使用 IUP 提供的 IupGetParam。 + // 为了最简单实现,我们使用 IUP 的 IupGetParam,但是它很难调整宽度。 + // 所以还是手动构建对话框。 + + // 为了获取返回值,我们需要设置按钮回调。 + // 但为了避免定义额外的全局函数,我们可以使用 IupPopup 阻塞特性。 + // 我们需要定义两个简单的回调函数。 + // 为了简化,这里定义两个静态辅助函数。 + + // 由于 C 语言闭包限制,我们需要用全局或静态变量传递状态,或者使用 Dialog 的 Attribute。 + IupSetAttribute(dlg, "MY_STATUS", "0"); + + // 注册回调 (使用 IupSetCallback 注册 lambda 类似的逻辑比较难,这里用名字) + // 必须定义全局函数。为了避免污染,我们在文件顶部定义静态函数。 + // 见下文的 static int on_dialog_ok... + + // 由于不能在函数内部定义函数,我们需要调整代码结构。 + // 见下文重构。 + + return 0; // 占位 +} + +// 静态辅助函数:对话框确定 +static int on_dialog_ok(Ihandle *self) +{ + Ihandle *dlg = IupGetDialog(self); + IupSetAttribute(dlg, "MY_STATUS", "1"); + return IUP_CLOSE; +} + +// 静态辅助函数:对话框取消 +static int on_dialog_cancel(Ihandle *self) +{ + Ihandle *dlg = IupGetDialog(self); + IupSetAttribute(dlg, "MY_STATUS", "0"); + return IUP_CLOSE; +} + +// 真正的实现函数 +int custom_input_dialog(const char *title, const char *label_text, char *buffer, int buffer_size) +{ + Ihandle *text = IupText(NULL); + IupSetAttribute(text, "VALUE", buffer); + IupSetAttribute(text, "EXPAND", "HORIZONTAL"); + IupSetAttribute(text, "RASTERSIZE", "500x"); + IupSetAttribute(text, "NAME", "INPUT_TEXT"); + + Ihandle *btn_ok = IupButton("确定", NULL); + IupSetCallback(btn_ok, "ACTION", on_dialog_ok); + IupSetAttribute(btn_ok, "RASTERSIZE", "80x25"); + // 设置为默认按钮 + + Ihandle *btn_cancel = IupButton("取消", NULL); + IupSetCallback(btn_cancel, "ACTION", on_dialog_cancel); + IupSetAttribute(btn_cancel, "RASTERSIZE", "80x25"); + + Ihandle *vbox = IupVbox( + IupLabel(label_text), + text, + IupHbox(IupFill(), btn_ok, btn_cancel, NULL), + NULL); + IupSetAttribute(vbox, "MARGIN", "15x15"); + IupSetAttribute(vbox, "GAP", "10"); + + Ihandle *dlg = IupDialog(vbox); + IupSetAttribute(dlg, "TITLE", title); + IupSetAttribute(dlg, "MINBOX", "NO"); + IupSetAttribute(dlg, "MAXBOX", "NO"); + IupSetAttribute(dlg, "RESIZE", "NO"); + + IupSetAttributeHandle(dlg, "DEFAULTENTER", btn_ok); + IupSetAttributeHandle(dlg, "DEFAULTESC", btn_cancel); + + IupPopup(dlg, IUP_CENTER, IUP_CENTER); + + int result = IupGetInt(dlg, "MY_STATUS"); + if (result == 1) + { + char *val = IupGetAttribute(text, "VALUE"); + if (val) + { + strncpy(buffer, val, buffer_size); + buffer[buffer_size - 1] = '\0'; + } + } + + IupDestroy(dlg); + return result; +} + // 按钮回调:新建 int btn_new_cb(Ihandle *self) { char buffer[1024] = ""; - if (IupGetParam("新建环境变量", NULL, NULL, "路径: %s\n", buffer, NULL)) + if (custom_input_dialog("新建环境变量", "请输入路径:", buffer, sizeof(buffer))) { if (strlen(buffer) > 0) { @@ -34,19 +162,41 @@ int btn_edit_cb(Ihandle *self) char *current_val = IupGetAttributeId(list_path, "", selected); char buffer[4096]; // 假设单个路径不超过4096 - strncpy(buffer, current_val, 4096); - buffer[4095] = '\0'; + if (current_val) + { + strncpy(buffer, current_val, 4096); + buffer[4095] = '\0'; + } + else + { + buffer[0] = '\0'; + } - if (IupGetParam("编辑环境变量", NULL, NULL, "路径: %s\n", buffer, NULL)) + if (custom_input_dialog("编辑环境变量", "编辑路径:", buffer, sizeof(buffer))) { if (strlen(buffer) > 0) { IupSetAttributeId(list_path, "", selected, buffer); + refresh_list_style(); } } return IUP_DEFAULT; } +// 双击回调 +int list_dblclick_cb(Ihandle *self, int item, char *text) +{ + // 这里的 item 是点击的行号 + if (item > 0) + { + // 选中该行 + IupSetInt(list_path, "VALUE", item); + // 调用编辑逻辑 + btn_edit_cb(NULL); + } + return IUP_DEFAULT; +} + // 按钮回调:浏览 int btn_browse_cb(Ihandle *self) { diff --git a/src/main.c b/src/main.c index f9e5676..47cadca 100644 --- a/src/main.c +++ b/src/main.c @@ -53,13 +53,16 @@ int main(int argc, char **argv) IupSetCallback(btn_up, "ACTION", (Icallback)btn_up_cb); IupSetCallback(btn_down, "ACTION", (Icallback)btn_down_cb); - // 设置按钮大小 (宽度) - IupSetAttribute(btn_new, "RASTERSIZE", "80x"); - IupSetAttribute(btn_edit, "RASTERSIZE", "80x"); - IupSetAttribute(btn_browse, "RASTERSIZE", "80x"); - IupSetAttribute(btn_del, "RASTERSIZE", "80x"); - IupSetAttribute(btn_up, "RASTERSIZE", "80x"); - IupSetAttribute(btn_down, "RASTERSIZE", "80x"); + // 设置双击回调 + IupSetCallback(list_path, "DBLCLICK_CB", (Icallback)list_dblclick_cb); + + // 设置按钮大小 (宽度和高度都增加约1/4) + IupSetAttribute(btn_new, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_edit, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_browse, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_del, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_up, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_down, "RASTERSIZE", "100x32"); Ihandle *vbox_btns = IupVbox( btn_new, btn_edit, btn_browse, btn_del, @@ -87,9 +90,9 @@ int main(int argc, char **argv) IupSetCallback(btn_cancel, "ACTION", (Icallback)btn_cancel_cb); IupSetCallback(btn_help, "ACTION", (Icallback)btn_help_cb); - IupSetAttribute(btn_ok, "RASTERSIZE", "80x25"); - IupSetAttribute(btn_cancel, "RASTERSIZE", "80x25"); - IupSetAttribute(btn_help, "RASTERSIZE", "80x25"); + IupSetAttribute(btn_ok, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_cancel, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_help, "RASTERSIZE", "100x32"); Ihandle *hbox_bottom = IupHbox(lbl_status, IupFill(), btn_help, btn_ok, btn_cancel, NULL); IupSetAttribute(hbox_bottom, "GAP", "10");