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:
2026-03-19 20:58:41 +08:00
parent 6509ef98e4
commit a769a6b9b3
30 changed files with 1351 additions and 1243 deletions
+22
View File
@@ -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
+19
View File
@@ -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
+14
View File
@@ -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