mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-05-10 02:09:46 +08:00
refactor: 重构项目结构,拆分回调函数并新增功能模块
- 将 callbacks.c 拆分为 cb_edit.c、cb_file.c、cb_main.c 三个模块,提高代码可维护性 - 新增 ui_utils.c 提供通用 UI 辅助函数 - 新增历史记录功能(撤销/重做)和主题切换支持 - 增加合并预览标签页,优化路径有效性检查和环境变量展开 - 更新 Makefile 以支持新的源文件结构
This commit is contained in:
@@ -1,30 +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_clean_cb(Ihandle *self);
|
||||
int btn_ok_cb(Ihandle *self);
|
||||
int btn_cancel_cb(Ihandle *self);
|
||||
int btn_help_cb(Ihandle *self);
|
||||
|
||||
// 搜索回调
|
||||
int txt_search_cb(Ihandle *self);
|
||||
|
||||
// 双击回调
|
||||
int list_dblclick_cb(Ihandle *self, int item, char *text);
|
||||
|
||||
// 拖拽回调
|
||||
int list_dropfiles_cb(Ihandle *self, const char *filename, int num, int x, int y);
|
||||
|
||||
// 键盘按键回调
|
||||
int list_k_any_cb(Ihandle *self, int c);
|
||||
|
||||
#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
|
||||
+48
-16
@@ -9,22 +9,29 @@
|
||||
#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; // 搜索框
|
||||
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 {
|
||||
@@ -36,9 +43,34 @@ typedef struct {
|
||||
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
|
||||
@@ -12,4 +12,6 @@ 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
|
||||
@@ -14,6 +14,9 @@ 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user