mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-05-10 19:03:29 +08:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ec22eaae0 | |||
| c92d20b4b3 | |||
| 6a22202ce5 | |||
| db01c1ad53 | |||
| 1681473357 | |||
| 50f9f95ad5 | |||
| 6ccdc696d2 | |||
| 1219a53391 | |||
| 3302132644 | |||
| 59db3dc33b | |||
| 197b318c61 | |||
| b35fac5358 | |||
| 7db190306c | |||
| 575fcca5c4 | |||
| 39d06e20e0 |
@@ -0,0 +1,75 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(PathEditor VERSION 3.0 LANGUAGES C)
|
||||
|
||||
# 启用资源编译器以处理 .rc 文件
|
||||
enable_language(RC)
|
||||
|
||||
# 设置 C 标准
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_EXTENSIONS OFF) # 禁用特定编译器的扩展(如 gnu17),强制使用标准 C17
|
||||
|
||||
# 定义源文件
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
src/utils.c
|
||||
src/registry.c
|
||||
src/ui.c
|
||||
src/globals.c
|
||||
src/ui_utils.c
|
||||
src/cb_edit.c
|
||||
src/cb_file.c
|
||||
src/cb_main.c
|
||||
ico/resources.rc
|
||||
)
|
||||
|
||||
# 创建 GUI 可执行文件(WIN32 属性会自动添加 -mwindows 参数)
|
||||
add_executable(${PROJECT_NAME} WIN32 ${SOURCES})
|
||||
|
||||
# 添加宏定义
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
_WIN32
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
# 添加编译选项
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
-Wall
|
||||
-O2
|
||||
-fexec-charset=UTF-8
|
||||
)
|
||||
endif()
|
||||
|
||||
# 设置头文件搜索路径
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/libs/IUP/include
|
||||
)
|
||||
|
||||
# 设置库文件搜索路径
|
||||
target_link_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/libs/IUP
|
||||
)
|
||||
|
||||
# 链接所需库
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
iup
|
||||
iupcd
|
||||
gdi32
|
||||
comdlg32
|
||||
comctl32
|
||||
uuid
|
||||
ole32
|
||||
advapi32
|
||||
)
|
||||
|
||||
# 编译完成后,仅将程序实际需要的核心 DLL 文件复制到构建输出目录
|
||||
set(IUP_REQUIRED_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/libs/IUP/iup.dll")
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${IUP_REQUIRED_DLLS}
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying required DLLs to build directory..."
|
||||
)
|
||||
@@ -1,54 +0,0 @@
|
||||
CC = gcc
|
||||
WINDRES = windres
|
||||
|
||||
# Paths - specific to user environment
|
||||
IUP_DIR = libs/iup-3.31_Win64_dllw6_lib
|
||||
INCLUDE_DIR = $(IUP_DIR)/include
|
||||
LIB_DIR = $(IUP_DIR)
|
||||
LOCAL_INCLUDE_DIR = include
|
||||
|
||||
# Output Directories
|
||||
OBJ_DIR = obj
|
||||
BIN_DIR = bin
|
||||
|
||||
# Flags
|
||||
# -mwindows: Create GUI app (no console)
|
||||
# -DUNICODE -D_UNICODE: Use Wide Character API
|
||||
CFLAGS = -Wall -O2 -I$(INCLUDE_DIR) -I$(LOCAL_INCLUDE_DIR) -D_WIN32 -DUNICODE -D_UNICODE -fexec-charset=UTF-8
|
||||
LDFLAGS = -L$(LIB_DIR) -liup -liupcd -lgdi32 -lcomdlg32 -lcomctl32 -luuid -lole32 -ladvapi32 -mwindows
|
||||
|
||||
# Source
|
||||
SRC = src/main.c src/utils.c src/registry.c src/callbacks.c
|
||||
RES = ico/resources.rc
|
||||
OBJ = $(OBJ_DIR)/main.o $(OBJ_DIR)/utils.o $(OBJ_DIR)/registry.o $(OBJ_DIR)/callbacks.o $(OBJ_DIR)/resources.o
|
||||
EXE = $(BIN_DIR)/PathEditor.exe
|
||||
|
||||
all: $(BIN_DIR) $(OBJ_DIR) $(EXE)
|
||||
|
||||
$(BIN_DIR):
|
||||
if not exist $(BIN_DIR) mkdir $(BIN_DIR)
|
||||
|
||||
$(OBJ_DIR):
|
||||
if not exist $(OBJ_DIR) mkdir $(OBJ_DIR)
|
||||
|
||||
$(EXE): $(OBJ)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
$(OBJ_DIR)/main.o: src/main.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/utils.o: src/utils.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/registry.o: src/registry.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/callbacks.o: src/callbacks.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/resources.o: ico/resources.rc
|
||||
$(WINDRES) -i $< -o $@
|
||||
|
||||
clean:
|
||||
if exist $(OBJ_DIR)\*.o del /Q $(OBJ_DIR)\*.o
|
||||
if exist $(BIN_DIR)\*.exe del /Q $(BIN_DIR)\*.exe
|
||||
@@ -1,18 +1,51 @@
|
||||
# Path Editor (系统环境变量编辑器)
|
||||
|
||||
一个简单、轻量级的 Windows 系统环境变量(PATH)编辑器,基于 C 语言和 IUP 图形库开发。
|
||||
* Path Editor 是一个专为 Windows 用户设计的系统环境变量(PATH)管理工具。它基于原生 C 语言和 IUP 图形库开发,旨在替代 Windows 自带的简陋编辑界面。
|
||||
* 相比系统自带的编辑器,Path Editor 提供了更加直观的双视图(系统/用户变量)界面、智能的路径有效性检测、自动备份机制以及便捷的拖拽操作,让环境变量的管理变得安全、高效且轻松。无论您是开发者还是系统管理员,它都是您配置开发环境的得力助手。
|
||||
|
||||
## ✨ 功能特点
|
||||
|
||||
* **可视化编辑**:直观地查看和管理系统 PATH 环境变量。
|
||||
* **安全操作**:必须以管理员身份运行才能保存更改,防止误操作。
|
||||
* **🛡️ 安全第一**:
|
||||
* **自动备份**:每次保存前自动备份注册表,防止意外。
|
||||
* **只读模式**:非管理员运行时自动切换到只读模式,防止误操作。
|
||||
* **权限检测**:智能检测当前运行权限。
|
||||
|
||||
* **📑 双视图与预览**:
|
||||
* **分离管理**:完美支持 **System (系统变量)** 和 **User (用户变量)** 的分离查看与编辑。
|
||||
* **合并预览**:新增标签页,展示最终解析后的完整 PATH 顺序(系统在前,用户在后),方便排查冲突。
|
||||
* **变量展开**:鼠标悬停在包含变量(如 `%JAVA_HOME%`)的路径上时,自动显示解析后的绝对路径。
|
||||
|
||||
* **🔴 智能诊断与维护**:
|
||||
* **无效路径高亮**:自动检测路径是否存在,不存在的显示为红色。
|
||||
* **重复路径高亮**:自动检测重复项,重复的显示为橙色。
|
||||
* **一键清理**:智能移除所有无效和重复的路径,保持环境整洁。
|
||||
|
||||
* **📂 高级交互**:
|
||||
* **多选支持**:支持使用 `Ctrl` 或 `Shift` 进行多选,批量删除或移动路径。
|
||||
* **撤销/重做**:支持 `Ctrl+Z` 撤销和 `Ctrl+Y` 重做,防止误操作,并提供直观的工具栏按钮。
|
||||
* **拖拽支持**:直接将文件夹拖入窗口即可添加(支持管理员模式下的 UIPI 穿透)。
|
||||
* **实时搜索**:顶部搜索框支持不区分大小写的实时过滤查找(支持快捷键 `Ctrl+F`)。
|
||||
* **全局快捷键**:支持 `Ctrl+N` 新建、`Ctrl+S` 保存、`Delete` 删除等快捷操作。
|
||||
|
||||
* **🎨 个性化**:
|
||||
* **深色模式**:一键切换深色主题,保护视力。
|
||||
|
||||
* **便捷管理**:
|
||||
* ➕ **新建**:添加新路径到列表。
|
||||
* 📂 **浏览**:直接从文件资源管理器选择目录添加。
|
||||
* ✏️ **编辑**:修改现有路径。
|
||||
* ✏️ **编辑**:双击或点击按钮修改现有路径。
|
||||
* 🗑️ **删除**:移除不需要的路径。
|
||||
* ⬆️⬇️ **排序**:上移/下移调整路径优先级。
|
||||
* **轻量级**:原生 C 语言编写,运行速度快,占用资源少。
|
||||
* 📥/📤 **导入导出**:支持将环境变量导出为 `.txt` 文本文件备份,或从文件导入恢复。
|
||||
|
||||
* **轻量级**:原生 C 语言编写,无臃肿依赖,运行速度极快。
|
||||
|
||||
## 🏗️ 架构与二次开发
|
||||
|
||||
本项目注重代码的模块化和可维护性,非常适合作为 C 语言桌面程序开发的参考:
|
||||
|
||||
* **统一配置中心**:所有的 UI 尺寸、间距、颜色等常量配置均提取在 `include/config.h` 中,只需修改宏定义即可轻松定制属于你的专属界面风格。
|
||||
* **清晰的全局状态**:全局变量和常量被独立分离在 `src/globals.c` / `include/globals.h` 中管理,使得核心业务逻辑更加整洁。
|
||||
|
||||
## 📦 下载与安装
|
||||
|
||||
@@ -28,11 +61,14 @@
|
||||
|
||||
* Windows 操作系统
|
||||
* GCC 编译器 (推荐 MinGW-w64)
|
||||
* Make 工具
|
||||
* CMake 工具
|
||||
* IUP 库 (已包含在 `libs` 目录下)
|
||||
* Inno Setup 6 (仅打包需要)
|
||||
|
||||
### 编译步骤
|
||||
|
||||
本项目使用 CMake 构建系统,支持生成更标准的构建文件并集成到各大 IDE。
|
||||
|
||||
1. 克隆仓库:
|
||||
|
||||
```bash
|
||||
@@ -40,30 +76,44 @@
|
||||
cd PathEditor
|
||||
```
|
||||
|
||||
2. 编译项目:
|
||||
2. 使用 CMake 配置和编译:
|
||||
|
||||
```bash
|
||||
mingw32-make
|
||||
# 生成构建系统 (以 MinGW 为例)
|
||||
cmake -B build -G "MinGW Makefiles"
|
||||
|
||||
# 编译项目
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
3. 运行:
|
||||
编译成功后,可执行文件位于 `bin/PathEditor.exe`。
|
||||
编译成功后,可执行文件位于 `build/PathEditor.exe`。
|
||||
|
||||
### 打包 (可选)
|
||||
|
||||
本项目使用 Inno Setup 生成安装包。
|
||||
|
||||
1. 确保已安装 [Inno Setup 6](https://jrsoftware.org/isdl.php)。
|
||||
2. 编译项目生成 exe 文件。
|
||||
3. 使用 Inno Setup 编译 `dist/installer.iss` 脚本。
|
||||
2. 运行根目录下的 `build_installer.bat` 脚本。
|
||||
3. 生成的安装包将位于 `dist/dist/PathEditorSetup.exe`。
|
||||
|
||||
## 📝 使用说明
|
||||
|
||||
1. **启动**:右键点击程序图标,选择“以管理员身份运行”。
|
||||
2. **查看**:程序启动后会自动加载当前的系统 PATH 变量。
|
||||
3. **修改**:使用右侧按钮栏进行添加、删除、移动等操作。
|
||||
4. **保存**:操作完成后,务必点击底部的【确定】按钮保存更改。
|
||||
5. **生效**:保存后,某些正在运行的程序可能需要重启才能识别新的环境变量。CMD 或 PowerShell 窗口需要重新打开。
|
||||
* **红色**条目表示路径不存在。
|
||||
* **橙色**条目表示路径重复。
|
||||
* **变量预览**:鼠标悬停在带 `%` 的变量上可查看实际路径。
|
||||
3. **搜索**:在顶部输入关键词或按 `Ctrl+F` 可快速筛选。
|
||||
4. **修改**:
|
||||
* **拖拽**:将文件夹拖入列表可直接添加。
|
||||
* **多选**:按住 `Ctrl` 或 `Shift` 可选中多项进行批量删除。
|
||||
* **撤销/重做**:误操作时可使用 `Ctrl+Z` / `Ctrl+Y` 或工具栏按钮回退。
|
||||
* **常规操作**:使用右侧按钮栏进行新建、编辑、移动等操作。
|
||||
* **清理**:点击“一键清理”可自动删除无效和重复项。
|
||||
* **导入/导出**:使用导入导出功能备份或恢复配置。
|
||||
5. **保存**:操作完成后,务必点击底部的【确定】按钮(或按 `Ctrl+S`)保存更改。
|
||||
6. **生效**:保存后,某些正在运行的程序可能需要重启才能识别新的环境变量。CMD 或 PowerShell 窗口需要重新打开。
|
||||
|
||||
## 👤 作者信息
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
@echo off
|
||||
|
||||
echo Building Installer...
|
||||
"D:\Program Files (x86)\Inno Setup 6\ISCC.exe" "dist\installer.iss"
|
||||
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo Installer build failed!
|
||||
exit /b %ERRORLEVEL%
|
||||
)
|
||||
|
||||
echo Done! Installer is in dist\dist\
|
||||
pause
|
||||
Vendored
+2
-2
@@ -37,8 +37,8 @@ Name: "english"; MessagesFile: "compiler:Default.isl"
|
||||
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
|
||||
|
||||
[Files]
|
||||
Source: "d:\Code\doing_exercises\programs\PathEditor\bin\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "d:\Code\doing_exercises\programs\PathEditor\bin\*.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "d:\Code\doing_exercises\programs\PathEditor\build\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "d:\Code\doing_exercises\programs\PathEditor\build\*.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
||||
|
||||
[Icons]
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef CALLBACKS_H
|
||||
#define CALLBACKS_H
|
||||
|
||||
#include <iup.h>
|
||||
|
||||
// 按钮回调
|
||||
int btn_new_cb(Ihandle* self);
|
||||
int btn_edit_cb(Ihandle* self);
|
||||
int btn_browse_cb(Ihandle* self);
|
||||
int btn_del_cb(Ihandle* self);
|
||||
int btn_up_cb(Ihandle* self);
|
||||
int btn_down_cb(Ihandle* self);
|
||||
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
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef CB_EDIT_H
|
||||
#define CB_EDIT_H
|
||||
|
||||
#include <iup.h>
|
||||
|
||||
// 编辑相关回调
|
||||
int btn_new_cb(Ihandle *self);
|
||||
int btn_edit_cb(Ihandle *self);
|
||||
int list_dblclick_cb(Ihandle *self, int item, char *text);
|
||||
int btn_del_cb(Ihandle *self);
|
||||
int btn_up_cb(Ihandle *self);
|
||||
int btn_down_cb(Ihandle *self);
|
||||
int btn_clean_cb(Ihandle *self);
|
||||
|
||||
#endif // CB_EDIT_H
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef CB_FILE_H
|
||||
#define CB_FILE_H
|
||||
|
||||
#include <iup.h>
|
||||
|
||||
// 文件和历史记录回调
|
||||
int btn_browse_cb(Ihandle *self);
|
||||
int btn_undo_cb(Ihandle *self);
|
||||
int btn_redo_cb(Ihandle *self);
|
||||
int btn_export_cb(Ihandle *self);
|
||||
int btn_import_cb(Ihandle *self);
|
||||
int list_dropfiles_cb(Ihandle *self, const char *filename, int num, int x, int y);
|
||||
|
||||
#endif // CB_FILE_H
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef CB_MAIN_H
|
||||
#define CB_MAIN_H
|
||||
|
||||
#include <iup.h>
|
||||
|
||||
// 主界面交互回调
|
||||
int txt_search_cb(Ihandle *self);
|
||||
int list_k_any_cb(Ihandle *self, int c);
|
||||
int list_motion_cb(Ihandle *self, int x, int y, char *status);
|
||||
int dialog_k_any_cb(Ihandle *self, int c);
|
||||
int btn_ok_cb(Ihandle *self);
|
||||
int btn_cancel_cb(Ihandle *self);
|
||||
int btn_help_cb(Ihandle *self);
|
||||
int tabs_tabchange_cb(Ihandle *self, int new_pos, int old_pos);
|
||||
int btn_theme_cb(Ihandle *self);
|
||||
|
||||
#endif // CB_MAIN_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
// UI 常量定义
|
||||
#define UI_WINDOW_TITLE "Path Editor" // 窗口标题
|
||||
#define UI_WINDOW_SIZE "800x800" // 窗口默认大小 (像素)
|
||||
|
||||
// 按钮尺寸
|
||||
#define UI_BUTTON_SIZE "100x32" // 按钮默认大小 (像素)
|
||||
#define UI_BUTTON_SMALL_SIZE "80x32" // 小按钮大小 (像素)
|
||||
|
||||
// 布局间距
|
||||
#define UI_MARGIN_MAIN "10x10" // 主布局外边距 (像素)
|
||||
#define UI_GAP_MAIN "10" // 主布局间距 (像素)
|
||||
#define UI_GAP_BUTTONS "5" // 按钮间距 (像素)
|
||||
#define UI_GAP_BOTTOM "10" // 底部间距 (像素)
|
||||
|
||||
// 列表属性
|
||||
#define UI_LIST_ITEM_PADDING "5x5" // 列表项内边距 (像素)
|
||||
#define UI_LIST_BGCOLOR "255 255 255" // 列表背景颜色 (RGB)
|
||||
#define UI_LIST_MERGED_BGCOLOR "240 240 240"// 合并列表背景颜色 (RGB)
|
||||
|
||||
#endif // CONFIG_H
|
||||
+65
-13
@@ -4,21 +4,73 @@
|
||||
#include <iup.h>
|
||||
|
||||
// 注册表路径常量
|
||||
#define REG_PATH L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
|
||||
#define REG_PATH_SYS L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
|
||||
#define REG_PATH_USER L"Environment"
|
||||
#define REG_VALUE L"Path"
|
||||
|
||||
// 全局控件句柄声明
|
||||
extern Ihandle *dlg; // 主对话框句柄
|
||||
extern Ihandle *list_path; // 路径列表控件句柄
|
||||
extern Ihandle *lbl_status; // 状态标签句柄
|
||||
extern Ihandle *btn_new; // 新增按钮句柄
|
||||
extern Ihandle *btn_edit; // 编辑按钮句柄
|
||||
extern Ihandle *btn_browse; // 浏览按钮句柄
|
||||
extern Ihandle *btn_del; // 删除按钮句柄
|
||||
extern Ihandle *btn_up; // 上移按钮句柄
|
||||
extern Ihandle *btn_down; // 下移按钮句柄
|
||||
extern Ihandle *btn_ok; // 确认按钮句柄
|
||||
extern Ihandle *btn_cancel; // 取消按钮句柄
|
||||
extern Ihandle *btn_help; // 帮助按钮句柄
|
||||
extern Ihandle *dlg; // 主对话框句柄
|
||||
extern Ihandle *tabs_main; // 标签页容器
|
||||
extern Ihandle *list_sys; // 系统变量列表
|
||||
extern Ihandle *list_user; // 用户变量列表
|
||||
extern Ihandle *list_merged; // 合并变量列表
|
||||
extern Ihandle *lbl_status; // 状态标签句柄
|
||||
extern Ihandle *btn_new; // 新增按钮句柄
|
||||
extern Ihandle *btn_edit; // 编辑按钮句柄
|
||||
extern Ihandle *btn_browse; // 浏览按钮句柄
|
||||
extern Ihandle *btn_del; // 删除按钮句柄
|
||||
extern Ihandle *btn_up; // 上移按钮句柄
|
||||
extern Ihandle *btn_down; // 下移按钮句柄
|
||||
extern Ihandle *btn_clean; // 一键清理按钮句柄
|
||||
extern Ihandle *btn_undo; // 撤销按钮句柄
|
||||
extern Ihandle *btn_redo; // 重做按钮句柄
|
||||
extern Ihandle *btn_import; // 导入按钮句柄
|
||||
extern Ihandle *btn_export; // 导出按钮句柄
|
||||
extern Ihandle *btn_theme; // 主题切换按钮句柄
|
||||
extern Ihandle *btn_ok; // 确认按钮句柄
|
||||
extern int is_dark_mode; // 深色模式状态
|
||||
extern Ihandle *btn_cancel; // 取消按钮句柄
|
||||
extern Ihandle *btn_help; // 帮助按钮句柄
|
||||
extern Ihandle *txt_search; // 搜索框
|
||||
|
||||
// 简单字符串列表结构,用于搜索缓存
|
||||
typedef struct {
|
||||
char **items;
|
||||
int count;
|
||||
int capacity;
|
||||
} StringList;
|
||||
|
||||
extern StringList raw_sys_paths;
|
||||
extern StringList raw_user_paths;
|
||||
|
||||
// 历史记录节点
|
||||
typedef struct HistoryNode {
|
||||
StringList sys_paths;
|
||||
StringList user_paths;
|
||||
struct HistoryNode *next;
|
||||
} HistoryNode;
|
||||
|
||||
// 历史记录栈
|
||||
typedef struct {
|
||||
HistoryNode *top;
|
||||
int count;
|
||||
} HistoryStack;
|
||||
|
||||
extern HistoryStack undo_stack;
|
||||
extern HistoryStack redo_stack;
|
||||
extern Ihandle *btn_undo;
|
||||
extern Ihandle *btn_redo;
|
||||
|
||||
// 缓存操作函数声明
|
||||
void init_string_list(StringList *list);
|
||||
void add_string_list(StringList *list, const char *str);
|
||||
void clear_string_list(StringList *list);
|
||||
void copy_string_list(StringList *dest, StringList *src);
|
||||
|
||||
// 历史记录操作
|
||||
void init_history_stack(HistoryStack *stack);
|
||||
void push_history(HistoryStack *stack, StringList *sys, StringList *user);
|
||||
int pop_history(HistoryStack *stack, StringList *out_sys, StringList *out_user);
|
||||
void clear_history_stack(HistoryStack *stack);
|
||||
|
||||
#endif // GLOBALS_H
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
#ifndef REGISTRY_H
|
||||
#define REGISTRY_H
|
||||
|
||||
// 从注册表加载PATH到列表控件
|
||||
void load_path();
|
||||
// 从注册表加载所有PATH到列表控件
|
||||
void load_all_paths();
|
||||
|
||||
// 将列表控件中的PATH保存回注册表
|
||||
void save_path();
|
||||
void save_all_paths();
|
||||
|
||||
#endif // REGISTRY_H
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef UI_H
|
||||
#define UI_H
|
||||
|
||||
#include <iup.h>
|
||||
|
||||
// 创建列表控件
|
||||
Ihandle *create_path_list();
|
||||
|
||||
// 创建右侧功能按钮区域
|
||||
Ihandle *create_main_buttons();
|
||||
|
||||
// 创建底部按钮区域
|
||||
Ihandle *create_bottom_buttons();
|
||||
|
||||
Ihandle *create_main_dialog();
|
||||
|
||||
#endif // UI_H
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef UI_UTILS_H
|
||||
#define UI_UTILS_H
|
||||
|
||||
#include <iup.h>
|
||||
#include "globals.h"
|
||||
|
||||
// 辅助函数声明
|
||||
int get_first_selected_index(Ihandle *list);
|
||||
void set_single_selection(Ihandle *list, int index);
|
||||
void refresh_ui_from_raw(Ihandle *list, StringList *raw);
|
||||
void record_history();
|
||||
int custom_input_dialog(const char *title, const char *label_text, char *buffer, int buffer_size);
|
||||
Ihandle *get_current_list();
|
||||
void remove_from_raw_data(StringList *list, const char *str);
|
||||
void toggle_edit_buttons(int enable);
|
||||
void apply_theme();
|
||||
|
||||
#endif // UI_UTILS_H
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <windows.h>
|
||||
#include <wchar.h>
|
||||
#include <iup.h>
|
||||
|
||||
// 宽字符转UTF-8
|
||||
char* wide_to_utf8(const wchar_t* wstr);
|
||||
@@ -13,7 +14,20 @@ wchar_t* utf8_to_wide(const char* str);
|
||||
// 检查管理员权限
|
||||
int check_admin();
|
||||
|
||||
// 展开环境变量
|
||||
char* expand_env_vars(const char* path);
|
||||
|
||||
// 检查路径是否有效(存在且为目录)
|
||||
int is_path_valid(const char *path);
|
||||
|
||||
// 刷新列表样式(斑马纹)
|
||||
void refresh_list_style();
|
||||
void refresh_single_list_style(Ihandle *list);
|
||||
|
||||
// 备份注册表
|
||||
void backup_registry();
|
||||
|
||||
// 不区分大小写的字符串查找
|
||||
char *stristr(const char *haystack, const char *needle);
|
||||
|
||||
#endif // UTILS_H
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-327
@@ -1,327 +0,0 @@
|
||||
#include "callbacks.h"
|
||||
#include "globals.h"
|
||||
#include "registry.h"
|
||||
#include "utils.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// 简单的自定义输入对话框,支持更宽的输入框
|
||||
// 返回 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", "100x32");
|
||||
|
||||
Ihandle *btn_cancel = IupButton("取消", NULL);
|
||||
IupSetCallback(btn_cancel, "ACTION", on_dialog_cancel);
|
||||
IupSetAttribute(btn_cancel, "RASTERSIZE", "100x32");
|
||||
|
||||
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 (custom_input_dialog("新建环境变量", "请输入路径:", buffer, sizeof(buffer)))
|
||||
{
|
||||
if (strlen(buffer) > 0)
|
||||
{
|
||||
int count = IupGetInt(list_path, "COUNT");
|
||||
count++;
|
||||
IupSetAttributeId(list_path, "", count, buffer);
|
||||
IupSetInt(list_path, "COUNT", count);
|
||||
IupSetInt(list_path, "VALUE", count);
|
||||
|
||||
refresh_list_style();
|
||||
}
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:编辑
|
||||
int btn_edit_cb(Ihandle *self)
|
||||
{
|
||||
int selected = IupGetInt(list_path, "VALUE");
|
||||
if (selected == 0)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
char *current_val = IupGetAttributeId(list_path, "", selected);
|
||||
char buffer[4096]; // 假设单个路径不超过4096
|
||||
if (current_val)
|
||||
{
|
||||
strncpy(buffer, current_val, 4096);
|
||||
buffer[4095] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Ihandle *filedlg = IupFileDlg();
|
||||
IupSetAttribute(filedlg, "DIALOGTYPE", "DIR");
|
||||
IupSetAttribute(filedlg, "TITLE", "选择目录");
|
||||
|
||||
IupPopup(filedlg, IUP_CENTER, IUP_CENTER);
|
||||
|
||||
if (IupGetInt(filedlg, "STATUS") != -1)
|
||||
{
|
||||
char *value = IupGetAttribute(filedlg, "VALUE");
|
||||
if (value)
|
||||
{
|
||||
int count = IupGetInt(list_path, "COUNT");
|
||||
count++;
|
||||
IupSetAttributeId(list_path, "", count, value);
|
||||
IupSetInt(list_path, "COUNT", count);
|
||||
IupSetInt(list_path, "VALUE", count);
|
||||
|
||||
refresh_list_style();
|
||||
}
|
||||
}
|
||||
IupDestroy(filedlg);
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:删除
|
||||
int btn_del_cb(Ihandle *self)
|
||||
{
|
||||
int selected = IupGetInt(list_path, "VALUE");
|
||||
if (selected == 0)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
IupSetAttribute(list_path, "REMOVEITEM", "SELECTED");
|
||||
|
||||
// 重新刷新,因为删除了中间项,后面的奇偶性变了
|
||||
refresh_list_style();
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:上移
|
||||
int btn_up_cb(Ihandle *self)
|
||||
{
|
||||
int selected = IupGetInt(list_path, "VALUE");
|
||||
if (selected <= 1)
|
||||
return IUP_DEFAULT; // 已经是第一个或未选中
|
||||
|
||||
char *current = IupGetAttributeId(list_path, "", selected);
|
||||
char *prev = IupGetAttributeId(list_path, "", selected - 1);
|
||||
|
||||
// 交换内容
|
||||
char buf_curr[4096], buf_prev[4096];
|
||||
strncpy(buf_curr, current, 4096);
|
||||
buf_curr[4095] = '\0';
|
||||
strncpy(buf_prev, prev, 4096);
|
||||
buf_prev[4095] = '\0';
|
||||
|
||||
IupSetAttributeId(list_path, "", selected, buf_prev);
|
||||
IupSetAttributeId(list_path, "", selected - 1, buf_curr);
|
||||
|
||||
IupSetInt(list_path, "VALUE", selected - 1);
|
||||
|
||||
// 刷新样式(虽然颜色不需要变,但为了保险)
|
||||
refresh_list_style();
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:下移
|
||||
int btn_down_cb(Ihandle *self)
|
||||
{
|
||||
int selected = IupGetInt(list_path, "VALUE");
|
||||
int count = IupGetInt(list_path, "COUNT");
|
||||
if (selected == 0 || selected >= count)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
char *current = IupGetAttributeId(list_path, "", selected);
|
||||
char *next = IupGetAttributeId(list_path, "", selected + 1);
|
||||
|
||||
char buf_curr[4096], buf_next[4096];
|
||||
strncpy(buf_curr, current, 4096);
|
||||
buf_curr[4095] = '\0';
|
||||
strncpy(buf_next, next, 4096);
|
||||
buf_next[4095] = '\0';
|
||||
|
||||
IupSetAttributeId(list_path, "", selected, buf_next);
|
||||
IupSetAttributeId(list_path, "", selected + 1, buf_curr);
|
||||
|
||||
IupSetInt(list_path, "VALUE", selected + 1);
|
||||
|
||||
refresh_list_style();
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:确定
|
||||
int btn_ok_cb(Ihandle *self)
|
||||
{
|
||||
save_path();
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:取消
|
||||
int btn_cancel_cb(Ihandle *self)
|
||||
{
|
||||
IupExitLoop();
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:帮助
|
||||
int btn_help_cb(Ihandle *self)
|
||||
{
|
||||
IupMessage("使用说明",
|
||||
"1. 本程序用于编辑系统环境变量 PATH。\n"
|
||||
"2. 必须以【管理员身份】运行才能保存更改。\n"
|
||||
"3. 操作说明:\n"
|
||||
" - 新建:添加新路径到列表末尾。\n"
|
||||
" - 编辑:修改选中的路径。\n"
|
||||
" - 浏览:从文件系统选择目录添加。\n"
|
||||
" - 删除:移除选中的路径。\n"
|
||||
" - 上移/下移:调整路径优先级。\n"
|
||||
"4. 点击【确定】保存更改并生效。\n"
|
||||
"5. 注意:某些正在运行的程序可能需要重启才能识别新的环境变量。\n\n"
|
||||
"--------------------------------------------------\n"
|
||||
"作者:LHY\n"
|
||||
"邮箱:3364451258@qq.com\n"
|
||||
"GitHub:https://github.com/LHY0125/PathEditor\n"
|
||||
"记得给我的项目点个star!");
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
#include "cb_edit.h"
|
||||
#include "ui_utils.h"
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// 按钮回调:新建
|
||||
int btn_new_cb(Ihandle *self)
|
||||
{
|
||||
char buffer[1024] = "";
|
||||
if (custom_input_dialog("新建环境变量", "请输入路径:", buffer, sizeof(buffer)))
|
||||
{
|
||||
if (strlen(buffer) > 0)
|
||||
{
|
||||
// 记录历史
|
||||
record_history();
|
||||
|
||||
Ihandle *current_list = get_current_list();
|
||||
int count = IupGetInt(current_list, "COUNT");
|
||||
count++;
|
||||
IupSetAttributeId(current_list, "", count, buffer);
|
||||
IupSetInt(current_list, "COUNT", count);
|
||||
|
||||
// 更新选中状态
|
||||
set_single_selection(current_list, count);
|
||||
|
||||
// 同时添加到 raw_data
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
if (raw_data) {
|
||||
add_string_list(raw_data, buffer);
|
||||
}
|
||||
|
||||
refresh_single_list_style(current_list);
|
||||
}
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:编辑
|
||||
int btn_edit_cb(Ihandle *self)
|
||||
{
|
||||
Ihandle *current_list = get_current_list();
|
||||
// 获取第一个选中的项
|
||||
int selected = get_first_selected_index(current_list);
|
||||
if (selected == 0)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
char *current_val = IupGetAttributeId(current_list, "", selected);
|
||||
char buffer[4096]; // 假设单个路径不超过4096
|
||||
if (current_val)
|
||||
{
|
||||
strncpy(buffer, current_val, 4096);
|
||||
buffer[4095] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
|
||||
if (custom_input_dialog("编辑环境变量", "编辑路径:", buffer, sizeof(buffer)))
|
||||
{
|
||||
if (strlen(buffer) > 0)
|
||||
{
|
||||
// 记录历史
|
||||
record_history();
|
||||
|
||||
// 更新 UI
|
||||
IupSetAttributeId(current_list, "", selected, buffer);
|
||||
|
||||
// 更新 raw_data
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
|
||||
char *filter = IupGetAttribute(txt_search, "VALUE");
|
||||
if (!filter || strlen(filter) == 0) {
|
||||
if (raw_data && selected <= raw_data->count) {
|
||||
free(raw_data->items[selected-1]);
|
||||
raw_data->items[selected-1] = _strdup(buffer);
|
||||
}
|
||||
} else {
|
||||
// 搜索状态下,忽略同步问题,或者编辑后清除搜索。
|
||||
}
|
||||
|
||||
refresh_single_list_style(current_list);
|
||||
}
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 双击回调
|
||||
int list_dblclick_cb(Ihandle *self, int item, char *text)
|
||||
{
|
||||
// 这里的 self 就是触发双击的列表控件
|
||||
if (item > 0)
|
||||
{
|
||||
// 选中该行 (单选)
|
||||
set_single_selection(self, item);
|
||||
// 调用编辑逻辑
|
||||
btn_edit_cb(NULL);
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:删除 (支持多选)
|
||||
int btn_del_cb(Ihandle *self)
|
||||
{
|
||||
Ihandle *current_list = get_current_list();
|
||||
char *value = IupGetAttribute(current_list, "VALUE");
|
||||
if (!value)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
int len = strlen(value);
|
||||
int has_selection = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (value[i] == '+') {
|
||||
has_selection = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_selection)
|
||||
{
|
||||
IupMessage("提示", "请先选择要删除的项");
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 记录历史
|
||||
record_history();
|
||||
|
||||
// 获取 raw_data 缓存
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
|
||||
// 从后往前遍历删除,避免索引错位
|
||||
for (int i = len - 1; i >= 0; i--)
|
||||
{
|
||||
if (value[i] == '+')
|
||||
{
|
||||
int item_index = i + 1; // IUP 索引从 1 开始
|
||||
char *val = IupGetAttributeId(current_list, "", item_index);
|
||||
|
||||
// 从缓存删除
|
||||
if (val && raw_data)
|
||||
{
|
||||
char *val_copy = _strdup(val);
|
||||
remove_from_raw_data(raw_data, val_copy);
|
||||
free(val_copy);
|
||||
}
|
||||
|
||||
// 从界面删除
|
||||
IupSetInt(current_list, "REMOVEITEM", item_index);
|
||||
}
|
||||
}
|
||||
|
||||
// 重新刷新
|
||||
refresh_single_list_style(current_list);
|
||||
|
||||
// 更新状态栏
|
||||
IupSetAttribute(lbl_status, "TITLE", "状态: 已删除选中项");
|
||||
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:上移 (支持多选)
|
||||
int btn_up_cb(Ihandle *self)
|
||||
{
|
||||
Ihandle *current_list = get_current_list();
|
||||
char *value = IupGetAttribute(current_list, "VALUE");
|
||||
if (!value)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
int len = strlen(value);
|
||||
char *new_value = _strdup(value);
|
||||
int moved = 0;
|
||||
|
||||
// 预检查是否有移动
|
||||
for (int i = 1; i < len; i++) {
|
||||
if (new_value[i] == '+' && new_value[i - 1] == '-') {
|
||||
moved = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (moved) {
|
||||
// 记录历史
|
||||
record_history();
|
||||
|
||||
// 同步 raw_data (假设非搜索状态,raw_data 与 UI 一致)
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
|
||||
// 从前往后遍历,如果当前项被选中且前一项未选中,则交换
|
||||
for (int i = 1; i < len; i++)
|
||||
{
|
||||
if (new_value[i] == '+' && new_value[i - 1] == '-')
|
||||
{
|
||||
// 交换列表项内容
|
||||
char *curr_text = IupGetAttributeId(current_list, "", i + 1);
|
||||
char *prev_text = IupGetAttributeId(current_list, "", i);
|
||||
|
||||
// 需要复制,防止指针失效
|
||||
char *curr_copy = curr_text ? _strdup(curr_text) : NULL;
|
||||
char *prev_copy = prev_text ? _strdup(prev_text) : NULL;
|
||||
|
||||
IupSetAttributeId(current_list, "", i, curr_copy);
|
||||
IupSetAttributeId(current_list, "", i + 1, prev_copy);
|
||||
|
||||
if (curr_copy) free(curr_copy);
|
||||
if (prev_copy) free(prev_copy);
|
||||
|
||||
// 交换 raw_data
|
||||
if (raw_data && i < raw_data->count) {
|
||||
char *temp = raw_data->items[i];
|
||||
raw_data->items[i] = raw_data->items[i-1];
|
||||
raw_data->items[i-1] = temp;
|
||||
}
|
||||
|
||||
// 交换选中状态
|
||||
new_value[i] = '-';
|
||||
new_value[i - 1] = '+';
|
||||
}
|
||||
}
|
||||
|
||||
// 更新选中状态
|
||||
IupSetAttribute(current_list, "VALUE", new_value);
|
||||
refresh_single_list_style(current_list);
|
||||
}
|
||||
free(new_value);
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:下移 (支持多选)
|
||||
int btn_down_cb(Ihandle *self)
|
||||
{
|
||||
Ihandle *current_list = get_current_list();
|
||||
char *value = IupGetAttribute(current_list, "VALUE");
|
||||
if (!value)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
int len = strlen(value);
|
||||
char *new_value = _strdup(value);
|
||||
int moved = 0;
|
||||
|
||||
// 预检查
|
||||
for (int i = len - 2; i >= 0; i--) {
|
||||
if (new_value[i] == '+' && new_value[i + 1] == '-') {
|
||||
moved = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (moved) {
|
||||
// 记录历史
|
||||
record_history();
|
||||
|
||||
// 同步 raw_data
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
|
||||
// 从后往前遍历,如果当前项被选中且后一项未选中,则交换
|
||||
for (int i = len - 2; i >= 0; i--)
|
||||
{
|
||||
if (new_value[i] == '+' && new_value[i + 1] == '-')
|
||||
{
|
||||
// 交换列表项内容
|
||||
char *curr_text = IupGetAttributeId(current_list, "", i + 1);
|
||||
char *next_text = IupGetAttributeId(current_list, "", i + 2);
|
||||
|
||||
// 需要复制
|
||||
char *curr_copy = curr_text ? _strdup(curr_text) : NULL;
|
||||
char *next_copy = next_text ? _strdup(next_text) : NULL;
|
||||
|
||||
IupSetAttributeId(current_list, "", i + 2, curr_copy);
|
||||
IupSetAttributeId(current_list, "", i + 1, next_copy);
|
||||
|
||||
if (curr_copy) free(curr_copy);
|
||||
if (next_copy) free(next_copy);
|
||||
|
||||
// 交换 raw_data
|
||||
if (raw_data && i + 1 < raw_data->count) {
|
||||
char *temp = raw_data->items[i];
|
||||
raw_data->items[i] = raw_data->items[i+1];
|
||||
raw_data->items[i+1] = temp;
|
||||
}
|
||||
|
||||
// 交换选中状态
|
||||
new_value[i] = '-';
|
||||
new_value[i + 1] = '+';
|
||||
}
|
||||
}
|
||||
|
||||
// 更新选中状态
|
||||
IupSetAttribute(current_list, "VALUE", new_value);
|
||||
refresh_single_list_style(current_list);
|
||||
}
|
||||
free(new_value);
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:一键清理
|
||||
int btn_clean_cb(Ihandle *self)
|
||||
{
|
||||
Ihandle *current_list = get_current_list();
|
||||
int count = IupGetInt(current_list, "COUNT");
|
||||
if (count == 0)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
// 弹出确认对话框
|
||||
if (IupAlarm("确认清理", "此操作将移除当前列表中所有【无效路径】和【重复路径】。\n确定要继续吗?", "确定", "取消", NULL) != 1)
|
||||
{
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 记录历史 (放在循环外,一次操作)
|
||||
record_history();
|
||||
|
||||
// 获取 raw_data 用于同步删除
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
|
||||
// 从后往前遍历删除,避免索引错位
|
||||
for (int i = count; i >= 1; i--)
|
||||
{
|
||||
char *item = IupGetAttributeId(current_list, "", i);
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
int should_remove = 0;
|
||||
|
||||
// 1. 检查有效性
|
||||
if (!is_path_valid(item))
|
||||
{
|
||||
should_remove = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2. 检查重复 (检查当前项之前是否出现过)
|
||||
// 注意:这里需要再次遍历,性能稍低但最稳妥
|
||||
for (int j = 1; j < i; j++)
|
||||
{
|
||||
char *prev_item = IupGetAttributeId(current_list, "", j);
|
||||
if (prev_item && _stricmp(item, prev_item) == 0)
|
||||
{
|
||||
should_remove = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (should_remove)
|
||||
{
|
||||
// 从 raw_data 删除
|
||||
if (raw_data) {
|
||||
char *val_copy = _strdup(item);
|
||||
remove_from_raw_data(raw_data, val_copy);
|
||||
free(val_copy);
|
||||
}
|
||||
|
||||
IupSetAttributeId(current_list, "REMOVEITEM", i, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
refresh_single_list_style(current_list);
|
||||
IupMessage("提示", "清理完成!");
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
+260
@@ -0,0 +1,260 @@
|
||||
#include "cb_file.h"
|
||||
#include "ui_utils.h"
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h> // for GetFileAttributesA
|
||||
|
||||
// 按钮回调:浏览
|
||||
int btn_browse_cb(Ihandle *self)
|
||||
{
|
||||
Ihandle *filedlg = IupFileDlg();
|
||||
IupSetAttribute(filedlg, "DIALOGTYPE", "DIR");
|
||||
IupSetAttribute(filedlg, "TITLE", "选择目录");
|
||||
|
||||
IupPopup(filedlg, IUP_CENTER, IUP_CENTER);
|
||||
|
||||
if (IupGetInt(filedlg, "STATUS") != -1)
|
||||
{
|
||||
char *value = IupGetAttribute(filedlg, "VALUE");
|
||||
if (value)
|
||||
{
|
||||
// 记录历史
|
||||
record_history();
|
||||
|
||||
Ihandle *current_list = get_current_list();
|
||||
int count = IupGetInt(current_list, "COUNT");
|
||||
count++;
|
||||
IupSetAttributeId(current_list, "", count, value);
|
||||
IupSetInt(current_list, "COUNT", count);
|
||||
|
||||
// 更新选中状态
|
||||
set_single_selection(current_list, count);
|
||||
|
||||
// 同步 raw_data
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
if (raw_data) {
|
||||
add_string_list(raw_data, value);
|
||||
}
|
||||
|
||||
refresh_single_list_style(current_list);
|
||||
}
|
||||
}
|
||||
IupDestroy(filedlg);
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 撤销回调
|
||||
int btn_undo_cb(Ihandle *self)
|
||||
{
|
||||
StringList sys = {0}, user = {0};
|
||||
if (pop_history(&undo_stack, &sys, &user)) {
|
||||
// Push current state to redo
|
||||
push_history(&redo_stack, &raw_sys_paths, &raw_user_paths);
|
||||
|
||||
// Restore
|
||||
clear_string_list(&raw_sys_paths);
|
||||
clear_string_list(&raw_user_paths);
|
||||
raw_sys_paths = sys;
|
||||
raw_user_paths = user;
|
||||
|
||||
// Refresh UI
|
||||
refresh_ui_from_raw(list_sys, &raw_sys_paths);
|
||||
refresh_ui_from_raw(list_user, &raw_user_paths);
|
||||
|
||||
IupSetAttribute(lbl_status, "TITLE", "状态: 已撤销");
|
||||
} else {
|
||||
IupSetAttribute(lbl_status, "TITLE", "状态: 没有可撤销的操作");
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 重做回调
|
||||
int btn_redo_cb(Ihandle *self)
|
||||
{
|
||||
StringList sys = {0}, user = {0};
|
||||
if (pop_history(&redo_stack, &sys, &user)) {
|
||||
// Push current state to undo
|
||||
push_history(&undo_stack, &raw_sys_paths, &raw_user_paths);
|
||||
|
||||
// Restore
|
||||
clear_string_list(&raw_sys_paths);
|
||||
clear_string_list(&raw_user_paths);
|
||||
raw_sys_paths = sys;
|
||||
raw_user_paths = user;
|
||||
|
||||
// Refresh UI
|
||||
refresh_ui_from_raw(list_sys, &raw_sys_paths);
|
||||
refresh_ui_from_raw(list_user, &raw_user_paths);
|
||||
|
||||
IupSetAttribute(lbl_status, "TITLE", "状态: 已重做");
|
||||
} else {
|
||||
IupSetAttribute(lbl_status, "TITLE", "状态: 没有可重做的操作");
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 导出配置
|
||||
int btn_export_cb(Ihandle *self)
|
||||
{
|
||||
Ihandle *current_list = get_current_list();
|
||||
int count = IupGetInt(current_list, "COUNT");
|
||||
if (count == 0) {
|
||||
IupMessage("提示", "当前列表为空,无法导出");
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
Ihandle *filedlg = IupFileDlg();
|
||||
IupSetAttribute(filedlg, "DIALOGTYPE", "SAVE");
|
||||
IupSetAttribute(filedlg, "TITLE", "导出配置");
|
||||
IupSetAttribute(filedlg, "FILTER", "*.txt");
|
||||
IupSetAttribute(filedlg, "FILTERINFO", "Text Files (*.txt)");
|
||||
|
||||
IupPopup(filedlg, IUP_CENTER, IUP_CENTER);
|
||||
|
||||
if (IupGetInt(filedlg, "STATUS") != -1) {
|
||||
char *filename = IupGetAttribute(filedlg, "VALUE");
|
||||
if (filename) {
|
||||
char final_path[1024];
|
||||
strncpy(final_path, filename, sizeof(final_path));
|
||||
final_path[sizeof(final_path)-1] = '\0';
|
||||
|
||||
// 检查是否以 .txt 结尾 (不区分大小写)
|
||||
size_t len = strlen(final_path);
|
||||
if (len < 4 || _stricmp(final_path + len - 4, ".txt") != 0) {
|
||||
if (len + 4 < sizeof(final_path)) {
|
||||
strcat(final_path, ".txt");
|
||||
}
|
||||
}
|
||||
|
||||
FILE *fp = fopen(final_path, "w");
|
||||
if (fp) {
|
||||
for (int i = 1; i <= count; i++) {
|
||||
char *item = IupGetAttributeId(current_list, "", i);
|
||||
if (item) fprintf(fp, "%s\n", item);
|
||||
}
|
||||
fclose(fp);
|
||||
IupMessage("提示", "导出成功!");
|
||||
} else {
|
||||
IupMessage("错误", "无法打开文件进行写入");
|
||||
}
|
||||
}
|
||||
}
|
||||
IupDestroy(filedlg);
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 导入配置
|
||||
int btn_import_cb(Ihandle *self)
|
||||
{
|
||||
Ihandle *filedlg = IupFileDlg();
|
||||
IupSetAttribute(filedlg, "DIALOGTYPE", "OPEN");
|
||||
IupSetAttribute(filedlg, "TITLE", "导入配置");
|
||||
IupSetAttribute(filedlg, "FILTER", "*.txt");
|
||||
IupSetAttribute(filedlg, "FILTERINFO", "Text Files (*.txt)");
|
||||
|
||||
IupPopup(filedlg, IUP_CENTER, IUP_CENTER);
|
||||
|
||||
if (IupGetInt(filedlg, "STATUS") != -1) {
|
||||
char *filename = IupGetAttribute(filedlg, "VALUE");
|
||||
if (filename) {
|
||||
FILE *fp = fopen(filename, "r");
|
||||
if (fp) {
|
||||
// Record history
|
||||
record_history();
|
||||
|
||||
Ihandle *current_list = get_current_list();
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
|
||||
char line[4096];
|
||||
int imported_count = 0;
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
// Trim newline
|
||||
size_t len = strlen(line);
|
||||
while (len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) {
|
||||
line[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
if (len > 0) {
|
||||
// Add to UI
|
||||
int count = IupGetInt(current_list, "COUNT");
|
||||
count++;
|
||||
IupSetAttributeId(current_list, "", count, line);
|
||||
IupSetInt(current_list, "COUNT", count);
|
||||
|
||||
// Add to raw_data
|
||||
if (raw_data) add_string_list(raw_data, line);
|
||||
|
||||
imported_count++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
refresh_single_list_style(current_list);
|
||||
|
||||
char msg[64];
|
||||
snprintf(msg, sizeof(msg), "导入成功!共导入 %d 条路径。", imported_count);
|
||||
IupMessage("提示", msg);
|
||||
} else {
|
||||
IupMessage("错误", "无法打开文件进行读取");
|
||||
}
|
||||
}
|
||||
}
|
||||
IupDestroy(filedlg);
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 拖拽回调
|
||||
int list_dropfiles_cb(Ihandle *self, const char *filename, int num, int x, int y)
|
||||
{
|
||||
// 获取当前列表和原始数据
|
||||
// 注意:拖拽的目标列表可能是 list_sys 或 list_user,由 self 参数决定
|
||||
// 但为了确保数据一致性,我们还是重新获取一下
|
||||
Ihandle *current_list = self;
|
||||
StringList *raw_data = NULL;
|
||||
if (self == list_sys)
|
||||
raw_data = &raw_sys_paths;
|
||||
else if (self == list_user)
|
||||
raw_data = &raw_user_paths;
|
||||
else
|
||||
return IUP_DEFAULT; // 异常情况
|
||||
|
||||
// 检查拖入的是否为目录
|
||||
DWORD attr = GetFileAttributesA(filename);
|
||||
if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
// 记录历史
|
||||
record_history();
|
||||
|
||||
// 如果正在搜索,先清空搜索框
|
||||
IupSetAttribute(txt_search, "VALUE", "");
|
||||
|
||||
// 添加到列表末尾
|
||||
int count = IupGetInt(current_list, "COUNT");
|
||||
count++;
|
||||
IupSetAttributeId(current_list, "", count, filename);
|
||||
IupSetInt(current_list, "COUNT", count);
|
||||
|
||||
// 更新选中状态
|
||||
set_single_selection(current_list, count);
|
||||
|
||||
// 同时添加到原始数据缓存,确保搜索时能搜到
|
||||
if (raw_data)
|
||||
{
|
||||
add_string_list(raw_data, filename);
|
||||
}
|
||||
|
||||
refresh_single_list_style(current_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果拖入的不是文件夹,可以在状态栏提示
|
||||
IupSetAttribute(lbl_status, "TITLE", "提示: 只能拖拽文件夹添加到 PATH");
|
||||
}
|
||||
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
#include "cb_main.h"
|
||||
#include "ui_utils.h"
|
||||
#include "globals.h"
|
||||
#include "registry.h"
|
||||
#include "utils.h"
|
||||
#include "cb_edit.h"
|
||||
#include "cb_file.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// 搜索回调
|
||||
int txt_search_cb(Ihandle *self)
|
||||
{
|
||||
char *filter = IupGetAttribute(self, "VALUE");
|
||||
if (!filter)
|
||||
return IUP_DEFAULT;
|
||||
|
||||
// 获取当前选中的 Tab 索引
|
||||
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||
Ihandle *current_list = (pos == 0) ? list_sys : list_user;
|
||||
StringList *raw_data = (pos == 0) ? &raw_sys_paths : &raw_user_paths;
|
||||
|
||||
// 清空列表
|
||||
IupSetAttribute(current_list, "REMOVEITEM", "ALL");
|
||||
|
||||
// 重新填充
|
||||
int count = 0;
|
||||
for (int i = 0; i < raw_data->count; i++)
|
||||
{
|
||||
// 如果 filter 为空,或包含 filter (不区分大小写)
|
||||
if (strlen(filter) == 0 || stristr(raw_data->items[i], filter) != NULL)
|
||||
{
|
||||
count++;
|
||||
IupSetAttributeId(current_list, "", count, raw_data->items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
IupSetInt(current_list, "COUNT", count);
|
||||
refresh_single_list_style(current_list);
|
||||
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 键盘按键回调
|
||||
int list_k_any_cb(Ihandle *self, int c)
|
||||
{
|
||||
// 处理 Delete 键
|
||||
if (c == K_DEL)
|
||||
{
|
||||
btn_del_cb(NULL);
|
||||
return IUP_IGNORE; // 阻止默认处理
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 鼠标移动回调
|
||||
int list_motion_cb(Ihandle *self, int x, int y, char *status)
|
||||
{
|
||||
int pos = IupConvertXYToPos(self, x, y);
|
||||
if (pos > 0)
|
||||
{
|
||||
char *item = IupGetAttributeId(self, "", pos);
|
||||
if (item)
|
||||
{
|
||||
char *expanded = expand_env_vars(item);
|
||||
if (expanded)
|
||||
{
|
||||
IupSetAttribute(self, "TIP", expanded);
|
||||
free(expanded);
|
||||
}
|
||||
else
|
||||
{
|
||||
IupSetAttribute(self, "TIP", item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IupSetAttribute(self, "TIP", NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IupSetAttribute(self, "TIP", NULL);
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 对话框全局按键回调
|
||||
int dialog_k_any_cb(Ihandle *self, int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case K_cN: // Ctrl+N 新建
|
||||
btn_new_cb(NULL);
|
||||
return IUP_IGNORE;
|
||||
case K_cS: // Ctrl+S 保存
|
||||
btn_ok_cb(NULL);
|
||||
return IUP_IGNORE;
|
||||
case K_cF: // Ctrl+F 搜索
|
||||
if (txt_search)
|
||||
{
|
||||
IupSetFocus(txt_search);
|
||||
}
|
||||
return IUP_IGNORE;
|
||||
case K_cZ: // Ctrl+Z 撤销
|
||||
btn_undo_cb(NULL);
|
||||
return IUP_IGNORE;
|
||||
case K_cY: // Ctrl+Y 重做
|
||||
btn_redo_cb(NULL);
|
||||
return IUP_IGNORE;
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:确定
|
||||
int btn_ok_cb(Ihandle *self)
|
||||
{
|
||||
save_all_paths();
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:取消
|
||||
int btn_cancel_cb(Ihandle *self)
|
||||
{
|
||||
IupExitLoop();
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 按钮回调:帮助
|
||||
int btn_help_cb(Ihandle *self)
|
||||
{
|
||||
IupMessage("使用说明",
|
||||
"1. 本程序用于编辑系统环境变量 PATH。\n"
|
||||
"2. 必须以【管理员身份】运行才能保存更改。\n"
|
||||
"3. 操作说明:\n"
|
||||
" - 新建:添加新路径到列表末尾。\n"
|
||||
" - 编辑:修改选中的路径。\n"
|
||||
" - 浏览:从文件系统选择目录添加。\n"
|
||||
" - 删除:移除选中的路径。\n"
|
||||
" - 上移/下移:调整路径优先级。\n"
|
||||
" - 导入/导出:备份和恢复配置。\n"
|
||||
" - 快捷键:\n"
|
||||
" Ctrl+N: 新建路径\n"
|
||||
" Ctrl+S: 保存更改\n"
|
||||
" Ctrl+F: 聚焦搜索框\n"
|
||||
" Ctrl+Z: 撤销\n"
|
||||
" Ctrl+Y: 重做\n"
|
||||
"4. 点击【确定】保存更改并生效。\n"
|
||||
"5. 注意:某些正在运行的程序可能需要重启才能识别新的环境变量。\n\n"
|
||||
"--------------------------------------------------\n"
|
||||
"作者:LHY\n"
|
||||
"邮箱:3364451258@qq.com\n"
|
||||
"GitHub:https://github.com/LHY0125/PathEditor\n"
|
||||
"记得给我的项目点个star!");
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 标签页切换回调
|
||||
int tabs_tabchange_cb(Ihandle *self, int new_pos, int old_pos)
|
||||
{
|
||||
if (new_pos == 2)
|
||||
{
|
||||
// 合并预览模式
|
||||
IupSetAttribute(list_merged, "REMOVEITEM", "ALL");
|
||||
int count = 0;
|
||||
|
||||
// 添加系统变量
|
||||
for (int i = 0; i < raw_sys_paths.count; i++)
|
||||
{
|
||||
count++;
|
||||
IupSetAttributeId(list_merged, "", count, raw_sys_paths.items[i]);
|
||||
}
|
||||
|
||||
// 添加用户变量
|
||||
for (int i = 0; i < raw_user_paths.count; i++)
|
||||
{
|
||||
count++;
|
||||
IupSetAttributeId(list_merged, "", count, raw_user_paths.items[i]);
|
||||
}
|
||||
|
||||
IupSetInt(list_merged, "COUNT", count);
|
||||
refresh_single_list_style(list_merged);
|
||||
|
||||
// 禁用编辑按钮
|
||||
toggle_edit_buttons(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 编辑模式 (检查管理员权限)
|
||||
if (check_admin())
|
||||
{
|
||||
toggle_edit_buttons(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
toggle_edit_buttons(0);
|
||||
}
|
||||
}
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
|
||||
// 主题切换回调
|
||||
int btn_theme_cb(Ihandle *self)
|
||||
{
|
||||
is_dark_mode = !is_dark_mode;
|
||||
if (is_dark_mode)
|
||||
IupSetAttribute(btn_theme, "TITLE", "浅色模式");
|
||||
else
|
||||
IupSetAttribute(btn_theme, "TITLE", "深色模式");
|
||||
|
||||
apply_theme();
|
||||
return IUP_DEFAULT;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user