mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-05-10 02:09:46 +08:00
refactor: 重构项目为 MVC 架构并移除全局变量
- 将原有扁平目录结构重构为 MVC 分层架构: * src/core/: 核心业务逻辑(Model),完全独立于 UI 框架 * src/ui/: 界面组件构建(View),负责纯视觉展示 * src/controller/: 用户交互处理(Controller),连接数据与界面 * src/utils/: 底层工具函数,专注于系统调用和字符串处理 - 引入 AppContext 结构体统一管理应用状态,替代原有的全局变量模式 - 重命名并重新组织头文件,按功能模块划分到对应子目录 - 更新 CMakeLists.txt 以适配新的目录结构 - 同步更新 README.md 文档,说明新的架构设计
This commit is contained in:
@@ -27,4 +27,7 @@ int list_dropfiles_cb(Ihandle *self, const char *filename, int num, int x, int y
|
||||
// 键盘按键回调
|
||||
int list_k_any_cb(Ihandle *self, int c);
|
||||
|
||||
// 载入数据与更新UI
|
||||
void load_all_paths(void);
|
||||
|
||||
#endif // CALLBACKS_H
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef APP_CONTEXT_H
|
||||
#define APP_CONTEXT_H
|
||||
|
||||
#include "utils/string_ext.h"
|
||||
#include <iup.h>
|
||||
|
||||
// 应用上下文结构体,用于存储应用运行时的状态
|
||||
typedef struct {
|
||||
StringList sys_paths;
|
||||
StringList user_paths;
|
||||
} AppContext;
|
||||
|
||||
// 创建应用上下文
|
||||
AppContext* create_app_context(void);
|
||||
|
||||
// 销毁应用上下文
|
||||
void destroy_app_context(AppContext* ctx);
|
||||
|
||||
// 获取应用上下文
|
||||
AppContext* get_app_context(Ihandle *ih);
|
||||
|
||||
#endif // APP_CONTEXT_H
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef PATH_MANAGER_H
|
||||
#define PATH_MANAGER_H
|
||||
|
||||
#include "utils/string_ext.h"
|
||||
|
||||
// 移除列表中指定索引的项
|
||||
void path_manager_remove_at(StringList *list, int index);
|
||||
|
||||
// 上移指定索引的项
|
||||
void path_manager_move_up(StringList *list, int index);
|
||||
|
||||
// 下移指定索引的项
|
||||
void path_manager_move_down(StringList *list, int index);
|
||||
|
||||
// 清理无效和重复的路径
|
||||
// 返回被清理的项数
|
||||
int path_manager_clean(StringList *list);
|
||||
|
||||
#endif // PATH_MANAGER_H
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef REGISTRY_SERVICE_H
|
||||
#define REGISTRY_SERVICE_H
|
||||
|
||||
#include "utils/string_ext.h"
|
||||
|
||||
// 加载系统变量和用户变量到字符串列表
|
||||
int load_system_paths(StringList *list);
|
||||
int load_user_paths(StringList *list);
|
||||
|
||||
// 从字符串列表保存系统变量和用户变量
|
||||
int save_system_paths(const StringList *list);
|
||||
int save_user_paths(const StringList *list);
|
||||
|
||||
#endif // REGISTRY_SERVICE_H
|
||||
@@ -1,54 +0,0 @@
|
||||
#ifndef GLOBALS_H
|
||||
#define GLOBALS_H
|
||||
|
||||
#include <iup.h>
|
||||
|
||||
// 定义 Windows 消息常量
|
||||
#ifndef WM_COPYGLOBALDATA
|
||||
#define WM_COPYGLOBALDATA 0x0049
|
||||
#endif
|
||||
|
||||
// 消息过滤器常量
|
||||
#ifndef MSGFLT_ADD
|
||||
#define MSGFLT_ADD 1
|
||||
#endif
|
||||
|
||||
// 注册表路径常量
|
||||
#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 *tabs_main; // 标签页容器
|
||||
extern Ihandle *list_sys; // 系统变量列表
|
||||
extern Ihandle *list_user; // 用户变量列表
|
||||
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_ok; // 确认按钮句柄
|
||||
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;
|
||||
|
||||
// 缓存操作函数声明
|
||||
void init_string_list(StringList *list);
|
||||
void add_string_list(StringList *list, const char *str);
|
||||
void clear_string_list(StringList *list);
|
||||
|
||||
#endif // GLOBALS_H
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef REGISTRY_H
|
||||
#define REGISTRY_H
|
||||
|
||||
// 从注册表加载所有PATH到列表控件
|
||||
void load_all_paths();
|
||||
|
||||
// 将列表控件中的PATH保存回注册表
|
||||
void save_all_paths();
|
||||
|
||||
#endif // REGISTRY_H
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef UI_H
|
||||
#define UI_H
|
||||
|
||||
#include <iup.h>
|
||||
|
||||
// 创建列表控件
|
||||
Ihandle *create_path_list();
|
||||
|
||||
// 创建右侧功能按钮区域
|
||||
Ihandle *create_main_buttons();
|
||||
|
||||
// 创建底部按钮区域
|
||||
Ihandle *create_bottom_buttons();
|
||||
|
||||
#endif // UI_H
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef DIALOGS_H
|
||||
#define DIALOGS_H
|
||||
|
||||
// 自定义输入对话框
|
||||
// 返回值:0-取消,1-确认
|
||||
int custom_input_dialog(const char *title, const char *label_text, char *buffer, int buffer_size);
|
||||
|
||||
#endif // DIALOGS_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef MAIN_WINDOW_H
|
||||
#define MAIN_WINDOW_H
|
||||
|
||||
#include <iup.h>
|
||||
|
||||
// 创建主窗口
|
||||
Ihandle* create_main_window(void);
|
||||
|
||||
#endif // MAIN_WINDOW_H
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef UI_UTILS_H
|
||||
#define UI_UTILS_H
|
||||
|
||||
#include <iup.h>
|
||||
#include "utils/string_ext.h"
|
||||
|
||||
// 刷新单个列表框样式
|
||||
void refresh_single_list_style(Ihandle *list);
|
||||
|
||||
// 同步字符串列表到 UI 列表框
|
||||
void sync_string_list_to_ui(Ihandle *list_ui, const StringList *str_list);
|
||||
|
||||
#endif // UI_UTILS_H
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <wchar.h>
|
||||
#include <iup.h>
|
||||
|
||||
// 宽字符转UTF-8
|
||||
char* wide_to_utf8(const wchar_t* wstr);
|
||||
|
||||
// UTF-8转宽字符
|
||||
wchar_t* utf8_to_wide(const char* str);
|
||||
|
||||
// 检查管理员权限
|
||||
int check_admin();
|
||||
|
||||
// 检查路径是否有效(存在且为目录)
|
||||
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
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef OS_ENV_H
|
||||
#define OS_ENV_H
|
||||
|
||||
// 检查是否以管理员权限运行
|
||||
int check_admin(void);
|
||||
|
||||
// 检查路径是否有效
|
||||
int is_path_valid(const char *path);
|
||||
|
||||
// 备份注册表
|
||||
void backup_registry(void);
|
||||
|
||||
#endif // OS_ENV_H
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef STRING_EXT_H
|
||||
#define STRING_EXT_H
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
// 简单字符串列表结构
|
||||
typedef struct
|
||||
{
|
||||
char **items;
|
||||
int count;
|
||||
int capacity;
|
||||
} StringList;
|
||||
|
||||
// 字符串列表
|
||||
void init_string_list(StringList *list);
|
||||
void add_string_list(StringList *list, const char *str);
|
||||
void clear_string_list(StringList *list);
|
||||
|
||||
// 字符串转换函数
|
||||
char *wide_to_utf8(const wchar_t *wstr);
|
||||
wchar_t *utf8_to_wide(const char *str);
|
||||
char *stristr(const char *haystack, const char *needle);
|
||||
|
||||
#endif // STRING_EXT_H
|
||||
Reference in New Issue
Block a user